/* ============================================
   STORY FORGE — Base & Reset
   ============================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-deep);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-void);
}
::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* Selection */
::selection {
  background: rgba(124, 58, 237, 0.4);
  color: var(--text-primary);
}

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Links */
a {
  color: var(--text-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--accent-secondary); }

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

/* Paragraphs */
p { color: var(--text-secondary); }

/* Images */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Forms */
input, textarea, select {
  font-family: var(--font-sans);
  font-size: var(--text-base);
}

/* Lists */
ul, ol { list-style: none; }

/* HR */
hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: var(--space-5) 0;
}

/* Code */
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-accent);
}

/* Hidden utility */
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Typography utilities */
.text-serif   { font-family: var(--font-serif); }
.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-dim     { color: var(--text-dim) !important; }
.text-accent  { color: var(--text-accent) !important; }
.text-gold    { color: var(--accent-gold) !important; }
.text-teal    { color: var(--accent-teal) !important; }
.text-center  { text-align: center; }

/* Spacing utilities */
.mt-auto { margin-top: auto; }
.gap-2   { gap: var(--space-2); }
.gap-3   { gap: var(--space-3); }
.gap-4   { gap: var(--space-4); }

/* Flex utilities */
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* Page loader */
.page-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}
.loader-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Story content typography ── */
.story-content {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.9;
  color: var(--text-primary);
  letter-spacing: 0.012em;
  font-variant-ligatures: common-ligatures;
  -webkit-font-smoothing: antialiased;
}

/* Paragraphs — libro style: sin margen inferior, con sangría en todos menos el primero */
.story-content p {
  color: var(--text-primary);
  margin: 0;
  padding-bottom: 0;
  text-indent: 1.8em;
  text-align: justify;
  -webkit-hyphens: auto;
  hyphens: auto;
  orphans: 3;
  widows: 3;
}
/* Primer párrafo y párrafo tras un heading/blockquote: sin sangría */
.story-content p:first-child,
.story-content h2 + p,
.story-content h3 + p,
.story-content blockquote + p,
.story-content hr + p {
  text-indent: 0;
}
/* Separación visual entre párrafos sin sangría (estilo digital) */
.story-content p + p {
  margin-top: 0.1em;
}

/* Drop cap en el primer párrafo */
.story-content p:first-child::first-letter {
  font-size: 3.6em;
  font-weight: 700;
  float: left;
  line-height: 0.8;
  margin: 0.05em 0.1em 0 0;
  color: var(--accent-secondary);
  text-shadow: 0 0 32px rgba(168,85,247,0.35);
  font-family: var(--font-serif);
}

/* Section headings inside story */
.story-content h2 {
  font-family: var(--font-serif);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-dim);
  text-align: center;
  margin: var(--space-9) 0 var(--space-6);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  line-height: 1.5;
}
.story-content h2::before,
.story-content h2::after {
  content: ' ✦ ';
  color: var(--accent-primary);
  opacity: 0.45;
  font-size: 0.8em;
}
.story-content h3 {
  font-family: var(--font-serif);
  font-size: 1.1em;
  font-weight: 400;
  color: var(--text-secondary);
  margin: var(--space-7) 0 var(--space-4);
  font-style: italic;
  text-align: center;
  line-height: 1.4;
}

/* Horizontal rule → ornamento tipográfico */
.story-content hr {
  border: none;
  text-align: center;
  margin: var(--space-9) 0;
  overflow: visible;
  height: 0;
}
.story-content hr::after {
  content: '✦   ✦   ✦';
  display: inline-block;
  color: var(--text-dim);
  font-size: var(--text-xs);
  letter-spacing: 0.6em;
  opacity: 0.35;
}

/* Inline styles */
.story-content em {
  font-style: italic;
  color: inherit;
}
.story-content strong {
  font-weight: 700;
  color: var(--text-primary);
}

/* Blockquote — cita literaria con comillas */
.story-content blockquote {
  position: relative;
  margin: var(--space-7) var(--space-4);
  padding: var(--space-4) var(--space-6) var(--space-4) var(--space-7);
  border-left: 2px solid rgba(124,58,237,0.4);
  background: rgba(124,58,237,0.04);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-style: italic;
  color: var(--text-secondary);
  font-size: 1.02em;
  line-height: 1.75;
}
.story-content blockquote::before {
  content: '\201C';
  position: absolute;
  left: var(--space-3);
  top: -0.1em;
  font-size: 2.8em;
  color: var(--accent-primary);
  opacity: 0.3;
  font-family: Georgia, serif;
  line-height: 1;
  font-style: normal;
}

/* ── Dialogue paragraphs ─────────────────────────────────────────────────── */
/*
  A dialogue paragraph has class .dialogue.
  Inside it there are two spans:
    .speech      — the spoken words (starting with —)
    .attribution — the tag "dijo / respondió / etc." after the closing —
*/
.story-content p.dialogue {
  /* Hanging indent: — stays flush left, wrapped lines indent */
  text-indent: -1.4em !important;
  padding-left: 1.4em;
  margin-top: 0.55em !important;
}

.story-content p.dialogue .speech {
  color: var(--dialogue-text, #e2d9f8);
  font-style: normal;
}

.story-content p.dialogue .attribution {
  color: var(--attribution-text, #8878b8);
  font-style: italic;
  font-size: 0.93em;
}

/* Quoted dialogue variant */
.story-content p.dialogue--quoted .speech {
  color: var(--dialogue-text, #e2d9f8);
}

/* Label that floats left — tiny "DIÁLOGO" pill (optional, off by default) */

/* ── Thought paragraphs ──────────────────────────────────────────────────── */
/*
  A thought paragraph has class .thought.
  The entire line was wrapped in *...* by the AI — it's the character's
  internal monologue. Rendered in italic with a distinct, slightly muted tone
  and a subtle left visual cue.
*/
.story-content p.thought {
  text-indent: 0 !important;
  font-style: italic;
  color: var(--thought-text, #b8b0d8);
  padding-left: 2em;
  border-left: 2px solid rgba(168, 85, 247, 0.22);
  margin-top: 0.65em !important;
  margin-bottom: 0.1em;
  line-height: 1.75;
}

.story-content p.thought em {
  color: inherit;
  font-style: italic;
}

/* Ensure narration paragraphs keep their indent normally */
.story-content p.narration {
  /* inherits all base p styles — nothing extra needed */
}

/* Thought/dialogue after a heading: no extra adjustment needed,
   each class already sets its own text-indent via !important */
