/* Structural styling only: layout, sizes, states. The visual design comes later. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-x: none; }
body {
  margin: 0 auto; max-width: 480px; min-height: 100dvh; padding: 8px 16px 16px;
  font: 15px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f6f1e7; color: #23302b;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #1a5fb4; outline-offset: 2px; }

.top { display: flex; justify-content: space-between; align-items: center; min-height: 40px; }
.top h1 { font-size: 18px; margin: 0; }
.pill { background: #23302b; color: #f6f1e7; border-radius: 99px; padding: 2px 10px; font-weight: 700; font-size: 14px; }
.pill:empty { display: none; }

/* ---- pick ---- */
#pick { display: flex; flex-direction: column; }
#theme { margin: 0 0 2px; font-size: 13px; font-weight: 700; overflow-wrap: anywhere; }
#pick-help { margin: 2px 0 6px; font-size: 13px; }
.pick-heads { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; padding: 0 4px 4px; }
.head-left { color: #a8432b; }
.head-right { color: #24607d; }
#lanes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }

.lane {
  position: relative; height: 46px; border-radius: 10px;
  background: linear-gradient(90deg, #c2553a26 0 26%, #0000000a 26% 74%, #2f6f8f26 74%);
}
.lane-left, .lane-right {
  position: absolute; top: 0; width: 44px; height: 46px; padding: 0; border: 0; border-radius: 10px;
  background: transparent; font-size: 26px; line-height: 1; color: #5e584c; cursor: pointer;
}
.lane-left { left: 0; }
.lane-right { right: 0; }
.lane-left:disabled, .lane-right:disabled { visibility: hidden; }

/* The chip is 48 % of the lane; left / middle / right put it at 0 / 26 % / 52 %, so one step is
   wider than the 25 % drag threshold and the chip on a side covers that side's (useless) button. */
.chip {
  position: absolute; top: 3px; height: 40px; width: 48%; left: 26%; z-index: 1;
  display: flex; align-items: center; gap: 5px; padding: 0 6px;
  border-radius: 8px; background: #fff; border: 2px solid #cfc6b4;
  font-weight: 600; font-size: 14px; line-height: 1.1;
  cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: pan-y;    /* horizontal moves come to us; vertical ones still scroll the page */
  transition: left .18s ease-out, background-color .18s, border-color .18s;
}
.chip .flag { font-size: 20px; flex: none; }
.chip .name { overflow-wrap: anywhere; }
.chip[data-len="l"] { font-size: 13px; }
.chip[data-len="xl"] { font-size: 12px; line-height: 1; }
.chip[data-len="xl"] .flag { font-size: 16px; }
.lane[data-side="-1"] .chip { left: 0; background: #c2553a; border-color: #c2553a; color: #fff; }
.lane[data-side="1"] .chip { left: 52%; background: #2f6f8f; border-color: #2f6f8f; color: #fff; }
.lane.dragging .chip { transition: none; cursor: grabbing; }
.lane:focus-visible { outline: 3px solid #1a5fb4; outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .chip { transition: none; } }

#pick-count { text-align: center; margin: 8px 0 6px; font-weight: 600; min-height: 1.3em; }
#btn-start {
  width: 100%; min-height: 48px; border: 0; border-radius: 12px;
  background: #23302b; color: #f6f1e7; font-weight: 700; font-size: 16px; cursor: pointer;
}
#btn-start:disabled { opacity: .35; cursor: default; }
#rules-note { margin: 8px 0 0; font-size: 13px; text-align: center; }

/* ---- place (and the frozen pile once released) ---- */
/* The section fills the viewport below the header: field on top, one bar with the countdown and
   Release below. The field takes what is left; the viewBox keeps the world's aspect ("meet"). */
body[data-phase="place"], body[data-phase="released"] { overscroll-behavior: none; }
/* Spare height (a tall phone) goes above the field, so the field, the box and Release sit together near the thumb. */
#place { display: flex; flex-direction: column; justify-content: flex-end; height: calc(100dvh - 64px); min-height: 0; }
#field {
  display: block; flex: 0 1 auto; min-height: 0; width: 100%; overflow: hidden;
  touch-action: none;                                  /* no scroll, zoom or pull-to-refresh while dragging */
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
/* The box on top and its four doors (scene.js; drawn behind the countries). It fades out at the
   box-gone step (the transition time comes from CONFIG.release.boxFadeMs, set inline). */
#box { opacity: 1; }
svg[data-box="gone"] #box { opacity: 0; }
#box .box-frame { fill: #23302b0a; stroke: #5e584c; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#box .box-wall { stroke: #5e584c; stroke-width: 1; stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
#box .door { fill: #8a8170; stroke: #5e584c; stroke-width: 1; vector-effect: non-scaling-stroke; }
/* The dial (needle and scale) is hidden while the box is still there. */
#needle[data-shown="false"], #tilt-scale[data-shown="false"] { opacity: 0; }
/* The scale fades in with the same transition as the box fades out (set inline from boxFadeMs). */
/* A country that is gone is not shown (Task 24 styles it further). */
g.country[data-state="gone"] { display: none; }
#field .fulcrum { fill: #8a8170; }
#field #beam { fill: #5e584c; }
#field .side-left { fill: #c2553a12; }
#field .side-right { fill: #2f6f8f12; }
#pivot-line { stroke: #23302b; stroke-width: 1.5; stroke-dasharray: 6 5; vector-effect: non-scaling-stroke; }
#field .deco, #field text { pointer-events: none; }
/* The tilt needle and its scale (scene.js): decoration only, never a press target. */
#needle, #tilt-scale { pointer-events: none; }
#needle .needle-line { stroke: #23302b; stroke-opacity: .55; stroke-width: 2.5; stroke-linecap: round; vector-effect: non-scaling-stroke; }
#needle .needle-tip { fill: #23302b; }
#needle .needle-hub { fill: #23302b; }
#tilt-scale .arc { fill: none; stroke: #5e584c; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#tilt-scale .tick { stroke: #5e584c; stroke-width: 1; vector-effect: non-scaling-stroke; }
#tilt-scale .tick.major { stroke-width: 1.5; }
#tilt-scale .tick.centre { stroke: #23302b; stroke-width: 2.5; }
#tilt-scale .level-zone { fill: none; stroke: #3d8b5a; stroke-opacity: .55; stroke-width: 7; stroke-linecap: butt; vector-effect: non-scaling-stroke; }
#tilt-scale text { fill: #5e584c; font-weight: 600; }
#field .side-heads text { font-size: 0.42px; font-weight: 700; }
#field .head-left { fill: #a8432b; }
#field .head-right { fill: #24607d; }
.country { cursor: grab; }
.country path { stroke: #23302b; stroke-width: 1; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.country[data-side="-1"] path { fill: #c2553a; }
.country[data-side="1"] path { fill: #2f6f8f; }
.country[data-state="held"] { cursor: grabbing; }
.country[data-state="held"] path { stroke-width: 2; }
/* Waiting in the box: lighter, so the pile reads as the pile. Held: a firmer outline and a grab dot. */
.country[data-state="box"] path { fill-opacity: .8; }
.grab-dot { fill: #fff; stroke: #23302b; stroke-width: 2; vector-effect: non-scaling-stroke; }
.place-bar { flex: none; display: flex; align-items: center; gap: 10px; padding-top: 8px; }
/* Gone for good: one struck-through flag per country that fell away, between the clock and Release. */
#gone-list { flex: none; display: flex; gap: 2px; max-width: 30%; overflow: hidden; }
#gone-list:empty { display: none; }
.gone-flag { position: relative; font-size: 20px; line-height: 1; opacity: .7; }
.gone-flag::after { content: ""; position: absolute; left: -2px; right: -2px; top: 50%; border-top: 2.5px solid #b3121b; transform: rotate(-20deg); }
#build-notice { flex: none; margin: 6px 0 0; text-align: center; font-size: 14px; }
#timer { flex: none; min-width: 3.2em; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
#btn-release {
  flex: 1; min-height: 48px; border: 0; border-radius: 12px;
  background: #23302b; color: #f6f1e7; font-weight: 700; font-size: 16px; cursor: pointer;
}
#btn-release:disabled { opacity: .35; cursor: default; }

/* ---- the release and the result ---- */
#round-status { flex: none; margin: 6px 0 0; text-align: center; font-size: 18px; font-weight: 700; min-height: 1.3em; }
/* Fallen countries stay where they landed, faded, so a collapse can be read. */
.country[data-state="off"] path { fill-opacity: .45; stroke-dasharray: 4 3; }
#field.pile-hidden .country { visibility: hidden; }
body[data-phase="released"] .country, body[data-phase="done"] .country { cursor: default; }
/* Done: the page scrolls normally; the field is capped so the result fits below it. */
body[data-phase="done"] #place { height: auto; justify-content: flex-start; }
body[data-phase="done"] #field { touch-action: pan-y; max-height: 46dvh; }
#result { flex: none; padding-top: 6px; }
.result-total { margin: 0 0 6px; text-align: center; }
#score-total { font-size: 40px; line-height: 1; font-variant-numeric: tabular-nums; }
#score-max { font-size: 15px; font-weight: 600; }
.result-part { border-radius: 10px; padding: 6px 10px 8px; margin: 0 0 6px; }
.result-part h2 { font-size: 14px; margin: 0; text-transform: uppercase; letter-spacing: .04em; }
.part-note { margin: 0 0 4px; font-size: 12px; }
#selection { border: 2px dashed #cfc6b4; }
#stacking { background: #fff; border: 2px solid #23302b; }
.sel-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; }
.sel-row .sel-left b { color: #a8432b; }
.sel-row .sel-right b { color: #24607d; }
.part-row { display: grid; grid-template-columns: 1fr auto 6.5em; gap: 8px; align-items: baseline; padding: 2px 0; font-size: 14px; }
.part-value { font-variant-numeric: tabular-nums; }
.part-pts { text-align: right; font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 8px; }
#btn-send, #btn-replay, #btn-card {
  flex: 1; min-height: 44px; border: 0; border-radius: 12px;
  background: #23302b; color: #f6f1e7; font-weight: 700; font-size: 16px; cursor: pointer;
}
#btn-send:disabled, #btn-card:disabled { opacity: .5; cursor: default; }
#send-note { margin: 4px 0; text-align: center; font-size: 13px; }
#send-note[hidden], #send-text[hidden] { display: none; }
#send-text { display: block; width: 100%; box-sizing: border-box; font: inherit; font-size: 14px; }
#card-note { margin: 4px 0; text-align: center; font-size: 13px; }
#card-note[hidden] { display: none; }
#card-preview { display: block; max-width: 60%; margin: 8px auto; border-radius: 8px; }
#card-preview[hidden] { display: none; }
#result-notice { margin: 4px 0; text-align: center; font-size: 14px; }
#rank-line:empty, #result-link:empty { display: none; }
.result-next { margin: 6px 0 0; text-align: center; font-size: 13px; }
#app-notice { text-align: center; margin: 24px 0; }
/* Test host only: Play again (test). Plain and dashed, so it never reads as part of the game. */
.test-again { margin: 12px 0 0; padding: 8px; border: 2px dashed #8a8170; border-radius: 12px; text-align: center; }
#btn-again {
  width: 100%; min-height: 44px; border: 2px solid #23302b; border-radius: 10px;
  background: #fff; color: #23302b; font-weight: 700; font-size: 15px; cursor: pointer;
}
#again-note { margin: 6px 0 0; font-size: 12px; }

/* ---- the result-link page (/r/<pub>) ---- */
#link { display: flex; flex-direction: column; gap: 6px; padding-top: 6px; }
#link #field { max-height: 46dvh; touch-action: pan-y; }
#link-notice { margin: 4px 0; text-align: center; font-size: 15px; font-weight: 600; }
.link-result { flex: none; }
.btn-link, #btn-play {
  flex: 1; min-height: 44px; display: flex; align-items: center; justify-content: center; text-decoration: none;
  border-radius: 12px; background: #23302b; color: #f6f1e7; font-weight: 700; font-size: 16px;
}
body[data-view="locked"] #score-total { font-size: 56px; }
#from-link { display: block; margin: 8px 0 0; text-align: center; font-weight: 700; color: #1a5fb4; }
