/* ═══════════════════════════════════════
   0. CSS Custom Properties
   ═══════════════════════════════════════ */
:root {
  --ink:           #0a0705;
  --ink-2:         #15100b;
  --ink-3:         #201811;
  --parchment:     #e9dcc0;
  --parchment-dim: #b9ab8c;
  --candle:        #f5c96b;
  --candle-deep:   #d49a3a;
  --ember:         #c4602a;
  --blood:         #7d241a;
  --blood-dark:    #4a130d;
  --bone:          #c9b78d;
  --line:          rgba(201, 183, 141, 0.25);
  --line-strong:   rgba(201, 183, 141, 0.55);
}

/* ═══════════════════════════════════════
   1. Reset & Base
   ═══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

body {
  background: var(--ink);
  color: var(--parchment);
  font-family: 'Cormorant Garamond', serif;
  font-size: 18px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════
   2. Atmosphere — Vignette + Grain
   ═══════════════════════════════════════ */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  background:
    radial-gradient(ellipse 40% 60% at 15% 10%, rgba(245,201,107,0.12), transparent 60%),
    radial-gradient(ellipse 40% 60% at 85% 10%, rgba(245,201,107,0.10), transparent 60%),
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(125,36,26,0.15), transparent 70%),
    radial-gradient(ellipse 120% 100% at 50% 50%, transparent 40%, rgba(0,0,0,0.8) 100%);
  animation: flicker 5s ease-in-out infinite;
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 101;
  opacity: 0.08;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/></svg>");
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  8%       { opacity: 0.92; }
  12%      { opacity: 1; }
  45%      { opacity: 0.96; }
  50%      { opacity: 1; }
  78%      { opacity: 0.88; }
  82%      { opacity: 1; }
}

/* ═══════════════════════════════════════
   3. Layout — Chamber
   ═══════════════════════════════════════ */
.chamber {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 6vh 32px 10vh;
  text-align: center;
}

/* ═══════════════════════════════════════
   4. Header
   ═══════════════════════════════════════ */
.crest {
  font-family: 'Cinzel Decorative', serif;
  font-size: 18px;
  color: var(--candle);
  letter-spacing: 1.5em;
  margin-bottom: 8px;
  animation: glow-pulse 4s ease-in-out infinite;
}
@keyframes glow-pulse {
  0%, 100% { text-shadow: 0 0 8px rgba(245,201,107,0.3); }
  50%      { text-shadow: 0 0 16px rgba(245,201,107,0.5); }
}

h1 {
  font-family: 'Cinzel Decorative', serif;
  font-weight: 900;
  font-size: clamp(56px, 10vw, 96px);
  letter-spacing: 0.12em;
  color: var(--parchment);
  text-shadow:
    0 2px 4px rgba(0,0,0,0.8),
    0 0 40px rgba(245,201,107,0.15);
  margin-bottom: 12px;
  line-height: 1;
}

.subtitle {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 20px;
  color: var(--bone);
  max-width: 500px;
  margin: 0 auto 48px;
}

.intro-text {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 17px;
  color: var(--parchment-dim);
  max-width: 520px;
  margin: 0 auto 48px;
  line-height: 1.65;
}

/* ═══════════════════════════════════════
   5. Section Titles
   ═══════════════════════════════════════ */
.section-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 32px;
  max-width: 340px;
  margin-left: auto;
  margin-right: auto;
}
.section-title::before,
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--line-strong), transparent);
}
.section-title span {
  font-family: 'IM Fell English SC', serif;
  font-size: 14px;
  letter-spacing: 0.3em;
  color: var(--candle-deep);
  white-space: nowrap;
}

/* ═══════════════════════════════════════
   6. Option Grid (Bottles + Phials)
   ═══════════════════════════════════════
   FIX #1: No container boxes. Bottles and phials
   float on the dark background per reference. */
.option-row {
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  border: none;
  padding: 0;
}

#mood-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  max-width: 720px;
  margin: 0 auto 8px;
}

.option {
  display: block;
  cursor: pointer;
  text-align: center;
  transition: transform 0.25s ease;
  position: relative;
}
.option input { position: absolute; opacity: 0; width: 0; height: 0; }

.option figure {
  padding: 12px 10px 8px;
}

/* Selection and hover states on the label itself, not the figure */
.option {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.25s ease;
}

.option:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(212,154,58,0.15); }

/* Selected state — gentle, not dramatic */
.option:has(input:checked) {
  border-color: var(--candle-deep);
  box-shadow:
    0 0 0 1px var(--candle-deep),
    inset 0 0 20px rgba(245,201,107,0.08);
}

/* Focus state (keyboard) */
.option:has(input:focus-visible) {
  border-color: var(--candle);
  outline: 2px solid var(--candle);
  outline-offset: 2px;
}

/* FIX #5: Bottles scaled up to 160px */
.option--tier { max-width: 160px; }
.option--tier .bottle { height: 160px; width: auto; display: block; margin: 0 auto; }

/* FIX #4: Disable ligatures on tier and mood names */
.option--tier .tier-name {
  display: block;
  font-family: 'Cinzel Decorative', serif;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--parchment);
  margin-top: 8px;
  font-variant-ligatures: none;
}
.option--tier .tier-hint {
  display: block;
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 13px;
  color: var(--parchment-dim);
  margin-top: 2px;
}
.option--tier[data-tier="archmage"] .tier-hint { color: var(--ember); }

/* Shelf rule — thin gold hairline beneath bottles */
.shelf-rule {
  height: 1px;
  background: linear-gradient(to right, transparent, var(--candle-deep) 20%, var(--candle-deep) 80%, transparent);
  margin: 24px auto 0;
  max-width: 680px;
}

/* Phials — grid handles equal width, no fixed sizing needed */
.option--mood figure { padding: 10px 6px 8px; }
.option--mood .phial { height: 110px; width: auto; display: block; margin: 0 auto; }

/* FIX #4: Disable ligatures */
.option--mood .mood-name {
  display: block;
  font-family: 'Cinzel Decorative', serif;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--parchment);
  margin-top: 6px;
  font-variant-ligatures: none;
}
/* FIX #3: nowrap on mood hints to prevent line-breaking */
.option--mood .mood-hint {
  display: block;
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 12px;
  color: var(--parchment-dim);
  margin-top: 2px;
  white-space: nowrap;
}

/* ═══════════════════════════════════════
   7. Connective Text
   ═══════════════════════════════════════ */
.connective {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 16px;
  color: var(--parchment-dim);
  margin: 36px 0 32px;
}

/* ═══════════════════════════════════════
   8. Cast Button
   ═══════════════════════════════════════
   FIX #2: Clean Cinzel Decorative 700, no text
   distortion, no text-shadow on the text itself. */
#cast {
  display: inline-block;
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--parchment);
  background: linear-gradient(180deg, var(--blood), var(--blood-dark));
  border: 1px solid var(--candle-deep);
  padding: 20px 52px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow:
    0 0 0 1px rgba(212,154,58,0.2),
    0 4px 20px rgba(125,36,26,0.4),
    inset 0 1px 0 rgba(245,201,107,0.15);
  margin-top: 40px;
  /* FIX #2: Explicitly no text distortion */
  text-shadow: none;
  font-style: normal;
  font-variant: normal;
  -webkit-text-stroke: 0;
  font-variant-ligatures: none;
}
#cast:hover:not(:disabled) {
  background: linear-gradient(180deg, #8d2e1e, var(--blood-dark));
  box-shadow:
    0 0 0 1px rgba(212,154,58,0.3),
    0 4px 36px rgba(125,36,26,0.5),
    inset 0 1px 0 rgba(245,201,107,0.2);
  transform: translateY(-1px);
}
#cast:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#cast:focus-visible {
  outline: 2px solid var(--candle);
  outline-offset: 3px;
}

/* FIX #2: Fleur-de-lis sigils need symbol font fallback */
.sigil-fleur {
  font-family: "Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols 2", serif;
}

/* ═══════════════════════════════════════
   9. Prudence Mark + Footer
   ═══════════════════════════════════════ */
.prudence {
  font-family: 'IM Fell English SC', serif;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--parchment-dim);
  opacity: 0.7;
  margin-top: 16px;
}
.footer {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 13px;
  color: var(--parchment-dim);
  margin-top: 48px;
}

/* ═══════════════════════════════════════
   10. State Visibility
   ═══════════════════════════════════════ */
.state { display: none; }
.state.active { display: block; }

.state-fade-in {
  animation: fade-in 0.8s ease both;
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ═══════════════════════════════════════
   11. Divining State
   ═══════════════════════════════════════ */
.divining-section.active {
  padding: 40px 0;
  min-height: 50vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Hide header intro text during divining and result states */
.chamber:has(.divining-section.active) .intro-text,
.chamber:has(.divining-section.active) .subtitle,
.chamber:has(#state-result.active) .intro-text,
.chamber:has(#state-result.active) .subtitle {
  display: none;
}

.rune-ring {
  width: 140px;
  height: 140px;
  margin: 0 auto 64px;
  position: relative;
  border-radius: 50%;
}
.rune-ring.spinning { animation: spin 12s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.rune {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 18px;
  color: var(--candle);
  filter: drop-shadow(0 0 6px rgba(245,201,107,0.5));
  /* Each rune is positioned via inline style:
     transform: rotate(Xdeg) translateY(-62px) rotate(-Xdeg) */
  transform-origin: center center;
  margin: -9px 0 0 -9px; /* half of font-size to center the glyph */
}

.divining-phrase {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 22px;
  color: var(--candle);
  letter-spacing: 0.04em;
  min-height: 66px;
  transition: opacity 0.4s ease;
}
.divining-sub {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 16px;
  color: var(--parchment-dim);
  margin-top: 8px;
}

/* ═══════════════════════════════════════
   12. Result Scroll
   ═══════════════════════════════════════ */
.scroll {
  max-width: 680px;
  margin: 0 auto;
  padding: 64px 48px;
  border: 1px solid var(--line-strong);
  position: relative;
  background:
    radial-gradient(ellipse at center, rgba(32,24,17,0.85), rgba(10,7,5,0.95));
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.6),
    inset 0 0 60px rgba(245,201,107,0.04),
    0 20px 60px rgba(0,0,0,0.6);
  animation: reveal 1.2s ease both;
}
@keyframes reveal {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Corner brackets */
.scroll::before, .scroll::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--candle-deep);
  border-style: solid;
}
.scroll::before {
  top: 12px; left: 12px;
  border-width: 1px 0 0 1px;
}
.scroll::after {
  bottom: 12px; right: 12px;
  border-width: 0 1px 1px 0;
}
.corner-tr, .corner-bl {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--candle-deep);
  border-style: solid;
}
.corner-tr { top: 12px; right: 12px; border-width: 1px 1px 0 0; }
.corner-bl { bottom: 12px; left: 12px; border-width: 0 0 1px 1px; }

/* Scroll content */
.scroll-sigil {
  font-family: 'Cinzel Decorative', serif;
  font-size: 24px;
  color: var(--candle);
  margin-bottom: 12px;
  letter-spacing: 0.4em;
}

.mystical-name {
  font-family: 'Cinzel Decorative', serif;
  font-weight: 900;
  font-size: clamp(24px, 5vw, 36px);
  letter-spacing: 0.06em;
  color: var(--parchment);
  text-shadow: 0 0 20px rgba(245,201,107,0.15);
  margin-bottom: 8px;
  line-height: 1.2;
}

.real-name {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 18px;
  color: var(--candle-deep);
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.result-tagline {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 20px;
  color: var(--parchment-dim);
  max-width: 440px;
  margin: 0 auto 24px;
}

/* Divider */
.scroll-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 24px auto;
  max-width: 300px;
}
.scroll-divider::before, .scroll-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--line-strong), transparent);
}
.scroll-divider span {
  font-size: 14px;
  color: var(--candle-deep);
  letter-spacing: 0.3em;
}

/* Section labels in scroll */
.scroll-label {
  font-family: 'IM Fell English SC', serif;
  font-size: 14px;
  letter-spacing: 0.3em;
  color: var(--candle-deep);
  margin-bottom: 16px;
}

/* Reagents */
.reagents {
  list-style: none;
  max-width: 420px;
  margin: 0 auto 32px;
}
.reagents li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}
.reagents li:last-child { border-bottom: none; }
.reagent-amount {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 17px;
  color: var(--candle-deep);
  white-space: nowrap;
  margin-right: 16px;
}
.reagent-name {
  font-family: 'Cormorant Garamond', serif;
  font-size: 19px;
  color: var(--parchment);
  text-align: right;
}

/* Incantation steps */
.incantation {
  list-style: none;
  counter-reset: step;
  max-width: 540px;
  margin: 0 auto 32px;
  text-align: left;
}
.incantation li {
  counter-increment: step;
  position: relative;
  padding: 14px 0 14px 48px;
  border-bottom: 1px dashed var(--line);
  font-family: 'Cormorant Garamond', serif;
  font-size: 18px;
  line-height: 1.55;
  color: var(--parchment);
}
.incantation li:last-child { border-bottom: none; }
.incantation li::before {
  content: counter(step, upper-roman);
  position: absolute;
  left: 0;
  top: 14px;
  width: 36px;
  text-align: right;
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  font-size: 14px;
  color: var(--candle);
  letter-spacing: 0.1em;
  border-right: 1px solid var(--line-strong);
  padding-right: 8px;
}

/* Vessel / Adornment grid */
.vessel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 500px;
  margin: 0 auto 32px;
}
.vessel-cell-label {
  font-family: 'IM Fell English SC', serif;
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--candle);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.vessel-cell-value {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 17px;
  color: var(--parchment);
}

/* Omen */
.omen {
  max-width: 540px;
  margin: 0 auto 32px;
  padding: 28px 32px;
  border-left: 2px solid var(--candle-deep);
  border-right: 2px solid var(--candle-deep);
  background: radial-gradient(ellipse at center, rgba(125,36,26,0.10), transparent 70%);
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 19px;
  line-height: 1.6;
  color: var(--parchment);
  text-align: center;
}
.omen::first-letter {
  font-family: 'Cinzel Decorative', serif;
  font-weight: 900;
  font-size: 48px;
  float: left;
  color: var(--candle);
  font-style: normal;
  margin: 4px 10px 0 0;
  line-height: 1;
}

/* Cost mark */
.cost-mark {
  margin-bottom: 32px;
}
.cost-mark-label {
  font-family: 'IM Fell English SC', serif;
  letter-spacing: 0.3em;
  color: var(--candle-deep);
  font-size: 14px;
}
.cost-mark-value {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 17px;
  color: var(--parchment);
}

/* ═══════════════════════════════════════
   13. Oracle Section
   ═══════════════════════════════════════ */
.oracle-section { margin: 32px 0; }
.oracle-label {
  font-family: 'IM Fell English SC', serif;
  font-size: 13px;
  letter-spacing: 0.35em;
  color: var(--candle);
  margin-bottom: 16px;
}

#oracle-btn {
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.3em;
  color: var(--parchment);
  background: linear-gradient(180deg, var(--blood), var(--blood-dark));
  border: 1px solid var(--candle-deep);
  padding: 14px 28px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow:
    0 0 0 1px rgba(212,154,58,0.15),
    0 2px 12px rgba(125,36,26,0.3);
  opacity: 0.85;
  text-shadow: none;
  font-variant-ligatures: none;
}
#oracle-btn:hover:not(:disabled) {
  opacity: 1;
  transform: translateY(-1px);
}
#oracle-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
#oracle-btn:focus-visible {
  outline: 2px solid var(--candle);
  outline-offset: 3px;
}

.oracle-loading {
  display: none;
}
.oracle-loading.active {
  display: block;
}
.oracle-loading-phrase {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 15px;
  color: var(--candle-deep);
  letter-spacing: 0.02em;
  margin-top: 12px;
  min-height: 22px;
}

.oracle-panel {
  display: none;
  max-width: 540px;
  margin: 16px auto 0;
  padding: 24px 32px;
  transform: rotate(-0.8deg);
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 20px;
  line-height: 1.6;
  color: var(--candle-deep);
  letter-spacing: 0.02em;
  animation: sway 6s ease-in-out infinite;
  text-align: center;
  position: relative;
}
.oracle-panel.active { display: block; }

.oracle-quote-open,
.oracle-quote-close {
  font-family: 'Cinzel Decorative', serif;
  font-style: normal;
  font-size: 36px;
  color: var(--candle);
  opacity: 0.6;
  line-height: 1;
  vertical-align: text-top;
}
.oracle-quote-open { margin-right: 6px; }
.oracle-quote-close { margin-left: 6px; }

@keyframes sway {
  0%, 100% { transform: rotate(-0.8deg) translateX(0); }
  50%      { transform: rotate(-0.3deg) translateX(1.5px); }
}

.oracle-error {
  display: none;
  max-width: 540px;
  margin: 16px auto 0;
  padding: 24px 28px;
  border-left: 2px solid var(--blood);
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 16px;
  color: var(--ember);
  text-align: center;
}
.oracle-error.active { display: block; }

/* ═══════════════════════════════════════
   14. Reset Button
   ═══════════════════════════════════════ */
#reset-btn {
  font-family: 'IM Fell English SC', serif;
  font-size: 13px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--candle);
  background: transparent;
  border: none;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 16px 32px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 8px;
}
#reset-btn:hover {
  letter-spacing: 0.4em;
  border-color: var(--candle);
  color: var(--parchment);
}
#reset-btn:focus-visible {
  outline: 2px solid var(--candle);
  outline-offset: 3px;
}

/* ═══════════════════════════════════════
   15. Reduced Motion
   ═══════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  .crest { animation: none; }
  .rune-ring.spinning { animation: none; }
  .oracle-panel { animation: none; }
  .scroll { animation-duration: 0.1s; }
  .state-fade-in { animation-duration: 0.1s; }
  .divining-phrase { transition-duration: 0.1s; }
}

/* ═══════════════════════════════════════
   16. Responsive — 540px breakpoint
   ═══════════════════════════════════════ */
@media (max-width: 540px) {
  .chamber { padding: 4vh 20px 8vh; }

  .option-row { gap: 12px; }
  .option--tier { max-width: 120px; }
  .option--tier .bottle { height: 110px; }
  .option--tier .tier-name { font-size: 11px; }
  .option--tier .tier-hint { font-size: 11px; }

  #mood-row { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .option--mood .phial { height: 75px; }
  .option--mood .mood-name { font-size: 10px; }
  .option--mood .mood-hint { font-size: 10px; }

  #cast {
    padding: 18px 32px;
    letter-spacing: 0.3em;
    font-size: 14px;
  }

  .scroll { padding: 44px 24px; }

  .vessel-grid { grid-template-columns: 1fr; gap: 16px; }

  .incantation li { padding-left: 40px; font-size: 17px; }

  .omen { padding: 20px; font-size: 17px; }

  .crest { letter-spacing: 1em; }
}
