/* Layout: one phone-width column. Lobby = scrolling duel list under a dark rink-blue band.
   Game = full-bleed ice canvas with a translucent HUD on top and a control panel at the bottom. */
:root {
  --bg: #EDF4F8;          /* ice */
  --surface: #FFFFFF;
  --surface-2: #DCE9F1;   /* deep ice */
  --rink: #10233A;        /* night rink chrome */
  --rink-2: #1B3350;
  --rink-ink: #EAF2F8;
  --rink-muted: #8FA6BC;
  --ink: #152130;
  --muted: #5B6F82;
  --line: #C9DAE5;
  --red: #D7263D;         /* my handle */
  --yellow: #F2B632;      /* default opponent handle */
  --granite: #3A3F47;
  --granite-2: #767D86;
  --win: #2E9E6B;         /* my round / duel */
  --loss: #D7263D;        /* opponent's */
  --draw: #3AA0D8;        /* drawn */
  --accent: #1B3350;      /* actions and selection, never a result colour */
  --accent-ink: #FFFFFF;
  --font-display: "Barlow Condensed", "Arial Narrow", Impact, sans-serif;
  --font-body: "Barlow", "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --shadow: 0 6px 18px rgba(16, 35, 58, .10);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1622; --surface: #132338; --surface-2: #1A2E47; --ink: #E8EFF5; --muted: #92A6B9;
    --line: #27405C; --rink: #0B1622; --rink-2: #132338; --shadow: 0 6px 18px rgba(0, 0, 0, .35);
    --accent: #EAF2F8; --accent-ink: #10233A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B1622; --surface: #132338; --surface-2: #1A2E47; --ink: #E8EFF5; --muted: #92A6B9;
  --line: #27405C; --rink: #0B1622; --rink-2: #132338; --shadow: 0 6px 18px rgba(0, 0, 0, .35);
  --accent: #EAF2F8; --accent-ink: #10233A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  background: var(--rink); z-index: 10;
}
button { font: inherit; color: inherit; }
button:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); text-wrap: balance; }
#app { height: 100%; max-width: 520px; margin: 0 auto; position: relative; }
.screen { height: 100%; position: relative; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Lobby ---------- */
.lobby { height: 100%; display: flex; flex-direction: column; }
.lobby-head {
  background: var(--rink); color: var(--rink-ink);
  padding-block: 14px 18px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px;
}
.brand { font-family: var(--font-display); font-weight: 800; font-size: 34px; letter-spacing: .02em; line-height: 1; }
.brand small { display: block; font-family: var(--font-body); font-weight: 500; font-size: 13px; letter-spacing: 0; color: var(--rink-muted); margin-top: 4px; }
.me-chip {
  background: var(--rink-2); border: 0; border-radius: 999px; padding: 8px 14px;
  display: flex; align-items: center; gap: 10px; color: var(--rink-ink); cursor: pointer;
}
.me-chip .me-name { font-weight: 600; font-size: 15px; line-height: 1.1; text-align: left; }
.me-chip .me-sub { display: block; font-size: 12px; color: var(--rink-muted); font-weight: 400; }

.lobby-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-block: 16px 110px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 22px;
}
.sec { display: flex; flex-direction: column; gap: 10px; }
.sec-title { display: flex; align-items: baseline; gap: 8px; font-size: 18px; font-weight: 700; }
.sec-title .count { font-family: var(--font-body); font-weight: 600; font-size: 13px; color: var(--muted); }
.sec-empty { color: var(--muted); font-size: 14px; background: var(--surface-2); border-radius: 10px; padding: 12px 14px; }

.duel {
  width: 100%; text-align: left; border: 0; cursor: pointer;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  position: relative;
}
.duel .who { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.duel .name { font-weight: 700; font-size: 17px; line-height: 1.15; }
.duel .gname { font-size: 13px; color: var(--muted); }
.duel .status { font-size: 13.5px; margin-top: 4px; color: var(--ink); }
.duel .status { font-weight: 600; }
.duel .status.win { color: var(--win); }
.duel .status.loss { color: var(--loss); }
.duel .status.draw { color: var(--draw); }
.duel .score { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.duel .score .pts { font-family: var(--font-display); font-weight: 800; font-size: 30px; line-height: 1; letter-spacing: .02em; }
.duel .score .pts .sep { color: var(--muted); font-weight: 600; padding: 0 1px; }
.duel .cta {
  grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 2px;
}


.pick-list.games .pick { grid-template-columns: auto 1fr auto; }

/* five round cards (best of five) */
.cards5 { display: inline-flex; gap: 3px; }
.cards5 span {
  width: 11px; height: 15px; border-radius: 2px; border: 1.5px solid var(--line); background: transparent;
}
.cards5 span.me { background: var(--win); border-color: var(--win); }
.cards5 span.opp { background: var(--loss); border-color: var(--loss); }
.cards5 span.draw { background: var(--draw); border-color: var(--draw); }
.cards5.lg span { width: 16px; height: 22px; border-radius: 3px; }

.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; font-size: 15px; cursor: pointer;
  background: var(--surface-2); color: var(--ink);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.fab {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--rink); color: var(--rink-ink); border: 0; border-radius: 999px;
  padding: 14px 22px; font-weight: 700; font-size: 16px; cursor: pointer;
  box-shadow: 0 8px 24px rgba(16, 35, 58, .35); display: flex; align-items: center; gap: 10px;
}
.fab svg { width: 18px; height: 18px; }

/* bottom sheet */
.sheet-back { position: absolute; inset: 0; background: rgba(8, 18, 30, .45); z-index: 20; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.25);
  padding-block: 10px calc(20px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  max-height: 85%; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
}
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 2px; }
.sheet h2 { font-size: 26px; font-weight: 700; }
.sheet .sub { color: var(--muted); font-size: 14px; margin-top: -8px; }
.pick-list { display: flex; flex-direction: column; gap: 8px; }
.pick {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; text-align: left;
  border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface); cursor: pointer;
}
.pick.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pick:disabled { opacity: .55; cursor: default; }
.pick .t { font-weight: 700; font-size: 16px; }
.pick .d { font-size: 13px; color: var(--muted); }
.pick .tag { font-size: 12px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }
.game-icon { width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; }
.game-icon svg { width: 30px; height: 30px; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; }
.sheet .stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.sheet .stats .win { color: var(--win); } .sheet .stats .draw { color: var(--draw); } .sheet .stats .loss { color: var(--loss); }
.sheet .stats div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.sheet .stats .big { font-family: var(--font-display); font-weight: 700; font-size: 26px; line-height: 1; }
.sheet .stats .lbl { font-size: 12.5px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(12px + env(safe-area-inset-top, 0px)); z-index: 50;
  background: var(--rink-2); color: var(--rink-ink); padding: 10px 14px; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); font-size: 14px; font-weight: 500; max-width: calc(100% - 32px);
  animation: toast-in .25s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Game ---------- */
.game { position: absolute; inset: 0; background: #1C2B3A; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.game canvas.ice { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud-top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2;
  background: linear-gradient(to bottom, rgba(16,35,58,.92), rgba(16,35,58,.75));
  color: #EAF2F8;
  padding-block: 8px 10px;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; row-gap: 4px;
}
.hud-back { background: rgba(255,255,255,.08); border: 0; border-radius: 10px; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; color: inherit; }
.hud-back svg { width: 20px; height: 20px; }
.hud-score { display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 0; }
.hud-score .n { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 80px; }
.hud-score .n.me { color: #FF8A98; }
.hud-score .pts { font-family: var(--font-display); font-weight: 800; font-size: 30px; line-height: 1; }
.hud-sub { grid-column: 1 / -1; display: flex; justify-content: center; align-items: center; gap: 14px; font-size: 13px; color: #B9CBDC; }
.hud-sub .stones { display: inline-flex; gap: 3px; align-items: center; }
.hud-sub .stones i { width: 10px; height: 10px; border-radius: 50%; background: #3A3F47; border: 2px solid var(--c); display: inline-block; }
.hud-sub .stones i.used { opacity: .25; }

.hud-panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  background: linear-gradient(to top, rgba(16,35,58,.95), rgba(16,35,58,.8));
  color: #EAF2F8;
  padding-block: 10px calc(12px + env(safe-area-inset-bottom, 0px));
  padding-left: max(14px, env(safe-area-inset-left, 0px));
  padding-right: max(14px, env(safe-area-inset-right, 0px));
  display: grid; grid-template-columns: 92px 1fr; gap: 14px; align-items: center; min-height: 112px;
}
.dial-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dial-wrap canvas { width: 84px; height: 84px; touch-action: none; cursor: grab; border-radius: 50%; }
.dial-wrap .dl { font-size: 12px; color: #B9CBDC; white-space: nowrap; }
.dial-wrap .dl strong { color: #EAF2F8; font-weight: 600; }
.hint { font-size: 14.5px; line-height: 1.35; color: #D7E3EE; min-width: 0; }
.hint strong { font-family: var(--font-display); font-weight: 700; font-size: 20px; display: block; letter-spacing: .01em; color: #fff; }
.hint .meter { position: relative; margin-top: 6px; height: 8px; border-radius: 4px; background: rgba(255,255,255,.14); overflow: hidden; }
.hint .meter i { display: block; height: 100%; width: 0%; background: var(--yellow); border-radius: 4px; transition: width .08s linear, background-color .15s; }
.hint .meter.sweep i { background: #5BD1FF; }
.hint .meter.sweep i.push { background: var(--yellow); }
/* notch where sweeping starts to push the stone */
.hint .meter.sweep::after { content: ''; position: absolute; top: 0; bottom: 0; left: var(--push, 50%); width: 2px; background: rgba(255,255,255,.6); }
.hud-panel.is-sweep { grid-template-columns: 1fr; }
.hud-panel.is-sweep .dial-wrap { display: none; }
/* after a stone has come to rest: result on the left, Weiter on the right */
.hud-next { display: none; }
.hud-panel.is-wait { grid-template-columns: 1fr auto; }
.hud-panel.is-wait .dial-wrap { display: none; }
.hud-panel.is-wait .hud-next { display: block; padding: 12px 22px; }

.overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center;
  background: rgba(8, 18, 30, .55); padding: 20px;
}
.overlay .card {
  background: var(--surface); color: var(--ink); border-radius: 18px; padding: 22px 20px; width: 100%; max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45); display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.overlay h2 { font-size: 34px; font-weight: 800; line-height: 1; letter-spacing: .01em; }
.overlay .lead { font-size: 16px; color: var(--muted); }
.overlay .scoreline { display: flex; align-items: center; justify-content: center; gap: 14px; }
.overlay .scoreline .pts { font-family: var(--font-display); font-weight: 800; font-size: 44px; line-height: 1; }
.overlay .scoreline .nm { font-size: 13px; color: var(--muted); display: block; font-family: var(--font-body); font-weight: 600; }
.overlay .detail { font-size: 14px; color: var(--ink); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.overlay .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .hint .meter i { transition: none; }
}

/* lobby: two pills at the bottom (practice, new duel) and the first-run name field */
.fab-row {
  position: absolute; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex; justify-content: center; gap: 10px; pointer-events: none; z-index: 5;
}
.fab-row .fab { position: static; transform: none; pointer-events: auto; }
.fab.secondary { background: var(--surface); color: var(--ink); }
.input {
  width: 100%; font: inherit; font-size: 18px; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
/* waiting for the other side or sending: no dial, no button */
.hud-panel.is-idle { grid-template-columns: 1fr; }
.hud-panel.is-idle .dial-wrap { display: none; }
