/* ─────────────────────────────────────────────────────────────
   Natale in Pixel — stile UI (finestre RPG anni '90 + CRT)
   Priorità al computer, ma tutto resta comodo su telefono.
   ───────────────────────────────────────────────────────────── */

:root {
  --bg: #07070f;
  --ink: #f4efe6;
  --muted: #9a9cc4;
  --win: #10102a;
  --win-inner: #2a2a62;
  --accent: #ffd23f;
  --pink: #ff4fa3;
  --cyan: #4ff0ff;
  --red: #d8364a;
  --green: #2b6e4a;
  --ok: #6dff9a;
  --font: 'Press Start 2P', ui-monospace, 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: none;
  -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; }

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ── Barra in alto ───────────────────────────────── */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  font-size: 10px;
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand-title { color: var(--ink); letter-spacing: 2px; text-shadow: 2px 2px 0 var(--pink); }
.hud-date { color: var(--accent); }
.dev-badge { display: none; font-size: 8px; color: var(--bg); background: var(--cyan); padding: 4px 6px; }
body.is-dev .dev-badge { display: inline-block; }

.icon-btn {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  color: var(--ink); background: #1b1b3e;
  border: 2px solid var(--ink); box-shadow: 3px 3px 0 #000;
  cursor: pointer; padding: 0;
}
.icon-btn:hover { color: var(--accent); }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.icon-btn svg { image-rendering: pixelated; }

/* ── Bottoni ─────────────────────────────────────── */
.px {
  font: inherit;
  font-size: 10px;
  color: var(--ink);
  background: #1b1b3e;
  border: 2px solid var(--ink);
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: 3px 3px 0 #000;
  line-height: 1.3;
}
.px:hover { background: #26265a; }
.px:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.px:focus-visible, .icon-btn:focus-visible, .link-btn:focus-visible, .door:focus-visible { outline: 2px dashed var(--accent); outline-offset: 3px; }
.px--accent { background: var(--red); }
.px--accent:hover { background: #ec4a5e; }
.px--small { padding: 7px 9px; font-size: 9px; }
.px--on { background: #1f6b3a; border-color: var(--ok); }
.px--ghost { background: transparent; border-style: dashed; color: var(--muted); border-color: var(--muted); box-shadow: none; }
.px--found { display: block; margin: 16px auto 0; background: #1f6b3a; border-color: var(--ok); font-size: 11px; padding: 12px 16px; }
.px[hidden] { visibility: hidden; display: inline-block; }

.link-btn {
  font: inherit; font-size: 8px; color: var(--muted);
  background: none; border: 0; padding: 6px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 4px;
}
.link-btn:hover { color: var(--ink); }

/* ── Palco ───────────────────────────────────────── */
#stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 0 8px;
}
#stage-wrap > .stage-bar, #stage-wrap > .story { max-width: var(--stage-w, 960px); }
#stage {
  position: relative;
  line-height: 0;
  box-shadow: 0 0 0 3px #000, 0 0 0 6px #23234a, 0 0 60px rgba(90, 100, 220, 0.25);
}
#game { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
/* barra sopra la scena: chiamata a sinistra, luogo a destra */
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 40px; }
.place { margin: 0 0 0 auto; text-align: right; font-size: 11px; line-height: 1.5; color: var(--ink);
  background: #10102a; padding: 8px 10px; border: 2px solid rgba(244, 239, 230, 0.5); }
.place::before { content: '📍 '; }
.place:empty { display: none; }
/* riquadro dei dialoghi sotto la scena */
.story { width: 100%; min-height: 64px; margin: 0; padding: 10px 12px; box-sizing: border-box;
  background: #10102a; border: 2px solid #3a3a6a; font-size: 11px; line-height: 1.7; color: var(--ink); }
.story b { color: var(--accent); font-weight: normal; margin-right: 8px; }
.story.is-empty { opacity: .35; }
.story.is-empty::before { content: '…'; color: var(--muted); }
body.in-finale .stage-bar, body.in-finale .story { visibility: hidden; }

/* ── Azione principale ───────────────────────────── */
#actions {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 16px 16px 18px;
}
.px--main {
  font-size: 13px; padding: 16px 26px; min-width: min(420px, 100%);
  background: var(--red); border-width: 3px; box-shadow: 4px 4px 0 #000;
  animation: nudge 1.6s steps(2) infinite;
}
.px--main:hover { background: #ec4a5e; }
.px--main.px--quiet { background: #1b1b3e; animation: none; }
.px--main.px--quiet:hover { background: #26265a; }
@keyframes nudge { 50% { box-shadow: 4px 4px 0 #000, 0 0 0 3px var(--accent); } }
.main-msg { margin: 0; font-size: 9px; line-height: 1.8; color: var(--muted); text-align: center; min-height: 1.8em; }
body.in-finale #actions, body.in-finale #hud { visibility: hidden; }
body.in-finale #dialog { align-items: end; background: rgba(4, 4, 14, 0.35); }
body.in-finale #dialog .window { max-height: 52dvh; }

/* ── Overlay e finestre ──────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 14px;
  background: rgba(4, 4, 14, 0.74);
}
.hidden { display: none !important; }

.window {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: 20px;
  background: var(--win);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 0 0 3px #000, inset 0 0 0 3px var(--win-inner), 8px 8px 0 3px rgba(0, 0, 0, 0.55);
  animation: pop 0.18s steps(3);
}
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }

.win-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.win-head h2 { margin: 0; font-size: 14px; color: var(--accent); letter-spacing: 2px; }

/* ── Titolo ──────────────────────────────────────── */
.overlay--title { background: rgba(4, 4, 14, 0.55); cursor: pointer; }
.title-box { text-align: center; padding: 20px; }
.title-pre { font-size: 9px; color: var(--cyan); letter-spacing: 3px; margin: 0 0 16px; }
.title-logo {
  margin: 0;
  font-size: clamp(32px, 7vw, 60px);
  line-height: 1.25;
  color: var(--ink);
  text-shadow: 3px 3px 0 var(--pink), 6px 6px 0 #3a1a5a, -2px -2px 0 var(--cyan);
}
.title-for { margin: 22px 0 0; font-size: 11px; color: var(--accent); }
.title-press { margin: 40px 0 0; font-size: 12px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ── Calendario ──────────────────────────────────── */
.cal-msg { font-size: 9px; line-height: 1.8; color: var(--muted); min-height: 1.8em; margin: 0 0 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.door {
  aspect-ratio: 1;
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 13px; color: #fff;
  border: 2px solid #000; border-radius: 3px; cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.16), inset -3px -3px 0 rgba(0, 0, 0, 0.3), 3px 3px 0 #000;
  background: #8e2b36;
}
.door:nth-child(even) { background: var(--green); }
.door .ico { line-height: 0; min-height: 18px; display: grid; place-items: center; }
.door:active { transform: translate(2px, 2px); }
.door--locked { background: #22223a !important; color: #5f6290; cursor: not-allowed; }
.door--opened { background: #34284f !important; color: #c9b7f0; }
.door--found { background: #3a2440 !important; }
.door--today { outline: 3px solid var(--accent); animation: glow 0.8s steps(2) infinite; }
.door--available::after { content: ''; position: absolute; top: 5px; right: 5px; width: 5px; height: 5px; background: var(--accent); }
@keyframes glow { 50% { box-shadow: 0 0 0 3px var(--accent), 0 0 18px var(--accent), 3px 3px 0 #000; } }
.shake { animation: shake 0.32s steps(4); }
@keyframes shake { 25% { transform: translateX(-3px); } 50% { transform: translateX(3px); } 75% { transform: translateX(-2px); } }

/* ── Dialogo ─────────────────────────────────────── */
.dlg-window { display: flex; flex-direction: column; }
.tag { font-size: 9px; color: var(--bg); background: var(--accent); padding: 5px 7px; }
.dlg-body { font-size: 10px; line-height: 2; min-height: 200px; }
.dlg-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; gap: 8px; }
.pager { font-size: 9px; color: var(--muted); }

.kicker { color: var(--cyan); font-size: 10px; margin: 0 0 14px; letter-spacing: 1px; }
.item-card { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.item-icon {
  flex: none; width: 88px; height: 88px;
  display: grid; place-items: center;
  background: #070718; border: 2px solid var(--win-inner); box-shadow: inset 0 0 0 2px #000;
}
.item-icon canvas, .item-icon img { width: 64px; height: 64px; image-rendering: pixelated; object-fit: contain; }
.item-icon.center { margin: 4px auto 14px; }
.item-icon.beat canvas { animation: beat 0.9s steps(2) infinite; }
.item-icon.mystery { border-style: dashed; border-color: #6a5aa8; }
@keyframes beat { 50% { transform: scale(1.15); } }
.item-name { margin: 0 0 10px; font-size: 12px; line-height: 1.6; color: var(--ink); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.rarity, .category { display: inline-block; font-size: 8px; padding: 4px 6px; line-height: 1.4; }
.rarity { color: #1a1020; background: linear-gradient(90deg, #ffd23f, #ff9a3d); }
.category { color: var(--ink); border: 1px solid var(--muted); }
.item-desc { margin: 0 0 12px; color: #d8d4ea; }
.stats { list-style: none; padding: 0; margin: 0; font-size: 9px; }
.stats li { display: flex; gap: 6px; align-items: baseline; }
.stats .dots { flex: 1; border-bottom: 2px dotted #4a4a80; transform: translateY(-4px); }
.stats b { color: var(--ok); font-weight: normal; }

.letter { white-space: pre-line; margin: 0; min-height: 4em; }
.letter:not(.tw-done)::after, .clue p:not(.tw-done)::after { content: '▌'; animation: blink 0.6s steps(2) infinite; }
.letter.tw-done::after { content: ' ▼'; color: var(--accent); animation: blink 0.8s steps(2) infinite; }
.signature { text-align: right; color: var(--pink); margin: 14px 0 0; }
.clue { border: 2px dashed var(--accent); padding: 14px; background: rgba(255, 210, 63, 0.06); }
.clue p { margin: 0; white-space: pre-line; }
.hint { color: var(--muted); font-size: 8px; margin: 12px 0 0; text-align: center; }
.postcard, .center { text-align: center; }
.bonus { text-align: center; color: var(--ok); font-size: 9px; margin: 14px 0 0; }

/* ── Impostazioni ────────────────────────────────── */
.set-window { max-width: 460px; font-size: 10px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 2px dotted #2e2e60; }
.set-status { font-size: 9px; padding: 4px 6px; border: 2px solid currentColor; }
.set-status--on { color: var(--ok); }
.set-status--off { color: #ff6b6b; }
.set-sep { margin-top: 22px; display: flex; justify-content: center; }
.set-title { color: var(--accent); margin: 6px 0 12px; font-size: 11px; }
.set-text { white-space: pre-line; line-height: 2; color: #d8d4ea; margin: 0 0 16px; }
.set-code { display: flex; gap: 10px; margin-bottom: 8px; }
.set-code input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; letter-spacing: 6px; text-align: center;
  color: var(--ink); background: #070718; border: 2px solid var(--ink); padding: 10px;
}
.set-err { color: #ff6b6b; font-size: 9px; min-height: 1.6em; margin: 4px 0 14px; }
.set-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.set-dev { margin-top: 18px; padding: 14px; border: 2px dashed var(--cyan); }
.set-select { font: inherit; font-size: 9px; color: var(--ink); background: #070718; border: 2px solid var(--ink); padding: 8px; }

/* ── Mini-giochi ─────────────────────────────────── */
.gm-window { max-width: 560px; }
.gm-hud { flex: 1; text-align: right; font-size: 10px; color: var(--accent); white-space: nowrap; }
.gm-stage { display: grid; place-items: center; min-height: 320px; }
.gm-canvas {
  display: block; width: 100%; max-width: 480px; max-height: 64dvh;
  object-fit: contain; image-rendering: pixelated; touch-action: none; user-select: none;
  border: 2px solid #000; box-shadow: 0 0 0 2px var(--win-inner);
}
.gm-screen { text-align: center; font-size: 10px; line-height: 2; padding: 10px 4px; }
.gm-lock { color: var(--accent); margin: 0 0 12px; }
.gm-how { white-space: pre-line; margin: 0 0 14px; color: #d8d4ea; }
.gm-assist { color: #ff9ac0; font-size: 9px; margin: 0 0 14px; }
.gm-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.gm-big { font-size: 20px; line-height: 1.4; margin: 6px 0 14px; color: var(--accent); text-shadow: 3px 3px 0 #3a1a5a; }
.gm-big--ko { color: var(--red); animation: blink 0.9s steps(2) 3; }
.gm-stars { color: var(--accent); font-size: 18px; margin: 0 0 10px; animation: blink 0.5s steps(2) 4; }

.simon { width: 100%; display: grid; place-items: center; gap: 12px; }
.simon-tree {
  position: relative; width: min(280px, 72vw); aspect-ratio: 1 / 1.1;
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 18% 1fr 1fr 10%;
  gap: 8px; padding: 0 12%;
}
.simon-tree::before { content: ''; position: absolute; inset: 6% 0 10% 0; background: #1f5a3a; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.simon-star { grid-column: 1 / 3; grid-row: 1; justify-self: center; position: relative; color: var(--accent); font-size: 26px; line-height: 1; }
.simon-trunk { grid-column: 1 / 3; grid-row: 4; justify-self: center; width: 18%; background: #5a3a22; position: relative; }
.simon-btn {
  position: relative; border: 3px solid #000; border-radius: 50%; cursor: pointer;
  background: color-mix(in srgb, var(--c) 35%, #10102a); box-shadow: inset -4px -4px 0 rgba(0,0,0,.35), 3px 3px 0 #000;
  width: 70%; aspect-ratio: 1; justify-self: center; align-self: center;
}
.simon-btn--0 { grid-row: 2; grid-column: 1; }
.simon-btn--1 { grid-row: 2; grid-column: 2; }
.simon-btn--2 { grid-row: 3; grid-column: 1; }
.simon-btn--3 { grid-row: 3; grid-column: 2; }
.simon-btn.lit { background: var(--c); box-shadow: 0 0 0 4px #fff, 0 0 24px var(--c); }
.simon-status { font-size: 10px; margin: 0; min-height: 1.6em; }

.memory { display: grid; gap: 8px; width: 100%; max-width: 460px; }
.mem-card {
  aspect-ratio: 1; padding: 0; border: 2px solid #000; border-radius: 3px; cursor: pointer;
  background: #8e2b36; box-shadow: inset 0 0 0 2px rgba(255,255,255,.16), 3px 3px 0 #000;
  display: grid; place-items: center; font: inherit; color: #fff;
}
.mem-card:nth-child(even) { background: var(--green); }
.mem-card canvas { width: 70%; height: 70%; image-rendering: pixelated; display: none; }
.mem-card .mem-back { font-size: 14px; color: rgba(255,255,255,.55); }
.mem-card.up { background: #070718 !important; }
.mem-card.up canvas { display: block; }
.mem-card.up .mem-back { display: none; }
.mem-card.matched { box-shadow: 0 0 0 2px var(--accent), 3px 3px 0 #000; }

.quiz { width: 100%; }
.quiz-q { font-size: 11px; line-height: 2; margin: 0 0 16px; text-align: center; white-space: pre-line; }
.quiz-answers { display: grid; gap: 10px; }
.quiz-btn {
  font: inherit; font-size: 10px; line-height: 1.7; text-align: left; color: var(--ink);
  background: #1b1b3e; border: 2px solid var(--ink); padding: 10px 12px; cursor: pointer; box-shadow: 3px 3px 0 #000;
}
.quiz-btn::before { content: '▶ '; color: var(--accent); }
.quiz-btn.ok { background: #1f6b3a; border-color: var(--ok); }
.quiz-btn.ko { background: #4a1420; border-color: #ff6b6b; color: #c98a94; text-decoration: line-through; cursor: not-allowed; }

/* ── Effetto CRT ─────────────────────────────────── */
.crt { display: none; position: fixed; inset: 0; z-index: 100; pointer-events: none; }
body.crt-on .crt { display: block; }
.crt::before { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.22) 2px 3px); }
.crt::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.5) 100%); animation: flicker 4s infinite steps(1); }
body.crt-on #game { filter: contrast(1.08) saturate(1.15); }
@keyframes flicker { 0%, 100% { opacity: 1; } 47% { opacity: 0.92; } 48% { opacity: 1; } }

/* ── Telefono ────────────────────────────────────── */
@media (max-width: 600px) {
  #hud { padding: 10px 12px; }
  .brand { gap: 10px; }
  .brand-title { display: none; }
  .place { font-size: 9px; padding: 6px 8px; }
  #actions { padding: 12px 12px 16px; }
  .px--main { font-size: 11px; padding: 14px 16px; width: 100%; }
  .window { padding: 14px; }
  .cal-grid { gap: 7px; grid-template-columns: repeat(4, 1fr); }
  .door { font-size: 11px; gap: 4px; }
  .dlg-body { font-size: 9px; }
  .item-card { flex-direction: column; text-align: center; }
  .tags { justify-content: center; }
  .gm-hud { font-size: 8px; }
  .gm-stage { min-height: 260px; }
  .gm-big { font-size: 16px; }
}

/* telefono in verticale: scena e pulsante raggruppati al centro */
@media (max-aspect-ratio: 3/4) {
  #app { justify-content: center; gap: 6px; }
  #hud { position: absolute; top: env(safe-area-inset-top); left: 0; right: 0; }
  #stage-wrap { flex: 0 0 auto; height: auto; padding: 0 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}

/* ── Casella del calendario vero ─────────────────── */
.box-door {
  width: 120px; margin: 6px auto 18px; padding: 14px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: #8e2b36; border: 3px solid #000; border-radius: 4px;
  box-shadow: inset 0 0 0 3px #ffd23f, inset 0 0 0 6px #8e2b36, inset 0 0 0 7px rgba(255,255,255,.2), 5px 5px 0 #000;
  animation: glow 0.9s steps(2) infinite;
}
.box-label { font-size: 8px; color: #ffd23f; letter-spacing: 2px; }
.box-num { font-size: 34px; color: #fff; text-shadow: 3px 3px 0 #3a0a14; }

/* ── Croce direzionale dei giochi ────────────────── */
.gm-stage { gap: 12px; }
.dpad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 42px); gap: 6px; justify-content: center; }
.dpad-btn {
  font: inherit; font-size: 14px; color: var(--ink); background: #1b1b3e;
  border: 2px solid var(--ink); box-shadow: 3px 3px 0 #000; cursor: pointer; touch-action: none;
}
.dpad-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
@media (hover: hover) and (pointer: fine) { .dpad { display: none; } }


/* ── Istruzioni e comandi dei giochi ─────────────── */
.gm-rule { text-align: left; margin: 0 0 12px; padding: 10px 12px; border: 2px solid var(--win-inner); background: rgba(255,255,255,0.03); }
.gm-rule p { margin: 6px 0 0; line-height: 1.9; white-space: pre-line; color: #e8e4f4; }
.gm-rule-k { font-size: 8px; color: var(--accent); letter-spacing: 1px; }
.gm-other { font-size: 8px; color: var(--muted); margin: 0 0 6px; line-height: 1.8; }
.hold-bar { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.hold-btn {
  font: inherit; font-size: 16px; min-width: 54px; height: 48px; color: var(--ink); background: #1b1b3e;
  border: 2px solid var(--ink); box-shadow: 3px 3px 0 #000; cursor: pointer; touch-action: none; user-select: none;
}
.hold-btn.on { background: var(--red); transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.hold-bar--lanes .hold-btn { min-width: 30%; height: 56px; }
.hold-bar--lanes .hold-btn:nth-child(1) { border-color: #ff4a5a; }
.hold-bar--lanes .hold-btn:nth-child(2) { border-color: #3fe07a; }
.hold-bar--lanes .hold-btn:nth-child(3) { border-color: #4aa8ff; }
/* su computer i pulsanti a schermo restano piccoli; su telefono la croce è sempre visibile */
@media (hover: hover) and (pointer: fine) { .hold-btn { height: 34px; min-width: 40px; font-size: 12px; } }
@media (pointer: coarse) {
  .dpad { display: grid !important; }
  .gm-canvas { max-height: 50dvh; }
  .gm-window { padding: 10px; }
  .gm-stage { gap: 10px; }
}

.hold-bar--lanes { width: 100%; flex-wrap: nowrap; }
.hold-bar--lanes .hold-btn { flex: 1; min-width: 0; }

/* ── Salta, conferma e barre dei comandi ─────────── */
.gm-window { position: relative; }
.px--skip { margin-left: auto; background: transparent; border-style: dashed; color: var(--muted); border-color: var(--muted); box-shadow: none; }
.px--skip:hover { color: var(--ink); border-color: var(--ink); background: transparent; }
.px--skip[hidden] { display: none; }
.gm-confirm { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(4, 4, 14, 0.82); padding: 16px; }
.gm-confirm-panel { text-align: center; font-size: 10px; line-height: 2; padding: 18px; background: var(--win); border: 3px solid var(--ink); box-shadow: 0 0 0 3px #000; max-width: 360px; }
.gm-ask { white-space: pre-line; color: var(--accent); font-size: 9px; line-height: 2; margin: 6px 0 0; }
.hold-bar--hint { margin-top: 2px; }
.hint-chip { font-size: 9px; color: var(--accent); border: 2px dashed var(--accent); padding: 8px 12px; line-height: 1.6; text-align: center; }
.dpad { display: grid !important; }
.hold-bar--simon .hold-btn { font-size: 22px; min-width: 56px; }
.hold-bar--simon .hold-btn:nth-child(1) { color: #ff4a5a; border-color: #ff4a5a; }
.hold-bar--simon .hold-btn:nth-child(2) { color: #3fe07a; border-color: #3fe07a; }
.hold-bar--simon .hold-btn:nth-child(3) { color: #ffd23f; border-color: #ffd23f; }
.hold-bar--simon .hold-btn:nth-child(4) { color: #4aa8ff; border-color: #4aa8ff; }

/* pulsante per chiamarlo, in alto a sinistra sulla scena */
.call-btn {
  display: inline-flex; align-items: center; gap: 8px; margin: 0;
  font: inherit; font-size: 12px; color: #14142a; cursor: pointer;
  background: var(--accent); border: 2px solid #fff4c0; padding: 8px 10px;
  box-shadow: 0 3px 0 #8a6a10, 0 0 0 2px #14142a;
  animation: callPulse 1.6s ease-in-out infinite;
}
.call-btn:hover { filter: brightness(1.08); }
.call-btn--decode { background: #3fe07a; box-shadow: 0 3px 0 #1a6a3a, 0 0 0 2px #14142a; }
.call-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #8a6a10, 0 0 0 2px #14142a; }
.call-btn[hidden] { display: none; }
@keyframes callPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) { .call-btn { animation: none; } }

/* finestra introduttiva */
.intro-window { max-width: 520px; }
.intro-body { white-space: pre-line; min-height: 0; }

/* finale: il testo scorre, i pulsanti restano sotto */
.dlg-window .dlg-body { overflow-y: auto; min-height: 0; flex: 1 1 auto; }
.dlg-window .dlg-foot { flex: 0 0 auto; }
body.in-finale #dialog .window { max-height: 60dvh; display: flex; flex-direction: column; overflow: hidden; }
body.in-finale #dialog .dlg-body { min-height: 0; }

/* attesa prima del 1° dicembre */
.teaser-label, .teaser-date { margin: 14px 0 6px; text-align: center; font-size: 9px; letter-spacing: 2px; color: var(--accent); }
.teaser-date { margin: 8px 0 14px; color: #7fd6ff; }
.teaser-count { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.teaser-count span { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 64px; padding: 10px 6px;
  background: #14142a; border: 2px solid #3a3a6a; font-size: 8px; color: #b8c0e0; }
.teaser-count b { font-size: 20px; color: #fff; font-weight: normal; }
@media (max-width: 520px) { .teaser-count span { min-width: 54px; } .teaser-count b { font-size: 16px; } }

/* accesso con codice */
.gate { z-index: 100; background: radial-gradient(ellipse at center, #1a1a40 0%, #05050c 75%); opacity: 1; transition: opacity .4s; }
.gate.gate--open { opacity: 0; pointer-events: none; }
.gate-window { max-width: 360px; width: calc(100% - 32px); text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.gate-pre { margin: 0; font-size: 8px; letter-spacing: 2px; color: var(--accent); }
.gate-label { font-size: 9px; line-height: 1.6; color: #b8c0e0; }
.gate-input { font: inherit; font-size: 22px; letter-spacing: 12px; text-align: center; padding: 12px 8px 12px 20px;
  background: #0a0a18; color: #fff; border: 2px solid #3a3a6a; outline: none; }
.gate-input:focus { border-color: var(--accent); }
.gate-msg { margin: 0; min-height: 12px; font-size: 9px; color: #ff6a7a; }
.gate-shake { animation: gateShake .35s; }
@keyframes gateShake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
body.is-gated .crt, body.is-gated #title { visibility: hidden; }

/* introduzione e attesa: pulsante a tutta larghezza */
.intro-window .dlg-foot { display: block; }
.intro-window .dlg-foot > span { display: none; }
.intro-window .dlg-foot .px { display: block; width: 100%; }

/* attesa e introduzione: sfondo pieno, la scena dietro non si vede */
#teaser, #intro { background: radial-gradient(ellipse at center, #1a1a40 0%, #05050c 75%); }
#teaser .window, #intro .window { background: #0e0e22; }

/* schermata iniziale: sfondo pieno, sotto non si vede niente */
#title { background: radial-gradient(ellipse at center, #1a1a40 0%, #05050c 75%); z-index: 30; }

/* oggetto per la prossima tappa */
.travel-card { display: flex; gap: 14px; align-items: center; margin-top: 16px; padding: 12px; border: 2px dashed var(--accent); background: #16163a; border-radius: 4px; animation: travelIn .5s ease-out .4s both; }
.travel-icon { flex: 0 0 auto; width: 60px; height: 60px; display: grid; place-items: center; background: #dfe4f4; border: 2px solid #8a8ab8; }
.travel-icon canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.travel-info { min-width: 0; }
.travel-kicker { margin: 0 0 6px; font-size: 8px; letter-spacing: 1px; color: var(--accent); }
.travel-name { margin: 0 0 6px; font-size: 11px; color: #fff; }
.travel-text { margin: 0 0 6px; font-size: 9px; line-height: 1.6; color: #b8c0e0; }
.travel-keep { margin: 0; font-size: 9px; line-height: 1.6; color: var(--ok); }
@keyframes travelIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .travel-card { animation: none; } }

/* icone allineate al testo nei pulsanti */
.px--icon, .title-press { display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.px--main.px--icon { display: flex; }
.g { display: inline-block; flex: 0 0 auto; width: .9em; height: .9em; background: currentColor; }
.g-play { clip-path: polygon(0 0, 100% 50%, 0 100%); width: .8em; }
.g-heart { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 6' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h2v1h1V0h2v1h1v2H6v1H5v1H4v1H3V5H2V4H1V3H0V1h1z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 6' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h2v1h1V0h2v1h1v2H6v1H5v1H4v1H3V5H2V4H1V3H0V1h1z'/%3E%3C/svg%3E") center / contain no-repeat; color: #ff5a7a; }
.g-phone { width: 1.2em; height: 1.2em; flex: 0 0 auto; image-rendering: pixelated; }
.title-logo-sub { font-size: .8em; color: var(--accent); }

/* telefono: testi più grandi, spazio verticale usato meglio */
@media (max-width: 700px) {
  .story { font-size: 12px; min-height: 76px; }
  .call-btn { font-size: 12px; padding: 9px 12px; }
  .place { font-size: 10px; }
  .dlg-body, .letter, .item-desc, .intro-body { font-size: 12px !important; line-height: 1.8; }
  .item-name { font-size: 13px; }
  .kicker { font-size: 10px; }
  .travel-text, .travel-keep { font-size: 11px; }
  .travel-name { font-size: 13px; }
  .main-msg { font-size: 11px; }
  .link-btn { font-size: 10px; }
  body.in-finale #dialog .window { max-height: 70dvh; }
}

/* telefono: il gioco occupa tutto lo schermo e i comandi sono grandi */
@media (pointer: coarse) {
  #games { padding: 0; }
  #games .gm-window { max-width: none; height: 100dvh; max-height: 100dvh; border-radius: 0; display: flex; flex-direction: column; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  #games .gm-stage { flex: 1; min-height: 0; align-content: center; gap: 14px; }
  #games .gm-canvas { max-height: 64dvh; }
  .dpad { grid-template-columns: repeat(3, 80px); grid-template-rows: repeat(2, 66px); gap: 10px; }
  .dpad-btn { font-size: 24px; }
  .hold-btn { height: 64px; min-width: 76px; font-size: 22px; }
  .hold-bar--lanes .hold-btn { height: 68px; }
  .hold-bar--simon .hold-btn { font-size: 30px; min-width: 70px; }
  .gm-hud { font-size: 10px; }
  .gm-rule p { font-size: 11px; }
  .hint-chip { font-size: 11px; }
}
body.in-finale #dialog .dlg-body { font-size: 12px; line-height: 1.9; }
.px--icon .g { margin-left: 2px; }
.px--icon .g-heart { width: 1.15em; height: 1em; }
.title-press .g-play { margin-right: 2px; }

/* filmato iniziale */
#stage { position: relative; }
#stage::after { content: ''; position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .42s ease; }
#stage.is-fading::after { opacity: 1; }
body.in-movie #actions { visibility: hidden; }
body.in-movie #btnCall { display: none; }
.movie-skip { background: #f4efe6; box-shadow: 0 3px 0 #8a8a9a, 0 0 0 2px #14142a; animation: none; }
.movie-skip[hidden] { display: none; }
.link-row { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; }
.link-btn[hidden] { display: none; }

.teaser-head { margin: 4px 0 14px; font-size: 16px; line-height: 1.4; color: var(--accent); }
.teaser-head[hidden] { display: none; }

/* la scena e le sue barre usano tutta la larghezza */
#stage-wrap > .stage-bar, #stage-wrap > .story { width: var(--stage-w, 100%); max-width: 100%; }
/* comandi dei giochi ancora più grandi sul telefono */
@media (pointer: coarse) {
  .dpad { grid-template-columns: repeat(3, 92px); grid-template-rows: repeat(2, 76px); gap: 10px; }
  .dpad-btn { font-size: 28px; }
  .hold-btn { height: 76px; min-width: 88px; font-size: 26px; }
  .hold-bar--lanes .hold-btn { height: 80px; }
  .hold-bar--simon .hold-btn { font-size: 34px; min-width: 76px; height: 76px; }
}
@media (pointer: coarse) and (max-width: 360px) {
  .dpad { grid-template-columns: repeat(3, 80px); grid-template-rows: repeat(2, 70px); }
}

/* ── Sala giochi ── */
.link-btn--arcade { color: var(--accent, #ffd23f); }
.arc-window { max-width: 460px; width: min(100%, 460px); max-height: 94dvh; overflow-y: auto; }
.arc-sub { margin: 0 0 12px; font-size: 13px; opacity: .85; text-align: center; }
.arc-list { display: grid; gap: 10px; }
.arc-card { display: grid; grid-template-columns: 44px 1fr; grid-template-rows: auto auto auto; column-gap: 10px; row-gap: 4px; text-align: left;
  background: #14143a; color: inherit; border: 2px solid #4a4a8a; padding: 12px; font: inherit; cursor: pointer; }
.arc-card:hover, .arc-card:focus-visible { border-color: #ffd23f; background: #1c1c4a; }
.arc-ico { grid-row: 1 / 4; font-size: 30px; align-self: center; text-align: center; }
.arc-name { font-family: 'Press Start 2P', monospace; font-size: 12px; color: #ffd23f; }
.arc-rec { font-size: 12px; color: #7fd6ff; }
.arc-delio { font-size: 11px; color: #c8c8e0; }
.arc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; }
.arc-score { font-family: 'Press Start 2P', monospace; font-size: 12px; color: #ffd23f; }
.arc-canvas { display: block; margin: 0 auto; width: min(100%, calc((94dvh - 190px) * 0.75)); aspect-ratio: 3 / 4; image-rendering: pixelated;
  border: 2px solid #4a4a8a; touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; }
.arc-help { font-size: 12px; opacity: .8; margin: 8px 0 0; text-align: center; line-height: 1.5; }
.arc-pad { margin-top: 10px; }
.arc-pad .hold-bar { flex-wrap: nowrap; }
.arc-pad .hold-btn { flex: 1; min-width: 0; }
.arc-ctl--nuvole .hold-btn { max-width: 45%; }
.arc-canvas { width: min(100%, calc((94dvh - 280px) * 0.75)); }
.arc-ctl .hold-btn { white-space: nowrap; font-size: 16px; }
@media (hover: hover) and (pointer: fine) { .arc-ctl .hold-btn { font-size: 12px; } }

/* casella da toccare quando è stata aperta */
.box-door--tap { width: 150px; cursor: pointer; font: inherit; color: inherit; animation: boxBlink 0.8s steps(2) infinite; margin-top: 14px; }
.box-door--tap:active { transform: translate(3px, 3px); box-shadow: inset 0 0 0 3px #ffd23f, 2px 2px 0 #000; }
.box-tap { font-size: 8px; color: #fff; line-height: 1.6; padding: 0 8px; text-align: center; }
@keyframes boxBlink { 0% { background: #8e2b36; } 50% { background: #d8364a; } }
#dlgReplay { margin-right: auto; }
#dialog .win-head { gap: 10px; }
.hold-btn:disabled { opacity: .35; filter: grayscale(1); pointer-events: none; }
.gm-levels { font-size: 10px; color: #7fd6ff; text-align: center; margin: 4px 0; line-height: 1.6; }

/* avviso stesso dispositivo / navigazione privata */
.device-note { font-size: 11px; line-height: 1.6; color: #c8d8ff; background: rgba(74,168,255,.1); border: 2px dashed #4a6aa8; padding: 8px 10px; margin: 10px 0 0; }
.device-note b { color: #ffd23f; font-weight: normal; }
.priv-warn { position: fixed; left: 8px; right: 8px; top: 8px; z-index: 300; display: flex; gap: 10px; align-items: center;
  background: #3a0a14; border: 3px solid #ff5a7a; box-shadow: 4px 4px 0 #000; padding: 10px 12px; color: #fff; font-size: 12px; line-height: 1.5; }
.priv-warn[hidden] { display: none; }
.priv-warn p { margin: 0; flex: 1; }
.mute-btn { font-size: 18px; margin-left: auto; margin-right: 8px; }
#hud .mute-btn + .icon-btn { margin-left: 0; }
.challenge { margin: 12px 0 4px; padding: 10px 12px; border: 2px dashed #ffd23f; background: rgba(255,210,63,.07); font-size: 12px; line-height: 1.6; }
.challenge p { margin: 0; }
.challenge b { color: #ffd23f; font-weight: normal; }
.challenge-k { color: #ffd23f; font-size: 10px; letter-spacing: 1px; margin-bottom: 4px !important; }
.challenge-ok { color: #3fe07a; margin-top: 4px !important; }
.challenge-rec { color: #7fd6ff; margin-top: 4px !important; }
.note-action { display: block; margin: 12px auto 0; }
.trip { list-style: none; margin: 8px 0; padding: 0; font-size: 10px; line-height: 1.5; }
.trip li { display: grid; grid-template-columns: 26px 1fr; column-gap: 8px; padding: 4px 0; border-bottom: 1px dashed #2a2a5a; opacity: .55; }
.trip li.trip-ok { opacity: 1; }
.trip-day { grid-row: 1 / 3; color: #ffd23f; font-size: 13px; text-align: right; }
.trip-place { color: #7fd6ff; }
.trip-gift { color: #fff; }
.trip-rec { margin: 12px 0; font-size: 11px; line-height: 1.6; }
.trip-rec p { margin: 2px 0; }

/* ── attesa: pulsanti grandi, segreti, guardaroba, letterina ── */
.fun-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; max-width: 560px; margin: 10px auto 4px; }
.fun-btn { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; font: inherit; font-size: 10px; letter-spacing: 1px; color: var(--ink, #fff);
  background: #1b1b3e; border: 3px solid #4a4a8a; box-shadow: 3px 3px 0 #000; cursor: pointer; }
.fun-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.fun-ico { font-size: 22px; line-height: 1; }
.fun-btn--arcade { border-color: #ff5a9a; color: #ffd23f; animation: funPulse 1.6s ease-in-out infinite; }
@keyframes funPulse { 50% { border-color: #4ae8ff; box-shadow: 3px 3px 0 #000, 0 0 12px rgba(255,90,154,.6); } }
.secret-chip { font-size: 11px; color: #ffd23f; background: #141020; border: 2px solid #ffd23f; padding: 4px 8px; margin-left: auto; margin-right: 6px; white-space: nowrap; }
.secret-chip[hidden] { display: none; }
.ward-window, .let-window { max-width: 460px; width: min(100%, 460px); max-height: 94dvh; overflow-y: auto; }
.ward-preview { display: block; margin: 4px auto 8px; width: 200px; height: 150px; image-rendering: pixelated; background: radial-gradient(#26305e, #121236); border: 2px solid #4a4a8a; }
.ward-msg { font-size: 12px; text-align: center; opacity: .85; line-height: 1.5; margin: 0 0 10px; }
.ward-list { display: grid; gap: 8px; }
.ward-item { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 10px 12px; font: inherit; font-size: 12px; color: inherit; background: #14143a; border: 2px solid #4a4a8a; cursor: pointer; }
.ward-item b { font-weight: normal; color: #ffd23f; }
.ward-item span { font-size: 11px; color: #7fd6ff; }
.ward-item--on { border-color: #3fe07a; background: #143a2a; }
.ward-item--on span { color: #3fe07a; }
.ward-item--locked { opacity: .55; cursor: default; }
.ward-item--locked b { color: #c8c8e0; }
.let-intro { font-size: 12px; line-height: 1.6; opacity: .9; margin: 0 0 10px; }
.let-text { width: 100%; box-sizing: border-box; font: 15px/1.6 'Courier New', monospace; color: #2a1a10; background: #fff8e6; border: 3px solid #c8a070; padding: 10px; resize: vertical; }
.let-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 10px; }
.let-count { font-size: 11px; opacity: .7; }
.trip-letter { margin: 12px 0; padding: 10px; border: 2px dashed #c8a070; background: rgba(255,248,230,.06); }
.let-helper { display: inline-block; margin-top: 6px; color: #ffd23f; font-size: 11px; }
/* caselle dei giorni senza regalo: diario e racconto di Natale */
.door--story-open { background: #6a5426 !important; color: #ffe9b0; }
.door--story .ico { font-size: 16px; line-height: 1; }
.story-when { font-size: 10px; color: #c8a070; margin: -4px 0 8px; letter-spacing: 1px; }
.postcard--story .letter { white-space: pre-line; }
