/* =========================================================
   AETHERIA — Prologo giocabile
   Palette: inchiostro, pergamena, oro, ametista, rosso vernice.
   Tipografia: Cinzel (titoli), Alegreya (lettura), Alegreya Sans (interfaccia).
   ========================================================= */

:root{
  --ink:          #06080F;
  --ink-soft:     #0C1120;
  --parchment:    #EDE3CE;
  --parchment-dim:#B7AC96;
  --gold:         #C6A052;
  --gold-lit:     #EBD08A;
  --blood:        #AD2A20;
  --amethyst:     #8E79BE;

  --display: 'Cinzel', 'Times New Roman', serif;
  --body:    'Alegreya', Georgia, serif;
  --ui:      'Alegreya Sans', system-ui, -apple-system, sans-serif;

  --pad-x: clamp(20px, 6.5vw, 110px);

  --spray: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='120'><filter id='f'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/><feColorMatrix type='matrix' values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 1.7 -0.22 0'/></filter><rect width='320' height='120' filter='url(%23f)'/></svg>");
}

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

[hidden]{ display: none !important; }

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

html, body{
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--parchment);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body{
  font-family: var(--body);
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection{ background: rgba(198,160,82,.35); color: #fff; }

button, a{ -webkit-tap-highlight-color: transparent; }

:focus-visible{
  outline: 2px solid var(--gold-lit);
  outline-offset: 4px;
}

/* ---------- Stage e sfondi ---------- */

.stage{
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
}

.bgs{ position: absolute; inset: 0; z-index: 0; }

.bg{
  position: absolute;
  inset: -3%;
  background-color: var(--ink);
  background-size: cover;
  background-position: var(--pos, 50% 50%);
  background-repeat: no-repeat;
  opacity: 0;
  transform: scale(1.04);
  transition: opacity 1.1s ease;
  will-change: opacity, transform;
}
.bg.on{ opacity: 1; animation: drift 44s ease-in-out infinite alternate; }
.bg.void{
  background-image: radial-gradient(120% 90% at 50% 38%, #121829 0%, #080B14 55%, #05070d 100%);
}

@keyframes drift{
  from{ transform: scale(1.04) translate3d(0,0,0); }
  to  { transform: scale(1.10) translate3d(-1.2%, -1.4%, 0); }
}

/* vela di colore + vignettatura */
.grade{
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(120% 85% at 50% 45%, rgba(6,8,15,0) 38%, rgba(6,8,15,.55) 100%),
    linear-gradient(to bottom, rgba(6,8,15,.55) 0%, rgba(6,8,15,.05) 30%, rgba(6,8,15,.55) 82%, rgba(5,7,13,.9) 100%);
}

/* grana sottile, come carta stampata */
.grain{
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  opacity: .045;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
  mix-blend-mode: screen;
}

/* ---------- Dorso del libro ---------- */

.spine{
  position: absolute; left: clamp(10px, 2vw, 26px); top: 0; bottom: 0; z-index: 11;
  display: flex; align-items: center; margin: 0; pointer-events: none;
}
.spine span{
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--ui);
  font-size: .58rem;
  font-weight: 500;
  letter-spacing: .52em;
  text-transform: uppercase;
  color: rgba(198,160,82,.62);
}
.spine::before{
  content: ''; position: absolute; left: -9px; top: 16%; bottom: 16%; width: 1px;
  background: linear-gradient(to bottom, transparent, rgba(198,160,82,.35), transparent);
}

/* ---------- HUD ---------- */

.hud{
  position: absolute; top: 0; left: 0; right: 0; z-index: 14;
  display: flex; align-items: center; justify-content: space-between;
  padding: clamp(15px, 3vw, 28px) var(--pad-x);
  pointer-events: none;
}
.hud-label{
  margin: 0;
  font-family: var(--ui);
  font-size: .62rem;
  font-weight: 500;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: rgba(237,227,206,.42);
}
.hud-tools{ display: flex; gap: 8px; pointer-events: auto; }
.tool{
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(198,160,82,.3);
  background: rgba(6,8,15,.38);
  color: rgba(237,227,206,.72);
  font-family: var(--body);
  font-size: .95rem;
  line-height: 1;
  cursor: pointer;
  transition: color .2s, border-color .2s, background .2s;
}
.tool:hover{ color: var(--gold-lit); border-color: rgba(198,160,82,.7); background: rgba(6,8,15,.6); }
.tool[aria-pressed="false"]{ opacity: .4; }

/* ---------- Il Marchio ---------- */

.marchio{
  position: absolute;
  z-index: 6;
  right: clamp(24px, 8vw, 130px);
  top: 50%;
  transform: translateY(-50%) rotate(-4deg);
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(30px, 4.6vw, 58px);
  line-height: 1;
  letter-spacing: .05em;
  color: var(--blood);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1s ease, color 1.4s ease, filter 1.4s ease;
  filter: drop-shadow(0 2px 18px rgba(173,42,32,.35));
}
.marchio .mark-word{
  display: block;
  -webkit-mask-image: var(--spray);
  mask-image: var(--spray);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
}
.drip{
  position: absolute;
  top: 74%;
  width: 2px;
  border-radius: 0 0 2px 2px;
  background: linear-gradient(to bottom, var(--blood), rgba(173,42,32,0));
}
.d1{ left: 14%; height: 26px; }
.d2{ left: 47%; height: 15px; }
.d3{ left: 78%; height: 34px; }

.marchio[data-level="1"]{ opacity: .48; }
.marchio[data-level="2"]{ opacity: .72; }
.marchio[data-level="3"]{ opacity: .94; animation: markPulse 4s ease-in-out infinite; }

@keyframes markPulse{
  0%, 100%{ filter: drop-shadow(0 2px 16px rgba(173,42,32,.3)); }
  50%     { filter: drop-shadow(0 2px 26px rgba(173,42,32,.6)); }
}

/* il velo brucia la maledizione: la vernice diventa una cicatrice d'oro */
.marchio.burned{
  color: var(--gold);
  opacity: .42;
  filter: drop-shadow(0 0 22px rgba(235,208,138,.35));
  animation: none;
}
.marchio.burned .drip{ display: none; }
.marchio.burned .mark-word{
  -webkit-mask-image: none; mask-image: none;
  text-shadow: 0 0 22px rgba(235,208,138,.25);
}

/* ---------- Schermate ---------- */

.screen{ position: absolute; inset: 0; z-index: 10; }

/* --- Titolo --- */

.title{
  position: absolute; inset: 0;
  display: flex; align-items: flex-end;
  padding: clamp(32px, 8vh, 84px) var(--pad-x) clamp(40px, 8vh, 76px);
  background-image: url("assets/img/soglia.webp");
  background-size: cover;
  background-position: 58% 50%;
}
.title::before{
  content: ''; position: absolute; inset: 0;
  background:
    linear-gradient(100deg, rgba(5,7,13,.95) 0%, rgba(5,7,13,.82) 34%, rgba(5,7,13,.18) 66%, rgba(5,7,13,.5) 100%),
    linear-gradient(to top, rgba(5,7,13,.88) 0%, rgba(5,7,13,.1) 48%, rgba(5,7,13,.35) 100%);
}
.title-inner{ position: relative; max-width: 640px; }

.eyebrow{
  margin: 0 0 18px;
  font-family: var(--ui);
  font-size: .64rem;
  font-weight: 500;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: rgba(198,160,82,.85);
}

.wordmark{
  /* il gradiente è ritagliato sul testo: il riquadro deve contenere tutta la parola,
     altrimenti le lettere che sbordano restano trasparenti */
  display: inline-block;
  width: max-content;
  max-width: none;
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(2.9rem, 10.5vw, 7.6rem);
  line-height: .92;
  letter-spacing: .1em;
  text-transform: uppercase;
  background: linear-gradient(176deg, #F6E3AE 0%, #DDB871 38%, #A97C2F 58%, #EDD391 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 26px rgba(0,0,0,.55));
}

.subtitle{
  margin: 14px 0 0;
  font-family: var(--body);
  font-style: italic;
  font-size: clamp(1.05rem, 1.7vw, 1.42rem);
  letter-spacing: .04em;
  color: rgba(237,227,206,.9);
}

.rule{
  width: 84px; height: 1px; margin: 26px 0 0;
  background: linear-gradient(90deg, var(--gold), rgba(198,160,82,0));
}
.rule.slim{ width: 54px; margin: 22px auto 0; background: linear-gradient(90deg, transparent, var(--gold), transparent); }

.kind{
  margin: 22px 0 0;
  font-family: var(--ui);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--parchment-dim);
}

.actions{
  display: flex; flex-wrap: wrap; gap: 14px;
  margin-top: 34px;
}

.btn{
  display: inline-flex; align-items: center; justify-content: center;
  padding: 15px 32px;
  border: 1px solid rgba(198,160,82,.5);
  border-radius: 1px;
  background: rgba(198,160,82,.08);
  color: var(--parchment);
  font-family: var(--ui);
  font-size: .74rem;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background .25s, color .25s, border-color .25s;
}
.btn:hover{ background: var(--gold); border-color: var(--gold); color: #10131C; }
.btn.ghost{
  border-color: transparent;
  background: transparent;
  color: var(--parchment-dim);
  padding-inline: 18px;
}
.btn.ghost:hover{ background: transparent; color: var(--gold-lit); border-color: rgba(198,160,82,.3); }

.title-note{
  margin: 28px 0 0;
  font-family: var(--ui);
  font-size: .66rem;
  letter-spacing: .1em;
  color: rgba(237,227,206,.38);
}

/* Romanzo e canzone: raggiungibili dal titolo, senza dover finire il gioco */
.title-links{
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin: 22px 0 0;
}
.btn.small{
  padding: 11px 20px;
  font-size: .64rem;
  letter-spacing: .16em;
  white-space: nowrap;
}

/* --- Gioco --- */

.play{ position: absolute; inset: 0; }
.play::before{
  content: ''; position: absolute; inset: auto 0 0 0; height: 64%; pointer-events: none;
  background: linear-gradient(to top, rgba(5,7,13,.97) 8%, rgba(5,7,13,.86) 40%, rgba(5,7,13,0) 100%);
}

.plate{
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0 var(--pad-x) calc(clamp(26px, 5vh, 56px) + env(safe-area-inset-bottom));
  max-width: 900px;
  max-height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: opacity .5s ease;
}
.play.card .plate{ opacity: 0; pointer-events: none; }

.who{
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 12px;
  font-family: var(--ui);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--gold-lit);
}
.who::before{
  content: ''; width: 20px; height: 1px; background: var(--gold); flex: none;
}

.text{
  max-width: 62ch;
  font-size: clamp(1.1rem, .75vw + .55rem, 1.3rem);
  line-height: 1.66;
  color: var(--parchment);
  text-shadow: 0 1px 30px rgba(0,0,0,.6);
  min-height: 3.4em;
  animation: rise .55s cubic-bezier(.2,.7,.3,1) both;
}
.text em{
  font-style: italic;
  color: #EAD6A8;
}
.text .voice{
  display: block;
  font-style: italic;
  font-size: 1.12em;
  color: var(--gold-lit);
  letter-spacing: .02em;
}

@keyframes rise{
  from{ opacity: 0; transform: translateY(8px); }
  to  { opacity: 1; transform: none; }
}

.choices{
  display: grid;
  margin-top: 26px;
  max-width: 680px;
  animation: rise .45s cubic-bezier(.2,.7,.3,1) both;
}
.choice{
  display: flex; align-items: baseline; gap: 14px;
  width: 100%;
  padding: 15px 4px 15px 0;
  border: 0;
  border-top: 1px solid rgba(198,160,82,.22);
  background: none;
  color: #DCD1BA;
  font-family: var(--body);
  font-size: clamp(1.02rem, .55vw + .62rem, 1.15rem);
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  transition: color .2s, padding-left .25s, border-color .25s;
}
.choice:last-child{ border-bottom: 1px solid rgba(198,160,82,.22); }
.choice:hover, .choice:focus-visible{
  color: var(--gold-lit);
  padding-left: 10px;
  border-color: rgba(198,160,82,.55);
}
.choice .k{
  flex: none;
  min-width: 1.1em;
  font-family: var(--ui);
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: rgba(198,160,82,.6);
}
.choice.done{ opacity: .4; pointer-events: none; }
.choice.exit{ color: var(--gold-lit); border-bottom-color: rgba(198,160,82,.35); }
.choice.exit .k{ color: var(--gold); }
.choice.done .t{ text-decoration: line-through; text-decoration-thickness: 1px; text-decoration-color: rgba(198,160,82,.6); }

.hint{
  margin: 24px 0 0;
  font-family: var(--ui);
  font-size: .64rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: rgba(237,227,206,.42);
  display: flex; align-items: center; gap: 8px;
}
.hint::after{
  content: '▸';
  color: rgba(198,160,82,.8);
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob{ 0%,100%{ transform: translateX(0); opacity:.5 } 50%{ transform: translateX(5px); opacity:1 } }

/* --- Carta di capitolo --- */

.chapter-card{
  position: absolute; inset: 0; z-index: 9;
  display: grid; place-content: center; justify-items: center;
  padding: 24px;
  text-align: center;
  background: radial-gradient(65% 65% at 50% 45%, #0D1322 0%, #05070D 76%);
  opacity: 0;
  transition: opacity .85s ease;
}
.chapter-card.on{ opacity: 1; }
.chapter-num{
  margin: 0;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 4rem);
  letter-spacing: .06em;
  color: var(--gold);
  line-height: 1;
  text-transform: uppercase;
}
.chapter-title{
  margin: 16px 0 0;
  font-family: var(--body);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.45rem, 3.1vw, 2.25rem);
  line-height: 1.25;
  color: var(--parchment);
  max-width: 22ch;
}

/* --- Toast --- */

.toast{
  position: absolute;
  z-index: 8;
  top: clamp(66px, 11vh, 104px);
  right: var(--pad-x);
  max-width: 290px;
  margin: 0;
  font-family: var(--body);
  font-style: italic;
  font-size: .96rem;
  line-height: 1.4;
  text-align: right;
  color: #E8C88C;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .55s ease, transform .55s ease;
  text-shadow: 0 1px 20px rgba(0,0,0,.7);
}
.toast.on{ opacity: 1; transform: none; }

/* --- Fine --- */

.fin{
  position: absolute; inset: 0; z-index: 12;
  display: grid; align-content: center;
  padding: clamp(28px, 7vh, 72px) var(--pad-x);
  overflow-y: auto;
  background-image:
    linear-gradient(115deg, rgba(5,7,13,.95) 0%, rgba(5,7,13,.88) 46%, rgba(5,7,13,.72) 100%),
    url("assets/img/soglia.webp");
  background-size: cover;
  background-position: center;
}
.fin-inner{ position: relative; max-width: 640px; }
.fin-title{
  margin: 0;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(1.8rem, 4.2vw, 2.9rem);
  line-height: 1.1;
  letter-spacing: .02em;
  color: var(--parchment);
}
.fin-text{
  margin: 20px 0 0;
  max-width: 54ch;
  font-size: clamp(1rem, .8vw + .66rem, 1.14rem);
  line-height: 1.62;
  color: var(--parchment-dim);
}
.stats{
  display: grid; gap: 20px;
  margin: 34px 0 0; padding: 24px 0 0;
  border-top: 1px solid rgba(198,160,82,.24);
  max-width: 520px;
}
@media (min-width: 620px){
  .stats{ grid-template-columns: 1fr 1fr; }
}
.stats dt{
  font-family: var(--ui);
  font-size: .62rem;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: rgba(237,227,206,.45);
}
.stats dd{
  margin: 7px 0 0;
  font-size: 1.16rem;
  color: var(--gold-lit);
}
.fin-note{
  margin: 30px 0 0;
  font-family: var(--ui);
  font-size: .64rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: rgba(237,227,206,.35);
}

/* ---------- Progresso ---------- */

.progress{
  position: absolute; left: 0; right: 0; bottom: 0; height: 2px; z-index: 20;
  background: rgba(237,227,206,.08);
  pointer-events: none;
  transition: opacity .6s ease;
}
.stage.at-title .progress{ opacity: 0; }
.progress i{
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, rgba(198,160,82,.45), var(--gold-lit));
  transition: width .6s ease;
}

/* ---------- Velo e braci ---------- */

.veil-flash{
  position: absolute; inset: 0; z-index: 7; pointer-events: none; opacity: 0;
  background: radial-gradient(58% 58% at 50% 47%, #FFFCF2 0%, #FFE1A8 26%, rgba(255,190,110,0) 66%);
}
.veil-flash.on{ animation: veil 2.3s ease-out forwards; }
@keyframes veil{
  0%  { opacity: 0; transform: scale(.55); }
  14% { opacity: 1; }
  62% { opacity: .8; }
  100%{ opacity: 0; transform: scale(1.7); }
}

.embers{ position: absolute; inset: 0; z-index: 7; pointer-events: none; }
.embers i{
  position: absolute;
  width: 3px; height: 3px; border-radius: 50%;
  background: #F2CE86;
  box-shadow: 0 0 10px #F2CE86;
  animation: ember 3s ease-out forwards;
}
@keyframes ember{
  0%  { opacity: 0; transform: translate3d(0,0,0) scale(.6); }
  20% { opacity: 1; }
  100%{ opacity: 0; transform: translate3d(var(--dx, 10px), -70vh, 0) scale(1.4); }
}

/* ---------- Adattamenti ---------- */

@media (max-width: 900px){
  .spine{ display: none; }
  /* le scene verticali (la camera) vanno inquadrate diversamente sul telefono */
  .bg{ background-position: var(--pos-m, var(--pos, 50% 50%)); }
  .marchio{
    top: auto; bottom: auto;
    right: 20px;
    top: 16vh;
    transform: rotate(-4deg);
    font-size: 26px;
  }
  .toast{
    top: 15vh;
    right: auto;
    left: 20px;
    max-width: 58vw;
    text-align: left;
    font-size: .9rem;
  }
  .title{ background-position: 66% 45%; align-items: flex-end; }
}

@media (max-width: 620px){
  body{ font-size: 17px; }
  .title{ padding-bottom: calc(38px + env(safe-area-inset-bottom)); }
  .title::before{
    background:
      linear-gradient(to top, rgba(5,7,13,.97) 6%, rgba(5,7,13,.82) 42%, rgba(5,7,13,.15) 78%, rgba(5,7,13,.4) 100%);
  }
  .wordmark{ font-size: clamp(2.9rem, 14vw, 4.4rem); letter-spacing: .08em; }
  .plate{ max-width: 100%; }
  .text{ max-width: 100%; min-height: 3em; }
  .choices{ max-width: 100%; }
  .btn{ padding: 14px 24px; }
  .fin{ align-content: start; padding-top: calc(72px + env(safe-area-inset-top)); }
}

@media (min-width: 1500px){
  .plate{ max-width: 1000px; }
  .text{ max-width: 66ch; }
}

/* ---------- Movimento ridotto ---------- */

@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .bg.on{ animation: none; transform: none; }
}
