/* =====================================================================
   Poker — design system
   Palette chiara e calda in stile Claude, serif per i titoli, sans per il testo.
   ===================================================================== */

:root {
  /* Colori — scala chiara: fondo crema quasi bianco, card bianche, bordi leggeri */
  --bg: #FBFAF7;            /* crema chiarissimo */
  --surface: #FFFFFF;       /* card, campi, dialog */
  --surface-2: #F4F3EE;     /* stato premuto */
  --text: #141413;          /* quasi nero */
  --text-2: #66655F;        /* secondario */
  --text-3: #8F8E87;        /* etichette, placeholder */
  --border: #EEECE5;
  --border-strong: #DDDAD0;
  --accent: #D97757;        /* terracotta */
  --accent-strong: #C15F3C; /* hover / premuto / testo in accento */
  --accent-soft: #FBEEE8;
  --on-accent: #FFFFFF;
  --positive: #3E7B4F;
  --positive-soft: #EEF5EB;
  --negative: #B0412F;
  --negative-soft: #FBEDE9;
  --warning: #8A6116;
  --warning-soft: #FBF4E3;
  --focus: rgba(217, 119, 87, .28);
  --shadow: 0 1px 2px rgba(20, 20, 19, .03), 0 2px 10px rgba(20, 20, 19, .03);

  /* Tipografia */
  --font-serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --fs-xs: 13px;
  --fs-sm: 15px;
  --fs-md: 17px;            /* >= 16px: Safari non zooma sui campi */
  --fs-lg: 20px;
  --fs-xl: 26px;
  --fs-2xl: 34px;

  /* Spaziature (base 4px) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;

  /* Forme */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-pill: 999px;
  --tap: 52px;              /* altezza minima dei controlli */
  --maxw: 560px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;      /* sempre chiara, anche se l'iPhone è in modalità scura */
}

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--font-serif); font-weight: 500; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--s5) var(--s4) calc(120px + var(--safe-bottom));
  outline: none;
}

/* ------------------------------------------------------------------ */
/* Barra superiore                                                      */
/* ------------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.topbar__inner {
  max-width: var(--maxw); margin: 0 auto;
  height: 56px; padding: 0 var(--s2);
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
}
.brand {
  grid-column: 2; justify-self: center;
  display: flex; align-items: center; gap: var(--s2);
  font-family: var(--font-serif); font-size: var(--fs-lg); font-weight: 600;
}
.brand__mark { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 4; }
.brand__mark circle + circle { stroke-dasharray: none; fill: var(--accent); stroke: none; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: var(--r-pill);
  display: grid; place-items: center; cursor: pointer; color: var(--text);
}
#btn-back { grid-column: 1; }
#btn-menu { grid-column: 3; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
#btn-back svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.steps {
  max-width: var(--maxw); margin: 0 auto; padding: 0 var(--s4) var(--s3);
  list-style: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--s1);
  font-size: 11px; color: var(--text-3); text-align: center; letter-spacing: .02em;
}
.steps li { padding-top: var(--s2); border-top: 3px solid var(--border); }
.steps li.is-done { border-color: var(--accent); color: var(--text-2); }
.steps li.is-current { border-color: var(--accent); color: var(--text); font-weight: 600; }

.banner {
  max-width: var(--maxw); margin: var(--s3) auto 0; padding: var(--s3) var(--s4);
  background: var(--warning-soft); color: var(--warning); border-radius: var(--r-md);
  font-size: var(--fs-sm);
}

/* ------------------------------------------------------------------ */
/* Sezioni e card                                                       */
/* ------------------------------------------------------------------ */
.page-head { margin-bottom: var(--s5); }
.page-head p { color: var(--text-2); margin-top: var(--s2); }

.section { margin-top: var(--s6); }
.section:first-child { margin-top: 0; }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.section__head h3 { font-size: var(--fs-lg); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.card--pad { padding: var(--s4); }
.card + .card { margin-top: var(--s3); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: var(--s3) var(--s4); border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }

/* Totali */
.stats { display: grid; grid-template-columns: 1fr 1fr; }
.stat { padding: var(--s4); }
.stat + .stat { border-left: 1px solid var(--border); }
.stat__label { font-size: var(--fs-xs); color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.stat__value { font-family: var(--font-serif); font-size: var(--fs-xl); margin-top: var(--s1); }
.stat__value--sm { font-size: var(--fs-lg); }

/* ------------------------------------------------------------------ */
/* Form                                                                 */
/* ------------------------------------------------------------------ */
.field { display: block; }
.field + .field { margin-top: var(--s4); }
.label { display: block; font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); margin-bottom: var(--s2); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input {
  width: 100%; min-height: var(--tap);
  padding: 0 var(--s4);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  appearance: none; -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.input.is-invalid { border-color: var(--negative); }
.input--num { text-align: right; font-variant-numeric: tabular-nums; }
.input-wrap .suffix { position: absolute; right: var(--s4); color: var(--text-3); pointer-events: none; font-size: var(--fs-sm); }
.input-wrap .input--num { padding-right: 40px; padding-left: var(--s3); }
.input-wrap--long .input--num { padding-right: 64px; }
.input-wrap .suffix { right: var(--s3); }
.error { color: var(--negative); font-size: var(--fs-xs); margin-top: var(--s1); min-height: 0; }
.error:empty { display: none; }
.help { color: var(--text-3); font-size: var(--fs-xs); margin-top: var(--s2); }

.rate { display: grid; grid-template-columns: 1fr auto 1fr; gap: var(--s2); align-items: end; }
.rate__eq { font-family: var(--font-serif); font-size: var(--fs-xl); color: var(--text-3); padding-bottom: 10px; }

/* Stepper numero giocatori */
.stepper { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); }
.stepper__ctrl { display: flex; align-items: center; gap: var(--s3); }
.stepper__value { font-family: var(--font-serif); font-size: var(--fs-xl); min-width: 2ch; text-align: center; }
.round-btn {
  width: 48px; height: 48px; border-radius: var(--r-pill);
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 24px; line-height: 1; display: grid; place-items: center; cursor: pointer;
}
.round-btn:active { background: var(--surface-2); }
.round-btn:disabled { opacity: .35; cursor: default; }

/* Riga giocatore con input */
.prow { display: grid; grid-template-columns: 28px 1fr; gap: var(--s3); align-items: start; }
.prow__idx {
  width: 28px; height: var(--tap); display: grid; place-items: center;
  color: var(--text-3); font-size: var(--fs-sm);
}
.prow + .prow { margin-top: var(--s3); }

.player-line { display: grid; grid-template-columns: 1fr minmax(120px, 44%); gap: var(--s3); align-items: center; }
.player-line__name { font-weight: 600; overflow-wrap: anywhere; }
.player-line__meta { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }

/* ------------------------------------------------------------------ */
/* Pulsanti                                                             */
/* ------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s5);
  border-radius: var(--r-md); border: 1px solid transparent;
  font-size: var(--fs-md); font-weight: 600; cursor: pointer;
  text-decoration: none; user-select: none; -webkit-user-select: none;
  transition: background .15s, transform .05s;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
@media (hover: hover) {
  .btn--primary:hover:not(:disabled) { background: var(--accent-strong); }
}
.btn--primary:active { background: var(--accent-strong); }
.btn--secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn--secondary:active { background: var(--surface-2); }
.btn--ghost { background: transparent; color: var(--accent-strong); padding: 0 var(--s3); }
.btn--danger { background: var(--negative); color: #fff; }
.btn--block { width: 100%; }
.btn--sm { min-height: 40px; padding: 0 var(--s3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-row { display: flex; gap: var(--s3); }
.btn-row > .btn:not(.flex-none) { flex: 1; }
.btn-stack { display: grid; gap: var(--s3); }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: var(--s3) var(--s4) calc(var(--s3) + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.actionbar__inner { max-width: var(--maxw); margin: 0 auto; display: flex; gap: var(--s3); }
.actionbar__inner > .btn { flex: 1; }
.actionbar__inner > .btn--secondary { flex: 0 0 auto; }

/* ------------------------------------------------------------------ */
/* Valori, badge, avvisi                                                */
/* ------------------------------------------------------------------ */
.pos { color: var(--positive); }
.neg { color: var(--negative); }
.muted { color: var(--text-2); }
.small { font-size: var(--fs-sm); }
.right { text-align: right; }
.serif { font-family: var(--font-serif); }
.fs-lg { font-size: var(--fs-lg); }
/* Utilità di spaziatura (niente attributi style: la CSP li blocca) */
.m0 { margin: 0; }
.mt2 { margin-top: var(--s2); }
.mt3 { margin-top: var(--s3); }
.mt4 { margin-top: var(--s4); }
.mb4 { margin-bottom: var(--s4); }
.flex1 { flex: 1; }
.flex-none { flex: 0 0 auto; }
.textarea { padding: var(--s3); line-height: 1.4; min-height: 240px; resize: none; }

.badge {
  display: inline-block; padding: 2px var(--s2); border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 600; background: var(--accent-soft); color: var(--accent-strong);
}

.notice { padding: var(--s3) var(--s4); border-radius: var(--r-md); font-size: var(--fs-sm); }
.notice--ok { background: var(--positive-soft); color: var(--positive); }
.notice--warn { background: var(--warning-soft); color: var(--warning); }
.notice--err { background: var(--negative-soft); color: var(--negative); }
.notice strong { font-weight: 600; }

/* Controllo fiches */
.check { display: grid; grid-template-columns: 1fr auto; row-gap: var(--s1); font-size: var(--fs-sm); }
.check dt { color: var(--text-2); }
.check dd { margin: 0; text-align: right; font-weight: 600; }
.check .check__diff { padding-top: var(--s2); margin-top: var(--s1); border-top: 1px solid currentColor; }

/* Pagamenti */
.payment { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--s3); }
.payment__who { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; font-weight: 600; }
.payment__arrow { color: var(--accent); font-weight: 400; }
.payment__amount { font-family: var(--font-serif); font-size: var(--fs-lg); white-space: nowrap; }

/* Tabella saldi */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: var(--s3) var(--s3); text-align: right; white-space: nowrap; }
.table th:first-child, .table td:first-child { text-align: left; white-space: normal; padding-left: var(--s4); }
.table th:last-child, .table td:last-child { padding-right: var(--s4); }
.table thead th { font-size: var(--fs-xs); color: var(--text-3); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
.table tbody tr + tr td { border-top: 1px solid var(--border); }
.table tfoot td { border-top: 1px solid var(--border-strong); font-weight: 600; }

/* Movimenti */
.entry { display: grid; grid-template-columns: 1fr auto auto; gap: var(--s2); align-items: center; }
.entry__time { color: var(--text-3); font-size: var(--fs-xs); }

/* Home */
/* Solo il pulsante "Nuova partita", al centro dello schermo */
.home {
  position: fixed; inset: 0; z-index: 0;
  display: grid; place-items: center;
  padding: 0 var(--s4);
  pointer-events: none;
}
.home .btn { pointer-events: auto; width: min(100%, 320px); min-height: 60px; font-size: var(--fs-lg); }

/* ------------------------------------------------------------------ */
/* Dialog (bottom sheet su telefono)                                    */
/* ------------------------------------------------------------------ */
.dialog {
  border: 0; padding: 0; color: var(--text); background: var(--surface);
  width: min(100% - 2 * var(--s4), 440px); border-radius: var(--r-lg);
  box-shadow: 0 16px 48px rgba(20, 20, 19, .14);
}
.dialog::backdrop { background: rgba(20, 20, 19, .28); }
.dialog__form { padding: var(--s5) var(--s4) var(--s4); }
.dialog__title { font-size: var(--fs-xl); margin-bottom: var(--s3); }
.dialog__body { color: var(--text-2); }
.dialog__body .field { color: var(--text); }
.dialog__actions { display: flex; flex-direction: row-reverse; gap: var(--s3); margin-top: var(--s5); }
.dialog__actions .btn { flex: 1; padding: 0 var(--s3); }

@media (max-width: 600px) {
  .dialog {
    width: 100%; max-width: 100%; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding-bottom: var(--safe-bottom);
  }
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); z-index: 30;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: var(--s3) var(--s4);
  border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 500;
  width: max-content; max-width: calc(100% - 2 * var(--s4)); text-align: center;
  transition: opacity .2s, transform .2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* Schermi larghi (PC) */
@media (min-width: 720px) {
  .container { padding-top: var(--s6); }
  h1 { font-size: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
