/* =========================================================================
   Score — design system inspired by the SmartHub screenshots:
   deep navy, teal→blue gradients, soft cards, pill badges, big numbers.
   Zoom is driven by --ui root font-size (rem everywhere). Range 25–500 %.
   ========================================================================= */

:root {
  --ui: 16px;                 /* set by settings.js for zoom 25–500 % */

  --bg:        #0a111e;
  --bg-grad:   radial-gradient(1200px 700px at 70% -10%, #122036 0%, #0a111e 60%);
  --card:      #131e2e;
  --card-2:    #16233597;
  --card-brd:  rgba(255,255,255,.07);
  --inset:     rgba(255,255,255,.04);

  --text:      #e9eef6;
  --muted:     #8a98ab;
  --faint:     #5d6b80;

  --acc-1:     #2dd4bf;       /* teal  */
  --acc-2:     #3b82f6;       /* blue  */
  --acc:       #34d399;
  --grad:      linear-gradient(95deg, var(--acc-1), var(--acc-2));
  --grad-soft: linear-gradient(95deg, rgba(45,212,191,.18), rgba(59,130,246,.18));

  --good:      #34d399;
  --bad:       #fb7185;
  --warn:      #fbbf24;

  --r-lg: 1.25rem;
  --r-md: .85rem;
  --r-sm: .55rem;
  --gap:  .9rem;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg:        #eef2f7;
  --bg-grad:   radial-gradient(1200px 700px at 70% -10%, #dde8f6 0%, #eef2f7 60%);
  --card:      #ffffff;
  --card-2:    #f4f7fb;
  --card-brd:  rgba(15,30,55,.10);
  --inset:     rgba(15,30,55,.04);
  --text:      #16202e;
  --muted:     #5a6b82;
  --faint:     #93a1b5;
  --shadow: 0 8px 24px rgba(30,50,90,.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { font-size: var(--ui); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* zoom is controlled only via settings: kill double-tap & pinch zoom */
html, body { touch-action: manipulation; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }
h1,h2,h3 { margin: 0; }

/* ----- layout shells ---------------------------------------------------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: .75rem clamp(.6rem, 2vw, 1.25rem) 4rem; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem clamp(.6rem, 2vw, 1.25rem);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-brd);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; letter-spacing: .3px; }
.brand .dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--good); box-shadow: 0 0 10px var(--good); }
.brand .dot.off { background: var(--faint); box-shadow: none; }
.spacer { flex: 1; }

/* ----- cards ------------------------------------------------------------ */
.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--card-brd);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.card.pad { padding: clamp(.85rem, 2vw, 1.25rem); }
.section-title { color: var(--muted); font-size: .8rem; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; margin: 1.4rem .2rem .6rem; }

/* ----- buttons ---------------------------------------------------------- */
.btn {
  border: 1px solid var(--card-brd);
  background: var(--inset);
  border-radius: var(--r-md);
  padding: .6rem .9rem;
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  transition: transform .06s ease, filter .15s ease, background .15s ease;
  user-select: none;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:hover { filter: brightness(1.08); }
.btn.grad { background: var(--grad); border: none; color: #06231f; font-weight: 800; }
.btn.soft { background: var(--grad-soft); border-color: transparent; color: var(--text); }
.btn.ghost { background: transparent; }
.btn.icon { padding: .5rem; min-width: 2.3rem; }
.btn.sm { padding: .38rem .6rem; font-size: .85rem; border-radius: var(--r-sm); }
.btn.lg { padding: .85rem 1.1rem; font-size: 1.05rem; }
.btn.block { width: 100%; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn:disabled { opacity: .45; pointer-events: none; }

.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--inset); border: 1px solid var(--card-brd);
  border-radius: 999px; padding: .25rem .65rem; font-size: .78rem; color: var(--muted); font-weight: 600;
}

/* ----- inputs ----------------------------------------------------------- */
.field { position: relative; }
.input, select.input {
  width: 100%;
  background: var(--inset);
  border: 1px solid var(--card-brd);
  border-radius: var(--r-md);
  padding: .7rem .85rem;
  color: var(--text);
  outline: none;
}
.input:focus { border-color: var(--acc-1); box-shadow: 0 0 0 3px rgba(45,212,191,.18); }
.input::placeholder { color: var(--faint); }
label.lbl { display: block; color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .4px; margin: .1rem 0 .35rem; text-transform: uppercase; }

/* suggestions dropdown */
.suggest { position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + .3rem);
  background: var(--card); border: 1px solid var(--card-brd); border-radius: var(--r-md);
  box-shadow: var(--shadow); overflow: hidden; max-height: 16rem; overflow-y: auto; }
.suggest .opt { padding: .55rem .8rem; display: flex; align-items: center; gap: .5rem; }
.suggest .opt:hover, .suggest .opt.active { background: var(--inset); }
.swatch { width: .85rem; height: .85rem; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0,0,0,.2) inset; }

/* chips row */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ===== HOME ============================================================= */
.hero { text-align: center; padding: 1.6rem 0 .4rem; }
.hero h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); letter-spacing: -.5px; }
.hero h1 .accent { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); margin: .4rem 0 0; }

.recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: var(--gap); }
.recent { padding: .9rem 1rem; display: flex; align-items: center; gap: .8rem; cursor: pointer; }
.recent:hover { border-color: color-mix(in srgb, var(--acc-1) 45%, var(--card-brd)); }
.recent .meta { flex: 1; min-width: 0; }
.recent .meta .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent .meta .s { color: var(--muted); font-size: .8rem; }

.player-edit-row { display: flex; align-items: center; gap: .5rem; }
.player-edit-row .swatch-btn { width: 1.6rem; height: 1.6rem; border-radius: 50%; border: 2px solid rgba(0,0,0,.25); flex: none; cursor: pointer; }

/* ===== GAME BOARD ======================================================= */
.game-head { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin: .4rem .2rem .2rem; }
.game-head h2 { font-size: clamp(1.3rem, 4vw, 1.8rem); }
.game-head .opts { display: flex; gap: .4rem; flex-wrap: wrap; }

.presence { display: flex; align-items: center; gap: -.3rem; }
.presence .who { width: 1.4rem; height: 1.4rem; border-radius: 50%; display: grid; place-items: center;
  font-size: .7rem; font-weight: 800; color: #06231f; margin-left: -.35rem; border: 2px solid var(--bg); }

/* players grid: stacked on phones, side-by-side on wide screens */
.players { display: grid; gap: var(--gap); grid-template-columns: 1fr; }
@media (min-width: 720px)  { .players { grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); } }

.pcard { padding: .9rem; display: flex; flex-direction: column; gap: .7rem; position: relative; overflow: hidden; }
.pcard::before { content:""; position: absolute; inset: 0 auto 0 0; width: .35rem; background: var(--pc, var(--acc)); }
.pcard .phead { display: flex; align-items: center; gap: .6rem; }
.pcard .pname { font-weight: 800; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .rank { font-size: .8rem; color: var(--muted); font-weight: 700; }
.pcard .edit { margin-left: auto; }

.score-row { display: flex; align-items: baseline; gap: .5rem; }
.score { font-size: clamp(2rem, 8vw, 2.8rem); font-weight: 800; line-height: 1; letter-spacing: -1px;
  font-variant-numeric: tabular-nums; }
.gaps { display: inline-flex; flex-direction: column; font-size: .72rem; line-height: 1.05; font-weight: 700; }
.gaps .up { color: var(--good); } .gaps .dn { color: var(--bad); }

/* progress ring */
.ring { --p: 0; width: 2.8rem; height: 2.8rem; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .bg { stroke: var(--inset); }
.ring .fg { stroke: var(--pc, var(--acc)); transition: stroke-dashoffset .4s ease; }
.ring .lbl { font-size: .72rem; font-weight: 800; fill: var(--text); }

.qadd { color: var(--good); } .qsub { color: var(--bad); }
.score.tappable { cursor: pointer; }
.score.tappable:active { opacity: .7; }

/* desktop inline entry (type + Enter) */
.dentry { display: flex; gap: .4rem; }
.dentry .pinput { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.dentry .btn { flex: none; padding-inline: .9rem; }

/* per-player tabular history (laptop) */
.phist { display: flex; flex-direction: column; margin-top: .2rem; }
.phist .h { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .5rem;
  padding: .28rem .15rem; border-bottom: 1px solid var(--card-brd); cursor: pointer;
  font-variant-numeric: tabular-nums; }
.phist .h:last-child { border-bottom: none; }
.phist .h:hover { background: var(--inset); }
.phist .h .d { font-weight: 800; }
.phist .h .d.pos { color: var(--good); } .phist .h .d.neg { color: var(--bad); } .phist .h .d.zero { color: var(--muted); }
.phist .h .tot { color: var(--muted); font-weight: 600; }
.phist .h .when { color: var(--faint); font-size: .72rem; text-align: right; }
.phist .h.undone { opacity: .45; text-decoration: line-through; }
.phist .h .mid { display: flex; align-items: baseline; gap: .4rem; min-width: 0; }
.phist .h .mid .by { font-size: .68rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* action bar + participants */
.game-actions { display: flex; align-items: center; gap: .4rem; margin: .1rem .2rem .7rem; }
.participants { margin-bottom: var(--gap); }
.participants .plist { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.participants .pitem { display: flex; align-items: center; gap: .45rem; background: var(--inset);
  border: 1px solid var(--card-brd); border-radius: 999px; padding: .28rem .5rem .28rem .6rem; }
.by { color: var(--faint); font-size: .78rem; }

/* global log */
.log { display: flex; flex-direction: column; }
.log .row { display: flex; align-items: center; gap: .6rem; padding: .5rem .2rem; border-bottom: 1px solid var(--card-brd); }
.log .row:last-child { border-bottom: none; }
.log .who { font-weight: 700; display: flex; align-items: center; gap: .4rem; }
.log .delta { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.log .when { color: var(--faint); font-size: .75rem; width: 4.2rem; text-align: right; }
.log .note { color: var(--muted); font-size: .8rem; }
.log .row.undone { opacity: .45; }

/* ===== OVERLAY / MODAL ================================================== */
#overlay:empty { display: none; }
.backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(3,7,15,.55);
  display: grid; place-items: end center; backdrop-filter: blur(3px); }
@media (min-width: 640px) { .backdrop { place-items: center; } }
.modal { background: linear-gradient(180deg, var(--card), var(--card-2)); border: 1px solid var(--card-brd);
  width: min(34rem, 100%); max-height: 92dvh; overflow-y: auto;
  border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--shadow); padding: 1.1rem; animation: up .18s ease; }
@media (min-width: 640px) { .modal { border-radius: var(--r-lg); } }
@keyframes up { from { transform: translateY(18px); opacity: .6; } }
.modal h3 { margin-bottom: .9rem; display: flex; align-items: center; gap: .5rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.modal .row-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }

/* ----- numeric keypad (phone) — always full viewport width, zoom-independent ----- */
.modal.sheet { width: 100vw; max-width: 100vw; border-radius: var(--r-lg) var(--r-lg) 0 0; }
.kp-cur { margin-left: auto; font-weight: 600; font-size: .85rem; color: var(--muted); }
.kp-display { background: var(--inset); border: 1px solid var(--card-brd); border-radius: var(--r-md);
  padding: .5rem .9rem; text-align: right; font-size: 2.4rem; font-weight: 800; letter-spacing: -1px;
  font-variant-numeric: tabular-nums; min-height: 3.4rem; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: .6rem 0; }
.kp-key { border: 1px solid var(--card-brd); background: var(--card-2); border-radius: var(--r-md);
  padding: 1rem 0; font-size: 1.5rem; font-weight: 800; transition: transform .05s, filter .1s;
  display: grid; place-items: center; }
.kp-key:active { transform: scale(.95); filter: brightness(1.2); }
.kp-key.kp-fn { background: var(--inset); color: var(--muted); font-size: 1.2rem; }
.kp-note { margin-bottom: .6rem; }
.kp-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: .45rem; }
.swatches .sw { aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches .sw.active { border-color: var(--text); transform: scale(1.08); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .55rem 0; border-bottom: 1px solid var(--card-brd); }
.switch:last-child { border-bottom: none; }
.switch .lab { font-weight: 600; }
.switch .hint { color: var(--muted); font-size: .76rem; }
.toggle { width: 2.8rem; height: 1.6rem; border-radius: 999px; background: var(--inset); border: 1px solid var(--card-brd); position: relative; flex: none; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 50%; left: .2rem; transform: translateY(-50%); width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--text); transition: left .15s; }
.toggle.on { background: var(--grad); border-color: transparent; }
.toggle.on::after { left: calc(100% - 1.3rem); background: #06231f; }

/* segmented control */
.seg { display: inline-flex; background: var(--inset); border: 1px solid var(--card-brd); border-radius: 999px; padding: .2rem; gap: .2rem; }
.seg button { border: none; background: transparent; padding: .35rem .8rem; border-radius: 999px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--grad); color: #06231f; }

/* range */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: .4rem; border-radius: 999px;
  background: var(--inset); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: var(--grad); cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
input[type=range]::-moz-range-thumb { width: 1.3rem; height: 1.3rem; border: none; border-radius: 50%; background: var(--acc-1); cursor: pointer; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .5rem; pointer-events: none; }
#toast .t { background: var(--card); border: 1px solid var(--card-brd); padding: .6rem 1rem; border-radius: 999px; box-shadow: var(--shadow); animation: up .2s ease; }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.mt { margin-top: 1rem; } .mt-s { margin-top: .5rem; }
.flex { display: flex; gap: .5rem; align-items: center; }
.wrapf { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hide { display: none !important; }
.ico { display: inline-flex; align-items: center; justify-content: center; }
.ico svg { display: block; }
.pcard.cardtap { cursor: pointer; }
.pcard.cardtap:active { filter: brightness(1.06); }

/* phone: compact single-row player line (ring · name/place · score+gaps) */
.pcard.pcard-row { flex-direction: row; align-items: center; gap: .75rem; padding: .6rem .85rem;
  cursor: pointer; user-select: none; -webkit-touch-callout: none; }
.pcard.pcard-row:active { filter: brightness(1.06); }
.pcard.pcard-row .ring { width: 2.7rem; height: 2.7rem; }
.pcard.pcard-row .pname { font-size: 1rem; }
.pcard.pcard-row .score-row { margin-left: auto; flex: none; align-items: baseline; }
.pcard.pcard-row .score { font-size: clamp(1.6rem, 7vw, 2.1rem); }
