: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;
}
* { 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: 980px; display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.brand { font-weight: 800; letter-spacing: .02em; font-size: 18px; }
.brand span, h1 span { color: var(--gold); }
.status { flex: 1; min-width: 0; font-size: 0; color: transparent; }   /* the text is for screen readers; the arrow beside the name shows whose turn it is */
.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; }

/* board: name rows above and below an SVG board that scales to the space left */
#board { flex: 1 1 auto; min-height: 0; width: 100%; max-width: 900px; display: flex; flex-direction: column; align-items: stretch; padding: 0 8px 8px; gap: 4px; }
#bwrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
#bsvg { width: 100%; height: 100%; display: block; touch-action: none; }
.prow { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 2px 6px; }
.prow .who { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.prow .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow.mine .nm { color: var(--gold); }
.prow .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.prow .meta b { color: var(--ink); font-weight: 600; }
.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)); flex: none; }
.turnslot { width: 12px; flex: none; display: flex; align-items: center; }
.chip { display: inline-block; width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid rgba(0,0,0,.35); }
.chip.light { background: #f1ede2; border-color: #c9b98a; } .chip.dark { background: #b8323c; border-color: #6e1820; }
.react { display: flex; gap: 4px; }
.react .rb { width: 32px; height: 30px; padding: 0; font-size: 16px; line-height: 1; border-radius: 8px; text-align: center; }
.react .rb[disabled] { opacity: .35; cursor: default; }

/* svg board */
.pt-hit { fill: transparent; }
.chk { filter: drop-shadow(0 2px 2px rgba(0,0,0,.5)); }
.chk.src { cursor: grab; }
.src-glow { fill: none; stroke: var(--teal); stroke-width: 4; opacity: .9; }
.sel-ring { fill: none; stroke: var(--gold); stroke-width: 5; }
.tgt-tri { fill: rgba(56,194,176,.42); stroke: #7fe8d8; stroke-width: 3; }
.tgt-dot { fill: rgba(56,194,176,.5); stroke: #7fe8d8; stroke-width: 3; stroke-dasharray: 6 5; }
.tgt-over { fill: rgba(56,194,176,.55); }
.rollbtn { cursor: pointer; }
.die-used { opacity: .28; }
.ghost-chk { pointer-events: none; }
@keyframes glow { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.src-glow { animation: glow 1.6s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .src-glow { animation: none; } }

/* 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; }

#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); }

.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; }

/* 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; }
