:root {
  --bg: #07060a;
  --ink: #ecdcbc;
  --ink-dim: rgba(236, 220, 188, .5);
  --amber: #f3b765;
  --font-old: "IM Fell English", "Old Standard TT", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-board: "IM Fell English SC", "IM Fell English", "Old Standard TT", Georgia, serif;
  --vol: 0;      /* volumul vocii (0–1), setat din voice.js */
  --px: 0px;     /* paralaxă */
  --py: 0px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-old);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- atmosfera ---------- */
.room {
  position: fixed;
  inset: -50px;
  z-index: 0;
  background: #0b0806 url("img/fundal.jpg") center 58% / cover no-repeat;
  filter: blur(2px) brightness(.82) saturate(.92);
  transform: translate(var(--px), var(--py)) scale(1.04);
  transition: filter 4s ease, transform 1.2s cubic-bezier(.2, .7, .2, 1);
  opacity: 0;
  animation: breathe 22s ease-in-out infinite alternate, fadein 5s .2s ease forwards;
}
@keyframes breathe { from { background-position: center 56%; } to { background-position: center 60%; } }

/* lumina focului din cămin: pâlpâie neregulat și se revarsă în cameră */
.fire-glow {
  position: fixed;
  left: 50%;
  top: 62%;
  width: 120vmax;
  height: 80vmax;
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
  mix-blend-mode: screen;
  background: radial-gradient(closest-side, rgba(255, 140, 50, .22), rgba(200, 80, 20, .08) 45%, transparent 75%);
  animation: fire 3.7s infinite linear, fadein 6s .5s ease both;
  opacity: 0;
}
@keyframes fire {
  0% { opacity: .75; transform: translate(-50%, -50%) scale(1); }
  9% { opacity: .95; } 14% { opacity: .7; } 22% { opacity: 1; transform: translate(-50.4%, -50.6%) scale(1.02); }
  31% { opacity: .8; } 38% { opacity: .9; } 47% { opacity: .65; transform: translate(-49.7%, -49.6%) scale(.99); }
  55% { opacity: .92; } 63% { opacity: .78; } 71% { opacity: 1; transform: translate(-50.2%, -50.3%) scale(1.015); }
  80% { opacity: .72; } 88% { opacity: .9; } 100% { opacity: .75; transform: translate(-50%, -50%) scale(1); }
}
@keyframes fadein { to { opacity: 1; } }

#smoke, #fog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
#smoke { z-index: 1; }
#fog { z-index: 3; opacity: .85; transition: opacity 3s ease; }

.candle-glow {
  position: fixed;
  left: 50%;
  top: 44%;
  width: 130vmax;
  height: 90vmax;
  transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, rgba(255, 150, 60, .1), rgba(140, 60, 20, .04) 55%, transparent 75%);
  z-index: 1;
  pointer-events: none;
  animation: flicker 5s infinite steps(1, end);
  transition: opacity 3s ease;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 40%, rgba(0, 0, 0, .35) 75%, rgba(0, 0, 0, .85) 100%);
}

@keyframes flicker {
  0% { opacity: .9 } 7% { opacity: .75 } 13% { opacity: 1 } 21% { opacity: .85 }
  34% { opacity: .95 } 47% { opacity: .8 } 58% { opacity: 1 } 71% { opacity: .88 }
  83% { opacity: .97 } 92% { opacity: .78 } 100% { opacity: .9 }
}

/* când „legătura" e greu de prins: lumina slăbește, ceața crește */
body.struggle .room { filter: blur(4px) brightness(.5) saturate(.6); }
body.struggle .candle-glow { animation-duration: 1.1s; opacity: .55; }
body.struggle #fog { opacity: 1; }

/* ---------- butonul de sunet ---------- */
.sound-toggle {
  position: fixed;
  z-index: 5;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  width: 40px;
  height: 40px;
  border: 0;
  padding: 8px;
  border-radius: 50%;
  background: transparent;
  color: rgba(236, 220, 188, .38);
  cursor: pointer;
  transition: color .4s ease;
}
.sound-toggle:hover { color: rgba(236, 220, 188, .75); }
.sound-toggle svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sound-toggle .spk { fill: currentColor; stroke: none; }
.sound-toggle .mute { display: none; }
.sound-toggle[aria-pressed="false"] .wave { display: none; }
.sound-toggle[aria-pressed="false"] .mute { display: inline; }

/* ---------- tabla ---------- */
.stage {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px 4px;
  gap: 1.2vh;
}

.board-wrap {
  width: min(94vw, 1000px, calc((100dvh - 230px) * 1.5));
  aspect-ratio: 3 / 2;
  opacity: 0;
  animation: appear 3.5s 0.3s ease-out forwards;
}

.board-float {
  width: 100%;
  height: 100%;
  animation: float 9s ease-in-out infinite;
  filter: drop-shadow(0 34px 40px rgba(0, 0, 0, .8)) drop-shadow(0 0 70px rgba(255, 140, 50, .08));
}

.board-wrap { perspective: 1600px; }
#board {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  transform: rotateX(11deg);
  transform-origin: 50% 60%;
}
body.tall #board { transform: rotateX(6deg); }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-0.35deg); }
  50% { transform: translateY(-10px) rotate(0.35deg); }
}

@keyframes appear {
  from { opacity: 0; transform: scale(.96); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}

/* litere de pe tablă: vopsea veche, ușor tocită */
.glyph {
  font-family: var(--font-board);
  fill: #1d110a;
  stroke: #1d110a;
  stroke-width: 1.3px;
  paint-order: stroke;
  transition: fill .6s ease, stroke .6s ease;
  user-select: none;
}
.glyph.lit {
  fill: #ffd391;
  stroke: #8a420d;
  filter: url(#glow);
  transition: fill .12s ease, stroke .12s ease;
}

/* urma literelor */
.trace {
  min-height: 1.6em;
  font-family: var(--font-board);
  font-size: clamp(18px, 3.6vw, 30px);
  letter-spacing: .35em;
  text-align: center;
  color: var(--amber);
  text-shadow: 0 0 12px rgba(243, 183, 101, .55), 0 0 30px rgba(243, 120, 40, .25);
  transition: opacity 2.5s ease, filter 2.5s ease;
  max-width: 94vw;
  overflow-wrap: anywhere;
}
.trace.fade { opacity: 0; filter: blur(4px); }
.trace span { display: inline-block; animation: ink 0.9s ease-out; }
@keyframes ink { from { opacity: 0; filter: blur(5px); transform: translateY(4px); } to { opacity: 1; filter: none; transform: none; } }

/* ---------- dialog ---------- */
.dialog {
  position: relative;
  z-index: 4;
  padding: 4px 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  animation: appear 2s 2.2s ease-out forwards;
}

.echo {
  height: 1.5em;
  font-style: italic;
  font-size: 16px;
  color: var(--ink-dim);
  text-align: center;
  max-width: 680px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.echo.rise { animation: rise 6s ease-out forwards; }
@keyframes rise {
  0% { opacity: 0; transform: translateY(8px); filter: blur(3px); }
  15% { opacity: 1; transform: none; filter: none; }
  70% { opacity: .7; }
  100% { opacity: 0; transform: translateY(-26px); filter: blur(5px); }
}

/* caseta: ramă de lemn vechi, imperfectă, cu pânză de păianjen */
.altar {
  position: relative;
  width: min(700px, 100%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px 0 16px;
  border: 18px solid transparent;
  border-image: url("img/rama-dialog.png") 18 stretch;
  background:
    radial-gradient(120% 160% at 50% 0%, rgba(255, 170, 90, .07), transparent 60%),
    linear-gradient(180deg, rgba(20, 14, 11, .9), rgba(10, 7, 6, .94));
  background-clip: padding-box;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .7), inset 0 0 22px rgba(0, 0, 0, .8);
  transition: box-shadow .6s ease;
}
.altar:focus-within, .altar.listening {
  box-shadow: 0 16px 40px rgba(0, 0, 0, .7), 0 0 40px rgba(255, 140, 50, .16), inset 0 0 22px rgba(0, 0, 0, .8);
}
.web { position: absolute; pointer-events: none; z-index: 2; }
.web-tl { top: -22px; left: -22px; width: 118px; opacity: .55; }
.web-br { bottom: -22px; right: -22px; width: 84px; opacity: .38; transform: rotate(180deg); }

#question {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-family: var(--font-old);
  font-size: 21px; /* >=16px: iPhone nu mai face zoom */
  padding: 8px 0;
  caret-color: var(--amber);
  text-shadow: 0 0 8px rgba(255, 200, 130, .15);
}
#question::placeholder { color: rgba(236, 220, 188, .42); font-style: italic; }
#question.interim { font-style: italic; color: rgba(243, 200, 140, .8); }

.modes { display: flex; align-items: center; gap: 2px; flex: none; }
.divider { width: 1px; height: 38px; background: linear-gradient(transparent, rgba(214, 170, 110, .45), transparent); margin: 0 4px; }

.mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: 64px;
  padding: 4px 2px 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(236, 220, 188, .62);
  font-family: var(--font-old);
  font-style: italic;
  font-size: 13px;
  letter-spacing: .06em;
  cursor: pointer;
  transition: color .35s ease, background .35s ease;
}
.mode:hover, .mode:focus-visible { color: var(--ink); background: rgba(255, 200, 130, .05); outline: 0; }
.mode svg { width: 40px; height: 40px; overflow: visible; }
.mode:disabled { opacity: .35; cursor: default; }

/* pana */
.quill .feather { fill: url(#featherG); opacity: .9; }
.quill .rachis, .quill .barbs, .quill .ink { fill: none; stroke: #4a2f1a; stroke-width: 1.1; stroke-linecap: round; }
.quill .rachis { stroke: #6b4a2c; stroke-width: 1.4; }
.quill .barbs { opacity: .55; }
.quill .nib { fill: #2a1a10; }
.quill .ink { stroke: var(--amber); stroke-width: 1.4; stroke-dasharray: 12; stroke-dashoffset: 12; transition: stroke-dashoffset .5s ease; }
.quill svg { transition: transform .5s cubic-bezier(.3, 1.4, .5, 1); transform-origin: 20% 90%; }
.quill:hover svg, .quill.ready svg { transform: rotate(-8deg) translateY(-1px); }
.quill.ready .ink, .quill:hover .ink { stroke-dashoffset: 0; }
.quill.ready { color: var(--amber); }

/* lumânarea */
.candle .wax { stroke: rgba(0, 0, 0, .35); stroke-width: .6; }
.candle .ember { fill: #ff9a3c; opacity: .55; animation: ember 2.4s ease-in-out infinite alternate; }
.candle.lit .ember { opacity: 0; }
@keyframes ember { from { opacity: .25; } to { opacity: .8; } }
.candle .drip { fill: #d9cbab; opacity: .8; }
.candle .holder { fill: #3a2a1a; stroke: rgba(214, 170, 110, .5); stroke-width: .7; }
.candle .wick { stroke: #1a0f08; stroke-width: 1.4; stroke-linecap: round; }
.candle .flame-wrap { transform-origin: 24px 21px; transform: scale(0); opacity: 0; transition: transform .6s cubic-bezier(.3, 1.5, .5, 1), opacity .4s ease; }
.candle .flame-core { fill: #fffdf3; opacity: .85; }
.candle .halo { opacity: 0; transition: opacity .6s ease; }
.candle .smoke-wisp { fill: none; stroke: rgba(220, 210, 200, .45); stroke-width: 1; stroke-linecap: round; opacity: 0; stroke-dasharray: 26; stroke-dashoffset: 26; }
.candle:hover .flame-wrap { transform: scale(.35); opacity: .6; }

.candle.lit { color: var(--amber); }
.candle.lit .flame-wrap {
  opacity: 1;
  transform: scale(calc(.85 + var(--vol) * .55)) skewX(calc(var(--vol) * 6deg));
  animation: candleFlicker .18s infinite alternate;
}
.candle.lit .halo { opacity: calc(.5 + var(--vol) * .5); }
.candle.out .smoke-wisp { animation: wisp 1.8s ease-out; }
@keyframes candleFlicker {
  from { filter: brightness(1); }
  to { filter: brightness(1.18); }
}
@keyframes wisp {
  0% { opacity: .8; stroke-dashoffset: 26; }
  60% { opacity: .5; }
  100% { opacity: 0; stroke-dashoffset: -26; transform: translateY(-6px); }
}

.hint {
  margin: 12px 0 0;
  font-size: 14px;
  font-style: italic;
  letter-spacing: .12em;
  color: rgba(236, 220, 188, .34);
  transition: opacity 2s ease;
  text-align: center;
  min-height: 1.2em;
}
.hint.gone { opacity: 0; }
.hint.note { opacity: 1; color: rgba(243, 183, 101, .65); }

body.tall .board-wrap {
  width: min(94vw, calc((100dvh - 240px) * 800 / 980));
  aspect-ratio: 800 / 980;
}

@media (max-width: 480px) {
  .altar { padding-left: 10px; gap: 4px; border-width: 14px; }
  .web-tl { width: 90px; top: -18px; left: -18px; }
  #question { font-size: 18px; }
  .mode { width: 52px; font-size: 12px; }
  .mode svg { width: 30px; height: 30px; }
}

@media (max-height: 520px) {
  .hint { display: none; }
  .board-wrap { width: min(94vw, calc((100dvh - 140px) * 1.5)); }
}

@media (prefers-reduced-motion: reduce) {
  .board-float, .candle-glow, .room { animation: none; opacity: 1; }
}

/* schimbarea limbii: textul se evaporă și se condensează la loc */
.evap-out { animation: evapOut .9s ease-in forwards; }
.evap-in { animation: evapIn 1.3s ease-out; }
@keyframes evapOut {
  to { opacity: 0; filter: blur(5px); transform: translateY(-7px); letter-spacing: .25em; }
}
@keyframes evapIn {
  from { opacity: 0; filter: blur(6px); transform: translateY(5px); }
  to { opacity: 1; filter: none; transform: none; }
}
#question.ph-fade::placeholder { color: transparent; }
#question::placeholder { transition: color .9s ease; }
.mode .lbl { display: inline-block; }

/* lumânarea „doarme" până când tabla îți cunoaște limba */
.candle.dormant { opacity: .38; cursor: default; }
.candle.dormant svg { filter: grayscale(.85) brightness(.8); }
.candle.dormant .ember { display: none; }
.candle.dormant:hover .flame-wrap { transform: scale(0); opacity: 0; }
.candle.awaken svg { animation: awaken 2.6s ease-out; }
.candle.awaken .flame-wrap { animation: awakenFlame 2.6s ease-out; }
@keyframes awaken {
  0% { filter: grayscale(.85) brightness(.8); }
  40% { filter: grayscale(0) brightness(1.5) drop-shadow(0 0 8px rgba(255, 170, 80, .8)); }
  100% { filter: none; }
}
@keyframes awakenFlame {
  0% { transform: scale(0); opacity: 0; }
  35% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}

/* lumânarea pregătită (vocea e disponibilă): jarul pulsează clar */
.candle.ready:not(.lit) { color: var(--ink); }
.candle.ready:not(.lit) .ember { opacity: .9; r: 2.2; animation: ember 1.6s ease-in-out infinite alternate; }

/* lumânarea ascultă: semnal puternic, imposibil de ratat */
.candle.lit {
  color: #ffd49a;
  background: radial-gradient(circle at 50% 40%, rgba(255, 170, 70, .28), rgba(255, 120, 40, .06) 70%);
  box-shadow: 0 0 0 1px rgba(255, 190, 110, .55), 0 0 26px rgba(255, 140, 40, .45);
  animation: listenPulse 1.3s ease-in-out infinite;
}
.candle.lit .lbl { font-style: normal; letter-spacing: .12em; }
@keyframes listenPulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 190, 110, .55), 0 0 18px rgba(255, 140, 40, .35); }
  50% { box-shadow: 0 0 0 2px rgba(255, 200, 120, .8), 0 0 38px rgba(255, 140, 40, .6); }
}
.altar.listening {
  box-shadow: 0 16px 40px rgba(0, 0, 0, .7), 0 0 60px rgba(255, 140, 50, .35), inset 0 0 30px rgba(255, 120, 40, .12);
}
.altar.listening #question::placeholder { color: rgba(255, 200, 140, .75); }

/* mesaje scurte afișate direct în casetă */
#question.noting::placeholder { color: rgba(255, 196, 120, .9); font-style: italic; }

/* tabla în alt alfabet (chirilic, grecesc): literă veche, tipărită */
#board.script-other .glyph { font-family: "Old Standard TT", Georgia, serif; font-weight: 700; }

/* schimbarea cuvintelor / alfabetului pe tablă: literele se estompează și reapar */
#board .glyphs { transition: opacity 1.3s ease, filter 1.3s ease; }
#board.morphing .glyphs { opacity: 0; filter: blur(6px); }

/* ---------- link discret: termeni · confidențialitate ---------- */
.legal-link {
  position: fixed;
  z-index: 5;
  top: max(22px, calc(env(safe-area-inset-top) + 8px));
  left: 16px;
  font-family: "IM Fell English", Georgia, serif;
  font-style: italic;
  font-size: 13px;
  letter-spacing: .04em;
  color: rgba(236, 220, 188, .26);
  text-decoration: none;
  transition: color .4s;
}
.legal-link:hover, .legal-link:focus-visible { color: rgba(236, 220, 188, .7); }
@media (max-width: 600px) { .legal-link { font-size: 12px; left: 12px; } }
/* link spre ghid, sub cel de termeni */
.guide-link { top: max(42px, calc(env(safe-area-inset-top) + 28px)); }
/* titlul paginii pentru Google și cititoare de ecran (tabla e desenată, nu are text) */
.seo-title { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- butonul de share (apare după fiecare răspuns) ---------- */
.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  /* stă peste rândul cu ecoul întrebării (gol când apare), ca tabla să nu se miște */
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  width: fit-content;
  margin: 0 auto;
  z-index: 1;
  padding: 6px 14px;
  border: 1px solid rgba(243, 183, 101, .28);
  border-radius: 999px;
  background: rgba(20, 12, 8, .55);
  color: rgba(243, 200, 140, .82);
  font-family: var(--font-old);
  font-style: italic;
  font-size: 15px;
  letter-spacing: .06em;
  cursor: pointer;
  opacity: 0;
  transition: color .4s ease, border-color .4s ease, box-shadow .4s ease;
}
.share-btn[hidden] { display: none; }
.share-btn.show { animation: shareIn 1.6s 1.2s ease-out forwards; }
.share-btn:hover, .share-btn:focus-visible { color: #ffd49a; border-color: rgba(255, 190, 110, .6); box-shadow: 0 0 22px rgba(255, 140, 40, .25); outline: 0; }
.share-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.share-btn.working { opacity: .5 !important; cursor: progress; }
@keyframes shareIn { from { opacity: 0; filter: blur(4px); transform: translateY(4px); } to { opacity: 1; filter: none; transform: none; } }
@media (max-width: 480px) { .share-btn { font-size: 14px; padding: 5px 12px; } }
