:root {
  --radius-small: 4px;
  --radius-medium: 8px;
  --radius-control: 4px;
  --radius-control-compact: 4px;
  --radius-panel: 4px;
  --radius-pill: 999px;
  --radius-circle: 50%;
  --space-control: 12px;
  --space-control-compact: 10px;
  --space-panel: 16px;
  --space-dialog: 24px;
  --border-choice: 1px;
  --focus-width: 3px;
  --focus-offset: 3px;
  --focus-color: #2449b4;
  --border-plate: 1px;
  --font-title-minimum: 20px;
  --font-title-preferred: 3vw;
  --font-title-maximum: 27px;
  --badge-summary-size: 26px;
  --badge-marker-size: 18px;
  --location-switch-size: 40px;
  --location-dialog-width: 440px;
  --location-viewport-inset: 32px;
  --control-radius: var(--radius-control);
  --control-padding-block: 12px;
  --control-padding-inline: 18px;
  --ink: #242124;
  --muted: #61595f;
  --line: #d0c3c7;
  --paper: #f4eee8;
  --plate: #193d68;
  --plate-deep: #193d68;
  --accent: #2449b4;
  --ok: #226047;
  --bad: #b73527;
  --map-paper: #e6cedf;
  --map-yellow: #e6d63b;
  --shadow: 0 3px 12px rgb(36 33 36 / 10%);
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { touch-action: manipulation; }
h1, h2 { font-weight: 400; }
#map { position: fixed; inset: 0; background: var(--map-paper); }
.maplibregl-map { font: inherit; }
.maplibregl-ctrl-bottom-right { bottom: 4px; }
.maplibregl-ctrl-group { border-radius: var(--radius-medium); overflow: hidden; }
.maplibregl-ctrl-group button,
.maplibregl-ctrl-group button:first-child,
.maplibregl-ctrl-group button:last-child { border-radius: 0; }
.maplibregl-ctrl-group button:focus-visible { outline-offset: calc(-1 * var(--focus-width)); }
.maplibregl-ctrl-attrib { border-radius: var(--radius-medium) 0 0 0; }
.maplibregl-ctrl-attrib.maplibregl-compact { border-radius: var(--radius-pill); }
.surface { background: var(--paper); border-radius: var(--radius-panel); padding: var(--surface-inset); box-shadow: var(--shadow); }
.control { border: 0; border-radius: var(--control-radius); padding: var(--control-padding-block) var(--control-padding-inline); cursor: pointer; }
.badge { display: inline-grid; place-items: center; width: var(--badge-size); height: var(--badge-size); border-radius: var(--radius-circle); font-weight: 400; }
button:focus-visible, .choice input:focus-visible + span, input:focus-visible, select:focus-visible,
.plate-title[role="button"]:focus-visible { outline: var(--focus-width) solid var(--focus-color); outline-offset: var(--focus-offset); }

/* Signs keep the city and selected area together, at every viewport size. */
.plate {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  --plate-padding: var(--space-panel);
  padding: var(--plate-padding);
  background: var(--plate); color: #fffefa; text-align: center;
  border: var(--border-plate) solid var(--plate); border-radius: var(--control-radius);
}
.plate::before { content: ''; position: absolute; inset: 4px; border: 1px solid rgb(255 254 250 / 70%); border-radius: 2px; pointer-events: none; }
.plate-label { font-size: 11px; font-weight: 400; line-height: 1.4; letter-spacing: .08em; overflow-wrap: anywhere; }
.plate-label.dark { color: var(--muted); }
.plate-name { font-size: clamp(20px, 3vw, 30px); font-weight: 400; line-height: 1.2; overflow-wrap: anywhere; text-wrap: balance; }
.plate-title { --plate-padding: 14px; margin: 0; width: fit-content; max-width: 100%; }
.plate-title .plate-name { font-size: clamp(var(--font-title-minimum), var(--font-title-preferred), var(--font-title-maximum)); }
.plate-title[role="button"] { cursor: pointer; }
.setup-plate { width: fit-content; margin: 0 0 22px; }
.setup-plate .plate-name { font-size: 27px; }

/* Game controls. */
#hud { position: fixed; z-index: 1000; top: 14px; left: 14px; right: 14px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 12px; pointer-events: none; }
#hud > * { pointer-events: auto; }
#btn-menu { grid-column: 1; }
#plate { grid-column: 2; max-width: min(640px, 100%); }
#stats { grid-column: 3; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.chip { justify-self: start; --control-padding-block: 10px; --control-padding-inline: 16px; background: var(--paper); border-radius: var(--control-radius); padding: var(--control-padding-block) var(--control-padding-inline); font-size: 13px; font-weight: 400; box-shadow: var(--shadow); }
button.chip:hover { background: #eae3e9; }
.stats { justify-self: end; display: flex; gap: 14px; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-weight: 400; }
.stats b { font-weight: 400; color: var(--ink); }
#dock { position: fixed; z-index: 1000; left: 50%; bottom: 22px; transform: translateX(-50%); width: min(600px, calc(100vw - 24px)); --surface-inset: var(--space-control); }
.dock-row { display: flex; align-items: center; gap: 14px; }
.tip-text { flex: 1; margin: 0; font-size: 14px; color: var(--muted); }
.tip-text.ready { color: var(--ink); }
.actions { display: flex; gap: 8px; }
.actions.stretch > * { flex: 1; }
.btn { font-size: 14px; font-weight: 400; white-space: nowrap; transition: background .15s; }
.btn.primary { background: var(--accent); color: #fffefa; }
.btn.primary:hover { background: #193d8b; }
.btn.primary:disabled { background: #9da9c9; cursor: not-allowed; }
.btn.ghost { background: #eae3e9; color: var(--ink); }
.btn.ghost:hover { background: #ded5dc; }
.btn.ghost:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { --control-padding-block: 15px; width: 100%; font-size: 15px; background: var(--ink); }
.btn.big:hover { background: var(--accent); }
.res-main { flex: 1; min-width: 0; }
.res-head { font-size: 22px; font-weight: 400; line-height: 1.2; }
.res-head.ok { color: var(--ok); }
.res-head.bad { color: var(--bad); }
.res-sub { margin-top: 4px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.res-sub b { color: var(--ink); font-weight: 400; }
.bar { margin-top: 10px; height: 4px; border-radius: var(--radius-pill); background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: var(--radius-pill); background: var(--accent); transition: width .3s; }
.bar i.ok { background: var(--ok); }
.res-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.res-pts { font-size: 24px; font-weight: 400; font-variant-numeric: tabular-nums; }

/* Menu: setup beside the actual map, with no separate logo. */
.overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: safe center; padding: 20px; background: rgb(36 33 36 / 35%); overflow-y: auto; }
.card { --surface-inset: var(--space-dialog); width: min(460px, 100%); }
#menu { background: transparent; padding: 28px; }
.menu-shell { width: min(1280px, 100%); box-shadow: 0 0 0 100vmax var(--paper); border: 1px solid var(--ink); }
.menu-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 22px 32px; background: var(--paper); border-bottom: 1px solid var(--ink); }
.location-heading { display: flex; align-items: center; gap: 18px; min-width: 0; }
.location-heading .plate-title { flex: 0 1 auto; min-width: 0; }
.location-switch { flex: 0 0 auto; padding: 12px 0; background: none; font-size: 12px; text-decoration: underline; text-underline-offset: 4px; }
.menu-navigation { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.menu-navigation .control { font-size: 12px; padding: 10px; background: transparent; }
.menu-navigation .account-actions { margin: 0; }
.menu-body { display: grid; grid-template-columns: minmax(0, 48%) minmax(0, 52%); }
.menu-card { width: 100%; --surface-inset: 36px; border-radius: 0; box-shadow: none; }
.lede { margin: 0 0 26px; color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 380px; }
.choice { border: 0; padding: 0; margin: 0 0 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice legend { padding: 0; margin-bottom: 10px; font-size: 12px; font-weight: 400; color: var(--ink); }
.choice label { position: relative; cursor: pointer; min-width: 0; }
.choice input { position: absolute; opacity: 0; inset: 0; }
.choice label > span { display: flex; flex-direction: column; gap: 5px; height: 100%; padding: var(--control-padding-block) var(--space-control); border: var(--border-choice) solid #a79ba3; border-radius: var(--control-radius); transition: border-color .15s, background .15s; }
.choice label:hover > span { border-color: var(--ink); }
.choice input:checked + span { border-color: var(--accent); background: var(--accent); color: #fffefa; }
.choice b { font-size: 14px; font-weight: 400; }
.choice small { font-size: 11px; color: var(--muted); line-height: 1.4; }
.choice small i { font-style: normal; font-weight: 400; }
.choice input:checked + span small { color: #fffefa; }
.meta { min-height: 18px; margin: 0 0 12px; font-size: 12px; line-height: 1.5; color: var(--muted); }
.meta b { color: var(--ink); font-weight: 400; }
.guest-note { margin: 10px 0 0; font-size: 11px; color: var(--muted); text-align: center; }
.keys { margin: 22px 0 0; font-size: 11px; color: var(--muted); }
kbd { font: inherit; font-size: 11px; padding: 1px 5px; border-radius: var(--radius-small); border: 1px solid var(--line); background: var(--paper); }
.multiplayer-settings { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }
.multiplayer-settings h2 { font-size: 14px; margin: 0 0 14px; }
.multiplayer-row { display: grid; grid-template-columns: 1fr 1fr; align-items: end; gap: 12px; }
.mp-settings { display: grid; gap: 7px; font-size: 11px; }
#btn-mp-history { padding: 12px 0 0; background: transparent; font-size: 11px; text-decoration: underline; text-underline-offset: 4px; }
.menu-map { position: relative; min-height: 540px; overflow: hidden; background: rgb(230 206 223 / 35%); border-left: 1px solid var(--ink); }
.map-place { position: absolute; left: 32px; top: 32px; right: 65px; display: grid; gap: 8px; font-size: clamp(26px, 3vw, 44px); line-height: 1.2; letter-spacing: -1px; overflow-wrap: anywhere; }
#menu-map-zone { font-size: 20px; letter-spacing: 0; }
.map-directions { position: absolute; top: 0; right: 0; bottom: 0; width: 48px; background: var(--ink); color: var(--map-paper); display: flex; flex-direction: column; justify-content: space-around; align-items: center; font-size: 44px; line-height: 1; }
.map-note { position: absolute; left: 32px; bottom: 45px; margin: 0; padding: 18px; background: var(--map-yellow); color: var(--ink); font-size: 20px; transform: rotate(-3deg); }
.map-crossing { position: absolute; left: 0; right: 48px; bottom: 0; height: 22px; background: repeating-linear-gradient(125deg, var(--accent) 0 18px, var(--map-yellow) 18px 32px); }

/* Results and replays. */
#summary { position: fixed; z-index: 1000; top: 14px; right: 14px; bottom: 14px; width: 360px; display: flex; flex-direction: column; gap: 16px; --surface-inset: var(--space-panel); }
.sum-top { padding: 0 6px; }
.sum-total { display: flex; align-items: baseline; gap: 8px; margin-top: 8px; }
.sum-total b { font-size: 40px; font-weight: 400; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.sum-total span { color: var(--muted); font-weight: 400; }
.sum-verdict { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.sum-list { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.sum-list button { width: 100%; display: grid; grid-template-columns: var(--badge-summary-size) minmax(0, 1fr) auto; gap: 10px; align-items: center; --control-padding-block: 10px; --control-padding-inline: 8px; background: none; text-align: left; }
.sum-list button:hover { background: #eae3e9; }
.sum-n { --badge-size: var(--badge-summary-size); font-size: 13px; color: #fffefa; background: var(--bad); }
.sum-n.ok { background: var(--ok); }
.sum-name { font-weight: 400; font-size: 14px; line-height: 1.3; }
.sum-sub { font-size: 12px; color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
.sum-pts { font-weight: 400; font-variant-numeric: tabular-nums; font-size: 14px; }
.tag { border-radius: var(--radius-medium); padding: 5px 9px; color: #fffefa; pointer-events: none; font-size: 13px; font-weight: 400; white-space: nowrap; box-shadow: var(--shadow); }
.tag-ok { background: var(--ok); }
.tag-bad { background: var(--bad); }
.tag-hover { background: var(--ink); }
.tag-dist { background: var(--paper); color: var(--ink); font-variant-numeric: tabular-nums; }
.tag .num { --badge-size: var(--badge-marker-size); margin: 0 6px 0 -3px; background: var(--paper); color: var(--ok); font-size: 11px; }
.tag-bad .num { color: var(--bad); }
#hover-tip { position: fixed; z-index: 900; left: 0; top: 0; will-change: transform; }

/* Account, location and multiplayer dialogs reuse the same surfaces. */
.account-actions { margin-top: var(--space-control); }
#account-dialog { border: 0; color: var(--ink); max-height: calc(100% - var(--space-dialog)); overflow-y: auto; }
#account-dialog::backdrop, .location-dialog::backdrop { background: rgb(36 33 36 / 40%); }
.account-fields { display: contents; }
.account-form { display: flex; flex-direction: column; gap: var(--space-control); }
.account-form h2 { margin: 0; font-size: 25px; }
.account-form label { font-weight: 400; font-size: 13px; }
.account-form small { color: var(--muted); font-size: 12px; }
.account-input { width: 100%; min-width: 0; font: inherit; color: var(--ink); background: #fffefa; border: var(--border-choice) solid #a79ba3; cursor: text; }
select.account-input { cursor: pointer; }
.account-form .meta { margin: 0; color: var(--bad); }
.competition-card { display: flex; flex-direction: column; gap: var(--space-control); max-height: calc(100dvh - var(--space-dialog)); }
.competition-card h2, .competition-card .meta { margin: 0; }
.competition-card .sum-list { flex: 1 1 auto; }
.competition-card .sum-list button { display: block; }
.competition-card .sum-list li { padding: var(--space-control); border-bottom: var(--border-choice) solid var(--line); }
.location-dialog { width: min(var(--location-dialog-width), calc(100% - var(--location-viewport-inset))); max-height: calc(100dvh - var(--location-viewport-inset)); overflow: auto; border: 0; }
.location-dialog h2 { font-size: 25px; }
.location-dialog select { width: 100%; min-width: 0; }
#location-status:empty { display: none; }
#mp-invite { display: grid; gap: 10px; margin-block: 12px; }
#mp-link { width: 100%; min-width: 0; }
.mp-legend { font-size: 12px; line-height: 1.5; }
.mp-mine { color: var(--ok); }
.mp-theirs { color: var(--accent); }
#mp-status { margin: 0 0 8px; }
#mp-list button { width: 100%; text-align: left; overflow-wrap: anywhere; }
#mp-forfeit { float: right; font-size: 12px; padding: 6px 8px; }
.mp-actions { flex-wrap: wrap; }

@media (max-width: 1000px) and (min-width: 761px) {
  .menu-header { align-items: start; gap: 16px; padding: 20px; }
  .location-heading { gap: 12px; }
  .location-switch { max-width: 75px; }
  .menu-navigation { max-width: 210px; }
  .menu-card { --surface-inset: 26px; }
}
@media (max-width: 760px) {
  :root { --control-radius: var(--radius-control-compact); --space-control: var(--space-control-compact); --control-padding-block: 11px; --control-padding-inline: 14px; }
  #menu { padding: 0; display: block; }
  .menu-shell { border: 0; min-height: 100%; }
  .menu-header { padding: 16px 20px; display: block; }
  .location-heading { justify-content: space-between; gap: 14px; }
  .location-heading .plate-title { --plate-padding: 12px; }
  .location-heading .plate-name { font-size: clamp(18px, 5vw, 22px); }
  .location-switch { max-width: 85px; text-align: right; font-size: 11px; }
  .menu-navigation { margin-top: 14px; justify-content: flex-start; flex-wrap: wrap; gap: 4px; }
  .menu-navigation .control { padding: 8px 10px; min-height: 40px; }
  .menu-navigation .control:first-child { padding-left: 0; }
  .menu-body { grid-template-columns: 1fr; }
  .menu-map { grid-row: 1; min-height: 180px; border-left: 0; border-bottom: 1px solid var(--ink); }
  .map-place { top: 20px; left: 22px; font-size: 28px; right: 45px; }
  #menu-map-zone { font-size: 16px; }
  .map-directions { width: 30px; font-size: 27px; }
  .map-directions span:nth-child(n+4) { display: none; }
  .map-note { font-size: 15px; bottom: 27px; left: auto; right: 45px; padding: 10px 14px; transform: none; }
  .map-crossing { right: 30px; height: 12px; }
  .menu-card { --surface-inset: 24px; }
  .setup-plate { --plate-padding: 12px; margin-bottom: 18px; }
  .setup-plate .plate-name { font-size: 24px; }
  .lede { font-size: 13px; margin-bottom: 22px; }
  .choice { margin-bottom: 22px; }
  .choice label > span { padding: 11px 9px; }
  .choice b { font-size: 13px; }
  .choice small { font-size: 11px; }
  #hud { grid-template-columns: auto 1fr; top: 10px; left: 10px; right: 10px; gap: 8px; }
  #plate { grid-column: 1 / -1; grid-row: 2; justify-self: center; --plate-padding: var(--space-control); }
  #stats { grid-column: 2; }
  .chip { --control-padding-block: 9px; --control-padding-inline: 13px; font-size: 13px; }
  #dock { bottom: max(12px, env(safe-area-inset-bottom)); }
  .dock-row { flex-wrap: wrap; }
  .dock-row > .actions { flex: 1 1 100%; }
  .dock-row > .actions > .btn { flex: 1; }
  .tip-text { font-size: 13px; }
  #summary { top: auto; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); width: auto; max-height: 58dvh; }
  .sum-total b { font-size: 34px; }
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl-group { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
