:root {
  color-scheme: dark;
  --bg: #0f1215; --card: #171b20; --card-2: #1e2329; --text: #e7eaee; --muted: #a0a9b3; --faint: #6f7882;
  --line: #262c33; --accent: #4cc9f0; --accent-ink: #06222c; --you: #4cc9f0; --them: #ff7aa8;
  --ok: #34c06f; --warn: #e5b322; --crit: #f0554b;
  --easy: #34c06f; --medium: #e5b322; --hard: #f0554b;
  --radius: 12px;
  --top: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100dvh;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: clamp(26px, 4vw, 38px); letter-spacing: -0.02em; }
h2 { font-size: 19px; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
small { color: var(--faint); font-size: 13px; }

button, input { font: inherit; color: inherit; }
button {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 16px;
  cursor: pointer; font-weight: 600; transition: background .12s, border-color .12s, opacity .12s;
}
button:hover:not(:disabled) { border-color: var(--faint); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover:not(:disabled) { background: #6fd5f3; border-color: #6fd5f3; }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; width: 100%;
}
input::placeholder { color: var(--faint); }

/* ------------------------------------------------------------ top bar */
.topbar {
  height: var(--top); flex: none; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-weight: 700;
  font-size: 17px; letter-spacing: -0.01em; }
.brand img { border-radius: 6px; }
.hud { display: flex; align-items: center; gap: 14px; margin-left: auto; min-width: 0; }
.hud-round { color: var(--muted); white-space: nowrap; }
.hud-timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; min-width: 3.2ch; text-align: right; }
.hud-timer.low { color: var(--crit); }
.hud-scores { display: flex; gap: 12px; white-space: nowrap; }
.hud-scores .s { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.hud-scores .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.hud-scores .name { color: var(--muted); max-width: 9ch; overflow: hidden; text-overflow: ellipsis; }
.hud-scores .lock { font-size: 12px; color: var(--ok); }
.conn { margin-left: auto; color: var(--warn); font-size: 13px; }
.hud:not([hidden]) ~ .conn { margin-left: 0; }
.chip { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px;
  border-radius: 99px; border: 1px solid currentColor; }
.chip.easy { color: var(--easy); } .chip.medium { color: var(--medium); } .chip.hard { color: var(--hard); }
.timebar { height: 3px; flex: none; background: transparent; }
.timebar div { height: 100%; width: 0; background: var(--accent); }
.timebar.low div { background: var(--crit); }

main { flex: 1; display: flex; min-height: 0; }
.screen { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 24px 16px; min-width: 0; }

/* ------------------------------------------------------------ cards and forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h2 + p { color: var(--muted); }
.home { width: 100%; max-width: 860px; display: grid; gap: 16px; }
.hero p { color: var(--muted); max-width: 62ch; font-size: 16px; }
.setup { display: grid; gap: 20px; }
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 24px; }
.actions { display: flex; gap: 12px 24px; flex-wrap: wrap; padding-top: 18px; border-top: 1px solid var(--line); }
.action { display: grid; gap: 6px; justify-items: start; }
.action button { min-width: 160px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 3px;
  background: var(--bg); width: max-content; max-width: 100%; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; color: var(--muted); }
.seg button.on { background: var(--card-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.join { display: flex; align-items: center; gap: 10px; padding: 14px 20px; }
.join > span { color: var(--muted); white-space: nowrap; }
.join input { max-width: 160px; text-transform: uppercase; letter-spacing: .25em; font-weight: 700;
  font-family: ui-monospace, monospace; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ------------------------------------------------------------ lobby */
.lobby, .final { width: 100%; max-width: 520px; display: grid; gap: 14px; }
.lobby p, .final p { margin: 0; }
.code { font-family: ui-monospace, monospace; letter-spacing: .15em; color: var(--accent); }
.share { display: flex; gap: 8px; }
.share input { font-family: ui-monospace, monospace; font-size: 13px; }
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.players li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 9px; }
.players .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .st { font-size: 13px; color: var(--muted); }
.players .st.ready { color: var(--ok); }
.players .st.off { color: var(--warn); }
.players li.empty { color: var(--faint); border-style: dashed; }

/* ------------------------------------------------------------ game */
#screen-game { padding: 12px; align-items: stretch; }
.game {
  flex: 1; display: grid; column-gap: 12px; row-gap: 8px; min-height: 0; align-content: start;
  grid-template-columns: min(46vw, calc(100dvh - var(--top) - 88px)) 1fr;
}
/* Both panels share the grid's two rows, so the map is exactly as tall as the square clue. */
.panel { display: grid; grid-row: span 2; grid-template-rows: subgrid; min-width: 0; min-height: 0; position: relative; }
.viewport { position: relative; background: #0a0c0e; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.viewport.square { aspect-ratio: 1; width: 100%; }
.map-panel .viewport { flex: 1; min-height: 0; cursor: crosshair; }
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.crosshair { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; transform: translate(-50%, -50%);
  pointer-events: none; z-index: 1; filter: drop-shadow(0 0 1px #000) drop-shadow(0 0 2px rgba(0, 0, 0, .8)); }
.crosshair::before { content: ''; position: absolute; inset: 20px; border: 2.5px solid #fff; border-radius: 50%; }
.crosshair::after { content: ''; position: absolute; inset: 0; background:
  linear-gradient(#fff, #fff) left center / 16px 2.5px no-repeat, linear-gradient(#fff, #fff) right center / 16px 2.5px no-repeat,
  linear-gradient(#fff, #fff) center top / 2.5px 16px no-repeat, linear-gradient(#fff, #fff) center bottom / 2.5px 16px no-repeat; }
.panel-foot, .map-foot { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.panel-foot .muted, .map-foot .muted { flex: 1; font-size: 13px; }
.map-foot button { min-width: 130px; }
.veil { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center;
  background: #0a0c0e; z-index: 2; padding: 14px; }
.showcase { position: absolute; inset: 0; }
.showcase canvas { transition: opacity .3s; }
.showcase canvas.fade { opacity: 0; }
.veil-msg { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-radius: 99px;
  background: rgba(15, 18, 21, .85); border: 1px solid var(--line); color: var(--text); text-align: center; }
.spinner { width: 18px; height: 18px; flex: none; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.result {
  position: absolute; left: 50%; bottom: 60px; transform: translateX(-50%); z-index: 3;
  width: min(440px, calc(100% - 24px)); background: rgba(23, 27, 32, .96); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
  backdrop-filter: blur(6px);
}
.result-head { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; }
.result-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.result-rows li { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 10px; align-items: center; }
.result-rows .dot { width: 10px; height: 10px; border-radius: 50%; }
.result-rows .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-rows .d { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.result-rows .pts { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 5ch; text-align: right; }
.result-rows li.best .pts { color: var(--ok); }

/* ------------------------------------------------------------ final */
.final h2 { font-size: 26px; }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.totals .t { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 12px; }
.totals .t.win { border-color: var(--ok); }
.totals .n { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.totals .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rounds { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rounds th, .rounds td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.rounds th:first-child, .rounds td:first-child { text-align: left; }
.rounds th { color: var(--muted); font-weight: 600; font-size: 13px; }

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 10;
  width: min(420px, calc(100% - 32px)); }
.toast { background: var(--card-2); border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: 9px; padding: 10px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.4); }

/* ------------------------------------------------------------ narrow screens */
@media (max-width: 820px) {
  .setup-grid { grid-template-columns: 1fr; }
  .game { grid-template-columns: 1fr; grid-template-rows: auto minmax(300px, 1fr); row-gap: 12px; align-content: stretch; }
  .panel { display: flex; flex-direction: column; gap: 8px; grid-row: auto; }
  .clue-panel .viewport.square { width: min(100%, 44dvh); margin: 0 auto; }
  .panel-foot { display: none; }
  .hud { gap: 9px; }
  .hud-round .of { display: none; }
  .hud-scores .name { display: none; }
  #map-hint { display: none; }
  .map-foot button { flex: 1; }
  /* The result card goes below the map instead of covering the reveal. */
  .map-foot:has(> #lock[hidden]) { display: none; }
  .result { position: static; transform: none; width: auto; box-shadow: none; padding: 12px 14px; }
}
@media (max-width: 480px) {
  .brand span, .topbar .brand { font-size: 0; gap: 0; }
  .hud { margin-left: auto; }
}
