/* Medium-style Typography & Custom Themes for BranchTales (Optimized for zero-blocking offline & instant rendering) */
:root {
  --font-serif: ui-serif, 'Lora', 'Georgia', 'Songti SC', 'Source Han Serif SC', 'Noto Serif CJK SC', serif;
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-display: 'Cinzel', ui-serif, 'Lora', 'Georgia', serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Fira Code', 'Liberation Mono', monospace;

  --bg-color: #fafaf9; /* Stone-50 */
  --text-color: #1c1917; /* Stone-900 */
  --text-muted: #78716c; /* Stone-500 */
  --border-color: #e7e5e4; /* Stone-200 */
}

[data-theme="sepia"] {
  --bg-color: #fbf7ee;
  --text-color: #2c2724;
  --text-muted: #786f66;
  --border-color: #ebdcc9;
}

[data-theme="dark"] {
  --bg-color: #0c0a09; /* Stone-950 */
  --text-color: #e7e5e4; /* Stone-200 */
  --text-muted: #a8a29e; /* Stone-400 */
  --border-color: #292524; /* Stone-800 */
}

/* Prevent horizontal overflow on mobile viewports */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: background-color 0.2s ease, color 0.2s ease;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Medium-like Reading Prose Optimized for Mobile & Tablet */
.prose-reading {
  font-family: var(--font-serif);
  font-size: 1.125rem; /* 18px on desktop/iPad */
  line-height: 1.85;
  letter-spacing: 0.01em;
  color: var(--text-color);
  word-break: break-word;
  overflow-wrap: break-word;
}

.prose-reading p {
  margin-bottom: 1.5em;
  text-align: justify;
  text-justify: inter-ideograph;
}

/* Drop-cap: Only on desktop/tablet screens, disabled on narrow phones to avoid overlap */
@media (min-width: 641px) {
  .prose-reading p:first-of-type::first-letter {
    font-size: 3em;
    float: left;
    line-height: 0.85;
    margin-right: 0.15em;
    margin-top: 0.05em;
    font-family: var(--font-display);
    font-weight: 700;
    color: inherit;
  }
}

/* Dedicated Mobile Optimizations (iPhone / Small Phones) */
@media (max-width: 640px) {
  .prose-reading {
    font-size: 1.0625rem; /* ~17px optimal for iPhone */
    line-height: 1.75;
    letter-spacing: 0.02em;
  }
  .prose-reading p {
    margin-bottom: 1.25em;
    text-align: left; /* Better flow on mobile screen */
  }
  .prose-reading blockquote {
    padding-left: 0.875rem;
    font-size: 0.95em;
  }
}

/* iPad / Tablet Optimizations (641px - 1024px) */
@media (min-width: 641px) and (max-width: 1024px) {
  .prose-reading {
    font-size: 1.15rem;
    line-height: 1.9;
  }
}

.prose-reading h2 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.5rem;
  margin-top: 1.75em;
  margin-bottom: 0.75em;
  letter-spacing: -0.015em;
}

.prose-reading h3 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.25rem;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.prose-reading blockquote {
  border-left: 3px solid currentColor;
  padding-left: 1.25rem;
  margin-left: 0;
  margin-right: 0;
  font-style: italic;
  opacity: 0.85;
}

/* User-controlled Font Size Scales */
body.font-sm .prose-reading { font-size: 0.95rem; line-height: 1.7; }
body.font-md .prose-reading { font-size: 1.125rem; line-height: 1.85; }
body.font-lg .prose-reading { font-size: 1.25rem; line-height: 1.95; }
body.font-xl .prose-reading { font-size: 1.4rem; line-height: 2.05; }

/* Smooth scrolling container for touch devices */
.smooth-scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.smooth-scroll-x::-webkit-scrollbar {
  display: none;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}
[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #334155;
}

/* Pulse Glow for AI badges */
.ai-badge-glow {
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
}
