/* Il Segreto dell'Opus Magnum — componenti del telefono nati con l'avventura di chimica (cantiere C):
   chiavi a tessere (modello, serratura, vassoio), sigillo della porta, registro di laboratorio, scheda che si scrive.
   I colori vengono dal tema (base.css); i valori dopo la virgola sono il ripiego se una variabile manca.
   Pensato per telefoni economici: niente filtri pesanti in movimento, bottoni da almeno 48 px. */

/* ─────────── consegna con il sigillo della porta ─────────── */
.consegna-riga { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }

.sigillo-porta { display: grid; justify-items: center; gap: 2px; width: 66px; }
.sigillo-porta svg { width: 60px; height: 60px; overflow: visible; }
.sigillo-porta small { font-family: var(--font-inciso, serif); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--testo-3, #8d7d64); white-space: nowrap; }
.sigillo-porta.completo small { color: var(--oro-vivo, #f4d389); }
.sigillo-porta .anello-esterno { fill: none; stroke: var(--oro-scuro, #8c6224); stroke-width: 1.6; stroke-dasharray: 2 3; }
.sigillo-porta .meta { fill: var(--lapis-3, #2d241b); stroke: var(--oro-scuro, #8c6224); stroke-width: 1.4; transition: fill 0.4s; }
.sigillo-porta .meta.accesa { fill: var(--oro, #d9a441); stroke: var(--oro-vivo, #f4d389); }
.sigillo-porta .inc { fill: none; stroke: var(--testo-3, #8d7d64); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sigillo-porta .meta-1.accesa ~ .inc-1,
.sigillo-porta .meta-2.accesa ~ .inc-2 { stroke: var(--inchiostro, #2a190c); }
.sigillo-porta .fessura { stroke: var(--notte, #090705); stroke-width: 2.4; }
.sigillo-porta.completo .fessura { stroke: var(--oro-vivo, #f4d389); stroke-width: 1; opacity: 0.8; }
.sigillo-porta.completo svg,
.sigillo-porta .meta.accesa { filter: drop-shadow(0 0 6px rgba(244, 211, 137, 0.55)); }
.sigillo-porta .meta.nuova { animation: meta-accende 1.2s cubic-bezier(.2, .9, .3, 1.2) both; transform-box: fill-box; transform-origin: center; }
@keyframes meta-accende {
  0% { fill: var(--lapis-3, #2d241b); transform: scale(0.9); }
  35% { fill: #fff6dc; transform: scale(1.12); filter: drop-shadow(0 0 14px rgba(255, 236, 180, 0.95)); }
  100% { fill: var(--oro, #d9a441); transform: scale(1); }
}
/* Nel timbro della chiave il sigillo è grande. */
.sigillo-porta.grande { width: 170px; gap: 8px; }
.sigillo-porta.grande svg { width: 160px; height: 160px; }
.timbro.timbro-chiave { background: radial-gradient(circle at 50% 42%, rgba(40, 26, 12, 0.94), rgba(9, 7, 5, 0.86) 75%); animation: velo-chiave 1.9s ease both; }
@keyframes velo-chiave { 0% { opacity: 0; } 12%, 82% { opacity: 1; } 100% { opacity: 0; } }
.sigillo-porta.grande small { display: none; }
.timbro.timbro-chiave > div { animation-duration: 1.9s; }
.timbro.timbro-chiave b { color: var(--oro-vivo, #f4d389); text-shadow: 0 0 22px rgba(244, 211, 137, 0.75); }
.timbro .porta-aperta { font-family: var(--font-inciso, serif); font-style: italic; font-size: 1.15rem; color: var(--papiro, #efe1c0); }

/* ─────────── modello del composto ─────────── */
.modello-composto { margin: 2px 0 12px; }
.modello-composto img { display: block; width: 100%; height: auto; aspect-ratio: 1060 / 520; object-fit: contain; border-radius: 12px;
  border: 1px solid var(--bordo, rgba(217, 164, 65, 0.26)); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); background: var(--papiro-2, #dcc796); }

/* ─────────── la serratura ─────────── */
.serratura { border-radius: 16px; padding: 10px 10px 8px; border: 2px solid var(--oro-scuro, #8c6224);
  background: linear-gradient(180deg, rgba(58, 48, 39, 0.92), rgba(21, 17, 13, 0.95)); box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.6), 0 6px 18px rgba(0, 0, 0, 0.35); }
.serratura-testa { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.serratura-testa > span { font-family: var(--font-inciso, serif); font-size: 0.78rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--oro, #d9a441); }
.serratura .svuota { min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--bordo, rgba(217, 164, 65, 0.26));
  background: rgba(0, 0, 0, 0.25); color: var(--testo-2, #c7b697); font: 600 0.88rem var(--font-ui, sans-serif); }
.serratura .svuota:disabled { opacity: 0.35; }
.serratura .slot { list-style: none; margin: 0; padding: 8px; min-height: 68px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  border-radius: 10px; background: rgba(0, 0, 0, 0.42); box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.7); }
.serratura .slot li { display: flex; }
.serratura .slot li.vuoto span { display: grid; place-items: center; min-width: 48px; height: 52px; border-radius: 10px;
  border: 2px dashed rgba(217, 164, 65, 0.35); color: rgba(217, 164, 65, 0.5); font: 600 1.2rem var(--font-inciso, serif); }
.serratura .anteprima { margin: 8px 2px 2px; min-height: 2.1em; text-align: center; font-family: var(--font-voce, serif); line-height: 1.25; overflow-wrap: anywhere; }
.serratura .anteprima .resa { font-size: 1.4rem; font-weight: 600; color: var(--oro-vivo, #f4d389); }
.modo-formula .serratura .anteprima .resa,
.modo-ioni .serratura .anteprima .resa { font-size: 1.7rem; letter-spacing: 0.02em; }
.serratura .anteprima .vuota { font-size: 0.98rem; font-style: italic; color: var(--testo-3, #8d7d64); }
.serratura .esito-serratura { margin: 6px 0 2px; padding: 8px 10px; border-radius: 10px; text-align: center; font-family: var(--font-voce, serif); font-style: italic; font-size: 1.05rem; line-height: 1.3;
  color: #ffd9d4; background: rgba(214, 70, 79, 0.16); border: 1px solid rgba(214, 70, 79, 0.5); }
.serratura .esito-serratura.quasi { color: var(--papiro, #efe1c0); background: rgba(217, 164, 65, 0.12); border-color: rgba(217, 164, 65, 0.45); }
.serratura .esito-serratura[hidden] { display: none; }
.serratura.trema { animation: serratura-trema 0.55s cubic-bezier(.36, .07, .19, .97) both; border-color: var(--rubino, #d6464f); }
@keyframes serratura-trema {
  10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); } 40%, 60% { transform: translateX(7px); }
}
.giusta .serratura { border-color: var(--oro-vivo, #f4d389); box-shadow: 0 0 26px rgba(244, 211, 137, 0.45), inset 0 2px 10px rgba(0, 0, 0, 0.6); transition: box-shadow 0.3s, border-color 0.3s; }

/* ─────────── le tessere ─────────── */
.vassoio-titolo { margin: 14px 0 8px; text-align: center; font-size: 0.82rem; color: var(--testo-3, #8d7d64); }
.vassoio { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.tessera-btn { min-width: 48px; min-height: 52px; padding: 0 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--papiro-ombra, #b39866); border-bottom-width: 4px;
  background: linear-gradient(180deg, var(--papiro, #efe1c0), var(--papiro-2, #dcc796));
  color: var(--inchiostro, #2a190c); font: 600 1.18rem/1 var(--font-voce, serif); letter-spacing: 0.01em;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; transition: transform 0.08s, opacity 0.2s; }
.tessera-btn:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; margin-top: 2px; }
.tessera-btn:focus-visible { outline: 3px solid var(--solfato, #5cb3ec); outline-offset: 2px; }
/* Prefissi (tri-, di-, osso-): si agganciano alla tessera dopo. Numeri romani: si agganciano a quella prima. */
.tessera-btn.prefisso { background: linear-gradient(180deg, #f3d2b4, #e0b58f); border-right-style: dashed; border-right-width: 2px; }
.tessera-btn.romano { background: linear-gradient(180deg, #d9e8f2, #b7cfe0); border-left-style: dashed; border-left-width: 2px; font-family: var(--font-voce, serif); }
.tessera-btn.pedice { font-size: 1.5rem; min-width: 48px; padding: 0 10px; }
.modo-formula .tessera-btn, .modo-ioni .tessera-btn { font-size: 1.35rem; }
.vassoio .tessera-btn.usata { opacity: 0.22; border-style: dashed; border-bottom-width: 1px; margin-top: 3px; box-shadow: none; cursor: default; }
.tessera-btn.posata { box-shadow: 0 0 0 1px rgba(244, 211, 137, 0.35); }
.tessera-btn.appena { animation: tessera-posa 0.24s cubic-bezier(.2, .9, .3, 1.3) both; }
@keyframes tessera-posa { from { opacity: 0.3; transform: translateY(-16px) scale(0.86); } }
.gira-chiave .glifo { width: 22px; height: 22px; }
/* Pedici e apici nei testi (consegne, racconti, scelte): niente salti di riga. */
#app sub, #app sup, .narra-solo sub, .narra-solo sup { line-height: 0; font-size: 0.7em; }
/* Pedici e apici delle formule (Fe₂O₃, Na⁺): resi con sub/sup perché non tutti i font li disegnano. */
.tessera-btn sub, .serratura .anteprima sub { font-size: 0.68em; vertical-align: -0.28em; line-height: 0; }
.tessera-btn sup, .serratura .anteprima sup { font-size: 0.66em; vertical-align: 0.55em; line-height: 0; }
.tessera-btn.pedice sub { font-size: 0.8em; vertical-align: -0.2em; }

/* ─────────── il registro di laboratorio ─────────── */
.registro-btn { position: relative; }
.registro-btn .glifo { width: 20px; height: 20px; }
.registro-btn .conta { position: absolute; top: -5px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--rame, #c8733f); color: #fff; font: 700 0.68rem/18px var(--font-ui, sans-serif); text-align: center; box-shadow: 0 0 0 2px var(--notte, #090705); }
.registro-btn.nuova-pagina { animation: registro-pulsa 0.9s ease-out both; }
@keyframes registro-pulsa {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(244, 211, 137, 0.8); }
  40% { transform: scale(1.22); box-shadow: 0 0 0 10px rgba(244, 211, 137, 0); }
  100% { transform: scale(1); }
}

.registro-pannello { position: fixed; inset: 0; z-index: 85; display: grid; place-items: center; padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  background: rgba(6, 4, 3, 0.86); animation: registro-entra 0.25s ease-out both; }
.registro-pannello.va-via { animation: registro-esce 0.25s ease-in both; }
@keyframes registro-entra { from { opacity: 0; } }
@keyframes registro-esce { to { opacity: 0; } }
.registro-libro { width: min(100%, 470px); max-height: 100%; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px;
  border-radius: 16px; border: 2px solid var(--oro-scuro, #8c6224);
  background: linear-gradient(160deg, #3a2414, #1f130a 60%, #160d07); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7), inset 0 0 0 4px rgba(217, 164, 65, 0.08);
  animation: libro-apre 0.35s cubic-bezier(.2, .9, .3, 1.1) both; }
@keyframes libro-apre { from { transform: translateY(24px) scale(0.96); opacity: 0; } }
.registro-libro header { display: flex; align-items: center; gap: 10px; }
.registro-libro header h2 { flex: 1; margin: 0; font-family: var(--font-inciso, serif); font-size: 1.12rem; font-variant: small-caps; letter-spacing: 0.06em; color: var(--oro-vivo, #f4d389); }
.registro-icona .glifo { width: 26px; height: 26px; color: var(--oro, #d9a441); }
.registro-libro .chiudi, .registro-nav button { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--bordo, rgba(217, 164, 65, 0.26));
  background: rgba(0, 0, 0, 0.3); color: var(--oro-vivo, #f4d389); font: 400 1.7rem/1 var(--font-inciso, serif); display: grid; place-items: center; }
.registro-nav button:disabled { opacity: 0.25; }
.registro-pagine { min-height: 0; display: grid; place-items: center; perspective: 1400px; touch-action: pan-y; }
.pagina-registro { margin: 0; display: grid; justify-items: center; gap: 6px; }
.pagina-registro img { display: block; width: auto; max-width: 100%; max-height: calc(100dvh - 190px); aspect-ratio: 3 / 4; border-radius: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6); background: var(--papiro-2, #dcc796); }
.pagina-registro figcaption { font-family: var(--font-voce, serif); font-style: italic; font-size: 0.95rem; color: var(--testo-2, #c7b697); }
.pagina-registro.gira-avanti { animation: pagina-avanti 0.45s ease-out both; transform-origin: left center; }
.pagina-registro.gira-indietro { animation: pagina-indietro 0.45s ease-out both; transform-origin: right center; }
@keyframes pagina-avanti { from { transform: rotateY(-75deg); opacity: 0.2; } }
@keyframes pagina-indietro { from { transform: rotateY(75deg); opacity: 0.2; } }
.registro-nav { display: flex; align-items: center; justify-content: space-between; }
.registro-nav[hidden] { display: none; }
.registro-nav .segno { font-size: 0.85rem; color: var(--testo-3, #8d7d64); }
.registro-vuoto { padding: 40px 18px; text-align: center; font-family: var(--font-voce, serif); color: var(--testo-2, #c7b697); }
.registro-vuoto p:first-child { font-size: 1.25rem; color: var(--papiro, #efe1c0); font-style: italic; }

/* ─────────── la scheda che si scrive nel registro (racconto d'esito) ─────────── */
.scheda-registro { display: block; width: min(100%, 360px); margin: 16px auto 8px; padding: 0; border: 0; background: none; cursor: zoom-in; text-align: center;
  -webkit-tap-highlight-color: transparent; }
.scheda-registro .foglio { position: relative; display: block; overflow: hidden; border-radius: 6px; aspect-ratio: 3 / 4; background: var(--papiro, #efe1c0);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(217, 164, 65, 0.4); transform-origin: 50% 0;
  animation: foglio-arriva 0.7s cubic-bezier(.2, .9, .3, 1.1) both; }
.scheda-registro img { display: block; width: 100%; height: 100%; object-fit: cover; }
/* Il foglio bianco si ritira dall'alto in basso: la pagina sembra scriversi, con il bordo d'inchiostro dorato che scende. */
.scheda-registro .inchiostro { position: absolute; inset: 0; background: var(--papiro, #efe1c0);
  box-shadow: 0 -3px 0 rgba(140, 98, 36, 0.9), 0 -10px 18px rgba(244, 211, 137, 0.75);
  animation: pagina-scrive 1.9s cubic-bezier(.45, .05, .55, .95) 0.55s both; }
@keyframes foglio-arriva { from { opacity: 0; transform: translateY(18px) rotate(-2deg) scale(0.94); } }
@keyframes pagina-scrive { from { transform: translateY(0); } to { transform: translateY(104%); } }
.scheda-registro .didascalia { display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; font-family: var(--font-voce, serif); font-style: italic;
  font-size: 1rem; color: var(--oro, #d9a441); animation: didascalia-entra 0.6s ease 1.6s both; }
.scheda-registro .didascalia .glifo { width: 20px; height: 20px; }
@keyframes didascalia-entra { from { opacity: 0; transform: translateY(6px); } }
.pagina-in-volo { position: fixed; z-index: 90; pointer-events: none; border-radius: 6px; background-size: cover; background-position: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); will-change: transform, opacity; }

@media (prefers-reduced-motion: reduce) {
  .sigillo-porta .meta.nuova, .tessera-btn.appena, .serratura.trema, .registro-btn.nuova-pagina, .registro-pannello, .registro-libro,
  .pagina-registro.gira-avanti, .pagina-registro.gira-indietro, .scheda-registro .foglio, .scheda-registro .didascalia { animation: none; }
  .scheda-registro .inchiostro { display: none; }
}
