:root {
  --bg: #f2f1ee;
  --surface: #ffffff;
  --surface-2: #f7f6f3;
  --text: #1f2023;
  --muted: #6c6d70;
  --border: #dedcd6;
  --accent: #2f6fd1;
  --accent-text: #ffffff;
  --good: #2e8b57;
  --warn: #c0742c;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
  --radius: 10px;
  --wood-1: #e2bb72;
  --wood-2: #d4a95b;
  --wood-3: #c2944a;
  --wood-dark: #a77a35;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18191b;
    --surface: #232427;
    --surface-2: #1d1e21;
    --text: #e7e7e5;
    --muted: #9b9c9f;
    --border: #36373b;
    --accent: #5b94ea;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #18191b;
  --surface: #232427;
  --surface-2: #1d1e21;
  --text: #e7e7e5;
  --muted: #9b9c9f;
  --border: #36373b;
  --accent: #5b94ea;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.2; margin: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 20px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 650; font-size: 17px; }
.brand svg { width: 28px; height: 28px; }
.st-b { fill: #1b1b1b; } .st-w { fill: #f4f2ec; stroke: #b9b4aa; stroke-width: 1; }
.topbar nav { display: flex; gap: 14px; }
.topbar nav a { color: var(--muted); font-weight: 500; }
.topbar nav a:hover { color: var(--text); }
.iconbtn {
  margin-left: auto; width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 50%; cursor: pointer; padding: 0;
}
.iconbtn:hover { border-color: var(--muted); }
.iconbtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn .spk { fill: currentColor; }
.iconbtn .mute { display: none; }
.iconbtn.off { color: var(--muted); }
.iconbtn.off .wave { display: none; }
.iconbtn.off .mute { display: inline; }
.namechip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.namechip:hover { border-color: var(--muted); }

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-weight: 550; font-size: 14px;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: default; }
input {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%;
}
input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- home ---------- */
.hero { padding: 28px 0 26px; }
.hero h1 { font-size: clamp(26px, 4vw, 36px); font-weight: 700; letter-spacing: -.01em; }
.hero p { color: var(--muted); margin: 8px 0 0; font-size: 16px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.card .thumb { aspect-ratio: 16 / 8; display: grid; place-items: center; padding: 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.card .thumb .board { width: 100%; pointer-events: none; }
.card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card h3 { font-size: 18px; }
.card .meta { color: var(--muted); font-size: 13px; }
.card .btn { align-self: flex-start; }
.card .play { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
.card .play .btn { margin-top: 0; }
.vs-cpu { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--border); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.seg-btn {
  font: inherit; font-size: 13px; font-weight: 550; padding: 7px 11px; border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-checked="true"] { background: var(--surface); color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.rematch-level { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; }
.actions { flex-direction: column; gap: 12px; align-items: stretch; }
.botchip {
  display: inline-block; vertical-align: 2px; margin-left: 4px; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.pcard.is-bot .avatar::after {
  content: ""; position: absolute; right: -3px; bottom: -3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect x='3' y='5' width='10' height='8' rx='2' fill='%236c6d70'/%3E%3Ccircle cx='6.3' cy='9' r='1.1' fill='%23fff'/%3E%3Ccircle cx='9.7' cy='9' r='1.1' fill='%23fff'/%3E%3Crect x='7.4' y='2' width='1.2' height='3' fill='%236c6d70'/%3E%3C/svg%3E") center/12px no-repeat;
  border: 1px solid var(--border);
}
.card.soon { opacity: .6; box-shadow: none; }
.card.soon .thumb { font-size: 13px; color: var(--muted); }

/* ---------- room layout ---------- */
.room { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .room { grid-template-columns: minmax(0, 1fr); } }
.board-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.board-wrap { width: 100%; }
.status {
  text-align: center; font-size: 17px; font-weight: 600; min-height: 1.5em;
}
.status.yours { color: var(--good); }
.status .sub { display: block; font-size: 13px; font-weight: 450; color: var(--muted); margin-top: 2px; }

.sidebar { display: flex; flex-direction: column; gap: 12px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
}
.panel-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.join label { display: block; font-weight: 600; margin-bottom: 8px; }
.actions { display: flex; justify-content: center; }
.invite .muted { margin-top: 8px; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.rules li { margin: 4px 0; }

/* player cards */
.players { padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.pcard {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center;
  padding: 10px; border-radius: 8px; border: 2px solid transparent;
}
.pcard.turn { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.pcard .avatar { width: 40px; height: 40px; border-radius: 50%; position: relative; }
.pcard .avatar.b { background: radial-gradient(circle at 35% 30%, #6a6a6a, #111 70%); box-shadow: 0 2px 3px rgba(0,0,0,.35); }
.pcard .avatar.w { background: radial-gradient(circle at 35% 30%, #fff, #d5d0c6 75%); box-shadow: 0 2px 3px rgba(0,0,0,.25), inset 0 0 0 1px rgba(0,0,0,.08); }
.pcard .dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface); background: #9aa0a6; }
.pcard .dot.on { background: #34a853; }
.pcard .pname { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .psub { font-size: 12px; color: var(--muted); }
.pcard .score { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 1.6em; text-align: right; }
.pcard.empty .pname { color: var(--muted); font-weight: 500; font-style: italic; }
.pcard.empty .avatar { background: var(--surface-2); border: 2px dashed var(--border); box-shadow: none; }

/* ---------- mancala board ---------- */
.board {
  --gap: 2.2%;
  position: relative;
  display: grid;
  grid-template-columns: 1.15fr repeat(6, 1fr) 1.15fr;
  grid-template-rows: auto 1fr 1fr auto;
  column-gap: var(--gap);
  row-gap: 0;
  padding: 2.4% 3%;
  border-radius: 18px / 22px;
  background:
    radial-gradient(120% 90% at 30% 20%, rgba(255,255,255,.18), transparent 60%),
    repeating-linear-gradient(92deg, rgba(120,72,20,.0) 0 7px, rgba(120,72,20,.07) 7px 9px, rgba(120,72,20,0) 9px 17px, rgba(120,72,20,.05) 17px 18px),
    repeating-linear-gradient(88deg, rgba(255,240,200,.07) 0 23px, rgba(0,0,0,0) 23px 41px),
    linear-gradient(180deg, var(--wood-1), var(--wood-2) 55%, var(--wood-3));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.35),
    inset 0 -3px 6px rgba(90,55,15,.25),
    0 2px 0 var(--wood-dark),
    0 10px 24px rgba(60,35,10,.28);
  user-select: none;
  -webkit-user-select: none;
}
.lbl {
  text-align: center; font-size: clamp(11px, 1.6vw, 15px); font-weight: 700;
  color: rgba(70,40,10,.75); font-variant-numeric: tabular-nums; padding: 2px 0;
}
.lbl.slbl { font-size: clamp(13px, 2vw, 19px); color: rgba(60,34,8,.9); }
.lbl.hl { color: #1d4f9e; }

.pit, .store {
  position: relative;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 38%, rgba(0,0,0,.0) 50%, rgba(0,0,0,.10) 72%),
    linear-gradient(180deg, #b98943, #cfa45d 60%, #d9b06a);
  box-shadow:
    inset 0 4px 8px rgba(70,40,10,.55),
    inset 0 -2px 3px rgba(255,235,190,.45),
    0 1px 0 rgba(255,240,205,.5);
  margin: 6% 0;
  transition: box-shadow .15s, transform .15s;
}
.pit { aspect-ratio: 1; align-self: center; }
.store { grid-row: 2 / span 2; border-radius: 999px; margin: 3% 0; }
.pit.playable { cursor: pointer; }
.pit.playable:hover, .pit.playable:focus-visible {
  outline: none;
  box-shadow:
    inset 0 4px 8px rgba(70,40,10,.55),
    inset 0 -2px 3px rgba(255,235,190,.45),
    0 0 0 3px rgba(47,111,209,.75);
}
.pit.from::after, .store.from::after, .pit.target::after, .store.target::after {
  content: ""; position: absolute; inset: -4px; border-radius: inherit; pointer-events: none;
}
.pit.from::after { box-shadow: 0 0 0 2px rgba(255,255,255,.6); }
.pit.target::after, .store.target::after { box-shadow: 0 0 0 3px rgba(47,111,209,.45); border: 2px dashed rgba(29,79,158,.6); }
.pit.changed, .store.changed { animation: pulse .5s ease-out; }
.pit.captured { animation: flash .7s ease-out; }
@keyframes pulse { 0% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes flash { 0% { box-shadow: inset 0 0 0 40px rgba(200,60,40,.35); } 100% { } }

/* stones */
.flyer { position: absolute; z-index: 5; pointer-events: none; transform: translate(-50%, -50%); }
.flyer .stone { box-shadow: none; }
.stone.drop { animation: drop .16s cubic-bezier(.3,1.6,.5,1); }
@keyframes drop { 0% { transform: translate(-50%, -50%) scale(1.35); } 100% { transform: translate(-50%, -50%) scale(1); } }
.pit.lifting { box-shadow: inset 0 4px 8px rgba(70,40,10,.55), inset 0 -2px 3px rgba(255,235,190,.45), 0 0 0 3px rgba(255,255,255,.55); }
.lbl.bump { animation: bump .22s ease-out; }
@keyframes bump { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
.stone {
  position: absolute; aspect-ratio: 1; height: auto; border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.stone.b { background: radial-gradient(circle at 34% 30%, #7a7a7a 0, #2a2a2a 38%, #0c0c0c 75%); box-shadow: 1px 2px 2px rgba(0,0,0,.45); }
.stone.w { background: radial-gradient(circle at 34% 30%, #ffffff 0, #f1eee7 40%, #cfc9bd 85%); box-shadow: 1px 2px 2px rgba(0,0,0,.35), inset 0 0 0 .5px rgba(0,0,0,.12); }

.board.flat .pit.playable { cursor: default; }

/* ---------- misc ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
  padding: 20px; width: min(360px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h3 { margin-bottom: 12px; font-size: 18px; }
dialog .row { margin-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 22px); transform: translateX(-50%);
  background: #222; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); z-index: 50; max-width: calc(100vw - 32px);
}
.empty-state { text-align: center; padding: 60px 16px; }
.empty-state p { color: var(--muted); }

@media (max-width: 520px) {
  .topbar { gap: 12px; padding-left: 16px; padding-right: 16px; }
  .brand span { display: none; }
  .topbar nav { gap: 10px; font-size: 14px; }
  main { padding-top: 14px; }
  .board { padding: 2% 2.4%; border-radius: 12px; }
}

/* ---------- accounts / ratings ---------- */
.topbar nav a.active { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); padding-bottom: 2px; }
.acct { position: relative; }
.namechip { display: inline-flex; align-items: center; gap: 6px; }
.ranked-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 160px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 6px;
  display: flex; flex-direction: column;
}
.menu a, .menu button {
  font: inherit; text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--surface-2); }
.linkbtn { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
.linkbtn:hover, .claim-hint a:hover { text-decoration: underline; }
.claim-hint { margin-top: 12px; font-size: 14px; color: var(--muted); }
.join-alt { margin-top: 10px; }

.card .title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card .myrating { color: var(--text); font-weight: 550; }
.row.wrap { flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.check input { width: auto; }
select.botsel {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 8px; min-width: 0; flex: 1 1 140px;
}
.rematch-level select.botsel { flex: 0 1 auto; }

.pcard .pname a { color: inherit; }
.pcard .pname a:hover { color: var(--accent); }
.pcard .rating { font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up, .up { color: var(--good); }
.delta.down, .down { color: #c2453d; }
.center { text-align: center; }
.rated-tag {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px;
  color: var(--muted); background: var(--surface); border: 1px solid var(--border); cursor: help;
}
.rated-tag.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

/* dialog */
.dtabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; margin-bottom: 12px; }
.dtabs button {
  flex: 1; font: inherit; font-size: 13px; font-weight: 600; padding: 7px 6px; border-radius: 6px; border: 0;
  background: transparent; color: var(--muted); cursor: pointer;
}
.dtabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.field { display: block; font-size: 13px; font-weight: 600; margin-top: 10px; }
.field input { margin-top: 5px; font-weight: 400; }
.error { margin-top: 10px; color: #c2453d; font-size: 14px; }

/* pages */
.page { max-width: 760px; margin: 0 auto; }
.page-title { font-size: clamp(24px, 3.5vw, 30px); margin: 8px 0 6px; }
.tabs { display: flex; gap: 6px; margin: 12px 0 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: var(--surface); font-size: 14px; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }
.table-wrap { padding: 0; overflow-x: auto; }
table.lb { width: 100%; border-collapse: collapse; font-size: 14px; }
.lb th, .lb td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.lb th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.lb tr:last-child td { border-bottom: 0; }
.lb .num { text-align: right; font-variant-numeric: tabular-nums; }
.lb .strong { font-weight: 700; }
.lb tr.bot td { color: var(--muted); background: var(--surface-2); }
.lb tr.me td { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.lb a { color: var(--text); font-weight: 600; }
.lb a:hover { color: var(--accent); }
.page > p.small { margin-top: 12px; }

.rcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 16px 0 24px; }
.rcard .big { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.rcard .spark { display: block; width: 100%; height: 60px; margin-top: 10px; color: var(--accent); }
.games-list { list-style: none; margin: 0; padding: 0; }
.games-list li {
  display: grid; grid-template-columns: 52px minmax(0, 1fr) auto auto auto; gap: 12px; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px;
}
.games-list li:last-child { border-bottom: 0; }
.games-list .opp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.games-list .num { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; min-width: 3ch; }
.res { font-weight: 700; font-size: 13px; }
.res.win { color: var(--good); } .res.loss { color: #c2453d; } .res.draw { color: var(--muted); }
@media (max-width: 520px) {
  .games-list li { grid-template-columns: 46px minmax(0, 1fr) auto; }
  .games-list li .when, .games-list li > .small { display: none; }
  .lb th, .lb td { padding: 9px 10px; }
}

/* ---------- end-of-game results ---------- */
.result {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(20, 16, 10, .42); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fadein .25s ease-out;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.result-card {
  position: relative; width: min(420px, 100%); text-align: center;
  background: var(--surface); color: var(--text); border-radius: 18px; padding: 26px 24px 18px;
  box-shadow: 0 24px 70px rgba(0,0,0,.35); border: 1px solid var(--border);
}
.result-card.win { animation: pop .55s cubic-bezier(.2, 1.5, .4, 1); border-top: 5px solid #e2b04a; }
.result-card.loss { animation: rise .35s ease-out, shake .45s .3s ease-in-out; border-top: 5px solid #8a8d93; }
.result-card.draw { animation: rise .35s ease-out; border-top: 5px solid var(--accent); }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1); } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%,100% { transform: none; } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }
.result-x { position: absolute; top: 8px; right: 10px; border: 0; background: none; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.result-x:hover { background: var(--surface-2); color: var(--text); }
.result-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.result-title { font-size: clamp(34px, 8vw, 46px); font-weight: 800; letter-spacing: -.02em; margin: 6px 0 2px; }
.result-card.win .result-title {
  background: linear-gradient(90deg, #c98a1e, #f0c75e, #c98a1e); -webkit-background-clip: text; background-clip: text; color: transparent;
  background-size: 200% 100%; animation: shine 2.4s linear infinite;
}
@keyframes shine { to { background-position: -200% 0; } }
.result-card.loss .result-title { color: var(--muted); }
.result-score { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-sub { color: var(--muted); font-size: 14px; margin-top: 4px; min-height: 1.2em; }

.rating-block { margin: 16px 0 6px; padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.rating-line { display: flex; align-items: center; justify-content: center; gap: 10px; }
.rating-num { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.delta-pill {
  font-size: 15px; font-weight: 800; padding: 3px 10px; border-radius: 999px; font-variant-numeric: tabular-nums;
  opacity: 0; transform: scale(.4);
}
.delta-pill.show { animation: pill .45s cubic-bezier(.2, 1.8, .4, 1) forwards; }
@keyframes pill { to { opacity: 1; transform: scale(1); } }
.delta-pill.up { color: #fff; background: var(--good); }
.delta-pill.down { color: #fff; background: #c2453d; }
.delta-pill.flat { color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.ladder { margin-top: 12px; }
.ladder-track { position: relative; height: 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.ladder-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: linear-gradient(90deg, var(--accent), #6fa3f0); width: 0; }
.ladder-marker {
  position: absolute; top: 50%; width: 18px; height: 18px; border-radius: 50%; transform: translate(-50%, -50%); left: 0;
  background: radial-gradient(circle at 35% 30%, #fff, #d5d0c6 75%); box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.ladder-labels { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.ladder-labels span:first-child { text-align: left; }
.ladder-labels span:last-child { text-align: right; }
.ladder-to { color: var(--text); font-weight: 600; }
.badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 12px 0 2px; min-height: 0; }
.badge {
  font-size: 13px; font-weight: 700; padding: 5px 11px; border-radius: 999px; opacity: 0; transform: translateY(8px);
  animation: badgein .4s ease-out forwards; background: var(--surface-2); border: 1px solid var(--border);
}
.badge.gold { background: linear-gradient(180deg, #fbe7a9, #eec564); color: #5a3d00; border-color: #e0b54b; }
.badge.green { background: color-mix(in srgb, var(--good) 14%, var(--surface)); color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, var(--border)); }
.badge.fire { background: linear-gradient(180deg, #ffd3b0, #ff9a5a); color: #6b2300; border-color: #f08a4b; }
.badge.muted { color: var(--muted); }
@keyframes badgein { to { opacity: 1; transform: none; } }
.result-nudge { margin-top: 12px; font-size: 14px; color: var(--muted); }
.result-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.btn.big { padding: 11px 18px; font-size: 15px; }
.result-board { margin-top: 12px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) {
  .result, .result-card, .badge, .delta-pill.show, .result-card.win .result-title { animation: none !important; opacity: 1; transform: none; }
}

/* practice mode */
.practice-link { align-self: flex-start; flex-basis: 100%; color: var(--muted); }
.practice-link:hover { color: var(--accent); }
.practice-bar { display: flex; justify-content: center; gap: 8px; }
.rated-tag.practice { color: #8a5a00; border-color: #e0b54b; background: color-mix(in srgb, #f4c542 14%, var(--surface)); }
.pit.hint { animation: hintpulse 1.1s ease-in-out 3; }
@keyframes hintpulse {
  0%, 100% { box-shadow: inset 0 4px 8px rgba(70,40,10,.55), 0 0 0 0 rgba(244,197,66,0); }
  50% { box-shadow: inset 0 4px 8px rgba(70,40,10,.55), 0 0 0 5px rgba(244,197,66,.95); }
}
.vs-cpu select.botsel { flex-basis: 100%; }
.practice-note { flex-basis: 100%; }

/* ---------- generic game surface ---------- */
.surface { position: relative; width: 100%; }
.thumb-art { width: 100%; display: grid; place-items: center; }
.card .thumb .thumb-art .board { width: 100%; pointer-events: none; }
.opts { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- Scopa ---------- */
.sc-wrap {
  padding: clamp(6px, 1.2vw, 12px); border-radius: 18px;
  background:
    repeating-linear-gradient(92deg, rgba(120,72,20,0) 0 7px, rgba(120,72,20,.08) 7px 9px, rgba(120,72,20,0) 9px 17px),
    linear-gradient(180deg, #9a6a33, #7d5225 60%, #6b451f);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 10px 24px rgba(40,22,6,.35);
}
.sc-felt {
  --cw: clamp(44px, 7.6vw, 84px);
  --cwp: calc(var(--cw) * .7);
  position: relative; display: grid; gap: clamp(6px, 1.2vw, 12px); padding: clamp(8px, 1.4vw, 14px);
  border-radius: 12px; color: #f2efe6; overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 40%, rgba(255,255,255,.08), transparent 60%),
    repeating-linear-gradient(45deg, rgba(0,0,0,.025) 0 2px, rgba(255,255,255,.015) 2px 4px),
    linear-gradient(180deg, #2d6a45, #215337);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.18), inset 0 6px 18px rgba(0,0,0,.35);
  min-height: calc(var(--cw) * 1.65 * 3 + 80px);
}
.sc-head { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 13px; color: rgba(242,239,230,.8); }
.sc-head .sc-score { margin-left: 8px; padding: 2px 10px; border-radius: 999px; background: rgba(0,0,0,.25); font-variant-numeric: tabular-nums; color: #fff; }
.sc-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: calc(var(--cw) * 1.66); }
.sc-row .sc-hand { flex: 1; }
.sc-hand { display: flex; justify-content: center; align-items: center; gap: calc(var(--cw) * .12); min-height: calc(var(--cw) * 1.66); }
.sc-hand.theirs .pc { width: calc(var(--cw) * .82); }
.sc-hand.theirs .pc + .pc { margin-left: calc(var(--cw) * -.38); }
.sc-mid { display: flex; align-items: center; gap: clamp(8px, 1.6vw, 16px); }
.sc-deck { position: relative; flex: none; width: var(--cw); }
.sc-deck-count {
  position: absolute; right: -6px; bottom: -6px; min-width: 22px; padding: 1px 6px; border-radius: 999px;
  background: #1b1b1b; color: #fff; font-size: 12px; font-weight: 700; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.sc-table {
  flex: 1; min-height: calc(var(--cw) * 1.66 + 16px); display: flex; flex-wrap: wrap; align-content: center; justify-content: center;
  gap: calc(var(--cw) * .14); padding: 8px; border-radius: 10px; border: 1px dashed rgba(255,255,255,.14);
}
.sc-empty { color: rgba(242,239,230,.5); font-size: 13px; font-style: italic; }

.pc {
  position: relative; flex: none; width: var(--cw); aspect-ratio: 300 / 496; border-radius: calc(var(--cw) * .07);
  background: #fff center / cover no-repeat; box-shadow: 0 1px 1px rgba(0,0,0,.25), 0 3px 6px rgba(0,0,0,.28);
  transition: transform .14s ease, box-shadow .14s ease, outline-color .14s;
  outline: 3px solid transparent; outline-offset: 1px;
}
.pc.back { background-image: url(/cards/back.webp); }
.pc.slot { background: none; box-shadow: none; border: 1px dashed rgba(255,255,255,.25); }
.pc.mini { width: 30px; border-radius: 3px; }
.sc-hand.mine .pc.playable { cursor: pointer; }
.sc-hand.mine .pc.playable:hover, .sc-hand.mine .pc.playable:focus-visible { transform: translateY(-10px); box-shadow: 0 10px 18px rgba(0,0,0,.35); outline: none; }
.sc-hand.mine .pc.chosen { transform: translateY(-14px); outline-color: #f4c542; }
.sc-table .pc.target { outline-color: #f4c542; transform: translateY(-3px); }
.sc-table .pc.maybe { outline: 2px dashed rgba(244,197,66,.8); }
.pc.hint { animation: cardhint 1s ease-in-out 3; }
@keyframes cardhint { 50% { outline-color: #f4c542; transform: translateY(-8px); } }

.sc-stack { position: relative; width: var(--cw); aspect-ratio: 300 / 496; }
.sc-stack .pc { position: absolute; left: calc(var(--i) * 2px); top: calc(var(--i) * -2px); }
.sc-side { display: flex; align-items: center; gap: 10px; flex: none; min-width: 0; }
.sc-pile { position: relative; flex: none; }
.sc-pile .pc, .sc-pile .sc-stack { width: var(--cwp); }
.sc-scope-marks { position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%); display: flex; gap: 2px; }
.sc-mark { width: 16px; height: 10px; border-radius: 2px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.4); border-top: 3px solid #c9a227; }
.sc-info { display: grid; gap: 4px; max-width: 150px; }
.sc-name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.sc-chips .chip { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: rgba(0,0,0,.28); color: rgba(255,255,255,.88); white-space: nowrap; }
.sc-chips .chip.gold { background: linear-gradient(180deg, #f6dc8a, #d9ae3e); color: #4b3200; }
.sc-chips .chip.scope { background: rgba(255,255,255,.88); color: #1f4d31; }

.flyer-card { position: absolute; z-index: 30; pointer-events: none; transform-origin: center; will-change: transform; }

/* the Scopa moment: a gold glow sweeps the felt and the word is stamped down */
.sc-felt.scopa-glow::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(105deg, transparent 30%, rgba(255,226,140,.28) 50%, transparent 70%);
  background-size: 250% 100%; animation: sweep 1s ease-out forwards;
  box-shadow: inset 0 0 0 3px rgba(244,197,66,.6);
}
@keyframes sweep { from { background-position: 120% 0; } to { background-position: -60% 0; opacity: .0; } }
.sc-stamp {
  position: absolute; left: 50%; top: 50%; z-index: 40; pointer-events: none;
  font: italic 800 clamp(40px, 8vw, 74px)/1 Georgia, 'Times New Roman', serif; letter-spacing: .01em;
  color: #fbe7a9; text-shadow: 0 2px 0 #9a6f12, 0 6px 18px rgba(0,0,0,.45);
  transform: translate(-50%, -50%) rotate(-7deg); opacity: 0;
}
.sc-stamp.show { animation: stamp 1.1s cubic-bezier(.2,.9,.3,1) forwards; }
@keyframes stamp {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-7deg) scale(1.9); }
  18% { opacity: 1; transform: translate(-50%, -50%) rotate(-7deg) scale(.96); }
  26% { transform: translate(-50%, -50%) rotate(-7deg) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(-7deg) scale(1.02); }
}

.sc-chooser {
  position: absolute; right: 10px; bottom: 10px; z-index: 25; animation: sumin2 .18s ease-out;
  display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 12px; min-width: 200px;
  background: var(--surface); color: var(--text); box-shadow: 0 12px 30px rgba(0,0,0,.4);
}
.sc-chooser-title { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.sc-option {
  display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-radius: 8px; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
}
.sc-option:hover { border-color: var(--accent); }
.sc-option-label { margin-left: 6px; font-weight: 600; }

.sc-summary {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 35;
  width: min(360px, calc(100% - 24px)); padding: 16px; border-radius: 14px; text-align: center;
  background: var(--surface); color: var(--text); box-shadow: 0 18px 50px rgba(0,0,0,.45);
  animation: sumin .3s ease-out;
}
@keyframes sumin { from { opacity: 0; transform: translate(-50%, -44%); } to { opacity: 1; transform: translate(-50%, -50%); } }
.sc-sum-title { font-weight: 800; font-size: 18px; margin-bottom: 8px; }
table.sc-sum { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 12px; }
.sc-sum th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: right; padding: 4px 6px; }
.sc-sum td { padding: 5px 6px; border-top: 1px solid var(--border); text-align: left; }
.sc-sum td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sc-sum td.won { color: var(--good); font-weight: 800; }
.sc-sum td.won::before { content: "● "; font-size: 9px; vertical-align: 2px; }
.sc-sum tr.pts td { font-weight: 700; border-top: 2px solid var(--border); }
.sc-sum tr.tot td { font-weight: 800; }

.sc-thumb { display: flex; justify-content: center; padding: 10px 20px; border-radius: 10px; background: linear-gradient(180deg, #2d6a45, #215337); --cw: 62px; }
.sc-thumb .pc { transform: rotate(-9deg) translateY(4px); }
.sc-thumb .pc + .pc { margin-left: -14px; }
.sc-thumb .pc:nth-child(2) { transform: translateY(-4px); z-index: 1; }
.sc-thumb .pc:nth-child(3) { transform: rotate(9deg) translateY(4px); }

@media (max-width: 600px) {
  .sc-felt { --cw: clamp(40px, 13vw, 70px); }
  .sc-info { max-width: 92px; }
  .sc-chips .chip:not(.gold):not(.scope) { display: none; }
  .sc-chips .chip:first-child { display: inline-block; }
}
@media (prefers-reduced-motion: reduce) {
  .sc-stamp.show { animation-duration: .01s; opacity: 1; }
}
@keyframes sumin2 { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Scopa: choosing what to capture, directly on the table */
.sc-table .pc.pickable { cursor: pointer; outline: 3px solid rgba(244,197,66,.9); animation: pickpulse 1.4s ease-in-out infinite; }
.sc-table .pc.pickable:hover { transform: translateY(-4px); }
.sc-table .pc.picked { outline: 3px solid #f4c542; transform: translateY(-8px); box-shadow: 0 10px 18px rgba(0,0,0,.35); }
.sc-table .pc.dim { opacity: .45; filter: saturate(.6); }
@keyframes pickpulse { 50% { outline-color: rgba(244,197,66,.35); } }
.sc-prompt {
  position: absolute; left: 50%; top: 44px; transform: translateX(-50%); z-index: 20; pointer-events: none;
  padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap;
  background: rgba(0,0,0,.45); color: #fbe7a9; animation: sumin2 .18s ease-out;
}
@media (prefers-reduced-motion: reduce) { .sc-table .pc.pickable { animation: none; } }
