:root {
  --bg-1: #070b1f;
  --bg-2: #0f1d45;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #eef2ff;
  --muted: #a5b0d6;
  --accent: #ffd166;
  --accent-2: #06d6a0;
  --red: #ef476f;
  --green: #06c167;
  --yellow: #ffb703;
  --blue: #3a86ff;
  --l1: #06d6a0;
  --l2: #7ad151;
  --l3: #e9d53b;
  --l4: #ffb703;
  --l5: #fb6f3c;
  --l6: #ef476f;
  --easy: #06d6a0;
  --medium: #ffb703;
  --hard: #ef476f;
  --ok: #06d6a0;
  --bad: #ef476f;
  --radius: 18px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --font-display: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --depth: 300px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { background: var(--bg-1); }
body {
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 10% -10%, #1f3a8a55, transparent 60%),
    radial-gradient(900px 700px at 110% 110%, #0e7c8655, transparent 60%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
kbd {
  font-family: var(--font-body);
  font-size: 0.7em;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.18);
  margin-left: 6px;
  vertical-align: middle;
}

/* floating background blobs */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.sky span {
  position: absolute; width: 40vmax; height: 40vmax; border-radius: 50%;
  filter: blur(80px); opacity: 0.25; animation: drift 26s ease-in-out infinite alternate;
}
.sky span:nth-child(1) { background: #3a86ff; left: -10vmax; top: 20vh; }
.sky span:nth-child(2) { background: #06d6a0; right: -12vmax; top: -10vh; animation-delay: -8s; }
.sky span:nth-child(3) { background: #ef476f; left: 40vw; bottom: -25vmax; animation-delay: -16s; opacity: 0.15; }
@keyframes drift { to { transform: translate(6vmax, -4vmax) scale(1.15); } }

.screen { display: none; position: relative; z-index: 1; }
.screen.active { display: block; }

/* ================= SETUP ================= */
#setup.active { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.setup-card {
  width: min(560px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,0.09), rgba(255,255,255,0.04));
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  padding: 32px clamp(18px, 4vw, 36px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  animation: rise 0.7s cubic-bezier(.2,.9,.3,1.2) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(30px) scale(0.97); } }
.logo { text-align: center; margin-bottom: 18px; }
.logo-globe { font-size: 64px; display: inline-block; animation: spin-globe 6s ease-in-out infinite; filter: drop-shadow(0 8px 20px rgba(58,134,255,.5)); }
@keyframes spin-globe { 50% { transform: rotate(-12deg) scale(1.06); } }
.logo h1 {
  font-family: var(--font-display); font-size: clamp(44px, 9vw, 64px); margin: 4px 0 0; letter-spacing: 0.5px;
  line-height: 1;
}
.logo h1 span, .brand-name > span { color: var(--accent); }
.tagline { color: var(--muted); margin: 8px 0 0; font-size: 15px; }

.setup-section { margin: 22px 0; }
.setup-section h2 {
  font-family: var(--font-display); font-weight: 600; font-size: 15px; text-transform: uppercase;
  letter-spacing: 2px; color: var(--muted); margin: 0 0 10px;
}
.count-picker { display: flex; gap: 10px; margin-bottom: 14px; }
.count-btn {
  flex: 1; padding: 12px 0; font-size: 22px; font-family: var(--font-display); font-weight: 600;
  border-radius: 14px; border: 1px solid var(--panel-border); background: var(--panel); color: var(--text);
  transition: all .2s;
}
.count-btn:hover { background: rgba(255,255,255,0.12); }
.count-btn.active { background: var(--accent); color: #1b1b2f; border-color: transparent; box-shadow: 0 8px 24px rgba(255,209,102,.35); }

.player-inputs { display: grid; gap: 10px; }
.player-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 8px; min-width: 0;
  background: rgba(0,0,0,0.2); border-radius: 14px; border: 1px solid transparent;
  animation: rise .4s ease both;
}
.player-row:focus-within { border-color: var(--pc); }
.pawn-icon {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 30%, #fff8 0 12%, transparent 30%), var(--pc);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.25), 0 4px 12px color-mix(in srgb, var(--pc) 60%, transparent);
}
.player-row input {
  /* width: 0 + flex-grow: the name field takes whatever space is left instead of its natural ~20-character width */
  flex: 1 1 0; width: 0; min-width: 60px; background: transparent; border: 0; color: var(--text); font-size: 16px; font-weight: 600;
  padding: 8px 4px; outline: none; font-family: var(--font-body);
}
.player-row .color-name { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.difficulty-legend { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 14px; }
.dl {
  border-radius: 12px; padding: 8px; text-align: center; background: rgba(0,0,0,.2);
  border-top: 3px solid var(--c);
}
.dl b { display: block; font-size: 26px; line-height: 1.1; color: var(--c); font-weight: 400; }
.dl span { font-size: 11px; font-weight: 600; display: block; line-height: 1.2; }
.dl { padding: 6px 2px; }
.dl.easy { --c: var(--easy); } .dl.medium { --c: var(--medium); } .dl.hard { --c: var(--hard); }

.toggle { display: flex; align-items: center; gap: 12px; padding: 8px 0; cursor: pointer; font-size: 14px; color: #d8def5; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .sw {
  width: 42px; height: 24px; border-radius: 99px; background: rgba(255,255,255,.15); position: relative; flex: none;
  transition: background .2s;
}
.toggle .sw::after {
  content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .25s cubic-bezier(.3,1.5,.5,1);
}
.toggle input:checked + .sw { background: var(--accent-2); }
.toggle input:checked + .sw::after { transform: translateX(18px); }
.toggle input:focus-visible + .sw { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  border: 0; border-radius: 14px; padding: 12px 20px; font-weight: 700; font-size: 16px;
  background: linear-gradient(180deg, #ffe08a, var(--accent)); color: #22223b;
  box-shadow: 0 6px 0 #c9971f, 0 12px 24px rgba(255, 209, 102, .3);
  transition: transform .12s, box-shadow .12s, filter .2s;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #c9971f, 0 6px 12px rgba(255, 209, 102, .3); }
.btn-primary:disabled { filter: grayscale(.8) brightness(.7); cursor: not-allowed; transform: none; }
.btn-primary.big { width: 100%; padding: 16px; font-size: 19px; font-family: var(--font-display); letter-spacing: .5px; margin-top: 6px; }
.btn-ghost {
  border: 1px solid var(--panel-border); background: var(--panel); color: var(--text); border-radius: 14px;
  padding: 12px 20px; font-weight: 600; font-size: 15px;
}
.btn-ghost:hover { background: rgba(255,255,255,.12); }

.train-link {
  display: block; margin-top: 14px; padding: 12px; border-radius: 14px; text-align: center; text-decoration: none;
  color: var(--text); font-weight: 600; font-size: 14px; background: rgba(6,214,160,.12); border: 1px solid rgba(6,214,160,.45);
}
.train-link:hover { background: rgba(6,214,160,.22); }
.howto { margin-top: 18px; color: var(--muted); font-size: 14px; }
.howto summary { cursor: pointer; font-weight: 600; color: #d8def5; }
.howto ul { padding-left: 20px; line-height: 1.6; }

/* mode picker */
.mode-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.mode-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 12px 8px;
  border-radius: 14px; border: 1px solid var(--panel-border); background: rgba(0,0,0,.2); color: var(--text);
  transition: all .2s;
}
.mode-card:hover { background: rgba(255,255,255,.08); }
.mode-card .mode-icon { font-size: 26px; }
.mode-card b { font-family: var(--font-display); font-weight: 600; font-size: 15px; line-height: 1.15; }
.mode-card small { color: var(--muted); font-size: 12px; line-height: 1.3; }
.mode-card[data-mode="mixed"] { grid-column: 1 / -1; }
.mode-card.active { border-color: var(--accent); background: rgba(255,209,102,.12); box-shadow: 0 0 0 1px var(--accent) inset; }
.h2-note { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; float: right; }

/* resume banner */
.resume-card {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 18px; border-radius: 16px;
  background: linear-gradient(135deg, rgba(6,214,160,.18), rgba(58,134,255,.14)); border: 1px solid rgba(6,214,160,.5);
}
.resume-card[hidden] { display: none; }
.resume-card > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.resume-card small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resume-card .btn-primary { padding: 9px 14px; font-size: 14px; }

/* game-length presets */
.preset-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset-card {
  display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; padding: 12px 8px;
  border-radius: 14px; border: 1px solid var(--panel-border); background: rgba(0,0,0,.2); color: var(--text); transition: all .2s;
}
.preset-card:hover { background: rgba(255,255,255,.08); }
.preset-card .mode-icon { font-size: 24px; }
.preset-card b { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.preset-card small { color: var(--muted); font-size: 11.5px; line-height: 1.3; }
.preset-card.active { border-color: var(--accent); background: rgba(255,209,102,.12); box-shadow: 0 0 0 1px var(--accent) inset; }
.preset-summary { margin: 10px 0 0; padding-left: 20px; font-size: 13px; color: #cfd6f2; line-height: 1.6; }
.custom-rules { margin-top: 8px; padding: 6px 12px; border-radius: 14px; background: rgba(0,0,0,.2); }
.custom-rules[hidden], .preset-summary[hidden] { display: none; }

/* human / bot selector */
.type-select {
  flex: none; background: rgba(255,255,255,.08); color: var(--text); border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 6px 8px; font: 600 12.5px var(--font-body); cursor: pointer;
}
.type-select option { background: #1b2550; }
.piece-picker[hidden] { display: none; }
.botbadge { margin-left: 6px; font-size: 10.5px; font-weight: 600; color: var(--muted); }
.tokens { font-size: 12px; color: var(--text); }

/* mixed-mode category chips */
.mix-options { margin-top: 10px; padding: 12px; border-radius: 14px; background: rgba(0,0,0,.2); border: 1px dashed rgba(255,209,102,.45); }
.mix-options[hidden] { display: none; }
.mix-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.mix-title small { color: var(--muted); font-weight: 500; }
.mix-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mix-chip {
  border: 1px solid var(--panel-border); background: transparent; color: var(--muted); border-radius: 99px;
  padding: 7px 12px; font-size: 13px; font-weight: 600; transition: all .2s;
}
.mix-chip.active { background: rgba(255,209,102,.18); border-color: var(--accent); color: var(--text); }
.mix-chip.shake { animation: shake-x .35s; }
@keyframes shake-x { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.mix-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.history-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 12px; }
.link-btn { background: none; border: 0; color: var(--accent); font-size: 12px; text-decoration: underline; padding: 0; }

/* pieces-per-player picker */
.piece-picker { display: flex; gap: 3px; background: rgba(0,0,0,.25); padding: 3px; border-radius: 10px; flex: none; }
.piece-picker button {
  width: 28px; height: 28px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 700;
}
.piece-picker button:hover { color: var(--text); }
.piece-picker button.active { background: var(--pc); color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--pc) 50%, transparent); }

/* ================= GAME ================= */
#game.active { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; flex: none;
}
.brand { font-family: var(--font-display); font-size: 24px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.mode-chip {
  font-family: var(--font-body); font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--panel-border); padding: 3px 8px; border-radius: 99px;
}
.turn-pill {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px 8px 10px; border-radius: 99px;
  background: color-mix(in srgb, var(--pc, #888) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--pc, #888) 60%, transparent);
  font-weight: 700; transition: all .4s; font-size: 15px; white-space: nowrap; overflow: hidden;
}
.turn-pill .dot { width: 18px; height: 18px; border-radius: 50%; background: var(--pc, #888); box-shadow: 0 0 12px var(--pc); flex: none; }
.turn-pill .turn-label { font-weight: 500; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--panel-border); background: var(--panel);
  color: var(--text); font-size: 18px;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }

.layout {
  flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px;
  padding: 0 18px 18px;
}

/* ---------- The rolling stage ---------- */
.stage {
  position: relative; min-height: 0; perspective: 2200px; perspective-origin: 50% 50%;
  pointer-events: none; /* the 3D faces sit at z≈0 and must win hit-testing */
}
.prism { pointer-events: none; }
.face { pointer-events: auto; }
.prism {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transform: translateZ(calc(var(--depth) * -1)) rotateX(0deg);
  transition: transform calc(1.1s * var(--spd, 1)) cubic-bezier(.65, -0.05, .3, 1.05);
}
.prism.show-map { transform: translateZ(calc(var(--depth) * -1)) rotateX(90deg); }
/* At rest on the board the scene is flat too, so the pieces are reliably clickable. */
.prism.flat { transform: none; transition: none; }
.prism.flat .face-board { transform: none; }
.prism.flat .face-map { visibility: hidden; }
/* Once the roll has finished, flatten the 3D scene: identical picture, but reliable hit-testing. */
.prism.show-map.settled { transform: none; transition: none; }
.prism.show-map.settled .face-map { transform: none; }
.prism.show-map.settled .face-board { visibility: hidden; }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 24px; overflow: hidden;
}
.face-board { transform: translateZ(var(--depth)); display: grid; place-items: center; }
.face-map {
  transform: rotateX(-90deg) translateZ(var(--depth));
  display: flex; flex-direction: column; gap: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
  border: 1px solid var(--panel-border); padding: 12px;
}
/* subtle shading while rolling */
.face::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; background: #000; opacity: 0;
  transition: opacity calc(1.1s * var(--spd, 1)); border-radius: inherit;
}
.prism.show-map .face-board::after { opacity: .55; }
.prism.show-map .face-board, .prism:not(.show-map) .face-map { pointer-events: none; }
.prism:not(.show-map) .face-map::after { opacity: .55; }

.board-wrap {
  width: min(100%, calc(var(--depth) * 2)); aspect-ratio: 1; display: grid; place-items: center;
}
#board {
  width: 100%; height: auto; max-height: 100%; display: block;
  filter: drop-shadow(0 24px 40px rgba(0,0,0,.55));
}

/* Board pieces */
.piece { transition: transform calc(.3s * var(--spd, 1)) cubic-bezier(.3,.7,.4,1.3); cursor: default; outline: none; }
.piece .hit { pointer-events: none; }
.piece .pnum { pointer-events: none; }
.piece .ring { opacity: 0; transform-box: fill-box; transform-origin: center; pointer-events: none; }
.piece.selectable { cursor: pointer; }
.piece.selectable .hit { pointer-events: all; }
.piece.selectable .ring { opacity: 1; animation: ring-pulse 1s ease-in-out infinite; }
.piece.selectable .bob { animation: bob 1.1s ease-in-out infinite; }
.piece.selectable:hover .ring, .piece.selectable:focus-visible .ring { stroke: #fff; stroke-width: 4; animation: none; }
.piece.selectable .ring { filter: drop-shadow(0 0 4px rgba(255,183,3,.9)); }
.piece.selectable:hover .bob, .piece.selectable:focus-visible .bob { animation: none; transform: translateY(-6px) scale(1.08); }
.piece.moving { transition: transform calc(.22s * var(--spd, 1)) cubic-bezier(.3,.7,.4,1.3); }
@keyframes ring-pulse { 50% { transform: scale(1.18); opacity: .55; } }
.piece.flying { transition: transform calc(.8s * var(--spd, 1)) cubic-bezier(.5,-0.3,.4,1.2); }
.piece .bob { animation: none; transform-box: fill-box; transform-origin: 50% 100%; }
.piece.active .bob { animation: bob 1.1s ease-in-out infinite; }
.piece .halo { opacity: 0; transform-box: fill-box; transform-origin: center; }
.piece.active .halo { opacity: 1; animation: halo 1.6s ease-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px); } }
@keyframes halo { from { transform: scale(.6); opacity: .9; } to { transform: scale(1.6); opacity: 0; } }
.piece.hop .bob { animation: hop .22s ease-out; }
@keyframes hop { 40% { transform: translateY(-10px) scale(1.05, .95); } }
.piece.captured .bob { animation: shake .4s; }
@keyframes shake { 25% { transform: rotate(-15deg); } 75% { transform: rotate(15deg); } }
.cell-target { animation: pulse-cell 1s ease-in-out infinite; }
@keyframes pulse-cell { 50% { opacity: .35; } }

/* ---------- Quiz card ---------- */
.quiz-card {
  flex: none; display: flex; flex-direction: column; gap: 8px; padding: 14px 18px; border-radius: 18px;
  background: linear-gradient(135deg, rgba(10,16,40,.85), rgba(20,35,80,.85));
  border: 1px solid var(--panel-border); box-shadow: 0 10px 30px rgba(0,0,0,.3);
}
.quiz-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; padding: 4px 10px;
  border-radius: 99px; background: var(--c, #555); color: #111;
}
.chip.lvl { color: #10142a; }
.chip.tag { color: var(--text); }
.chip.easy { --c: var(--easy); } .chip.medium { --c: var(--medium); } .chip.hard { --c: var(--hard); color: #fff; }
.chip.player-chip { background: color-mix(in srgb, var(--pc) 85%, #000); color: #fff; }
.chip.ghost { background: rgba(255,255,255,.1); color: var(--muted); }
.quiz-main { display: flex; align-items: center; gap: 16px; }
.q-flag {
  height: 64px; width: auto; aspect-ratio: 4/3; border-radius: 6px; flex: none;
  box-shadow: 0 6px 18px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.2);
  animation: flag-in .6s cubic-bezier(.2,.9,.3,1.3) both;
}
@keyframes flag-in { from { transform: rotateY(90deg) scale(.6); } }
.q-text { flex: 1; min-width: 0; }
.q-kind { color: var(--muted); font-size: 14px; font-weight: 500; }
.q-prompt.long { font-family: var(--font-body); font-weight: 700; font-size: clamp(16px, 1.7vw, 21px); line-height: 1.3; }
.q-prompt { font-family: var(--font-display); font-weight: 600; font-size: clamp(22px, 3vw, 34px); line-height: 1.15; }
.timer { position: relative; width: 52px; height: 52px; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 4; }
.timer .t-bg { stroke: rgba(255,255,255,.12); }
.timer .t-fg { stroke: var(--accent-2); stroke-linecap: round; stroke-dasharray: 119.4; transition: stroke-dashoffset 1s linear, stroke .3s; }
.timer.low .t-fg { stroke: var(--bad); }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 16px; }
.timer.low span { color: var(--bad); animation: tick 1s infinite; }
@keyframes tick { 50% { transform: scale(1.2); } }

/* ---------- Map ---------- */
.map-wrap {
  position: relative; flex: 1; min-height: 0; border-radius: 18px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #1b4f8c, #0b2552 70%, #071735);
  border: 1px solid rgba(255,255,255,.1);
  touch-action: none;
}
#map { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; -webkit-user-select: none; }
#map.dragging { cursor: grabbing; }
#map .sphere { fill: url(#ocean); stroke: rgba(160,210,255,.35); }
#map .graticule { fill: none; stroke: rgba(160,210,255,.12); }
#map .country {
  stroke: rgba(10, 30, 60, .75); stroke-linejoin: round; cursor: pointer;
  transition: fill .2s, filter .2s;
}
#map .country.np { cursor: inherit; pointer-events: none; fill-opacity: .75; }
#map .country:hover, #map .country.hover { fill: #fff3b0 !important; }
#map .dot {
  fill: #ffd166; stroke: rgba(10,30,60,.9); cursor: pointer; opacity: .9;
}
#map .dot:hover { fill: #fff3b0; }
#map .citypin { fill: #fff; stroke: #ef476f; pointer-events: none; }
#map .citylabel { fill: #ffe08a; }
#map.locked .country, #map.locked .dot { cursor: default; }
#map.locked .country:hover { fill: inherit; }
#map .country.correct, #map .dot.correct { fill: var(--ok) !important; animation: glow-ok 1.2s ease-in-out infinite; }
#map .country.wrong, #map .dot.wrong { fill: var(--bad) !important; }
@keyframes glow-ok { 50% { fill: #9ff5d8; } }
#map .label {
  font-family: var(--font-display); font-weight: 600; fill: #fff; paint-order: stroke; stroke: rgba(0,0,0,.75);
  stroke-linejoin: round; pointer-events: none; text-anchor: middle;
}
#map .ping { fill: none; stroke: var(--ok); pointer-events: none; }
/* how far off a wrong answer was: a dashed arc from the pick to the answer */
#map .missline {
  fill: none; stroke: #ffd166; stroke-width: 2.5; stroke-linecap: round; pointer-events: none; opacity: .95;
  stroke-dasharray: 7 6; filter: drop-shadow(0 0 3px rgba(0,0,0,.6));
  animation: fade-in calc(.5s * var(--spd, 1)) both, missline-march 1.2s linear infinite;
}
@keyframes missline-march { to { stroke-dashoffset: -26; } }
#map .distlabel { fill: #ffd166; animation: fade-in calc(.3s * var(--spd, 1)) calc(.15s * var(--spd, 1)) both; }
@keyframes fade-in { from { opacity: 0; } }
.miss-dist { display: block; margin-top: 3px; font-size: 13px; color: #ffd166; }
.miss-dist.near { color: #9ff5d8; }

.map-controls {
  position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 6px;
}
.map-controls button {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(255,255,255,.2);
  background: rgba(8,16,40,.75); color: #fff; font-size: 20px; backdrop-filter: blur(6px);
}
.map-controls button:hover { background: rgba(30,50,100,.9); }
.map-hint {
  position: absolute; left: 12px; bottom: 10px; font-size: 12px; color: rgba(255,255,255,.6);
  background: rgba(0,0,0,.25); padding: 4px 10px; border-radius: 99px; pointer-events: none;
}

.result {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 14px; border-radius: 18px;
  background: rgba(8, 14, 36, .92); border: 2px solid var(--rc, var(--ok)); box-shadow: 0 20px 50px rgba(0,0,0,.5);
  width: max-content; max-width: calc(100% - 24px);
  animation: pop-up .45s cubic-bezier(.2,.9,.3,1.3) both;
  backdrop-filter: blur(8px);
}
.result[hidden] { display: none; }
@keyframes pop-up { from { transform: translate(-50%, 40px) scale(.9); opacity: 0; } }
.result.bad { --rc: var(--bad); }
.result-icon {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; font-weight: 800;
  background: var(--rc, var(--ok)); color: #0b1530; flex: none;
}
.result-title { font-family: var(--font-display); font-size: 20px; font-weight: 600; }
.result-sub { font-size: 14px; color: var(--muted); }
.result-sub b { color: var(--text); }

/* ================= SIDEBAR ================= */
.sidebar { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.panel {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius); padding: 16px;
  backdrop-filter: blur(10px);
}
.panel h3 {
  margin: 0 0 10px; font-family: var(--font-display); font-weight: 600; font-size: 13px; letter-spacing: 2px;
  text-transform: uppercase; color: var(--muted);
}
.dice-panel { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.roll-btn { width: 100%; }
.status { font-size: 14px; color: var(--muted); text-align: center; min-height: 20px; }
.status b { color: var(--text); }

/* 3D dice */
.dice-scene { width: 84px; height: 84px; perspective: 600px; margin: 10px 0 4px; cursor: pointer; }
.dice {
  --s: 84px; width: var(--s); height: var(--s); position: relative; transform-style: preserve-3d;
  transform: rotateX(-25deg) rotateY(25deg);
  transition: transform calc(1.2s * var(--spd, 1)) cubic-bezier(.2,.8,.25,1);
}
.dice.idle { animation: idle-spin 8s linear infinite; }
@keyframes idle-spin { from { transform: rotateX(-25deg) rotateY(0deg); } to { transform: rotateX(-25deg) rotateY(360deg); } }
.df {
  position: absolute; inset: 0; border-radius: 16px; background: radial-gradient(circle at 30% 25%, #fff, #e8ecf8 70%, #cfd6ea);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.05), inset 0 -6px 12px rgba(0,0,0,.08);
  display: grid; padding: 14px; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
}
.df i { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #555, #111); place-self: center; }
.f1 { transform: translateZ(42px); }
.f2 { transform: rotateY(90deg) translateZ(42px); }
.f3 { transform: rotateX(90deg) translateZ(42px); }
.f4 { transform: rotateX(-90deg) translateZ(42px); }
.f5 { transform: rotateY(-90deg) translateZ(42px); }
.f6 { transform: rotateY(180deg) translateZ(42px); }
.f1 i { grid-area: 2/2; background: radial-gradient(circle at 35% 35%, #ff6b8b, #c9184a); width: 18px; height: 18px; }
.f2 i:nth-child(1) { grid-area: 1/1; } .f2 i:nth-child(2) { grid-area: 3/3; }
.f3 i:nth-child(1) { grid-area: 1/1; } .f3 i:nth-child(2) { grid-area: 2/2; } .f3 i:nth-child(3) { grid-area: 3/3; }
.f4 i:nth-child(1) { grid-area: 1/1; } .f4 i:nth-child(2) { grid-area: 1/3; } .f4 i:nth-child(3) { grid-area: 3/1; } .f4 i:nth-child(4) { grid-area: 3/3; }
.f5 i:nth-child(1) { grid-area: 1/1; } .f5 i:nth-child(2) { grid-area: 1/3; } .f5 i:nth-child(3) { grid-area: 2/2; } .f5 i:nth-child(4) { grid-area: 3/1; } .f5 i:nth-child(5) { grid-area: 3/3; }
.f6 i:nth-child(1) { grid-area: 1/1; } .f6 i:nth-child(2) { grid-area: 2/1; } .f6 i:nth-child(3) { grid-area: 3/1; }
.f6 i:nth-child(4) { grid-area: 1/3; } .f6 i:nth-child(5) { grid-area: 2/3; } .f6 i:nth-child(6) { grid-area: 3/3; }
.dice-badge {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
}

.standings { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.standings li {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 12px; background: rgba(0,0,0,.18); border: 1px solid transparent; transition: all .3s;
}
.standings li.active { border-color: var(--pc); background: color-mix(in srgb, var(--pc) 16%, transparent); }
.standings .pawn-icon { width: 26px; height: 26px; }
.standings .nm { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standings .bar { height: 6px; border-radius: 99px; background: rgba(255,255,255,.1); margin-top: 5px; overflow: hidden; }
.standings .bar i { display: block; height: 100%; background: var(--pc); border-radius: inherit; transition: width .6s; }
/* progress bar with rescue-difficulty zones */
.standings .pinfo { min-width: 0; }
.pbar { position: relative; height: 12px; margin: 6px 0 4px; border-radius: 99px; background: rgba(255,255,255,.08); }
.pbar .z { position: absolute; top: 3px; bottom: 3px; background: var(--zc); opacity: .8; }
.pbar .z:first-child { border-radius: 99px 0 0 99px; }
.pbar .z.safe {
  border-radius: 0 99px 99px 0; opacity: .5;
  background: repeating-linear-gradient(135deg, rgba(255,255,255,.55) 0 3px, rgba(255,255,255,.15) 3px 6px);
}
.pbar .pm {
  position: absolute; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: var(--pc); border: 2px solid var(--zc, #fff); box-shadow: 0 0 0 1.5px rgba(0,0,0,.45), 0 0 8px var(--zc, transparent);
  font: 700 9px/12px var(--font-body); font-style: normal; color: #fff; text-align: center; transition: left .6s;
}
.pbar .pm.fin { border-color: #fff; }
.rinfo { font-size: 11px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: center; }
.rinfo .ri { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.rinfo .pd { width: 7px; height: 7px; border-width: 1.5px; }
.zone-legend { display: flex; align-items: center; gap: 6px; margin: -4px 0 10px; font-size: 11px; color: var(--muted); }
.zone-legend .zl { flex: 1; display: flex; height: 8px; border-radius: 99px; overflow: hidden; }
.zone-legend .zl i { flex: 1; background: var(--zc); }
.zone-legend .zl i.safe { flex: .6; background: repeating-linear-gradient(135deg, rgba(255,255,255,.55) 0 3px, rgba(255,255,255,.15) 3px 6px); }

/* pick-your-challenge panel (over the board) */
.level-picker {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(620px, calc(100% - 20px));
  padding: 12px 14px 14px; border-radius: 18px; background: rgba(8, 14, 36, .94); border: 2px solid var(--pc, var(--accent));
  box-shadow: 0 20px 50px rgba(0,0,0,.55); backdrop-filter: blur(8px); animation: pop-up-c .35s cubic-bezier(.2,.9,.3,1.3) both; z-index: 3;
}
.level-picker[hidden] { display: none; }
@keyframes pop-up-c { from { transform: translate(-50%, 30px) scale(.95); opacity: 0; } }
.lp-title { font-size: 14px; color: var(--muted); margin-bottom: 10px; text-align: center; }
.lp-title b { color: var(--text); font-family: var(--font-display); font-size: 17px; font-weight: 600; }
.lp-btns { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.lp-btns button {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 2px; border-radius: 12px;
  border: 2px solid color-mix(in srgb, var(--c) 70%, transparent); background: color-mix(in srgb, var(--c) 16%, rgba(0,0,0,.3));
  color: var(--text); transition: transform .12s, background .15s;
}
.lp-btns button:hover:not(:disabled), .lp-btns button:focus-visible, .lp-btns button.chosen {
  background: var(--c); color: #10142a; transform: translateY(-3px); outline: none;
}
.lp-btns button:disabled { opacity: .3; cursor: not-allowed; }
.lp-btns b { font-family: var(--font-display); font-size: 22px; line-height: 1; }
.lp-btns span { font-size: 10.5px; font-weight: 600; white-space: nowrap; }
.lp-btns em { font-style: normal; font-weight: 800; font-size: 13px; }

/* hints & steals */
.hint-btn {
  flex: none; border: 1px solid rgba(255,209,102,.6); background: rgba(255,209,102,.14); color: var(--text);
  border-radius: 12px; padding: 8px 12px; font-weight: 700; font-size: 14px;
}
.hint-btn:hover:not(:disabled) { background: rgba(255,209,102,.3); }
.hint-btn:disabled { opacity: .45; cursor: not-allowed; }
.hint-btn[hidden] { display: none; }
#map .country.dim { opacity: .28; }
/* the region stays readable: dark borders between its countries, a soft gold glow around them */
#map .country.hinted { stroke: rgba(10, 30, 60, .95); filter: drop-shadow(0 0 1.5px rgba(255, 209, 102, .9)); }
.quiz-card.steal { border-color: #ff9f1c; box-shadow: 0 0 0 2px rgba(255,159,28,.35), 0 10px 30px rgba(0,0,0,.3); }
.quiz-card.steal .q-kind { color: #ffc773; font-weight: 600; }
.result.compact { bottom: auto; top: 12px; animation: none; }
.result .btn-ghost { padding: 9px 14px; }
.result .btn-ghost[hidden], .result .btn-primary[hidden] { display: none; }
.win-stamps { margin: -8px 0 18px; font-size: 13px; color: #d8def5; line-height: 1.5; }
.win-stamps small { color: var(--muted); }

/* rescue question styling */
.quiz-card.rescue { border-color: #ef476f; box-shadow: 0 0 0 2px rgba(239,71,111,.35), 0 10px 30px rgba(0,0,0,.3); background: linear-gradient(135deg, rgba(60,10,30,.9), rgba(20,35,80,.85)); }
.quiz-card.rescue .q-kind { color: #ffb3c4; font-weight: 600; }

.standings .dots { display: flex; gap: 4px; margin-top: 5px; }
.standings .pd { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--pc); }
.standings .pd.out { background: var(--pc); }
.standings .pd.done { background: #fff; border-color: #fff; box-shadow: 0 0 6px var(--pc); }
.lvl-text { font-weight: 700; }
.standings .sc { font-size: 12px; color: var(--muted); text-align: right; line-height: 1.3; }
.standings .sc b { color: var(--text); font-size: 14px; }

.log-panel { flex: 1; min-height: 120px; display: flex; flex-direction: column; }
.log { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.log li { padding: 6px 8px 6px 10px; border-left: 3px solid var(--pc, #666); background: rgba(0,0,0,.15); border-radius: 0 8px 8px 0; animation: rise .3s ease both; color: #cfd6f2; }
.log li b { color: #fff; }

/* ================= WIN ================= */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(3, 6, 20, .7); backdrop-filter: blur(6px); animation: fade .4s both;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.win-card {
  width: min(460px, 100%); text-align: center; padding: 30px 24px; border-radius: 28px;
  background: linear-gradient(180deg, #1c2b63, #111a3d); border: 1px solid var(--panel-border); box-shadow: var(--shadow);
  animation: rise .6s cubic-bezier(.2,.9,.3,1.3) both;
}
.trophy { font-size: 72px; animation: spin-globe 2s ease-in-out infinite; }
.win-card h2 { font-family: var(--font-display); font-size: 28px; margin: 8px 0; }
.win-card p { color: var(--muted); margin: 0 0 16px; }
.win-table { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 6px; text-align: left; }
.win-table li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; background: rgba(0,0,0,.2); }
.win-table li .pawn-icon { width: 22px; height: 22px; }
.win-table li span:last-child { margin-left: auto; color: var(--muted); font-size: 13px; }
.win-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; width: 100%; height: 100%; }

/* ================= RESPONSIVE ================= */
@media (max-width: 900px) {
  #game.active { height: auto; min-height: 100vh; }
  .layout { grid-template-columns: 1fr; padding: 0 12px 16px; }
  .stage { height: min(calc(100vw - 24px), 80vh); min-height: 340px; }
  .sidebar { display: grid; grid-template-columns: 1fr 1fr; }
  .dice-panel { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .dice-panel .roll-btn { flex: 1; min-width: 180px; width: auto; }
  .dice-panel .status { flex-basis: 100%; }
  .log-panel { max-height: 260px; }
  .turn-label { display: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 8px 12px; }
  .brand { font-size: 20px; }
  .brand-name { white-space: nowrap; }
  .mode-chip { display: none; }
  .turn-pill { min-width: 0; }
  .sidebar { grid-template-columns: 1fr; }
  .difficulty-legend { grid-template-columns: repeat(3, 1fr); }
  .mode-picker { grid-template-columns: 1fr; }
  .mode-card { flex-direction: row; text-align: left; flex-wrap: wrap; column-gap: 10px; }
  .mode-card small { flex-basis: 100%; padding-left: 36px; margin-top: -4px; }
  .preset-card small { display: none; }
  .lp-btns { grid-template-columns: repeat(6, 1fr); gap: 4px; }
  .level-picker { bottom: 6px; padding: 8px; }
  .lp-title { font-size: 12px; margin-bottom: 6px; }
  .lp-title b { font-size: 14px; }
  .lp-title span { display: none; }
  .lp-btns button { padding: 6px 0; border-radius: 9px; }
  .lp-btns b { font-size: 17px; }
  .lp-btns span { display: none; }
  .player-row { flex-wrap: wrap; }
  .player-row input { min-width: 100px; }
  .player-row .pawn-icon { display: none; }
  .quiz-card { padding: 10px 12px; }
  .q-flag { height: 46px; }
  .face-map { padding: 8px; gap: 8px; }
  .map-hint { display: none; }
  .result { flex-wrap: wrap; justify-content: center; text-align: center; }
  .dice-scene { transform: scale(.8); margin: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .prism { transition-duration: .01s; }
  .sky span, .dice.idle, .logo-globe { animation: none; }
}

/* ================= IN-GAME DIALOG (replaces the browser's confirm) ================= */
.g-dialog { z-index: 40; }
.g-dialog-card { width: min(380px, 100%); padding: 24px 22px 22px; }
.g-dialog-card h2 { font-size: 22px; margin: 0 0 8px; }
.g-dialog-card p { line-height: 1.45; }
.g-dialog-card .win-actions button { min-width: 120px; }
.g-dialog-icon { font-size: 40px; line-height: 1; margin-bottom: 4px; }
.btn-primary.danger { background: linear-gradient(180deg, #ff7b7b, #e04f5f); color: #fff; box-shadow: 0 6px 0 #a83442, 0 10px 20px rgba(224, 79, 95, .3); }
.btn-primary.danger:active { box-shadow: 0 2px 0 #a83442, 0 6px 12px rgba(224, 79, 95, .3); }

/* ================= CHOICE MENU (replaces the browser's drop-down) ================= */
.g-menu {
  position: fixed; z-index: 45; display: flex; flex-direction: column; gap: 2px; padding: 6px; border-radius: 16px;
  background: linear-gradient(180deg, #1c2b63, #111a3d); border: 1px solid var(--panel-border);
  box-shadow: 0 18px 40px rgba(0,0,0,.55); animation: fade .15s both;
}
.g-menu-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 12px; text-align: left; cursor: pointer;
  padding: 9px 12px; border: 0; border-radius: 11px; background: transparent; color: var(--text); font: 600 14px var(--font-body);
}
.g-menu-item small { grid-column: 1; color: var(--muted); font-size: 12px; font-weight: 500; }
.g-menu-item small:empty { display: none; }
.g-menu-item i { grid-column: 2; grid-row: 1 / span 2; font-style: normal; color: var(--accent); visibility: hidden; }
.g-menu-item.current { background: rgba(255,209,102,.12); }
.g-menu-item.current i { visibility: visible; }
.g-menu-item:hover, .g-menu-item:focus-visible { background: rgba(255,255,255,.1); outline: none; }

/* ================= "All" switch + geography type on the category picker ================= */
.h2-row { display: flex; align-items: center; gap: 10px; }
.all-btn {
  margin-left: auto; padding: 4px 12px; border-radius: 999px; cursor: pointer; text-transform: none; letter-spacing: 0;
  font: 700 12px var(--font-body); color: var(--muted); background: rgba(255,255,255,.06); border: 1px solid var(--panel-border);
}
.all-btn:hover { color: var(--text); background: rgba(255,255,255,.12); }
.all-btn.active, .all-btn[aria-pressed="true"] { color: #10142a; background: var(--accent); border-color: var(--accent); }
.cat-btn .geo-type {
  margin-top: 2px; padding: 3px 8px; border-radius: 999px; font: 600 11px var(--font-body); color: var(--text); white-space: nowrap;
  background: rgba(255,255,255,.1); border: 1px solid var(--panel-border); cursor: pointer;
}
.cat-btn .geo-type:hover, .cat-btn .geo-type:focus-visible { background: rgba(255,255,255,.2); outline: none; }
.cat-btn.active .geo-type { border-color: var(--accent); }

/* Phones: the centred column may shrink to the screen (a long one-line text, e.g. the
 * "Game in progress" summary, otherwise widens it past the screen edge). */
#setup.active, #lobby.active { grid-template-columns: minmax(0, 1fr); }
.setup-card, .v-card { max-width: 100%; min-width: 0; }

/* ================= US states & Canadian provinces (WorldMap.setScope) ================= */
#map .region, #map .region-dot { display: none; }
#map.show-regions .region, #map.show-regions .region-dot { display: inline; }
#map.show-regions .country[data-id="USA"], #map.show-regions .country[data-id="CAN"] { display: none; }
#map.na-only .country:not(.region) { fill-opacity: .35; pointer-events: none; }
#map.na-only .dot:not(.region-dot) { display: none; }
/* the map scope menu button (world / + US states & Canada / only those) */
.scope-row { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 13px; color: var(--muted); font-weight: 600; }
.scope-btn {
  color: var(--text); font: 600 13.5px var(--font-body); padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--accent); background: rgba(255,209,102,.1); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.scope-btn:hover { background: rgba(255,209,102,.2); }

/* small flag pictures in labels (instead of flag emoji, which Windows shows as letters) */
.flag-icos { display: inline-flex; gap: 3px; vertical-align: -0.12em; }
.flag-ico { height: 0.95em; width: auto; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
