:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #111318;
  color: #f4f1e8;
  --bg: #111318;
  --panel: #191d25;
  --panel-2: #202631;
  --line: #343b48;
  --text: #f4f1e8;
  --muted: #aeb5c1;
  --accent: #ffcc4d;
  --cyan: #54d8c6;
  --red: #ff6b6b;
  --green: #86df6b;
  --blue: #6ba8ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}

html.light {
  color-scheme: light;
}

html.light body,
html.light .app-shell {
  background: #f0f2f8;
  color: #1a1e2e;
}

html.light {
  --bg: #f0f2f8;
  --panel: #e8eaf0;
  --panel-2: #dde0eb;
  --line: #c8ccd8;
  --text: #1a1e2e;
  --muted: #5a607a;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.10);
}

html.light body {
  background:
    linear-gradient(90deg, rgba(0,0,0,0.025) 1px, transparent 1px),
    linear-gradient(rgba(0,0,0,0.025) 1px, transparent 1px),
    var(--bg);
  background-size: 42px 42px, 42px 42px, auto;
}

html.light .topnav {
  background: rgba(220, 222, 232, 0.84);
}

html.light .status-strip span,
html.light .score-panel div {
  background: rgba(220, 222, 232, 0.92);
  box-shadow: 5px 5px 0 rgba(0,0,0,0.08);
}

html.light .brand-mark {
  box-shadow: 5px 5px 0 rgba(0,0,0,0.12);
}

html.light .game-art {
  background: #d8dce8;
}

html.light .game-meta span,
html.light .segmented-control,
html.light .stat-item {
  background: #dde0eb;
}

html.light .play-stage {
  background: #d0d4e0;
}

html.light .canvas-overlay {
  background: rgba(240,242,248,0.9);
}

html.light .control-panel {
  background: rgba(220,222,232,0.94);
}

/* Theme & sound toggle buttons in topbar */
#theme-toggle-arcade,
#sound-toggle-arcade {
  min-height: 40px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 12px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size:
    42px 42px,
    42px 42px,
    auto;
}

button {
  font: inherit;
}

main {
  min-width: 0;
}

.topnav,
.status-strip,
.score-panel,
.game-card {
  min-width: 0;
}

.game-info p,
.status-strip span {
  overflow-wrap: anywhere;
}

.app-shell {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 16px 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: 5px 5px 0 #000;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.1;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.topnav {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  background: rgba(25, 29, 37, 0.84);
}

.nav-button,
.back-button,
.primary-action,
.secondary-action,
.mobile-controls button {
  min-height: 40px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
}

.nav-button {
  min-width: 78px;
  padding: 0 14px;
}

.nav-button.is-active {
  color: #121212;
  background: var(--accent);
  border-color: var(--accent);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.home-heading,
.game-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 30px 0 22px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 5.1rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.game-header h1 {
  font-size: clamp(2rem, 5vw, 4rem);
}

.status-strip,
.score-panel {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.status-strip span,
.score-panel div {
  display: grid;
  min-width: 118px;
  min-height: 58px;
  align-content: center;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: rgba(25, 29, 37, 0.92);
  box-shadow: 5px 5px 0 #000;
}

.score-panel span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.score-panel strong {
  margin-top: 3px;
  font-size: 1.5rem;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.game-card {
  display: grid;
  grid-template-rows: 146px auto;
  min-height: 342px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.game-art {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #0f131c;
}

.game-art canvas {
  width: 100%;
  height: 100%;
}

.game-info {
  display: grid;
  align-content: space-between;
  gap: 14px;
  padding: 16px;
}

.game-info h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0;
}

.game-info p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.game-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.game-meta span {
  padding: 6px 8px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #151922;
  font-size: 0.76rem;
}

.play-card-button {
  width: 100%;
  min-height: 42px;
  border: 0;
  color: #111;
  background: var(--accent);
  font-weight: 900;
  cursor: pointer;
}

.play-card-button:disabled {
  color: var(--muted);
  background: #2d333f;
  cursor: not-allowed;
}

.back-button {
  min-width: 82px;
  padding: 0 14px;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 18px;
  align-items: start;
}

.play-stage {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 420px;
  border: 2px solid var(--stage-border, #3b82f6);   /* blu brand di default */
  background: #0b0e14;
  box-shadow: 0 0 0 1px var(--stage-border, #3b82f6),
              0 0 18px -2px var(--stage-glow, rgba(59, 130, 246, 0.45)),
              var(--shadow);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

/* Colore del bordo per gioco */
body[data-game="snake"] .play-stage {
  --stage-border: #ff4d4d;                    /* rosso per Snake */
  --stage-glow: rgba(255, 77, 77, 0.45);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-overlay {
  position: absolute;
  inset: auto 18px 18px 18px;
  display: none;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(17, 19, 24, 0.9);
}

.canvas-overlay.is-visible {
  display: grid;
}

.canvas-overlay strong {
  font-size: 1.1rem;
}

.canvas-overlay span {
  color: var(--muted);
}

.control-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(25, 29, 37, 0.94);
  box-shadow: var(--shadow);
}

.panel-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-action {
  color: #111;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 900;
}

.secondary-action {
  font-weight: 800;
}

.game-options.is-hidden {
  display: none;
}

.difficulty-panel {
  display: grid;
  gap: 8px;
}

.option-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  background: #151922;
}

.segmented-control button {
  min-width: 0;
  min-height: 38px;
  border: 1px solid transparent;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 800;
}

.segmented-control button.is-active {
  color: #111;
  border-color: var(--accent);
  background: var(--accent);
}

.stat-list {
  display: grid;
  gap: 8px;
}

.stat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #151922;
}

.stat-item span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-item strong {
  text-align: right;
}

/* Mobile start row: hidden on desktop, shown on mobile */
.mobile-start-row {
  display: none;
  gap: 10px;
  margin-bottom: 10px;
}

/* Fullscreen button */
.fullscreen-button {
  min-height: 40px;
  min-width: 44px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fullscreen-button:hover {
  background: var(--panel);
}

/* Desktop fullscreen button inside score-panel */
.desktop-fs {
  min-width: 44px;
  min-height: 58px;
  border: 1px solid var(--line);
  background: rgba(25, 29, 37, 0.92);
  box-shadow: 5px 5px 0 #000;
  font-size: 1.2rem;
}

/* D-pad mobile controls: hidden on desktop */
.mobile-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 20px;
  background: rgba(17, 19, 24, 0.96);
  border-top: 1px solid var(--line);
  gap: 24px;
  touch-action: none;
  user-select: none;
}

/* Giochi senza tasto azione (Snake, PacMaze): d-pad centrato, area azione nascosta */
.mobile-controls.no-action {
  justify-content: center;
}
.mobile-controls.no-action .action-area {
  display: none;
}

.dpad-area {
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad {
  display: grid;
  grid-template-rows: auto auto auto;
  align-items: center;
  justify-items: center;
  gap: 4px;
}

.dpad-middle-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dpad-center {
  width: 47px;
  height: 47px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;   /* inerte di default (decorativo) */
  cursor: default;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Attivo solo in Tetris: diventa il tasto soft-drop */
.dpad-center.is-active {
  pointer-events: auto;
  cursor: pointer;
  color: var(--accent);
  border-color: var(--accent);
  transition: transform 0.06s ease, opacity 0.06s ease;
}

.dpad-center.is-active:active,
.dpad-center.is-active.pressed {
  transform: scale(0.9);
  opacity: 0.7;
  background: var(--accent);
  color: #111;
}

.dpad-btn {
  width: 58px;
  height: 58px;
  min-height: unset;
  border: 2px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 1.26rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease, opacity 0.06s ease;
}

.dpad-btn:active,
.dpad-btn.pressed {
  transform: scale(0.9);
  opacity: 0.7;
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

.action-area {
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-btn {
  width: 80px;
  height: 80px;
  min-height: unset;
  border: 3px solid var(--accent);
  color: var(--accent);
  background: rgba(255, 204, 77, 0.12);
  cursor: pointer;
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease, opacity 0.06s ease;
}

.action-btn:active,
.action-btn.pressed {
  transform: scale(0.88);
  opacity: 0.7;
  background: var(--accent);
  color: #111;
}

@media (max-width: 980px) {
  .game-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  /* App shell */
  .app-shell {
    padding: 8px 8px 0;
  }

  /* Topbar: shrink */
  .topbar {
    min-height: 52px;
    gap: 8px;
  }

  .brand strong {
    font-size: 0.95rem;
  }

  .brand small {
    display: none;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 0.8rem;
  }

  .topnav {
    gap: 4px;
    padding: 4px;
  }

  .nav-button {
    min-width: 0;
    padding: 0 8px;
    font-size: 0.72rem;
  }

  #theme-toggle-arcade,
  #sound-toggle-arcade {
    padding: 0 8px;
    min-height: 36px;
    font-size: 0.85rem;
  }

  /* Game header: compact, stack vertically */
  .game-header {
    margin: 12px 0 10px;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  .game-header h1 {
    font-size: 1.6rem;
  }

  .game-title-block {
    flex: 1;
    min-width: 0;
  }

  .score-panel {
    gap: 6px;
  }

  .score-panel div {
    min-width: 78px;
    min-height: 44px;
    padding: 6px 10px;
  }

  .score-panel strong {
    font-size: 1.1rem;
  }

  /* Desktop fullscreen button: hide, mobile one is used instead */
  .desktop-fs {
    display: none;
  }

  /* Mobile start row: show */
  .mobile-start-row {
    display: flex;
    align-items: center;
  }

  .mobile-start-row .primary-action,
  .mobile-start-row .secondary-action {
    flex: 1;
  }

  /* Play layout: column */
  .play-layout {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  /* Canvas: full width, max 360px, centered */
  .play-stage {
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
    min-height: auto;
    aspect-ratio: 1 / 1;
  }

  #gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
  }

  /* Control panel: hidden on mobile (start/pause migrated above) */
  .control-panel {
    display: none;
  }

  /* D-pad: visible on mobile */
  .mobile-controls {
    display: flex;
    position: sticky;
    bottom: 0;
    z-index: 10;
    width: 100%;
    margin: 0 -8px;
    width: calc(100% + 16px);
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: 100%;
    max-width: 100%;
    padding: 8px 8px 0;
  }

  .topbar,
  .home-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .topnav,
  .status-strip,
  .score-panel {
    width: 100%;
  }

  .topnav {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .nav-button {
    padding: 0 5px;
    font-size: 0.72rem;
  }

  .status-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-button,
  .status-strip span,
  .score-panel div {
    flex: 1;
    min-width: 0;
  }

  .status-strip span {
    font-size: 0.9rem;
  }

  .game-grid {
    grid-template-columns: 1fr;
  }

  .play-stage {
    min-height: auto;
  }
}

/* iOS: il fullscreen via web non funziona per il canvas → nascondi il tasto */
html.is-ios .fullscreen-button { display: none !important; }

/* Pulsante Mancino/Destrorso (nella start-row, solo mobile) */
.hand-toggle,
.sound-toggle-game {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Hand-toggle: nascosto nei giochi senza tasto azione (Snake, PacMaze).
   La classe .no-action-game viene aggiunta al body da updateActionButton()
   quando non c'è il tasto azione → d-pad al centro, toggle nascosto. */
body.no-action-game .hand-toggle { display: none; }

/* Il tasto audio in vista gioco: nascosto di default (desktop lo vede già
   in topbar). Appare quando si sta giocando su qualsiasi schermo mobile,
   sia portrait (max-width:768px) sia landscape (spesso >768px su iPhone). */
.sound-toggle-game { display: none; }
body.playing .sound-toggle-game {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* Su desktop la topbar è sempre visibile → nascondi il doppione in-game */
@media (min-width: 769px) {
  body.playing .sound-toggle-game { display: none; }
}

/* ── Mirroring MANCINO (html.lefty) ──────────────────────────────────────────
   Portrait: inverto l'ordine flex dei controlli (d-pad a destra, azione a sx). */
html.lefty body.playing .mobile-controls {
  flex-direction: row-reverse;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE GAME VIEW — layout a viewport fisso (100dvh), canvas sempre intero
   Attivo solo quando si sta giocando (body.playing) su schermi piccoli.
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Niente scroll di pagina durante il gioco */
  body.playing {
    overflow: hidden;
  }

  /* Topbar nascosta in gioco: il pulsante "Back" riporta al menu */
  body.playing .topbar {
    display: none;
  }

  body.playing .app-shell {
    padding: 0;
  }

  /* Vista di gioco ANCORATA al viewport: niente scroll, niente taglio.
     svh = small viewport height (barre browser visibili) → fit garantito
     su Chrome iOS e Safari, dove dvh era instabile. */
  body.playing #gameView.is-active {
    position: fixed;
    inset: 0;
    height: 100vh;   /* fallback */
    height: 100svh;  /* moderni: altezza minima sicura */
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: calc(env(safe-area-inset-top, 0px) + 8px) 8px calc(env(safe-area-inset-bottom, 0px) + 8px);
    box-sizing: border-box;
    overflow: hidden;
    background: var(--bg);
  }

  /* Header e controlli: altezza fissa, non si comprimono */
  body.playing .game-header,
  body.playing .mobile-start-row,
  body.playing .mobile-controls {
    flex: 0 0 auto;
    margin: 0;
  }

  /* Header di gioco: riga compatta [← Menu] [Titolo] [Score] */
  body.playing .game-header {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  /* Back button ben visibile e toccabile */
  body.playing .back-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 9px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line);
  }

  /* Riduci l'eyebrow per guadagnare spazio */
  body.playing .game-header .eyebrow {
    display: none;
  }
  body.playing .game-title-block {
    flex: 1 1 auto;
    min-width: 0;
    text-align: center;
  }
  body.playing .game-header h1 {
    font-size: 1.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Score panel compatto: nascondi "Best" su schermi molto stretti */
  body.playing .score-panel {
    flex: 0 0 auto;
  }

  /* Area di gioco: occupa TUTTO lo spazio centrale rimasto e centra il canvas */
  body.playing .play-layout {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
  }

  /* Il canvas resta quadrato e si adatta al minore tra larghezza e altezza
     disponibili → sempre interamente visibile, senza tagli */
  body.playing .play-stage {
    aspect-ratio: 1 / 1;
    width: auto;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    min-height: 0;
    margin: 0 auto;
  }

  body.playing .control-panel {
    display: none;
  }

  /* D-pad compatto in fondo */
  body.playing .mobile-controls {
    width: 100%;
    margin: 0;
    padding-top: 4px;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE GAME VIEW — LANDSCAPE ("gamepad": d-pad SX, canvas centro, azione DX)
   Telefono in orizzontale = poca altezza. Controlli ai lati, canvas al centro.
   ═══════════════════════════════════════════════════════════════════════════ */
@media (orientation: landscape) and (max-height: 600px) {
  body.playing { overflow: hidden; }
  body.playing .topbar { display: none; }
  body.playing .control-panel { display: none; }
  body.playing .mobile-controls { display: contents; }  /* dpad/azione posizionati ai lati */

  body.playing #gameView.is-active {
    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100svh;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: calc(env(safe-area-inset-top, 0px) + 6px)
             max(8px, env(safe-area-inset-right, 0px))
             calc(env(safe-area-inset-bottom, 0px) + 6px)
             max(8px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
    overflow: hidden;
    background: var(--bg);
  }

  /* Header → solo Menu (alto-sx) + score (alto-dx), titolo nascosto.
     Assoluto: non occupa altezza, sta negli angoli (fuori dal canvas centrale). */
  body.playing .game-header {
    position: absolute;
    top: max(6px, env(safe-area-inset-top, 0px));
    left: max(8px, env(safe-area-inset-left, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
    margin: 0;
    z-index: 50;
    pointer-events: none;  /* il container non blocca; i figli riattivano */
  }
  body.playing .game-header .back-button,
  body.playing .game-header .score-panel { pointer-events: auto; }
  body.playing .game-header .game-title-block { display: none; }
  body.playing .score-panel { gap: 6px; }
  body.playing .score-panel div { min-width: 50px; min-height: 30px; padding: 2px 7px; }
  body.playing .score-panel span { font-size: 0.6rem; }
  body.playing .score-panel strong { font-size: 0.85rem; margin-top: 1px; }

  /* Start/Pause/⛶ → angolo in basso a sinistra (nel gutter, sotto il d-pad) */
  body.playing .mobile-start-row {
    position: absolute;
    left: max(8px, env(safe-area-inset-left, 0px));
    bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
    z-index: 50;
    gap: 6px;
    justify-content: flex-start;
    width: auto;
  }
  body.playing .mobile-start-row .primary-action,
  body.playing .mobile-start-row .secondary-action {
    flex: 0 0 auto;
    min-height: 30px;
    padding: 0 12px;
    font-size: 0.78rem;
  }
  body.playing .mobile-start-row .fullscreen-button { min-height: 30px; width: 34px; }
  body.playing .mobile-start-row .hand-toggle,
  body.playing .mobile-start-row .sound-toggle-game { min-height: 30px; padding: 0 8px; font-size: 0.75rem; }

  /* I controlli escono dal flusso e si posizionano ai lati, centrati in verticale */
  body.playing .mobile-controls { display: contents; }
  body.playing .dpad-area {
    position: fixed;
    left: max(10px, env(safe-area-inset-left, 0px));
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
  }
  body.playing .action-area {
    position: fixed;
    right: max(14px, env(safe-area-inset-right, 0px));
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
  }
  body.playing.no-action .action-area,
  body.playing .mobile-controls.no-action .action-area { display: none; }

  /* Canvas: usa TUTTA l'altezza disponibile; gutter laterali per i controlli.
     Header (angoli) e start-row (angolo basso-sx) sono assoluti → non rubano altezza. */
  body.playing .play-layout {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 118px 4px 196px;
  }
  body.playing .play-stage {
    aspect-ratio: 1 / 1;
    height: 100%;
    width: auto;
    max-width: 100%;
    max-height: 100%;
    margin: 0 auto;
  }

  /* MANCINO in landscape: d-pad a destra, azione a sinistra, gutter specchiati */
  html.lefty body.playing .dpad-area {
    left: auto;
    right: max(10px, env(safe-area-inset-right, 0px));
  }
  html.lefty body.playing .action-area {
    right: auto;
    left: max(14px, env(safe-area-inset-left, 0px));
  }
  html.lefty body.playing .play-layout {
    padding: 4px 196px 4px 118px;   /* gutter ampio ora a destra (d-pad) */
  }
  html.lefty body.playing .mobile-start-row {
    left: auto;
    right: max(8px, env(safe-area-inset-right, 0px));
    justify-content: flex-end;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SITE FOOTER + COOKIE BANNER
   ═══════════════════════════════════════════════════════════════════════════ */
.site-footer {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 16px calc(env(safe-area-inset-bottom, 0px) + 28px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

.footer-contact {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}
.footer-contact:hover {
  text-decoration: underline;
}

.footer-copy {
  color: var(--muted);
}

/* Hide the footer while a game is being played (keeps 100dvh layout intact) */
body.playing .site-footer {
  display: none;
}

.cookie-banner {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 1000;
  width: calc(100% - 24px);
  max-width: 720px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.85rem;
}
.cookie-banner[hidden] {
  display: none;
}
.cookie-text {
  flex: 1 1 240px;
  color: var(--muted);
  line-height: 1.4;
}
.cookie-accept {
  flex: 0 0 auto;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #111318;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 9px;
  cursor: pointer;
}
.cookie-accept:hover {
  filter: brightness(1.06);
}

@media (max-width: 480px) {
  .cookie-banner {
    flex-direction: column;
    align-items: stretch;
  }
  .cookie-accept {
    width: 100%;
  }
}
