/* Nothing-inspired tokens. Monochrome ramp for hierarchy; the accent is an interrupt. */

@font-face { font-family: "Grotesk"; src: url("../fonts/space_grotesk.ttf") format("truetype"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "Mono"; src: url("../fonts/space_mono.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Mono"; src: url("../fonts/space_mono_bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Dot"; src: url("../fonts/doto.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }

:root {
  --bg: #F3F2EE;
  --surface: #FFFFFF;
  --raised: #EAE8E2;
  --border: #D9D6CD;
  --border-strong: #B4B0A5;
  --ink: #000000;
  --text: rgba(0, 0, 0, .9);
  --text-2: rgba(0, 0, 0, .6);
  --text-3: rgba(0, 0, 0, .42);
  --success: #1F8A50;
  --accent: #D71921;
  --on-accent: #FFFFFF;
  /* Map: light mode needs real contrast, the regions used to melt into the page. */
  --map-fill: #DEDAD0;
  --map-stroke: #B9B4A6;
  --wash-a: 46%;
  --wash-b: 20%;
  --line: rgba(0, 0, 0, .07);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #0B0B0B;
  --raised: #141414;
  --border: #232323;
  --border-strong: #3A3A3A;
  --ink: #FFFFFF;
  --text: rgba(255, 255, 255, .9);
  --text-2: rgba(255, 255, 255, .6);
  --text-3: rgba(255, 255, 255, .4);
  --success: #2FBF71;
  --map-fill: #1A1A1A;
  --map-stroke: #363636;
  --wash-a: 34%;
  --wash-b: 15%;
  --line: rgba(255, 255, 255, .10);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #0B0B0B;
    --raised: #141414;
    --border: #232323;
    --border-strong: #3A3A3A;
    --ink: #FFFFFF;
    --text: rgba(255, 255, 255, .9);
    --text-2: rgba(255, 255, 255, .6);
    --text-3: rgba(255, 255, 255, .4);
    --success: #2FBF71;
    --map-fill: #1A1A1A;
    --map-stroke: #363636;
    --wash-a: 34%;
    --wash-b: 15%;
    --line: rgba(255, 255, 255, .10);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.4 "Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
img { display: block; max-width: 100%; }

/* ---- type ---------------------------------------------------------------------- */
.label {
  display: block;
  font: 400 12px/16px "Mono", ui-monospace, monospace;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text-2);
}
.caption { font: 400 11px/15px "Mono", ui-monospace, monospace; letter-spacing: .06em; }
.display { font: 700 96px/1 "Dot", ui-monospace, monospace; letter-spacing: -1px; color: var(--ink); }
.display .unit { font: 300 34px/1 "Grotesk", sans-serif; color: var(--text-2); margin-left: 4px; }
.headline { font: 300 34px/38px "Grotesk", sans-serif; letter-spacing: -.8px; color: var(--ink); }
.title { font: 400 22px/27px "Grotesk", sans-serif; letter-spacing: -.2px; color: var(--ink); }
.body { font-size: 16px; line-height: 22px; }
.readout { font: 700 28px/32px "Mono", ui-monospace, monospace; letter-spacing: -.5px; color: var(--ink); }
.dim { color: var(--text-3); }
.body.dim { color: var(--text-2); }
.acc { color: var(--accent) !important; }
.ok { color: var(--success) !important; }

/* spacing carries meaning: tight · group · new group */
.gap-xs { margin-top: 4px; }
.gap-s { margin-top: 8px; }
.gap-m { margin-top: 16px; }
.gap-l { margin-top: 28px; }
.gap-xl { margin-top: 40px; }

/* ---- layout -------------------------------------------------------------------- */
.screen {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(28px + env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
    calc(96px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
.bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; margin-top: 56px; margin-bottom: 8px; }
.dotfield {
  width: 64px; height: 64px; flex: none;
  background-image: radial-gradient(var(--border-strong) 1.1px, transparent 1.4px);
  background-size: 14px 14px;
  opacity: .6;
}
.hair { height: 1px; background: var(--border); }

/* ---- controls ------------------------------------------------------------------ */
.pill {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 56px; border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font: 400 12px "Mono", monospace; letter-spacing: .18em; text-transform: uppercase;
  transition: transform .12s ease-out;
}
.pill:active { transform: scale(.98); }
.pill.accent { background: var(--accent); color: var(--on-accent); }
.pill.short { height: 42px; }
.pill:disabled { background: var(--raised); color: var(--text-3); cursor: default; }

.tech {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 42px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  font: 400 12px/16px "Mono", monospace; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-2); text-align: center;
  transition: background-color .12s ease-out, color .12s ease-out;
}
.tech.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.tech.sm { min-height: 32px; padding: 4px 12px; }
.tech.wide { width: 100%; min-height: 52px; }

.chips { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.switch-row > span { display: grid; gap: 2px; }
.switch {
  position: relative; flex: none; width: 52px; height: 30px; border-radius: 999px;
  background: var(--raised); border: 1px solid var(--border);
}
.switch i {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--text-2); transition: transform .15s ease-out;
}
.switch.on { background: var(--ink); border-color: var(--ink); }
.switch.on i { background: var(--bg); transform: translateX(22px); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border);
  background: radial-gradient(circle, var(--c) 15px, transparent 15.5px);
}
.swatch.on { border: 2px solid var(--ink); background: radial-gradient(circle, var(--c) 11px, transparent 11.5px); }

.stat { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; }
.stat .value { color: var(--ink); text-align: right; }

/* ---- home ---------------------------------------------------------------------- */
.modes { margin-top: 40px; border-top: 1px solid var(--border); }
.mode-item { border-bottom: 1px solid var(--border); }
.mode { display: flex; align-items: center; gap: 16px; width: 100%; padding: 16px 0; text-align: left; }
.mode .mk { width: 8px; height: 8px; flex: none; background: var(--border-strong); }
.mode.on .mk { background: var(--ink); }
.mode .mt { display: grid; gap: 2px; flex: 1; }
.mode .t { font: 400 22px/27px "Grotesk", sans-serif; color: var(--text-2); }
.mode.on .t { color: var(--ink); }
.mode .n { color: var(--text-3); }
.mode.on .n { color: var(--ink); }
.inset { padding: 0 0 18px 24px; }

.misses { list-style: none; margin-top: 8px; }
.misses li { padding: 6px 0; }

/* ---- game ---------------------------------------------------------------------- */
.game { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); z-index: 1; }
.game-head {
  padding: calc(14px + env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
  max-width: 900px; width: 100%; margin: 0 auto;
}
.score { display: flex; align-items: flex-end; gap: 4px; }
.cells { display: flex; gap: 2px; margin-top: 14px; }
.cells i { flex: 1; height: 4px; background: var(--border); }
.cells i.ok { background: var(--ink); }
.cells i.no { background: var(--accent); }
.bar-progress { height: 4px; margin-top: 14px; background: var(--border); }
.bar-progress i { display: block; height: 100%; background: var(--ink); }
.meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; }

.map-wrap { position: relative; flex: 1; min-height: 0; touch-action: none; overflow: hidden; }
.map { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; cursor: pointer; }
.map path {
  fill: var(--map-fill);
  stroke: var(--map-stroke);
  stroke-width: 1;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: fill .15s ease-out;
}
.map path[data-s="s1"] { fill: var(--ink); stroke: var(--ink); }
.map path[data-s="s2"] { fill: color-mix(in srgb, var(--ink) 60%, var(--map-fill)); }
.map path[data-s="s3"] { fill: color-mix(in srgb, var(--ink) 30%, var(--map-fill)); }
.map path[data-s="failed"] { fill: color-mix(in srgb, var(--accent) 45%, var(--map-fill)); stroke: var(--accent); }
.map path[data-s="miss"] { fill: var(--accent); stroke: var(--accent); }
.map path[data-s="reveal"] { fill: color-mix(in srgb, var(--accent) 30%, var(--map-fill)); stroke: var(--accent); stroke-width: 2.5; }
/* The one just found gets an accent rim so it reads apart from earlier finds. */
.map path[data-s="hit"] { fill: var(--ink); stroke: var(--accent); stroke-width: 2; }

/* Bottom-right sits in the empty band a wide map leaves on a tall screen. */
.zoom { position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: 16px; display: grid; gap: 8px; }
.zoom .tech { width: 44px; height: 44px; min-height: 44px; padding: 0; background: var(--bg); color: var(--ink); font-size: 18px; }

.panel {
  min-height: 176px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 20px max(24px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
.panel > * { max-width: 852px; margin-left: auto; margin-right: auto; }
/* A long card must never push «Дальше» off the screen: the panel scrolls past a
   cap and the button stays pinned to its bottom edge. */
.panel { max-height: 62dvh; overflow-y: auto; overscroll-behavior: contain; }
.panel .pill[data-a="next"] { position: sticky; bottom: 0; box-shadow: 0 0 0 12px var(--surface); }
.flag {
  display: flex; align-items: center; justify-content: center;
  height: 132px; padding: 10px;
  background: var(--raised); border: 1px solid var(--border);
}
.flag img { max-height: 100%; width: auto; object-fit: contain; }
.note { max-height: min(180px, 22dvh); overflow-y: auto; }

/* ---- backdrop: wallpaper, not chrome — only on home and result ------------------- */
#backdrop { position: fixed; inset: 0; z-index: 0; pointer-events: none; display: none; }
body.wash #backdrop { display: block; }
#backdrop .wash {
  position: absolute; inset: 0;
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--accent) var(--wash-a), transparent) 0%,
    color-mix(in srgb, var(--accent) var(--wash-b), transparent) 34%,
    transparent 62%);
}
#backdrop svg { position: absolute; inset: 0; width: 100%; height: 100%; }
#backdrop svg * { fill: none; stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }

.loading { padding: 40vh 24px 0; text-align: center; color: var(--text-3); }

@media (min-width: 720px) {
  .display { font-size: 120px; }
  .panel { min-height: 160px; }
}

/* ---- desktop menu --------------------------------------------------------------- */
/* Stats stand aside, the map is the pack picker, modes are tiles. The page keeps
   one hero (the number) and one moment of colour (the hovered district). */
.desk {
  max-width: 1360px;
  padding: calc(32px + env(safe-area-inset-top)) 48px 72px;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-areas: "bar bar" "side main";
  column-gap: 56px;
  row-gap: 40px;
}
.desk-bar { grid-area: bar; }
.desk-side { grid-area: side; align-self: start; position: sticky; top: 32px; }
.desk-side .display { font-size: 136px; }
.desk-main { grid-area: main; min-width: 0; }

.preview-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
}
.preview-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.preview { margin-top: 16px; aspect-ratio: 1000 / 600; }
.preview-map { display: block; width: 100%; height: 100%; cursor: pointer; }
.preview-map path {
  fill: var(--map-fill);
  stroke: var(--bg);
  stroke-width: .75;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: fill .12s ease-out;
}
.preview-map path.in { fill: var(--ink); }
.preview-map path.hov { fill: var(--accent); }

.grid9 { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 6px; }
.grid9 .tech { padding: 6px 2px; letter-spacing: .04em; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 8px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  min-height: 128px; padding: 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  text-align: left;
  transition: background-color .12s ease-out, border-color .12s ease-out;
}
.tile:hover { border-color: var(--border-strong); }
.tile-top { display: flex; justify-content: space-between; width: 100%; margin-bottom: auto; }
.tile .key { color: var(--text-3); }
.tile .t { font: 400 22px/27px "Grotesk", sans-serif; color: var(--ink); padding-top: 18px; }
.tile .sub { color: var(--text-3); }
.tile.on { background: var(--ink); border-color: var(--ink); }
.tile.on .t, .tile.on .label { color: var(--bg); }
.tile.on .sub, .tile.on .key { color: color-mix(in srgb, var(--bg) 60%, transparent); }

.options { margin-top: 16px; padding: 20px; border: 1px solid var(--border); border-radius: 12px; }
.options .grid2 { grid-template-columns: repeat(4, 1fr); }

.desk-foot { display: flex; align-items: center; gap: 16px; }
.desk-foot .chips { flex: 0 0 300px; }
.desk-foot .pill { flex: 1; }

/* Short screens (a phone on its side): the map must keep most of the height. */
@media (max-height: 560px) {
  .game-head { padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 6px; }
  .cells, .bar-progress { margin-top: 8px; }
  .meta { margin-top: 4px; }
  .readout { font-size: 22px; line-height: 26px; }
  .panel { min-height: 0; padding-top: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .panel .headline { font-size: 24px; line-height: 28px; }
  .panel .gap-s { margin-top: 4px; }
  .panel .pill { height: 44px; }
  .flag { height: 72px; padding: 6px; }
  .note { max-height: 90px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
