: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;
  --c0: #38c2b0; --c1: #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; font-size: 0; min-width: 0; }   /* the status text is for screen readers only; the scoreboard 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; }

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

.viewercards { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; --cw: 60px; }
.viewercards .card.top { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

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

#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; }
/* 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); }
/* settings overlay */
.dialog h3 { margin: 6px 0 0; font-size: 15px; 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; }

/* scoreboard */
#score { width: min(100%, 980px); display: flex; align-items: stretch; justify-content: space-between; gap: 8px; padding: 0 12px 6px; }
#score .pl { flex: 1; min-width: 0; display: grid; grid-template-columns: auto 1fr; column-gap: 6px; align-items: center; padding: 5px 10px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
#score .pl .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#score .pl.p0 .nm { color: var(--c0); } #score .pl.p1 .nm { color: var(--c1); }
#score .pl.me .nm::after { content: " (you)"; color: var(--muted); font-weight: 400; font-size: 12px; }
#score .pl .last { grid-column: 2; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#score .pl .arrow { grid-row: 1 / span 2; width: 0; height: 0; border-left: 10px solid transparent; border-top: 8px solid transparent; border-bottom: 8px solid transparent; }
#score .pl.active { border-color: var(--gold); box-shadow: 0 0 14px rgba(233,185,73,.35); }
#score .pl.active .arrow { border-left-color: var(--gold); filter: drop-shadow(0 0 4px rgba(233,185,73,.7)); }
#score .pl.p1 { text-align: right; grid-template-columns: 1fr auto; }
#score .pl.p1 .arrow { grid-column: 2; grid-row: 1 / span 2; border-left: 0; border-right: 10px solid transparent; transform: none; }
#score .pl.p1.active .arrow { border-right-color: var(--gold); }
#score .pl.p1 .nm, #score .pl.p1 .last { grid-column: 1; }
#score .mid { text-align: center; display: flex; flex-direction: column; justify-content: center; min-width: 74px; }
#score .pts { font-size: 26px; font-weight: 800; line-height: 1; display: flex; gap: 6px; justify-content: center; align-items: baseline; }
#score .pts b { min-width: 1ch; } #score .pts span { color: var(--muted); font-weight: 400; }
#score .pts b.bump { animation: pulse .6s ease-out; color: var(--gold); }
#score .goal { font-size: 11px; color: var(--muted); }
@keyframes pulse { 0% { transform: scale(1); } 40% { transform: scale(1.5); } 100% { transform: scale(1); } }

/* battlefield */
#stage { position: relative; width: min(100%, 980px, calc((100dvh - 320px) * 1.7778)); min-width: 280px; flex: none; }
@supports not (height: 100dvh) { #stage { width: min(100%, 980px, calc((100vh - 320px) * 1.7778)); } }
#cv { display: block; width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; border: 1px solid var(--line); background: #0b1020; touch-action: none; }
#msg { width: max-content; max-width: 100%; min-height: 28px; margin: 6px auto 0; padding: 3px 12px; border-radius: 999px; font-size: 14px; text-align: center; color: var(--muted); }
#msg[hidden] { visibility: hidden; display: block; }
#msg.mine { background: var(--gold); color: #1b1405; font-weight: 700; }

/* controls */
#controls { width: min(100%, 980px, calc((100dvh - 320px) * 1.7778)); min-width: 280px; padding: 8px 0 12px; display: grid; gap: 6px; grid-template-columns: 1fr; }
.ctl .lbl { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); padding: 0 2px; }
.ctl .lbl b { font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; }
.ctl .adj { display: flex; align-items: center; gap: 6px; }
.ctl .adj input[type=range] { flex: 1; min-width: 0; height: 36px; accent-color: var(--gold); }
button.step { width: 40px; height: 38px; padding: 0; border-radius: 10px; font-size: 15px; flex: none; }
button.fire { font-size: 20px; padding: 12px; margin-top: 2px; letter-spacing: .04em; }
#controls.off { opacity: .55; }
#controls.off button.fire { background: var(--panel2); color: var(--muted); border-color: var(--line); }
@media (min-width: 820px) and (min-aspect-ratio: 5/4) {
  #controls { grid-template-columns: 1fr 1fr auto; align-items: end; gap: 14px; }
  button.fire { height: 52px; padding: 0 28px; }
}

/* target + result */
#targets label { flex: 1; }
#targets span { font-size: 18px; padding: 12px 4px; }
@media (prefers-reduced-motion: reduce) { #score .pts b.bump { animation: none; } }
@media (max-width: 560px) {
  #msg { font-size: 13px; }
  #score .pts { font-size: 22px; } #score .mid { min-width: 64px; }
  #score .pl { padding: 4px 8px; } #score .pl .nm { font-size: 14px; }
}
#angle { direction: rtl; }   /* slider to the right = lower angle = barrel aims further right; the buttons are mirrored to match */

/* driving (fuel) */
button.step.wide { width: auto; min-width: 74px; padding: 0 12px; }
.fuel { flex: 1; height: 12px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.fuel i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #e5646b, var(--gold) 45%, var(--teal)); transition: width .25s; }
@media (min-width: 820px) and (min-aspect-ratio: 5/4) { #controls { grid-template-columns: 1fr 1fr 1fr auto; } }
#resultPick label { font-size: 12px; color: var(--muted); } #resultTargets { margin: 4px 0 2px; } #resultTargets span { padding: 6px 4px; font-size: 15px; } #resultPick[hidden] { display: none; }
@media (min-width: 820px) and (min-aspect-ratio: 5/4) { #controls { grid-template-columns: 1fr 1fr; gap: 8px 16px; } button.fire { height: 46px; padding: 0 28px; align-self: end; } }
