/* Duelli+ V14 — struttura, layout e componenti.
   I colori e le forme di ogni tema sono in themes.css tramite variabili. */

@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap; src: url('../fonts/barlow-condensed-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 800; font-display: swap; src: url('../fonts/barlow-condensed-latin-800-normal.woff2') format('woff2'); }
@font-face { font-family: 'Rajdhani'; font-weight: 600; font-display: swap; src: url('../fonts/rajdhani-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Rajdhani'; font-weight: 700; font-display: swap; src: url('../fonts/rajdhani-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Cinzel'; font-weight: 700; font-display: swap; src: url('../fonts/cinzel-latin-700-normal.woff2') format('woff2'); }

:where(:root), :where(:root) * {
  --neon: #5fe3ff;
  --neon-rgb: 95, 227, 255;
  --neon2: #9cf7e8;
  --ink: #e9f8ff;
  --ink-dim: #8fb2c6;
  --deep: #02070f;
  --mid: #0a1f33;
  --surface: #071626;
  --surface-2: #0c2236;
  --line: rgba(var(--neon-rgb), .32);
  --danger: #ff5a6e;
  --gain: #39e08f;
  --loss: #ff4d63;
  --font-ui: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
  --font-lp: 'Barlow Condensed', 'Arial Narrow', Impact, sans-serif;
  --font-title: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
  --cut: 18px;
  --cut-s: 8px;
  --r: 0px;
  --gap: clamp(6px, 1.2vmin, 12px);
  --bg: radial-gradient(ellipse 60% 30% at 50% 0, rgba(var(--neon-rgb), .18), transparent 80%), linear-gradient(160deg, #02050e, var(--deep) 50%, #01030a);
  --bg-pattern: repeating-linear-gradient(90deg, transparent 0 63px, rgba(var(--neon-rgb), .035) 64px 65px), repeating-linear-gradient(0deg, transparent 0 63px, rgba(var(--neon-rgb), .025) 64px 65px);
  --panel-fill: radial-gradient(ellipse at 50% 0, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%), linear-gradient(170deg, var(--surface-2), var(--surface) 55%, #040d18);
  --panel-edge: linear-gradient(160deg, color-mix(in srgb, var(--accent) 85%, white 15%), rgba(var(--neon-rgb), .35) 40%, color-mix(in srgb, var(--accent) 60%, transparent));
  --btn-bg: linear-gradient(170deg, rgba(var(--neon-rgb), .13), rgba(var(--neon-rgb), .04));
  --btn-edge: rgba(var(--neon-rgb), .38);
  --shape: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut)));
  --shape-s: polygon(0 0, calc(100% - var(--cut-s)) 0, 100% var(--cut-s), 100% 100%, var(--cut-s) 100%, 0 calc(100% - var(--cut-s)));
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: var(--font-ui);
  font-weight: 600;
  color: var(--ink);
  background: var(--bg-pattern), var(--bg);
  background-color: var(--deep);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, rgba(var(--neon-rgb), .05) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: sweep 22s linear infinite;
}
@keyframes sweep { to { background-position: -250% 0; } }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:disabled { cursor: default; }
svg { width: 1em; height: 1em; flex: none; }
:focus-visible { outline: 2px solid var(--neon); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Struttura ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--gap);
  padding: max(var(--gap), env(safe-area-inset-top)) max(var(--gap), env(safe-area-inset-right)) max(var(--gap), env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left));
}

/* ---------- HUD superiore ---------- */
.hud {
  display: grid;
  grid-template-columns: auto 1fr 1fr 1fr auto;
  gap: 6px;
  align-items: stretch;
  min-height: 44px;
}
.hud-brand { display: flex; align-items: center; gap: 8px; padding: 0 4px 0 2px; }
.hud-mark {
  width: 26px; height: 26px; flex: none;
  background: conic-gradient(from 45deg, var(--neon), var(--neon2), var(--neon));
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  position: relative;
  filter: drop-shadow(0 0 6px rgba(var(--neon-rgb), .7));
}
.hud-mark::after { content: ''; position: absolute; inset: 5px; background: var(--deep); clip-path: inherit; box-shadow: inset 0 0 6px var(--neon); }
.hud-name { font-family: var(--font-title); font-weight: 700; letter-spacing: .14em; font-size: 15px; line-height: 1; }
.hud-name b { color: var(--neon); font-weight: 700; margin-left: 2px; }
.hud-chip {
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; align-content: center;
  min-width: 0; padding: 4px 10px; text-align: left;
  background: var(--btn-bg);
  clip-path: var(--shape-s);
  box-shadow: inset 0 0 0 1px var(--btn-edge);
  border-radius: var(--r);
  transition: background .15s;
}
.hud-chip:active { background: rgba(var(--neon-rgb), .25); }
.hud-label { grid-column: 1; font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-label b { color: var(--ink); }
.hud-value { grid-column: 1; font-family: var(--font-lp); font-weight: 600; font-size: 18px; line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.hud-ico { grid-column: 2; grid-row: 1 / 3; align-self: center; font-size: 18px; color: var(--neon); }
.hud-turn .hud-value { color: var(--neon); }
.hud-match.done .hud-value { color: #ffd36b; }
.hud-clock.running .hud-value { color: var(--neon); }
.hud-clock.low .hud-value { color: var(--danger); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .45; } }
.hud-icon {
  width: 44px; display: grid; place-items: center; font-size: 22px;
  background: var(--btn-bg); clip-path: var(--shape-s); box-shadow: inset 0 0 0 1px var(--btn-edge); border-radius: var(--r);
}
.hud-icon:active { background: rgba(var(--neon-rgb), .25); }

/* ---------- Dock inferiore ---------- */
.dock {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  min-height: 50px;
}
.dock button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 0; padding: 4px 2px;
  font-size: 10px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-dim);
  background: var(--btn-bg); clip-path: var(--shape-s); box-shadow: inset 0 0 0 1px rgba(var(--neon-rgb), .22); border-radius: var(--r);
  transition: color .15s, background .15s;
}
.dock button svg { font-size: 21px; color: var(--neon); }
.dock button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock button:active { background: rgba(var(--neon-rgb), .25); color: var(--ink); }
.dock button:disabled { opacity: .35; }
.dock .is-danger svg { color: var(--danger); }

/* ---------- Tabellone ---------- */
.board {
  display: grid; gap: var(--gap); min-height: 0;
  grid-template-columns: 1fr; grid-template-rows: 1fr 1fr;
}
.board[data-players="3"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.board[data-players="3"] .panel:first-child { grid-column: 1 / 3; }
.board[data-players="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
@media (min-aspect-ratio: 1/1) {
  .board[data-players="2"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
  .board[data-players="3"] { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr; }
  .board[data-players="3"] .panel:first-child { grid-column: auto; }
}
@media (min-aspect-ratio: 2/1) {
  .board[data-players="4"] { grid-template-columns: repeat(4, 1fr); grid-template-rows: 1fr; }
}

/* ---------- Pannello giocatore ---------- */
.panel {
  --accent: #2f7fd1;
  position: relative; min-width: 0; min-height: 0;
  container-type: size;
  transition: filter .25s;
}
.panel-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  gap: clamp(4px, 1.6cqh, 10px);
  padding: clamp(8px, 2.6cqh, 18px) clamp(9px, 3cqw, 20px) clamp(9px, 2.8cqh, 18px);
  transition: transform .45s cubic-bezier(.2, .8, .2, 1);
}
.panel.flipped .panel-inner { transform: rotate(180deg); }
.p-frame { position: absolute; inset: 0; z-index: 0; pointer-events: none; clip-path: var(--shape); border-radius: var(--r); background: var(--panel-edge); }
.p-frame::before { content: ''; position: absolute; inset: 2px; clip-path: var(--shape); border-radius: calc(var(--r) - 2px); background: var(--panel-fill); }
.p-frame::after {
  content: ''; position: absolute; inset: 7px; clip-path: var(--shape); border-radius: calc(var(--r) - 6px);
  background:
    linear-gradient(90deg, var(--accent) 0 14%, transparent 14% 86%, var(--accent) 86%) top / 100% 2px no-repeat,
    linear-gradient(90deg, rgba(var(--neon-rgb), .55) 0 8%, transparent 8% 92%, rgba(var(--neon-rgb), .55) 92%) bottom / 100% 1px no-repeat,
    var(--panel-deco, none);
  opacity: .9;
}
.panel-inner > :not(.p-frame) { position: relative; z-index: 1; }
.panel.active { filter: drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 65%, transparent)); }
.panel.ko .lp { color: var(--loss); text-shadow: 0 0 22px rgba(255, 77, 99, .55); }

.p-head { display: flex; align-items: center; gap: 8px; flex: none; min-height: 30px; }
.p-tag {
  flex: none; font-family: var(--font-lp); font-weight: 800; font-size: 13px; letter-spacing: .06em;
  padding: 3px 7px; color: #fff; background: var(--accent); clip-path: var(--shape-s); border-radius: calc(var(--r) / 2);
}
.p-name {
  margin: 0; flex: 1; min-width: 0; font-family: var(--font-title); font-weight: 700;
  font-size: clamp(14px, 4.6cqw, 21px); letter-spacing: .1em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.p-wins { color: #ffd36b; font-size: 14px; letter-spacing: 1px; text-shadow: 0 0 8px rgba(255, 211, 107, .6); flex: none; }
.p-wins:empty { display: none; }
.p-turn {
  display: none; flex: none; font-size: 10px; letter-spacing: .16em; text-transform: uppercase;
  padding: 3px 7px; color: var(--deep); background: var(--neon); clip-path: var(--shape-s); border-radius: calc(var(--r) / 2);
}
.panel.active .p-turn { display: inline-block; }
.p-icon {
  flex: none; width: 34px; height: 30px; display: grid; place-items: center; font-size: 18px; color: var(--ink-dim);
  background: var(--btn-bg); clip-path: var(--shape-s); box-shadow: inset 0 0 0 1px var(--btn-edge); border-radius: var(--r);
}
.p-icon:active { color: var(--neon); }

.p-lp {
  flex: 1 1 auto; min-height: 0; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 50%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%);
}
.lp {
  display: block; font-family: var(--font-lp); font-weight: 800; line-height: .86; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink);
  font-size: min(30cqw, 30cqh);
  text-shadow: 0 0 18px rgba(var(--neon-rgb), .35), 0 2px 0 rgba(0, 0, 0, .4);
  transition: color .3s;
}
.lp[data-len="5"] { font-size: min(25cqw, 30cqh); }
.lp[data-len="6"] { font-size: min(20cqw, 28cqh); }
.lp[data-len="8"] { font-size: min(15cqw, 24cqh); }
.lp-label { margin-top: clamp(2px, .8cqh, 6px); font-size: clamp(9px, 2.6cqw, 12px); letter-spacing: .38em; text-transform: uppercase; color: var(--ink-dim); }
.lp-bar { position: absolute; left: 10%; right: 10%; bottom: 0; height: 3px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.lp-bar i {
  position: absolute; inset: 0; transform-origin: left;
  background: linear-gradient(90deg, var(--loss), #ffb347 30%, var(--accent) 60%, var(--neon));
  background-size: calc(100% / var(--health, 1)) 100%;
  transition: transform .5s cubic-bezier(.2, .8, .2, 1);
}
.panel.gain .lp { animation: lp-gain .7s ease-out; }
.panel.loss .lp { animation: lp-loss .55s ease-out; }
.panel.gain .p-frame::before { animation: frame-gain .9s ease-out; }
.panel.loss .p-frame::before { animation: frame-loss .9s ease-out; }
.panel.loss .panel-inner { animation: shake .35s ease-out; }
.panel.flipped.loss .panel-inner { animation: shake-flip .35s ease-out; }
@keyframes lp-gain { 0% { color: var(--gain); text-shadow: 0 0 30px var(--gain); } 100% { } }
@keyframes lp-loss { 0% { color: var(--loss); text-shadow: 0 0 30px var(--loss); transform: scale(.96); } 100% { } }
@keyframes frame-gain { 0%, 20% { box-shadow: inset 0 0 60px rgba(57, 224, 143, .55); } 100% { box-shadow: none; } }
@keyframes frame-loss { 0%, 20% { box-shadow: inset 0 0 70px rgba(255, 77, 99, .65); } 100% { box-shadow: none; } }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-4px); } 50% { transform: translateX(3px); } 75% { transform: translateX(-2px); } }
@keyframes shake-flip { 0%, 100% { transform: rotate(180deg); } 25% { transform: rotate(180deg) translateX(-4px); } 50% { transform: rotate(180deg) translateX(3px); } 75% { transform: rotate(180deg) translateX(-2px); } }
.float-delta {
  position: absolute; top: 8%; right: 8%; z-index: 3; pointer-events: none;
  font-family: var(--font-lp); font-weight: 800; font-size: clamp(18px, 9cqw, 40px);
  animation: float-up 1.1s ease-out forwards;
}
.float-delta.gain { color: var(--gain); text-shadow: 0 0 12px rgba(57, 224, 143, .7); }
.float-delta.loss { color: var(--loss); text-shadow: 0 0 12px rgba(255, 77, 99, .7); }
@keyframes float-up { 0% { opacity: 0; transform: translateY(10px) scale(.8); } 15% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-30px); } }

.p-amounts { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(4px, 1.4cqw, 8px); flex: none; }
.p-amounts button {
  height: clamp(36px, 11cqh, 54px);
  font-family: var(--font-lp); font-weight: 800; font-size: clamp(16px, 5.4cqw, 24px); letter-spacing: .02em;
  background: var(--btn-bg); clip-path: var(--shape-s); box-shadow: inset 0 0 0 1px var(--btn-edge); border-radius: var(--r);
  transition: background .12s, transform .08s;
}
.p-amounts button.minor { color: var(--ink-dim); }
.p-amounts button:active { background: color-mix(in srgb, var(--accent) 45%, transparent); transform: scale(.96); color: #fff; }

.p-sum {
  flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px;
  min-height: clamp(28px, 8cqh, 40px); padding: 0 4px 0 10px;
  background: rgba(0, 0, 0, .25); box-shadow: inset 0 0 0 1px rgba(var(--neon-rgb), .18);
  clip-path: var(--shape-s); border-radius: var(--r);
}
.sum-expr { font-size: clamp(11px, 3.2cqw, 14px); color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-val { font-family: var(--font-lp); font-weight: 800; font-size: clamp(18px, 6cqw, 28px); font-variant-numeric: tabular-nums; color: var(--ink-dim); }
.panel.has-sum .sum-val { color: var(--neon); text-shadow: 0 0 10px rgba(var(--neon-rgb), .5); }
.panel.has-sum .sum-expr { color: var(--ink); }
.sum-clear { width: 30px; height: 28px; display: grid; place-items: center; font-size: 15px; color: var(--ink-dim); }
.sum-clear:disabled { opacity: .25; }

.p-apply { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: clamp(5px, 1.6cqw, 10px); }
.apply {
  height: clamp(42px, 13cqh, 66px); display: flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-lp); font-weight: 800; clip-path: var(--shape-s); border-radius: var(--r);
  transition: filter .15s, transform .08s, opacity .15s;
}
.apply b { font-size: clamp(26px, 9cqw, 40px); line-height: 1; font-weight: 800; }
.apply-val { font-size: clamp(16px, 5cqw, 24px); }
.apply.minus { color: #fff; background: linear-gradient(170deg, #ff5d72, #b11a35); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25), inset 0 -10px 20px rgba(0, 0, 0, .2); }
.apply.plus { color: #032016; background: linear-gradient(170deg, #5cf2a8, #1ea566); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3), inset 0 -10px 20px rgba(0, 0, 0, .15); }
.apply:disabled { opacity: .3; filter: saturate(.4); }
.apply:not(:disabled):active { transform: scale(.97); filter: brightness(1.15); }


/* adattamento allo spazio disponibile per ogni pannello */
@container (max-height: 300px) { .lp-label { display: none; } .sum-expr { font-size: 11px; } }
@container (max-height: 250px) {
  .p-head { min-height: 24px; }
  .p-icon { height: 26px; width: 30px; }
  .p-sum { display: none; }
  .panel-inner { gap: 4px; }
}
@container (max-width: 300px) { .p-head { gap: 5px; } .p-icon { width: 30px; } .p-turn { display: none !important; } }
@container (max-width: 260px) { .p-icon[data-x] { display: none; } }
@container (max-width: 230px) {
  .p-name { font-size: 13px; letter-spacing: .04em; }
  .p-turn { display: none !important; }
  .sum-expr { display: none; }
  .p-sum { grid-template-columns: 1fr auto; }
}
@container (min-width: 520px) and (min-height: 420px) {
  .lp { font-size: min(26cqw, 32cqh); }
}

/* modalità compatta */
.board.compact .p-amounts { grid-template-columns: 1fr 1fr; }
.board.compact .p-amounts .minor, .board.compact .lp-label { display: none; }
.board.compact .sum-expr { display: none; }
.board.compact .p-sum { grid-template-columns: 1fr auto; }
.board.compact .lp { font-size: min(24cqw, 30cqh); }

/* comandi bloccati */
body.lp-locked .p-amounts button, body.lp-locked .apply, body.lp-locked .p-icon[data-x] { opacity: .35; }
.lock-badge {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 58px); transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 6px; padding: 5px 12px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
  background: #2a1219; color: #ffc0c8; box-shadow: inset 0 0 0 1px rgba(255, 90, 110, .5); clip-path: var(--shape-s); pointer-events: none;
}
.lock-badge.pulse { animation: pulse .5s 2; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.1); background: #5a1a26; } }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 72px); z-index: 50; max-width: min(90vw, 420px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 16px; font-size: 15px; text-align: center; background: #0c2236f2; box-shadow: inset 0 0 0 1px var(--line), 0 10px 30px #000a;
  clip-path: var(--shape-s); border-radius: var(--r); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Dialoghi ---------- */
dialog {
  color: var(--ink); border: 0; padding: 0; background: transparent; max-width: none; max-height: none;
}
dialog::backdrop { background: rgba(1, 4, 10, .72); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
dialog[open] { animation: dlg-in .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(16px); } }
.sheet, .modal, .roll {
  width: min(100vw - 20px, 480px);
  max-height: calc(100dvh - 24px);
  padding: 18px;
  background: linear-gradient(170deg, var(--surface-2), var(--surface) 60%, #040c16);
  box-shadow: inset 0 0 0 1px var(--line), inset 0 2px 0 var(--neon);
  clip-path: var(--shape);
  border-radius: var(--r);
  overflow: auto;
  overscroll-behavior: contain;
}
.sheet { display: none; flex-direction: column; gap: 14px; }
.sheet > *, .modal > *, .roll > * { flex-shrink: 0; }
.sheet[open] { display: flex; }
.sheet-tall { width: min(100vw - 20px, 560px); padding: 0; }
.sheet-tall .sheet-head { padding: 18px 18px 0; }
.sheet-body { overflow: auto; padding: 0 18px 18px; display: flex; flex-direction: column; gap: 18px; -webkit-overflow-scrolling: touch; user-select: none; }
@media (max-width: 600px) {
  .sheet { margin: auto auto 0; width: 100vw; max-height: 92dvh; padding-bottom: max(18px, env(safe-area-inset-bottom)); clip-path: polygon(0 var(--cut), var(--cut) 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, 0 100%); }
  .sheet-tall { padding-bottom: 0; }
  .sheet-tall .sheet-body { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  dialog.sheet[open] { animation: sheet-up .28s cubic-bezier(.2, .8, .2, 1); }
}
@keyframes sheet-up { from { transform: translateY(40%); opacity: .4; } }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex: none; }
.sheet h2, .modal h2, .roll h2 { margin: 0; font-family: var(--font-title); font-weight: 700; font-size: 24px; letter-spacing: .08em; text-transform: uppercase; }
.kicker { display: block; font-size: 11px; letter-spacing: .26em; text-transform: uppercase; color: var(--neon); }
.muted { margin: 0; color: var(--ink-dim); font-size: 15px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; font-size: 20px; background: var(--btn-bg); box-shadow: inset 0 0 0 1px var(--btn-edge); clip-path: var(--shape-s); border-radius: var(--r); flex: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 16px;
  font-weight: 700; font-size: 15px; letter-spacing: .1em; text-transform: uppercase; text-decoration: none; text-align: center;
  background: var(--btn-bg); box-shadow: inset 0 0 0 1px var(--btn-edge); clip-path: var(--shape-s); border-radius: var(--r);
}
.btn svg { font-size: 18px; }
.btn:active { background: rgba(var(--neon-rgb), .25); }
.btn:disabled { opacity: .4; }
.btn-primary { color: var(--deep); background: linear-gradient(170deg, color-mix(in srgb, var(--neon) 80%, white 20%), var(--neon)); box-shadow: 0 0 18px rgba(var(--neon-rgb), .35); }
.btn-primary:active { filter: brightness(1.1); background: var(--neon); }
.btn-danger { color: #fff; background: linear-gradient(170deg, #ff6a7d, #c4223f); box-shadow: none; }
.row-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }

.seg { display: flex; gap: 4px; padding: 3px; background: rgba(0, 0, 0, .3); box-shadow: inset 0 0 0 1px rgba(var(--neon-rgb), .2); clip-path: var(--shape-s); border-radius: var(--r); }
.seg button { flex: 1; min-height: 38px; padding: 0 10px; font-weight: 700; font-size: 15px; letter-spacing: .04em; color: var(--ink-dim); clip-path: var(--shape-s); border-radius: var(--r); white-space: nowrap; }
.seg button[aria-checked="true"] { color: var(--deep); background: var(--neon); }
.seg-wrap { flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); }
.field input, .field select, .name-row input[type="text"] {
  min-height: 46px; padding: 0 12px; font-size: 18px; letter-spacing: .02em; text-transform: none; color: var(--ink);
  background: rgba(0, 0, 0, .35); border: 0; box-shadow: inset 0 0 0 1px var(--btn-edge); clip-path: var(--shape-s); border-radius: var(--r);
  -webkit-user-select: text; user-select: text;
}
.field select option { background: var(--surface); }

/* conferma */
.modal { width: min(100vw - 32px, 400px); display: none; flex-direction: column; gap: 14px; }
.modal[open] { display: flex; }
.modal p { margin: 0; color: var(--ink-dim); font-size: 16px; line-height: 1.35; }

/* calcolatrice */
.calc-target { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: 6px; }
.calc-target button {
  min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 6px;
  padding: 7px 8px; text-align: left;
  background: rgba(0, 0, 0, .25); box-shadow: inset 0 3px 0 var(--accent), inset 0 0 0 1px rgba(var(--neon-rgb), .18); clip-path: var(--shape-s); border-radius: var(--r);
}
.calc-target button[aria-checked="true"] { background: color-mix(in srgb, var(--accent) 38%, transparent); box-shadow: inset 0 3px 0 var(--accent), inset 0 0 0 2px var(--accent); }
.ct-tag { grid-row: 1; font-family: var(--font-lp); font-weight: 800; font-size: 18px; line-height: 1; padding: 3px 6px; justify-self: start; color: #fff; background: var(--accent); clip-path: var(--shape-s); border-radius: calc(var(--r) / 2); }
.ct-name { grid-row: 1; font-size: 12px; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-name:empty { display: none; }
.ct-lp { grid-column: 1 / -1; margin-top: 4px; font-family: var(--font-lp); font-weight: 800; font-size: 19px; line-height: 1; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.calc-screen {
  display: flex; flex-direction: column; align-items: flex-end; justify-content: center; min-height: 84px; padding: 8px 14px;
  background: rgba(0, 0, 0, .45); box-shadow: inset 0 0 0 1px rgba(var(--neon-rgb), .3), inset 0 0 24px rgba(var(--neon-rgb), .08); clip-path: var(--shape-s);
  border-radius: var(--r);
}
.calc-expr { font-size: 15px; color: var(--ink-dim); min-height: 18px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calc-screen output { font-family: var(--font-lp); font-weight: 800; font-size: 44px; line-height: 1; color: var(--neon); font-variant-numeric: tabular-nums; text-shadow: 0 0 14px rgba(var(--neon-rgb), .4); }
.calc-screen output.err { font-size: 24px; color: var(--danger); }
.calc-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.calc-quick button { min-height: 36px; font-size: 14px; color: var(--ink-dim); background: var(--btn-bg); box-shadow: inset 0 0 0 1px rgba(var(--neon-rgb), .2); clip-path: var(--shape-s); border-radius: var(--r); }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.calc-keys button {
  min-height: 52px; font-family: var(--font-lp); font-weight: 600; font-size: 26px;
  background: var(--btn-bg); box-shadow: inset 0 0 0 1px rgba(var(--neon-rgb), .22); clip-path: var(--shape-s); border-radius: var(--r);
}
.calc-keys button:active { background: rgba(var(--neon-rgb), .3); }
.calc-keys .op { color: var(--neon); }
.calc-keys .fn { color: var(--ink-dim); font-size: 22px; }
.calc-keys .zero { grid-column: span 2; }
.calc-keys .eq { grid-row: span 2; color: var(--deep); background: var(--neon); }
.calc-apply { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.calc-apply button { min-height: 54px; font-family: var(--font-lp); font-weight: 800; font-size: 20px; letter-spacing: .04em; clip-path: var(--shape-s); border-radius: var(--r); }
.btn-minus { color: #fff; background: linear-gradient(170deg, #ff5d72, #b11a35); }
.btn-plus { color: #032016; background: linear-gradient(170deg, #5cf2a8, #1ea566); }
.calc-apply button:disabled { opacity: .3; }
#calcDialog { gap: 10px; }
@media (max-height: 640px) {
  #calcDialog { gap: 8px; padding-top: 12px; }
  #calcDialog .sheet-head h2 { font-size: 20px; }
  .calc-quick button { min-height: 32px; }
  .calc-apply button { min-height: 46px; }
  .calc-keys button { min-height: 40px; font-size: 22px; }
  .calc-screen { min-height: 64px; }
  .calc-screen output { font-size: 34px; }
}

/* dado e moneta */
.roll { width: min(100vw - 32px, 360px); display: none; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.roll[open] { display: flex; }
.roll .row-actions { width: 100%; }
.roll-stage { width: 100%; height: 170px; display: grid; place-items: center; perspective: 600px; }
.roll-caption { margin: 0; min-height: 30px; font-size: 18px; color: var(--ink-dim); }
.roll-caption strong { font-family: var(--font-lp); font-weight: 800; font-size: 28px; letter-spacing: .06em; color: var(--neon); text-transform: uppercase; }
.die-face {
  width: 120px; height: 120px; padding: 16px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 4px;
  background: linear-gradient(150deg, #f6fbff, #c9d8e6); border-radius: 22px;
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, .18), inset 0 4px 8px #fff, 0 12px 30px rgba(0, 0, 0, .5), 0 0 30px rgba(var(--neon-rgb), .35);
}
.die-face i { border-radius: 50%; }
.die-face i.on { background: radial-gradient(circle at 35% 35%, #3a4655, #0b121b); box-shadow: inset 0 2px 3px rgba(0, 0, 0, .6); }
.is-die.rolling .die-face { animation: die-tumble .32s linear infinite; }
.is-die.done .die-face { animation: die-land .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes die-tumble { 0% { transform: rotate(0) translateY(0); } 50% { transform: rotate(20deg) translateY(-14px) scale(.94); } 100% { transform: rotate(0) translateY(0); } }
@keyframes die-land { from { transform: scale(1.25) rotate(-12deg); } }
.coin { width: 130px; height: 130px; position: relative; transform-style: preserve-3d; transition: transform .6s; }
.coin span {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: 50%; backface-visibility: hidden;
  font-family: 'Cinzel', Georgia, serif; font-size: 56px; font-weight: 700; color: #5a3a06;
  background: radial-gradient(circle at 35% 30%, #fff3c4, #f0c24f 45%, #b47c12 80%);
  box-shadow: inset 0 0 0 6px #d9a636, inset 0 0 0 9px #8a5c0a, 0 12px 30px rgba(0, 0, 0, .5), 0 0 26px rgba(255, 200, 80, .4);
}
.coin .coin-b { transform: rotateY(180deg); }
.is-coin.rolling .coin { animation: coin-spin .36s linear infinite; }
.coin.show-b { transform: rotateY(180deg); }
@keyframes coin-spin { to { transform: rotateY(360deg) translateY(0); } }

/* timer */
.timer-face { display: flex; flex-direction: column; align-items: center; padding: 18px 0 8px; }
.timer-face output { font-family: var(--font-lp); font-weight: 800; font-size: 84px; line-height: 1; font-variant-numeric: tabular-nums; color: var(--neon); text-shadow: 0 0 24px rgba(var(--neon-rgb), .4); }
.timer-face small { font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-dim); }
.timer-face.low output { color: var(--danger); text-shadow: 0 0 24px rgba(255, 90, 110, .45); }

/* registro */
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 52dvh; overflow: auto; }
.history-list li { display: grid; grid-template-columns: 48px 1fr; gap: 8px; padding: 8px 10px; font-size: 15px; background: rgba(0, 0, 0, .2); }
.history-list li:nth-child(odd) { background: rgba(var(--neon-rgb), .04); }
.history-list time { color: var(--neon); font-family: var(--font-lp); font-weight: 600; }
.history-list li.empty { display: block; color: var(--ink-dim); text-align: center; padding: 24px; }

/* match */
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.match-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 8px;
  background: linear-gradient(170deg, color-mix(in srgb, var(--accent) 30%, transparent), rgba(0, 0, 0, .25));
  box-shadow: inset 0 3px 0 var(--accent), inset 0 0 0 1px color-mix(in srgb, var(--accent) 60%, transparent);
  clip-path: var(--shape-s); border-radius: var(--r);
}
.match-card:disabled { opacity: .5; }
.mc-name { font-size: 15px; letter-spacing: .1em; text-transform: uppercase; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-score { font-family: var(--font-lp); font-weight: 800; font-size: 52px; line-height: 1; }
.mc-cta { display: flex; align-items: center; gap: 4px; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: #ffd36b; }

/* impostazioni */
.set-group { display: flex; flex-direction: column; gap: 10px; }
.set-group h3 { margin: 0; font-size: 12px; letter-spacing: .26em; text-transform: uppercase; color: var(--neon); padding-bottom: 6px; border-bottom: 1px solid rgba(var(--neon-rgb), .2); }
.set-row { display: flex; flex-direction: column; gap: 6px; }
.set-row > span { font-size: 15px; color: var(--ink-dim); }
.names-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.name-row { display: flex; gap: 6px; min-width: 0; }
.name-row input[type="text"] { flex: 1; min-width: 0; font-size: 16px; }
.swatch { position: relative; width: 46px; flex: none; background: var(--accent); clip-path: var(--shape-s); border-radius: var(--r); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25); }
.swatch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; font-size: 16px; cursor: pointer; }
.toggle input { appearance: none; -webkit-appearance: none; order: 2; width: 50px; height: 28px; flex: none; margin: 0; position: relative; background: rgba(255, 255, 255, .12); border-radius: 14px; transition: background .2s; cursor: pointer; }
.toggle input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #dbe8f2; transition: transform .2s; }
.toggle input:checked { background: var(--neon); }
.toggle input:checked::after { transform: translateX(22px); background: var(--deep); }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.theme-card { display: flex; flex-direction: column; gap: 6px; padding: 6px; text-align: left; background: rgba(0, 0, 0, .25); box-shadow: inset 0 0 0 1px rgba(var(--neon-rgb), .18); clip-path: var(--shape-s); border-radius: var(--r); }
.theme-card[aria-checked="true"] { box-shadow: inset 0 0 0 2px var(--neon); background: rgba(var(--neon-rgb), .1); }
.tc-text strong { display: block; font-size: 15px; letter-spacing: .06em; }
.tc-text small { display: block; font-size: 12px; color: var(--ink-dim); line-height: 1.2; }
.install-box { display: flex; flex-direction: column; gap: 8px; }
.install-box p { margin: 0; font-size: 15px; line-height: 1.4; color: var(--ink-dim); }
.install-box p strong, .install-box p b { color: var(--ink); }

/* splash VS / vittoria */
.splash { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; display: none; place-items: center; background: transparent; }
.splash[open] { display: grid; }
.splash::backdrop { background: radial-gradient(ellipse at center, rgba(var(--neon-rgb), .18), rgba(1, 3, 8, .92) 65%); backdrop-filter: blur(4px); }
.splash-inner { width: min(92vw, 520px); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 20px; }
.splash h2 {
  margin: 0; font-family: var(--font-title); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; line-height: 1;
  font-size: clamp(44px, 13vw, 92px); color: var(--ink);
  text-shadow: 0 0 24px rgba(var(--neon-rgb), .7), 0 0 60px rgba(var(--neon-rgb), .35);
  animation: splash-in .5s cubic-bezier(.2, 1.4, .4, 1);
  max-width: 100%; overflow-wrap: anywhere;
}
.splash p { margin: 0 0 12px; font-size: 20px; color: var(--ink-dim); letter-spacing: .08em; }
.splash .kicker { font-size: 13px; }
.splash .row-actions { width: 100%; grid-template-columns: 1fr; }
.splash[data-tone="win"] h2 { color: color-mix(in srgb, var(--accent, #ffd36b) 40%, #fff); text-shadow: 0 0 26px var(--accent, #ffd36b), 0 0 70px color-mix(in srgb, var(--accent, #ffd36b) 60%, transparent); }
.splash[data-tone="win"] .kicker { color: #ffd36b; }
.splash[data-tone="vs"] h2 { font-style: italic; }
@keyframes splash-in { from { transform: scale(1.6); opacity: 0; letter-spacing: .4em; } }

/* risparmio energetico: meno animazioni */
body.power-save::before { animation: none; display: none; }
body.power-save .panel, body.power-save .panel-inner, body.power-save .lp-bar i { transition: none; }
body.power-save .panel.active { filter: none; }
body.power-save .panel.active .p-frame { background: var(--accent); }
body.power-save dialog::backdrop { backdrop-filter: none; -webkit-backdrop-filter: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* schermi bassi in orizzontale */
@media (max-height: 500px) and (min-aspect-ratio: 1/1) {
  .hud { min-height: 36px; }
  .hud-name { display: none; }
  .hud-value { font-size: 15px; }
  .hud-label { font-size: 9px; }
  .hud-icon { width: 38px; }
  .app { grid-template-columns: minmax(0, 1fr) 64px; grid-template-rows: auto minmax(0, 1fr); }
  .hud { grid-column: 1 / 3; }
  .board { grid-column: 1; }
  .dock { grid-column: 2; grid-row: 2; grid-template-columns: 1fr; grid-auto-rows: 1fr; min-height: 0; }
  .dock button span { display: none; }
}
@media (max-width: 440px) { .hud-name { display: none; } .hud-brand { padding: 0; } }
@media (max-width: 380px) {
  .hud { grid-template-columns: auto 1fr 1fr 1fr auto; gap: 4px; }
  .hud-name { display: none; }
  .hud-chip { padding: 3px 7px; }
  .hud-value { font-size: 16px; }
  .dock button span { font-size: 9px; letter-spacing: .04em; }
}
@media (min-width: 900px) {
  .hud { min-height: 52px; }
  .hud-name { font-size: 18px; }
  .hud-value { font-size: 22px; }
  .dock { max-width: 900px; justify-self: center; width: 100%; }
}
