/* Nibbler - styles.css
   Look da sala giochi e layout guidato dallo spazio disponibile: la
   dimensione del tabellone arriva da --board, calcolata da js/layout.js
   in base al viewport, alla safe-area e alla scala di degrado.            */

:root {
  --bg: #05070f;
  --bg-2: #0a1122;
  --panel: rgba(12, 20, 38, 0.72);
  --panel-solid: #0d1730;
  --line: rgba(120, 170, 255, 0.22);
  --text: #dbe9ff;
  --muted: #8aa2c8;
  --accent: #7ef9ff;
  --accent-2: #ffd76a;
  --good: #6ef2a4;
  --bad: #ff6b81;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
  --gap: 8px;
  --board: min(100%, 420px);   /* valore di partenza: poi lo calcola js/layout.js */
  --pad-btn: 62px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 700px at 50% -10%, #16264a 0%, transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  font-family: "Consolas", "SFMono-Regular", "Menlo", "DejaVu Sans Mono", monospace;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* solo se nemmeno il layout minimo entra (schermi estremamente bassi) */
body.needs-scroll { overflow-y: auto; align-items: flex-start; }

.mono { font-variant-numeric: tabular-nums; }

/* ------------------------------- struttura ------------------------------- */
.app {
  width: min(100%, 720px);
  height: 100dvh;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-content: center;
  gap: var(--gap);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  touch-action: manipulation;
}

.app.compact { --gap: 6px; }
.app.pad-full { --pad-btn: 62px; }
.app.pad-mid { --pad-btn: 56px; }
.app.pad-small { --pad-btn: 52px; }
.app.pad-tiny { --pad-btn: 48px; }

/* --------------------------------- HUD --------------------------------- */
.hud {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.hud-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.value {
  font-size: clamp(15px, 3.6vw, 22px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  text-shadow: 0 0 12px rgba(126, 249, 255, 0.35);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lives { display: flex; gap: 5px; align-items: center; }

.life {
  width: clamp(9px, 2.4vw, 13px);
  height: clamp(9px, 2.4vw, 13px);
  border-radius: 3px;
  background: linear-gradient(180deg, var(--accent), #2f8bd8);
  box-shadow: 0 0 10px rgba(126, 249, 255, 0.65);
  display: inline-block;
}

.hud-actions { display: flex; gap: 6px; align-items: center; }

.btn {
  font-family: inherit;
  padding: 8px 14px;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
  border-radius: 12px;
  touch-action: manipulation;
}

.btn-icon[hidden] { display: none; }
.btn-icon.off { color: var(--bad); border-color: rgba(255, 107, 129, 0.55); }

.demo-badge {
  position: absolute;
  top: -9px;
  right: 12px;
  padding: 2px 8px;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #04121f;
  background: var(--accent-2);
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.demo-badge.visible { opacity: 1; }

/* HUD compatto: una sola riga per schermi piccoli */
.app.compact .hud {
  grid-template-columns: auto auto auto auto auto auto;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 8px;
}

.app.compact .hud-cell { flex-direction: row; align-items: baseline; gap: 4px; }
.app.compact .label { display: none; }
.app.compact .hud-cell.record { display: none; }
.app.compact .value { font-size: 14px; text-shadow: none; }
.app.compact .life { width: 9px; height: 9px; border-radius: 2px; }
.app.compact .hud-actions .btn-icon { width: 30px; height: 30px; border-radius: 10px; }
.app.compact .demo-badge { top: -8px; right: 8px; font-size: 9px; }

/* ------------------------------- tabellone ------------------------------- */
.stage {
  position: relative;
  flex: 0 0 auto;
  width: var(--board);
  height: var(--board);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #04070f;
  box-shadow: var(--shadow), inset 0 0 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  touch-action: none;
}

#board { display: block; width: 100%; height: 100%; }

.scanlines,
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scanlines {
  background: repeating-linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.045) 0px,
    rgba(255, 255, 255, 0.045) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
  opacity: 0.7;
}

.vignette {
  background: radial-gradient(120% 100% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.65) 100%);
}

/* modo leggero: via gli effetti che costano compositing */
.app.lite .scanlines,
.app.lite .vignette { display: none; }

/* -------------------------------- overlay -------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  text-align: center;
}

.overlay.visible { display: flex; }
.overlay.dim { background: rgba(4, 7, 16, 0.55); }

.card {
  max-width: 460px;
  width: 100%;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: clamp(12px, 3vw, 26px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: pop 0.28s ease-out;
}

.card-small { max-width: 380px; }

@keyframes pop {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.logo {
  margin: 0 0 6px;
  font-size: clamp(26px, 9vw, 52px);
  letter-spacing: 0.14em;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(126, 249, 255, 0.55), 0 0 40px rgba(47, 139, 216, 0.45);
}

.card h2 {
  margin: 0 0 8px;
  font-size: clamp(18px, 5.5vw, 30px);
  letter-spacing: 0.1em;
}

.card h2.over { color: var(--bad); text-shadow: 0 0 20px rgba(255, 107, 129, 0.5); }

.tagline { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.stats { margin: 0; color: var(--accent-2); font-size: 13px; letter-spacing: 0.06em; }
.big { margin: 6px 0 10px; font-size: clamp(18px, 4.6vw, 24px); }
.hintline { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

.cta {
  display: block;
  width: 100%;
  margin: 4px 0 12px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: clamp(12px, 3.2vw, 15px);
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #04121f;
  background: linear-gradient(180deg, var(--accent), #35b6e8);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(126, 249, 255, 0.4);
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

.cta:hover { filter: brightness(1.08); }

.keys {
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}

.keys b { color: var(--text); }

.settings-inline { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
}

.settings-grid label { display: flex; flex-direction: column; gap: 4px; }
.settings-grid label.check { flex-direction: row; align-items: center; gap: 8px; }

.settings-grid select {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
}
/* ------------------------------- barre stato ------------------------------- */
.status {
  display: grid;
  grid-template-columns: 1.6fr 0.8fr 1.2fr;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.gauge-cell { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.dots-cell { align-items: center; }

.gauge {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.gauge > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #4ad6a8);
  box-shadow: 0 0 14px rgba(126, 249, 255, 0.5);
  transition: width 0.12s linear;
}

.gauge > i.low { background: linear-gradient(90deg, #ff8a5c, var(--bad)); }
.gauge.speed > i { background: linear-gradient(90deg, var(--accent-2), var(--bad)); }
.gauge > i.off { box-shadow: none; }

.status .value { font-size: clamp(13px, 3.2vw, 17px); }

.app.compact .status {
  grid-template-columns: 1.4fr 0.7fr 1fr;
  gap: 8px;
  padding: 5px 8px;
}

.app.compact .status .label { display: none; }
.app.compact .status .value { font-size: 12px; text-shadow: none; }
.app.compact .gauge { height: 6px; }
.app.compact .gauge > i { box-shadow: none; }

.legend {
  margin: 0;
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}

.legend b { color: var(--text); }

.app.compact .legend { display: none; }
html.touch .legend { display: none; }

/* --------------------------------- toast --------------------------------- */
.toast-area {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: 94%;
}

.toast {
  padding: 6px 12px;
  font-size: 12px;
  letter-spacing: 0.06em;
  border-radius: 999px;
  background: rgba(6, 12, 24, 0.85);
  border: 1px solid var(--line);
  color: var(--text);
  animation: rise 0.3s ease-out;
}

.toast-good { border-color: rgba(110, 242, 164, 0.6); color: var(--good); }
.toast-bad { border-color: rgba(255, 107, 129, 0.6); color: var(--bad); }

@keyframes rise {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* -------------------------- croce direzionale -------------------------- */
.dpad {
  display: none;
  grid-template-columns: repeat(3, var(--pad-btn));
  grid-template-rows: repeat(2, var(--pad-btn));
  gap: 8px;
  justify-content: center;
  align-self: center;
  touch-action: none;
}

html.touch .dpad { display: grid; }

@media (hover: none) and (pointer: coarse) {
  .dpad { display: grid; }
}

.dpad button {
  width: var(--pad-btn);
  height: var(--pad-btn);
  font-size: calc(var(--pad-btn) * 0.34);
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease, border-color 0.08s ease, background 0.08s ease;
}

.dpad button.pressed,
.dpad button:active {
  transform: scale(0.94);
  border-color: var(--accent);
  background: #16264a;
}

.dpad [data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }

/* --------------------- orizzontale: due colonne --------------------- */
.app.landscape {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto 1fr;
  align-content: center;
  align-items: center;
}

.app.landscape .stage { grid-column: 1; grid-row: 1 / span 3; justify-self: center; }
.app.landscape .hud { grid-column: 2; grid-row: 1; width: min(44vw, 260px); }
.app.landscape .status { grid-column: 2; grid-row: 2; width: min(44vw, 260px); }
.app.landscape .dpad { grid-column: 2; grid-row: 3; }
.app.landscape .legend { display: none; }
.app.landscape .toast-area { left: 26%; }

@media (max-width: 380px) {
  .settings-grid { grid-template-columns: 1fr; }
  .hud { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .cta { animation: none; }
  .card { animation: none; }
  .toast { animation: none; }
}

/* --------------------------- croce per mancini --------------------------- */
.app.pad-left .dpad { justify-self: start; margin-left: 4px; }
.app.landscape.pad-left { grid-template-columns: auto minmax(0, 1fr); }
.app.landscape.pad-left .stage { grid-column: 2; }
.app.landscape.pad-left .hud,
.app.landscape.pad-left .status,
.app.landscape.pad-left .dpad { grid-column: 1; }

/* --------------------------- pannello di debug --------------------------- */
/* si attiva con ?debug nell'indirizzo: utilissimo sul telefono */
.debug {
  position: fixed;
  left: 4px;
  right: 4px;
  bottom: 4px;
  z-index: 20;
  padding: 3px 6px;
  font-size: 10px;
  line-height: 1.35;
  color: #9fe8ff;
  background: rgba(0, 0, 0, 0.66);
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
