:root {
  --bg: #0e1420; --bg2: #141d2e; --panel: #172136; --panel2: #1f2c47; --line: rgba(255,255,255,.1);
  --ink: #eef1f7; --muted: #8e9ab0; --gold: #e9b949; --teal: #38c2b0; --danger: #e5646b;
  --sq-light: #dfe5f1; --sq-dark: #3a5f94;
  /* the board is a fixed square so nothing jumps while pieces come and go */
  --S: min(calc(100vw - 16px), calc(100dvh - 292px), 720px);
}
@supports not (height: 100dvh) {
  :root { --S: min(calc(100vw - 16px), calc(100vh - 292px), 720px); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 30%, #1a2742 0%, var(--bg) 70%) fixed;
  color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; user-select: none; -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app { height: 100%; display: flex; flex-direction: column; align-items: center; }

/* header */
#top { width: 100%; max-width: 1100px; display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.brand { font-weight: 800; letter-spacing: .02em; font-size: 18px; color: var(--gold); }
h1 { color: var(--gold); }
.status { flex: 1; font-size: 0; min-width: 0; }   /* the status text is for screen readers only */
.tools { display: flex; gap: 6px; }
button.icon { width: 36px; height: 36px; padding: 0; border-radius: 10px; font-size: 18px; line-height: 1; }
button.icon.off { opacity: .45; }

/* layout: board column + move list */
#play { width: 100%; max-width: 1100px; flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0 8px 8px; }
#boardcol { width: var(--S); flex: none; display: flex; flex-direction: column; gap: 4px; }
#side { width: var(--S); flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; }
#side h3 { margin: 0 0 2px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
#movelist { margin: 0; padding: 0; list-style: none; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 2px 14px; font: 13px/1.5 ui-monospace, Consolas, monospace; color: var(--muted); }
#movelist li { white-space: nowrap; }
#movelist li b { color: var(--ink); font-weight: 600; }
#movelist .cur { color: var(--gold); font-weight: 700; }
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  :root { --S: min(calc(100dvh - 190px), calc(100vw - 380px), 720px); }
  #play { flex-direction: row; justify-content: center; align-items: flex-start; gap: 16px; }
  #side { width: 260px; flex: none; height: var(--S); margin-top: 42px; }
}

/* player bars */
.pbar { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 6px; font-size: 14px; color: var(--muted); min-width: 0; }
.pbar .disc { width: 20px; height: 20px; border-radius: 50%; flex: none; }
.pbar .disc.w { background: #fbf6e9; border: 2px solid #c9c0a6; }
.pbar .disc.b { background: #1a1f2b; border: 2px solid #5b6884; }
.pbar b { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pbar.mine b { color: var(--gold); }
.pbar .meta { margin-left: auto; white-space: nowrap; }
.pbar .meta em { font-style: normal; color: var(--ink); }
.turnslot { width: 14px; height: 18px; display: flex; align-items: center; flex: none; }
.turnarrow { width: 0; height: 0; border-left: 12px solid var(--gold); border-top: 8px solid transparent; border-bottom: 8px solid transparent; filter: drop-shadow(0 0 4px rgba(233,185,73,.7)); }
.pbar .react { display: flex; gap: 4px; margin-left: 4px; }
.pbar .rb { width: 30px; height: 26px; padding: 0; font-size: 15px; line-height: 1; border-radius: 8px; text-align: center; }
.pbar .rb[disabled] { opacity: .35; cursor: default; }

/* board */
#boardwrap { width: var(--S); height: var(--S); }
#board { position: relative; width: 100%; height: 100%; background: var(--sq-light); border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.5), 0 0 0 3px #22304d; touch-action: none; overflow: hidden; }
.sq { position: absolute; width: 10%; height: 10%; background: var(--sq-dark); }
.sq .num { position: absolute; left: 3px; top: 1px; font: normal 600 calc(var(--S) / 10 * .2)/1 system-ui, sans-serif; color: rgba(255,255,255,.55); pointer-events: none; }
.sq.last { background: #5b7fb8; }
.sq.sel { background: #b8923a; }
.sq.via { background: #7d6a38; }
.sq .dot { position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(56,194,176,.9); box-shadow: 0 0 10px rgba(56,194,176,.8); pointer-events: none; }
.sq .dot.mid { width: 20%; height: 20%; background: rgba(233,185,73,.95); box-shadow: 0 0 10px rgba(233,185,73,.8); }

.pc { position: absolute; width: 10%; height: 10%; cursor: pointer; }
.pc::before { content: ""; position: absolute; inset: 9%; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,.55), inset 0 0 0 calc(var(--S) / 10 * .045) var(--ring), inset 0 0 0 calc(var(--S) / 10 * .12) var(--face); background: var(--face2); }
.pc.w { --face: #fbf6e9; --face2: #f1e9cf; --ring: #cdc3a4; }
.pc.b { --face: #232a39; --face2: #181d29; --ring: #5d6b88; }
.pc.king::after { content: ""; position: absolute; inset: 28%; background: center / contain no-repeat url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23e9b949' stroke='%23684c0b' stroke-width='.8' d='M3 18h18l1-11-5 4-5-7-5 7-5-4zM3 20h18v2H3z'/></svg>"); pointer-events: none; }
.pc.must::before { box-shadow: 0 2px 4px rgba(0,0,0,.55), 0 0 0 calc(var(--S) / 10 * .04) rgba(56,194,176,.95), 0 0 14px rgba(56,194,176,.7), inset 0 0 0 calc(var(--S) / 10 * .045) var(--ring), inset 0 0 0 calc(var(--S) / 10 * .12) var(--face); }
.pc.mv::before { box-shadow: 0 2px 4px rgba(0,0,0,.55), 0 0 0 calc(var(--S) / 10 * .03) rgba(255,255,255,.35), inset 0 0 0 calc(var(--S) / 10 * .045) var(--ring), inset 0 0 0 calc(var(--S) / 10 * .12) var(--face); }
.pc.sel::before { box-shadow: 0 2px 6px rgba(0,0,0,.6), 0 0 0 calc(var(--S) / 10 * .05) var(--gold), 0 0 16px rgba(233,185,73,.8), inset 0 0 0 calc(var(--S) / 10 * .045) var(--ring), inset 0 0 0 calc(var(--S) / 10 * .12) var(--face); }
.pc.dragging { opacity: .3; }
.pc.cap { pointer-events: none; z-index: 5; }
.pc.ghost { position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; transform: translate(-50%, -50%) scale(1.1); filter: drop-shadow(0 10px 12px rgba(0,0,0,.6)); }

/* draw offer bar and actions */
#drawbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 10px; background: rgba(233,185,73,.14); color: var(--gold); font-size: 14px; }
#drawbar[hidden] { display: none; }
#drawBtns { display: flex; gap: 6px; }
#drawBtns button { padding: 6px 12px; }
#actions { display: flex; gap: 6px; }
#actions button { flex: 1; padding: 8px 4px; font-size: 13px; min-width: 0; white-space: nowrap; }
#actions button.on { border-color: var(--gold); color: var(--gold); }

/* buttons & inputs */
button { font: inherit; color: var(--ink); background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; cursor: pointer; }
button:hover { border-color: rgba(255,255,255,.3); }
button.primary { background: var(--gold); color: #1b1405; border-color: var(--gold); font-weight: 700; }
button:disabled { opacity: .5; cursor: default; }
input[type=text] { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; user-select: text; -webkit-user-select: text; }
input[type=text]:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(6,9,16,.78); display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.overlay[hidden], #toast[hidden], button[hidden], .note[hidden], #btnInstall[hidden] { display: none; }
.dialog { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px 20px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.5); max-height: 100%; overflow-y: auto; }
.dialog.wide { max-width: 560px; }
.dialog h1 { margin: 0; font-size: 32px; letter-spacing: .01em; }
.dialog h2 { margin: 0; font-size: 22px; }
.dialog h3 { margin: 6px 0 0; font-size: 15px; color: var(--gold); }
.dialog label { font-size: 13px; color: var(--muted); }
.tag { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.note { padding: 8px 12px; border-radius: 10px; background: rgba(233,185,73,.12); color: var(--gold); font-size: 14px; }
.chips { display: flex; gap: 8px; }
.chips label { flex: 1; color: var(--ink); }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: block; text-align: center; padding: 9px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); cursor: pointer; font-size: 14px; }
.chips input:checked + span { border-color: var(--gold); color: var(--gold); background: rgba(233,185,73,.1); }
.chips input:focus-visible + span { outline: 2px solid var(--teal); }
.joinrow, .row { display: flex; gap: 8px; }
.joinrow input { text-transform: uppercase; letter-spacing: .15em; }
.code { font-size: 20px; letter-spacing: .2em; color: var(--gold); }
details { font-size: 14px; color: var(--muted); }
summary { cursor: pointer; padding: 4px 0; }
details ul { padding-left: 18px; margin: 6px 0 0; }
details li { margin-bottom: 6px; }
button small { opacity: .7; }
#newGameBlock { display: flex; flex-direction: column; gap: 10px; }
#newGameBlock[hidden] { display: none; }

.rules h3 { margin: 8px 0 0; font-size: 15px; color: var(--gold); }
.rules p, .rules ul { margin: 4px 0 0; font-size: 14px; color: var(--ink); }
.rules ul { padding-left: 18px; }
.rules li { margin-bottom: 4px; }
.rules button { margin-top: 10px; }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70; max-width: min(92vw, 420px); background: #2a1519; color: #ffd9dc; border: 1px solid var(--danger); border-radius: 12px; padding: 10px 16px; font-size: 14px; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
#toast.info { background: var(--panel2); color: var(--ink); border-color: var(--line); }

/* result: a banner at the bottom, the finished board stays visible and clickable; a win gets a golden glow (plus confetti from game.js) */
#result.overlay { background: none; pointer-events: none; align-items: flex-end; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
#result .dialog { pointer-events: auto; max-width: 440px; text-align: center; padding: 12px 16px; gap: 6px; background: rgba(23,33,54,.96); animation: rise .45s ease-out; }
#result .dialog h2 { font-size: 24px; } #result .tag { margin: 0; }
#result .row { justify-content: center; }
#result .dialog.party { border-color: var(--gold); box-shadow: 0 0 34px rgba(233,185,73,.6), 0 10px 40px rgba(0,0,0,.5); }
#result .dialog.party h2 { color: var(--gold); animation: bounce 1s ease-in-out infinite; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bounce { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { #result .dialog, #result .dialog.party h2 { animation: none; } }

/* ranking overlay */
.ranking .rankwrap { max-height: 52vh; overflow: auto; border-radius: 10px; }
.ranking table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ranking th, .ranking td { padding: 6px 8px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.07); }
.ranking th { position: sticky; top: 0; background: var(--panel2); font-weight: 600; font-size: 12px; color: var(--muted); }
.ranking td.n, .ranking th.n { text-align: right; white-space: nowrap; }
.ranking tr.me td { background: rgba(233,185,73,.14); }
.ranking tr.top1 td:first-child { color: #ffd34d; font-weight: 800; } .ranking tr.top2 td:first-child { color: #d4d9e2; font-weight: 800; } .ranking tr.top3 td:first-child { color: #d99a63; font-weight: 800; }
.ranking .up { color: #54d18a; } .ranking .down { color: #ef7a80; } .ranking .muted { color: var(--muted); }
.ranking small { color: var(--gold); }
#pidShow { font-family: ui-monospace, Consolas, monospace; font-size: 11px; letter-spacing: 0; padding-left: 8px; padding-right: 6px; }
#pidInput { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
button.icon.pulse { animation: pulse .5s ease-out; }
@keyframes pulse { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
