/* totalino — one layout for every game; colours come from the game pack (CSS variables). */
:root {
  --bg: #FAF8F4; --surface: #FFFFFF; --surface2: #F1EEE8; --ink: #1E2235; --muted: #6B6F80;
  --line: #E6E1D8; --accent: #0B7F70; --accentInk: #FFFFFF; --logo: #1E2235; --ear: #FF8A7A;
  --mint: #0FA38F;
  --r: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
:root[data-scheme="dark"] { color-scheme: dark; --shadow: 0 1px 2px rgba(0,0,0,.3); }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: Rubik, system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 16px; line-height: 1.4;
  min-height: 100vh; transition: background .2s;
}
body.noscroll { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--logo); display: flex; flex: none; }
.brand .logo { height: 30px; width: auto; display: block; }
.top-title { flex: 1; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.langs { display: flex; gap: 2px; flex: none; }
.lang { border: 0; background: none; padding: 6px 7px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.lang.on { color: var(--ink); background: var(--surface2); }

.page { max-width: 760px; margin: 0 auto; padding: 16px; }
.page.with-bar { padding-bottom: 110px; }
h1 { font-size: 26px; font-weight: 600; margin: 8px 0 6px; line-height: 1.2; }
h2 { font-size: 15px; font-weight: 500; color: var(--muted); margin: 0 0 10px; text-transform: none; }
.section { margin: 22px 0; }
.hero p { margin: 0; color: var(--muted); }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 14px; margin: 16px 0; }
.small { font-size: 12px; }

/* buttons */
.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 500; }
.btn.primary { background: var(--accent); color: var(--accentInk); }
.btn.ghost { background: var(--surface2); color: var(--ink); }
.btn.wide { width: 100%; }
.btn.big { padding: 15px; font-size: 17px; }
.icon-btn { border: 0; background: none; width: 36px; height: 36px; border-radius: 10px; font-size: 22px; color: var(--muted); flex: none; }
.icon-btn.ph { visibility: hidden; }

/* home */
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.game-card {
  text-align: left; border: 1px solid var(--line); background: var(--card-bg); color: var(--card-ink);
  border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 4px; min-height: 120px;
  box-shadow: var(--shadow); transition: transform .12s;
}
.game-card:active { transform: scale(.98); }
.game-emoji { font-size: 30px; }
.game-name { font-weight: 600; font-size: 18px; }
.game-tag { font-size: 13px; opacity: .75; }
.continue {
  width: 100%; text-align: left; border: 0; border-radius: var(--r); padding: 16px; margin-top: 18px;
  background: var(--mint); color: #fff; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
}
.cont-label { font-weight: 600; font-size: 17px; }
.cont-game, .cont-players { font-size: 14px; opacity: .95; }
.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.recent li span:last-child { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.toggle { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

/* setup */
.plist { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; align-items: center; gap: 8px; }
.emoji-btn { width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 24px; flex: none; }
.prow .name {
  flex: 1; min-width: 0; height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 14px;
}
.field { margin: 14px 0; }
.label { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 999px; font-size: 15px; }
.chip.on { background: var(--accent); color: var(--accentInk); border-color: var(--accent); }
.chip-input { width: 84px; border: 1px solid var(--line); background: var(--surface); padding: 8px 12px; border-radius: 999px; }
.seg { display: inline-flex; background: var(--surface2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: 9px 14px; border-radius: 9px; font-size: 15px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 500; }

/* bottom bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.bar > * { max-width: 728px; margin: 0 auto; display: block; }
.bar.two { display: flex; gap: 10px; justify-content: center; }
.bar.two .btn { flex: 1; max-width: 359px; margin: 0; padding: 15px; }

/* scoreboard */
.play-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin-bottom: 8px; min-height: 20px; }
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.srow {
  display: grid; grid-template-columns: 26px 34px 1fr auto auto; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
}
.srow.first { outline: 2px solid var(--accent); }
.place { font-weight: 600; color: var(--muted); text-align: center; }
.srow.first .place { color: var(--accent); }
.pemoji { font-size: 24px; text-align: center; }
.pname { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; flex-direction: column; }
.gap { font-size: 12px; color: var(--muted); font-weight: 400; }
.gap.lead { color: var(--accent); }
.delta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ptotal { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 2.2em; text-align: right; }
.play-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.play-actions .btn { flex: 1 1 200px; }

.history summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: 14px; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 500; font-size: 13px; color: var(--muted); }
.th-name { display: block; max-width: 7em; overflow: hidden; text-overflow: ellipsis; margin: 0 auto; }
td.rn { color: var(--muted); }
sup { font-size: 10px; color: var(--accent); }

/* results */
.win { text-align: center; padding: 18px 0 22px; }
.win-label { color: var(--muted); font-size: 14px; }
.win-emoji { font-size: 64px; margin: 8px 0; animation: pop .5s ease-out; }
.win-name { font-size: 22px; font-weight: 600; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* round sheet */
.sheet-back, .dialog-back { position: fixed; inset: 0; z-index: 20; background: rgba(10,14,24,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 14px 14px max(12px, env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 17px; }
.entries { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 2px; }
.entry { display: grid; grid-template-columns: 32px 1fr 96px; align-items: center; gap: 8px; background: var(--surface); padding: 8px 10px; border-radius: 12px; border: 2px solid transparent; }
.entry.active { border-color: var(--accent); }
.entry .val { width: 100%; height: 42px; border: 0; border-radius: 10px; background: var(--surface2); text-align: right; padding: 0 12px; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.entry .val:focus { outline: none; }
.closer { margin: 10px 2px 2px; }
.closer .chip.on { background: var(--accent); color: var(--accentInk); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.keypad button { border: 0; border-radius: 12px; background: var(--surface); height: 52px; font-size: 22px; font-weight: 500; box-shadow: var(--shadow); }
.keypad button:disabled { opacity: .35; }
.keypad button:active { background: var(--surface2); }
.keypad .next { grid-column: 1 / -1; background: var(--accent); color: var(--accentInk); font-size: 18px; }
.sheet-foot { margin-top: 12px; }
@media (min-width: 700px) {
  .sheet-back { align-items: center; }
  .sheet { border-radius: 20px; max-height: 90vh; }
}

/* dialog */
.dialog-back { align-items: center; padding: 16px; z-index: 30; }
.dialog { background: var(--bg); border-radius: 18px; padding: 18px; max-width: 380px; width: 100%; }
.dialog p { margin: 0 0 16px; font-size: 17px; }
.dialog .row { display: flex; gap: 8px; }
.dialog .row .btn { flex: 1; }

/* toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 15px; box-shadow: var(--shadow); animation: up .2s ease-out; transition: opacity .4s; max-width: 92vw; }
.toast.out { opacity: 0; }

/* rooms */
.play-head { align-items: center; }
.room-badge { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 14px; font-weight: 500; letter-spacing: .5px; display: inline-flex; align-items: center; gap: 6px; }
.sync { width: 8px; height: 8px; border-radius: 50%; background: #2DBE7E; }
.sync.off { background: #E0705F; }
.join { display: flex; gap: 8px; }
.join input { flex: 1; min-width: 0; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; text-transform: uppercase; letter-spacing: 2px; font-weight: 500; }
.invite { text-align: center; }
.invite .sheet-head { text-align: left; }
.invite p.muted { font-size: 14px; margin: 0 0 12px; }
.qr { width: 220px; height: 220px; margin: 0 auto; background: #fff; border-radius: 14px; padding: 6px; }
.qr svg { width: 100%; height: 100%; display: block; }
.code-big { font-size: 32px; font-weight: 600; letter-spacing: 4px; margin: 12px 0 16px; font-variant-numeric: tabular-nums; }

/* footer */
.foot { max-width: 760px; margin: 10px auto 0; padding: 18px 16px 30px; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); }
.foot-row { margin: 4px 0; }
.foot b { font-weight: 500; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
