/* Base + shared components. Every game page loads tokens.css then this. */

*, *::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);
  font-size: var(--fs-m);
  line-height: 1.45;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- app frame: top bar, scroll area, tab bar; safe areas for the iPhone notch ---------- */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.topbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 56px;
  padding: var(--s2) var(--gutter);
}
.topbar .title { font-size: var(--fs-l); font-weight: 650; letter-spacing: -0.02em; }
.topbar .spacer { flex: 1; }
.topbar .sub { font-size: var(--fs-s); color: var(--text-2); }
.main { flex: 1; padding: 0 var(--gutter) calc(96px + env(safe-area-inset-bottom)); }
.has-fab .main { padding-bottom: calc(168px + env(safe-area-inset-bottom)); }
.fab {
  position: fixed; left: 0; right: 0; bottom: calc(76px + env(safe-area-inset-bottom));
  width: calc(100% - 2 * var(--gutter)); max-width: calc(var(--maxw) - 2 * var(--gutter));
  margin: 0 auto; box-shadow: var(--shadow-3);
}

.page-title {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  padding: var(--s2) 0 var(--s5);
}

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  padding: var(--s2) var(--gutter) calc(var(--s2) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(18px);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar nav { display: flex; width: 100%; max-width: var(--maxw); }
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--s1) 0;
  font-size: 11px; font-weight: 550;
  color: var(--text-3);
  transition: color var(--t) var(--ease);
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--text); }

/* ---------- game screens: content centred in the free space, actions at the bottom (thumb reach) ---------- */
.app.game { height: 100dvh; min-height: 0; }
.app.game .main { display: flex; flex-direction: column; padding-bottom: 0; min-height: 0; }
.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 0; }
.actions {
  display: flex; gap: var(--s3); align-items: center;
  padding: var(--s4) 0 calc(var(--s4) + env(safe-area-inset-bottom));
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 48px;
  padding: 0 var(--s5);
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform var(--t-fast) var(--ease), opacity var(--t) var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.small svg { width: 18px; height: 18px; }
.btn.block { width: 100%; }
.btn.quiet { background: var(--surface-2); color: var(--text); }
.btn.small { height: 36px; padding: 0 var(--s4); font-size: var(--fs-s); }
.icon-btn {
  width: 40px; height: 40px;
  display: inline-grid; place-items: center;
  border-radius: var(--r-full);
  color: var(--text);
  transition: background var(--t) var(--ease);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

.avatar {
  --size: 36px;
  width: var(--size); height: var(--size);
  border-radius: var(--r-full);
  display: inline-grid; place-items: center;
  font-size: calc(var(--size) * 0.4); font-weight: 650;
  color: #fff;
  background: var(--av, #6b6b74);
  flex: none;
}
.avatar.s { --size: 28px; }
.avatar.l { --size: 56px; }

/* ---------- section headers + list rows ---------- */
.section { margin-bottom: var(--s6); }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 var(--s1) var(--s3);
}
.section-head h2 { font-size: var(--fs-s); font-weight: 600; color: var(--text-2); letter-spacing: 0; }
.section-head .count { font-size: var(--fs-s); color: var(--text-3); }

.list {
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%;
  min-height: 72px;
  padding: var(--s3) var(--s4);
  text-align: left;
  position: relative;
  transition: background var(--t) var(--ease);
}
.row + .row::before {
  content: ""; position: absolute; top: 0; right: 0; left: 68px;
  border-top: 1px solid var(--line);
}
.row:active { background: var(--surface-2); }
.row .body { flex: 1; min-width: 0; }
.row .line1, .row .line2 { display: block; }
.row .line1 { font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .line2 { font-size: var(--fs-s); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: var(--fs-xs); color: var(--text-3); text-align: right; flex: none; }
.row .chev { width: 16px; height: 16px; color: var(--text-3); flex: none; }

.game-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--surface-2);
  flex: none;
}
.game-icon svg { width: 26px; height: 26px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--turn); flex: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 var(--s3);
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: var(--fs-s); font-weight: 550;
}
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- bottom sheet ---------- */
.scrim {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.32);
  animation: fade var(--t) var(--ease);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: var(--maxw); margin: 0 auto;
  background: var(--surface);
  border-radius: var(--r-l) var(--r-l) 0 0;
  padding: var(--s2) var(--gutter) calc(var(--s5) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-3);
  animation: rise var(--t-slow) var(--ease);
}
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 0 auto var(--s4); }
.sheet h3 { font-size: var(--fs-l); font-weight: 650; letter-spacing: -0.02em; margin-bottom: var(--s4); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }

/* ---------- segmented control ---------- */
.seg {
  display: flex; padding: 3px;
  background: var(--surface-2);
  border-radius: var(--r-full);
}
.seg button {
  flex: 1; height: 34px; border-radius: var(--r-full);
  font-size: var(--fs-s); font-weight: 550; color: var(--text-2);
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.tile-stat {
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  padding: var(--s4);
}
.tile-stat .k { font-size: var(--fs-xs); color: var(--text-2); font-weight: 550; }
.tile-stat .v { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile-stat .d { font-size: var(--fs-xs); color: var(--text-3); }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: var(--s4); }
.field span { display: block; font-size: var(--fs-s); color: var(--text-2); margin: 0 0 6px var(--s1); }
.field input {
  width: 100%; height: 52px;
  padding: 0 var(--s4);
  border-radius: var(--r);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  outline: none;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.field input:focus { border-color: var(--text); box-shadow: 0 0 0 3px var(--line); }

.banner {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s4);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-s);
}

.muted { color: var(--text-2); }
.center { text-align: center; }

/* ---------- app pages ---------- */
a.row, a.tab { color: inherit; text-decoration: none; }
.list.inset { box-shadow: none; background: var(--surface-2); }
.list.inset .row:active { background: var(--surface-3); }
.field-label { font-size: var(--fs-s); color: var(--text-2); margin: 0 0 var(--s2) var(--s1); }
.row.pick .check {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  box-shadow: inset 0 0 0 1.5px var(--line-strong);
  transition: background var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.row.pick[aria-pressed="true"] .check { background: var(--accent); box-shadow: inset 0 0 0 6px var(--accent), inset 0 0 0 9px var(--on-accent); }
.btn:disabled { opacity: 0.35; pointer-events: none; }
.btn:focus-visible, .icon-btn:focus-visible, .row:focus-visible, .tab:focus-visible, .card:focus-visible, .wtile:focus-visible {
  outline: 2px solid var(--text); outline-offset: 2px;
}
.empty { padding: var(--s6) 0; text-align: center; }
.pad { padding: var(--s4); }
.wrap { white-space: normal !important; }
.main.auth { display: flex; flex-direction: column; justify-content: center; padding-bottom: var(--s7); }
.hello { margin-bottom: 40px; }
.hello .page-title { padding: 0 0 6px; }
.brand { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 20px; }
.brand svg { width: 38px; height: 38px; }
.form-error { min-height: 20px; color: var(--bad); font-size: var(--fs-s); margin: 0 0 var(--s3) var(--s1); }
.small-print { font-size: 13px; margin-top: 20px; }
.offline-only { display: none; margin-bottom: var(--s5); }
:root[data-offline] .offline-only { display: flex; }
.toast[hidden] { display: none; }
