/* Bundled fonts (SIL Open Font License, see assets/fonts/OFL.txt): Fraunces for
   titles (soft, rounded serif), Nunito for everything else (rounded sans). */
@font-face { font-family: 'Fraunces'; src: url('../../assets/fonts/fraunces.woff2') format('woff2'); font-weight: 500 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'Nunito'; src: url('../../assets/fonts/nunito.woff2') format('woff2'); font-weight: 500 900; font-style: normal; font-display: swap; }

:root {
  --sky: #cfe8f3;
  --fog: #d9ecf2;
  --ink: #26353a;
  --ink-soft: #5b6b70;
  --paper: rgba(255, 251, 243, 0.94);
  --paper-solid: #fffbf3;
  --line: rgba(38, 53, 58, 0.12);
  --teal: #23a597;
  --teal-dark: #17857a;
  --coral: #ef6a59;
  --amber: #f2b134;
  --good: #3fb86a;
  --bad: #e2453c;
  --shadow: 0 6px 22px rgba(30, 45, 50, 0.16), 0 1px 3px rgba(30, 45, 50, 0.12);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: 'Nunito', ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  --font-title: 'Fraunces', 'Iowan Old Style', Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  font-family: var(--font); color: var(--ink);
  background: radial-gradient(120% 90% at 50% 0%, #fdf6e9 0%, var(--sky) 55%, color-mix(in srgb, var(--sky) 70%, #9fc6d6) 100%);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#view[data-tool="hand"] { cursor: grab; }
#view[data-tool="road"], #view[data-tool="roundabout"] { cursor: crosshair; }
#view[data-tool="bulldoze"] { cursor: not-allowed; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
body.title #labels { display: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
svg { width: 22px; height: 22px; display: block; }

/* ---------- boot ---------- */
.boot { position: fixed; inset: 0; display: grid; place-content: center; gap: 18px; justify-items: center; background: inherit; z-index: 50; transition: opacity .5s; }
.boot.done { opacity: 0; pointer-events: none; }
.boot-logo { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 12px; }
.boot-bar { width: 160px; height: 6px; border-radius: 6px; background: rgba(0,0,0,.08); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 40%; background: var(--teal); border-radius: 6px; animation: boot 1.1s ease-in-out infinite; }
@keyframes boot { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
.road-mark { width: 34px; height: 34px; border-radius: 10px; background: #5b5e63; position: relative; box-shadow: inset 0 0 0 3px #fff3; }
.road-mark::after { content: ''; position: absolute; left: 50%; top: 5px; bottom: 5px; width: 4px; margin-left: -2px; background: repeating-linear-gradient(#f3efe4 0 5px, transparent 5px 9px); }

/* ---------- labels in world ---------- */
.plabel { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 5px; padding: 4px 9px 4px 6px; border-radius: 999px; background: var(--paper); box-shadow: var(--shadow); font-size: 12.5px; font-weight: 700; white-space: nowrap; will-change: transform; }
.plabel .dot { width: 11px; height: 11px; border-radius: 50%; box-shadow: inset 0 0 0 2px #fff8; }
/* the thin line from a place's tag to where its road leaves the map, and a small pin on that point */
.pleader { position: absolute; left: 0; top: 0; height: 1.5px; background: var(--paper); box-shadow: 0 0 2px #0005; transform-origin: 0 50%; pointer-events: none; will-change: transform; }
.ppin { position: absolute; left: 0; top: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--c, #fff); box-shadow: 0 0 0 2px var(--paper), 0 1px 3px #0006; pointer-events: none; will-change: transform; }
.plabel .q:empty { display: none; }
.plabel .q { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; display: grid; place-items: center; }
.plabel.compact .nm { display: none; }
.plabel.compact { padding: 4px; }
.plabel.warn { animation: bob 1.2s ease-in-out infinite; }
.problem { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 4px; padding: 3px 8px 3px 4px; border-radius: 999px; background: var(--amber); color: #3b2a05; font-size: 12px; font-weight: 800; box-shadow: var(--shadow); animation: bob 1.4s ease-in-out infinite; }
.problem b { width: 17px; height: 17px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 12px; }
.problem.severe { background: var(--bad); color: #fff; }
.problem.severe b { color: var(--bad); }
@keyframes bob { 50% { margin-top: -4px; } }

/* ---------- generic ---------- */
.panel { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border: 0; border-radius: 14px; background: var(--paper-solid); box-shadow: 0 1px 0 rgba(0,0,0,.06), inset 0 0 0 1.5px var(--line); font-weight: 700; font-size: 15px; cursor: pointer; transition: transform .12s, background .2s, box-shadow .2s; }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--teal); color: #fff; box-shadow: 0 3px 0 var(--teal-dark); }
.btn.primary:active { box-shadow: 0 1px 0 var(--teal-dark); transform: translateY(2px); }
.btn.coral { background: var(--coral); color: #fff; box-shadow: 0 3px 0 #c9503f; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 13.5px; border-radius: 12px; }
.icon-btn { width: 48px; height: 48px; padding: 0; border-radius: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px; border-radius: 12px; border: 0; background: transparent; font-weight: 700; font-size: 13px; cursor: pointer; white-space: nowrap; color: var(--ink); }
.chip.on { background: var(--ink); color: #fff; }
.chip svg { width: 20px; height: 20px; }
.chip .cost { font-weight: 600; opacity: .6; font-size: 11.5px; }
.muted { color: var(--ink-soft); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar { position: absolute; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); display: flex; gap: 8px; align-items: stretch; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.topbar .title { flex: 1; min-width: 0; padding: 7px 14px; display: flex; flex-direction: column; justify-content: center; }
.topbar .title .nm { font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title .sub { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: flex; flex-direction: column; justify-content: center; align-items: flex-end; padding: 6px 12px; min-width: 74px; }
.pill .k { font-size: 10.5px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.pill .v { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pill .v.bad { color: var(--bad); }
.pill.score .v { color: var(--teal-dark); }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--teal); width: 0; transition: width .3s linear; }
.banner { position: absolute; top: calc(70px + var(--safe-t)); left: 50%; transform: translateX(-50%); padding: 8px 14px; font-size: 13px; font-weight: 700; display: flex; gap: 8px; align-items: center; white-space: nowrap; max-width: calc(100% - 20px); }
.banner.warn { background: #fff1d6; color: #7a4d00; }
.banner.test { background: var(--ink); color: #fff; }
.banner svg { width: 18px; height: 18px; }

/* ---------- bottom dock ---------- */
.bottom { position: absolute; left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; align-items: stretch; }
.bottom > * { pointer-events: auto; }
.options { display: flex; flex-direction: column; gap: 2px; padding: 5px; align-self: flex-start; max-width: 100%; }
.optrow { display: flex; gap: 4px; align-items: center; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.optrow::-webkit-scrollbar { display: none; }
.optrow.lanes-row { flex-wrap: wrap; row-gap: 4px; }
.costtag { display: inline-flex; flex-direction: column; align-items: flex-start; justify-content: center; padding: 0 10px; height: 44px; border-radius: 12px; background: var(--amber); color: #3b2a05; font-weight: 800; font-size: 14px; line-height: 1.1; flex: none; font-variant-numeric: tabular-nums; }
.costtag small { font-size: 10px; font-weight: 700; opacity: .75; text-transform: uppercase; letter-spacing: .04em; }
.options .chip.level.on.tunnel { background: #6b5b4b; color: #fff; }
.optrow.levelseg { display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); gap: 3px; padding: 3px; border-radius: 13px; background: rgba(38,53,58,.07); width: 100%; }
.levelseg .lvbtn { display: flex; align-items: center; justify-content: center; gap: 5px; height: 36px; min-width: 0; border: 0; border-radius: 10px; background: transparent; color: var(--ink-soft); font: inherit; font-size: 12.5px; font-weight: 800; cursor: pointer; transition: background .2s, color .2s, box-shadow .2s; }
.levelseg .lvbtn svg { width: 18px; height: 18px; flex: none; }
.levelseg .lvbtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.levelseg .lvbtn.on { color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.18), var(--shadow); }
.levelseg .lvbtn.ground.on { background: var(--ink); }
.levelseg .lvbtn.bridge.on, .levelseg .lvbtn.high.on { background: #4a78c9; }
.levelseg .lvbtn.tunnel.on { background: #7a5f45; }
.options .chip { flex: none; }
.options .chip.level { background: rgba(38,53,58,.07); }
.options .chip.level.on { background: var(--ink); color: #fff; }
.options .chip.icononly { padding: 0 9px; }
.optrow { flex-wrap: wrap; row-gap: 4px; }
.wchip { position: absolute; left: 0; top: 0; pointer-events: auto; zoom: var(--fs, 1); }
#labels .wchip { pointer-events: auto; }
.wchip.jsign { width: 40px; height: 40px; border-radius: 50%; background: var(--paper-solid); box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; }
.wchip.jsign:active { transform: scale(.92); }
.wchip.jsign svg { width: 28px; height: 28px; }
.wchip.jsign.main { box-shadow: 0 0 0 3px var(--amber), var(--shadow); }
.wchip.jsign.signal svg { color: var(--ink); }
.wchip.jlane { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: rgba(38,53,58,.78); box-shadow: var(--shadow); }
.wchip.jlane button { width: 28px; height: 28px; border: 0; border-radius: 7px; background: transparent; color: rgba(255,255,255,.45); display: grid; place-items: center; cursor: pointer; padding: 0; }
.wchip.jlane button.on { background: #fff; color: var(--ink); }
.wchip.jlane svg { width: 18px; height: 18px; }
.wchip.jadd { display: flex; align-items: center; gap: 4px; height: 30px; padding: 0 10px 0 6px; border-radius: 999px; background: var(--teal); color: #fff; font-size: 12px; font-weight: 800; box-shadow: var(--shadow); cursor: pointer; white-space: nowrap; }
.wchip.jadd svg { width: 16px; height: 16px; }
/* testing: the tools fold away and the test button grows into a wide Stop bar with the run's progress */
body.testing .sheet { display: none !important; }
.bottom .dock .tool { transition: max-width .42s cubic-bezier(.2,.8,.2,1), opacity .22s, padding .42s, margin .42s, flex-grow .42s; max-width: 120px; overflow: hidden; }
body.testing .bottom .dock .tool { max-width: 0; flex-grow: 0; opacity: 0; padding-left: 0; padding-right: 0; margin: 0; pointer-events: none; }
.bottom .options { transition: opacity .25s, transform .35s cubic-bezier(.2,.8,.2,1), visibility 0s linear 0s; }
body.testing .bottom .options { opacity: 0; transform: translateY(14px) scale(.98); visibility: hidden; pointer-events: none; transition: opacity .2s, transform .3s, visibility 0s linear .3s; }
.bottom .dock .testbtn { position: relative; overflow: hidden; justify-content: center; transition: flex-grow .42s cubic-bezier(.2,.8,.2,1), background .35s, box-shadow .35s, margin .42s; }
.bottom .dock .testbtn svg, .bottom .dock .testbtn span { position: relative; z-index: 1; }
.testbtn .tprog { position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--p, 0) * 100%); background: rgba(255,255,255,.12); transition: width .3s linear; z-index: 0; }
body.testing .bottom .dock .testbtn { flex: 1 1 auto; margin-left: 0; font-size: 16px; }
.pchoose { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 800; font-size: 13px; }
.pview.choosing .pframe { border-style: dashed; box-shadow: 0 0 0 999px rgba(30,45,50,.12); }
.reportways { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.reportways .btn { justify-content: center; }
.reportpic { width: 100%; border-radius: 12px; aspect-ratio: 1; max-height: 46vh; object-fit: contain; background: #dfe6d5; }
.reportnote { width: 100%; min-height: 80px; border-radius: 12px; border: 1.5px solid var(--line); padding: 10px; font: inherit; font-weight: 600; resize: vertical; user-select: text; -webkit-user-select: text; }
body.night .plabel { background: rgba(36,44,66,.92); color: #eef1f8; }
body.night .title-screen .logo h1, body.night .title-screen .logo p { color: #f4efe2; text-shadow: 0 2px 12px rgba(0,0,0,.5); }
.wchip.jdot { width: 30px; height: 30px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); display: grid; place-items: center; cursor: grab; touch-action: none; }
.wchip.jdot i { width: 16px; height: 16px; border-radius: 50%; display: block; }
.wchip.jtarget { width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 900; box-shadow: 0 0 0 4px rgba(255,255,255,.7), var(--shadow); }
.wchip.lhandle { width: 38px; height: 38px; border-radius: 50%; background: var(--amber); color: #3b2a05; display: grid; place-items: center; box-shadow: 0 0 0 3px #fff, var(--shadow); cursor: ew-resize; touch-action: none; }
.wchip.lhandle svg { width: 20px; height: 20px; }
.wchip.lside { width: 44px; height: 44px; border-radius: 14px; border: 3px dashed rgba(255,255,255,.95); background: rgba(35,165,151,.25); color: #fff; display: grid; place-items: center; cursor: pointer; transition: background .18s; }
.wchip.lside svg { width: 22px; height: 22px; opacity: .8; }
.wchip.lside.on { background: var(--teal, #23a597); border-style: solid; transform: scale(1.08); box-shadow: var(--shadow); }
.wchip.lside.on svg { opacity: 1; }
.wchip.jadd.ok { background: var(--ink); }
.wchip.jadd.cancel { background: var(--paper-solid); color: var(--ink); }
.house-warn { position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--bad); color: #fff; display: grid; place-items: center; box-shadow: var(--shadow); animation: bob 1.4s ease-in-out infinite; zoom: var(--fs, 1); }
.house-warn svg { width: 15px; height: 15px; }
.options .chip.level.on.bridge { background: var(--amber); color: #3b2a05; }
.options::-webkit-scrollbar { display: none; }
.options .sep { width: 1px; background: var(--line); margin: 6px 3px; flex: none; }
.dockrow { display: flex; gap: 8px; align-items: flex-end; }
.dock { display: flex; gap: 2px; padding: 5px; flex: 1; min-width: 0; justify-content: space-between; }
.tool { flex: 1; min-width: 44px; max-width: 74px; height: 56px; border: 0; border-radius: 14px; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 10.5px; font-weight: 700; cursor: pointer; color: var(--ink); transition: background .15s, transform .1s; }
.tool:active { transform: scale(.94); }
.tool.on { background: var(--ink); color: #fff; }
.tool[disabled] { opacity: .35; }
.tool .lbl { line-height: 1; }
.sim { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.simrow { display: flex; gap: 4px; padding: 5px; }
.simrow .tool { min-width: 40px; height: 44px; flex: none; width: 42px; }
.speed { font-weight: 800; font-size: 13px; }
.testbtn { height: 56px; padding: 0 16px; border: 0; border-radius: 16px; background: var(--coral); color: #fff; font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 8px; cursor: pointer; box-shadow: 0 3px 0 #c9503f, var(--shadow); white-space: nowrap; }
.testbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #c9503f; }
.testbtn.running { background: var(--ink); box-shadow: 0 3px 0 #111, var(--shadow); }
body.lefty .dockrow { flex-direction: row-reverse; }
body.lefty .options { align-self: flex-end; }

/* ---------- inspector sheet ---------- */
.sheet { position: absolute; left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); bottom: calc(84px + var(--safe-b)); padding: 14px; display: flex; flex-direction: column; gap: 10px; max-width: 460px; margin: 0 auto; animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }
.sheet h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.sheet .row { display: flex; gap: 6px; flex-wrap: wrap; }
.sheet .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat { background: rgba(38,53,58,.05); border-radius: 12px; padding: 8px 10px; }
.stat .k { font-size: 10.5px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sheet .close { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; min-height: 0; }
.seg-choice { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.seg-choice .chip { height: 44px; justify-content: flex-start; background: rgba(38,53,58,.05); }
.seg-choice .chip.on { background: var(--ink); }

/* ---------- tooltip + toast + hints ---------- */
.tooltip { position: fixed; left: 0; top: 0; padding: 6px 10px; border-radius: 10px; font-size: 13px; font-weight: 800; pointer-events: none !important; white-space: pre-line; max-width: min(320px, 86vw); text-align: center; line-height: 1.3; background: var(--ink); color: #fff; box-shadow: var(--shadow); transform: translate(-50%, calc(-100% - 46px)); z-index: 5; }
.tooltip.bad { background: var(--bad); }
.toasts { position: absolute; top: calc(118px + var(--safe-t)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none !important; }
.toast { padding: 9px 14px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 700; font-size: 13.5px; box-shadow: var(--shadow); animation: rise .2s ease-out; max-width: calc(100vw - 32px); text-align: center; }
.toast.bad { background: var(--bad); }
.redochip { pointer-events: auto !important; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px 0 9px; border: 0; border-radius: 999px; background: color-mix(in srgb, var(--paper) 88%, transparent); color: var(--ink); opacity: .82; font: inherit; font-size: 12.5px; font-weight: 700; box-shadow: var(--shadow); cursor: pointer; animation: rise .2s ease-out; }
.redochip .ico { display: inline-flex; width: 15px; height: 15px; transform: scaleX(-1); }
.redochip .ico svg { width: 100%; height: 100%; }
.redochip:active { transform: scale(.96); }
.toast.good { background: var(--teal); }
.hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(190px + var(--safe-b)); width: min(420px, calc(100% - 24px)); padding: 12px 14px 12px 14px; display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 600; line-height: 1.35; animation: rise .3s ease-out; }
.hint .ico { flex: none; width: 30px; height: 30px; border-radius: 10px; background: var(--amber); display: grid; place-items: center; color: #3b2a05; }
.hint .ico svg { width: 18px; height: 18px; }
.hint .count { font-size: 11px; color: var(--ink-soft); font-weight: 700; margin-top: 4px; }

/* ---------- modal / screens ---------- */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); }
.screen.dim { background: rgba(28, 40, 44, 0.32); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(440px, 100%); max-height: 100%; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; animation: pop .28s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
/* exits: what the UI takes away fades and settles out (see ui/anim.js) */
@keyframes fadeout { to { opacity: 0; } }
@keyframes popout { to { transform: scale(.96) translateY(6px); opacity: 0; } }
@keyframes swapin { from { opacity: 0; transform: translateX(8px); } }
.leaving { animation: fadeout .2s ease-in forwards !important; pointer-events: none !important; }
.screen.leaving > .modal, .screen.leaving > .levels, .screen.leaving > .panel { animation: popout .2s ease-in forwards !important; }
.swapin { animation: swapin .22s cubic-bezier(.2,.9,.3,1); }
@keyframes sheetout { to { transform: translateY(14px); opacity: 0; } }
.sheet.leaving { animation: sheetout .2s ease-in forwards !important; }
/* anything that appears inside a dialog (search results, a status line, a step's controls) fades in */
.modal > *, .modal .presults > *, .modal .psaved > *, .modal .pstatus > *, .modal .lb > *, .sheet > * { transition: opacity .24s ease, transform .24s ease; }
@starting-style {
  .modal > *, .modal .presults > *, .modal .psaved > *, .modal .pstatus > *, .modal .lb > *, .sheet > * { opacity: 0; transform: translateY(4px); }
}
.folding, .modal .folding, .modal .psaved > .folding, .modal > .folding { transition: height .28s cubic-bezier(.4,0,.2,1), opacity .2s ease, margin .28s ease, padding .28s ease !important; opacity: 0 !important; transform: none !important; min-height: 0 !important; margin-top: 0 !important; margin-bottom: 0 !important; padding-top: 0 !important; padding-bottom: 0 !important; }
@media (prefers-reduced-motion: reduce) { .leaving, .screen.leaving > .modal, .swapin, .sheet.leaving { animation: none !important; } .folding, .modal > *, .modal .presults > *, .modal .psaved > *, .sheet > * { transition: none !important; } }
.modal h2 { margin: 0; font-size: 24px; letter-spacing: -0.01em; }
.modal p { margin: 0; line-height: 1.45; color: var(--ink-soft); font-weight: 600; }
.modal .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.modal .actions .btn { flex: 1; }
.stars { display: flex; gap: 6px; justify-content: center; }
.stars svg { width: 46px; height: 46px; color: #e5ddcd; transition: color .3s, transform .3s; }
.stars svg.on { color: var(--amber); animation: starpop .5s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes starpop { from { transform: scale(0) rotate(-40deg); } }
.big-score { text-align: center; font-size: 54px; font-weight: 900; line-height: 1; letter-spacing: -0.03em; color: var(--teal-dark); }
.big-score small { display: block; font-size: 12px; font-weight: 800; color: var(--ink-soft); letter-spacing: .08em; text-transform: uppercase; margin-top: 4px; }
.meter { display: grid; grid-template-columns: 96px 1fr 44px; gap: 8px; align-items: center; font-size: 13px; font-weight: 700; }
.meter .bar { height: 10px; border-radius: 6px; background: rgba(38,53,58,.08); overflow: hidden; }
.meter .bar i { display: block; height: 100%; background: var(--teal); border-radius: 6px; transition: width .8s cubic-bezier(.2,.8,.2,1); }
.meter .num { text-align: right; font-variant-numeric: tabular-nums; }
.thresholds { display: flex; gap: 8px; justify-content: center; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.thresholds span { display: flex; align-items: center; gap: 3px; }
.thresholds svg { width: 15px; height: 15px; color: var(--amber); }
.tips { margin: 0; padding-left: 18px; color: var(--ink-soft); font-weight: 600; line-height: 1.45; font-size: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 700; padding: 4px 9px; border-radius: 999px; background: rgba(38,53,58,.06); }
.legend i { width: 10px; height: 10px; border-radius: 50%; }

/* ---------- title ---------- */
.title-screen { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: calc(28px + var(--safe-t)) 16px calc(22px + var(--safe-b)); pointer-events: none; }
.title-screen > * { pointer-events: auto; }
.logo { text-align: center; }
.logo h1 { margin: 0; font-size: clamp(44px, 12vw, 72px); font-weight: 900; letter-spacing: -0.04em; color: var(--ink); text-shadow: 0 2px 0 #fff8, 0 10px 30px rgba(255,255,255,.7); display: flex; gap: 12px; align-items: center; justify-content: center; }
.logo h1 .road-mark { width: clamp(40px, 10vw, 58px); height: clamp(40px, 10vw, 58px); border-radius: 14px; }
.logo p { margin: 6px 0 0; font-weight: 700; color: var(--ink-soft); text-shadow: 0 1px 8px #fff; }
.menu { width: min(400px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.menu .btn { min-height: 58px; justify-content: flex-start; padding: 0 16px; font-size: 17px; }
.menu .btn .meta { margin-left: auto; font-size: 12.5px; opacity: .75; font-weight: 700; text-align: right; }
.menu .btn svg { width: 24px; height: 24px; }
.menu .minor { display: flex; gap: 8px; }
.menu .minor .btn { flex: 1; min-height: 46px; font-size: 14px; justify-content: center; }

.levels { width: min(760px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.levels header { display: flex; align-items: center; gap: 10px; }
.levels header h2 { margin: 0; font-size: 22px; flex: 1; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; overflow-y: auto; padding: 2px; }
.lvl { position: relative; border: 0; border-radius: 16px; padding: 12px; text-align: left; background: var(--paper-solid); box-shadow: inset 0 0 0 1.5px var(--line); cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-height: 112px; overflow: hidden; }
.lvl:active { transform: scale(.97); }
.lvl .swatch { position: absolute; inset: 0 0 auto 0; height: 46px; opacity: .9; }
.lvl .num { position: relative; width: 30px; height: 30px; border-radius: 10px; background: #fff; display: grid; place-items: center; font-weight: 900; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.lvl .nm { position: relative; margin-top: 10px; font-weight: 800; font-size: 15px; }
.lvl .st { display: flex; gap: 2px; }
.lvl .st svg { width: 16px; height: 16px; color: #e0d7c6; }
.lvl .st svg.on { color: var(--amber); }
.lvl.locked { opacity: .55; cursor: default; }
.lvl.locked .lockico { position: absolute; right: 10px; top: 10px; }
.lvl .unlock { font-size: 11.5px; font-weight: 700; color: var(--ink-soft); }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 700; }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: rgba(38,53,58,.07); }
.seg button { border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; font-weight: 700; font-size: 13px; cursor: pointer; }
.seg button.on { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12); }

.sparkline { width: 100%; height: 44px; }

/* ---------- landscape ---------- */
@media (orientation: landscape) and (min-width: 720px) {
  .bottom { left: auto; right: calc(10px + var(--safe-r)); top: calc(76px + var(--safe-t)); bottom: calc(10px + var(--safe-b)); width: auto; flex-direction: row-reverse; align-items: flex-end; }
  .dockrow { flex-direction: column-reverse; align-items: stretch; height: 100%; justify-content: space-between; }
  .dock { flex-direction: column; flex: none; }
  .tool { width: 64px; max-width: none; flex: none; }
  .options { flex-direction: column; align-self: flex-end; max-height: 100%; overflow-y: auto; overflow-x: hidden; }
  .options .sep { width: auto; height: 1px; margin: 3px 6px; }
  .options .chip { justify-content: flex-start; }
  .sim { align-items: stretch; }
  .simrow { flex-direction: row; }
  .sheet { left: calc(10px + var(--safe-l)); right: auto; width: 380px; bottom: calc(10px + var(--safe-b)); margin: 0; }
  .hint { bottom: calc(16px + var(--safe-b)); left: calc(16px + var(--safe-l)); transform: none; }
  .title-screen { flex-direction: row; align-items: center; justify-content: space-around; }
  body.lefty .bottom { right: auto; left: calc(10px + var(--safe-l)); flex-direction: row; }
  body.lefty .sheet { left: auto; right: calc(10px + var(--safe-r)); }
}
@media (max-width: 430px) and (orientation: portrait) {
  .tool { min-width: 38px; }
  .simrow .tool { width: 38px; min-width: 38px; }
  .simrow { gap: 2px; }
  .testbtn { padding: 0 12px; }
  .dockrow { gap: 6px; }
}
@media (max-width: 380px) {
  .tool .lbl { display: none; }
  .tool { height: 50px; }
  .testbtn { height: 50px; padding: 0 12px; }
  .pill { min-width: 60px; padding: 6px 9px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- v2 controls ---------- */
.options { flex-direction: column; gap: 2px; }
.optrow { display: flex; gap: 4px; align-items: center; overflow-x: auto; scrollbar-width: none; }
.optrow::-webkit-scrollbar { display: none; }
.optrow .chip { flex: none; }
.optrow .sep { width: 1px; align-self: stretch; background: var(--line); margin: 6px 2px; flex: none; }
.chip.cost { opacity: .65; font-size: 12px; pointer-events: none; }
.stepper { display: inline-flex; align-items: center; gap: 2px; padding: 0 4px; background: rgba(38,53,58,.07); border-radius: 12px; height: 40px; font-weight: 800; font-size: 13px; }
.stepper button { width: 30px; height: 32px; border: 0; border-radius: 9px; background: #fff; font-weight: 900; font-size: 18px; line-height: 1; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.stepper span { min-width: 38px; text-align: center; white-space: nowrap; }
.stepper button:disabled, .sbsetup button:disabled { opacity: .4; cursor: default; }
.testrow { display: flex; gap: 6px; align-items: stretch; }
.ffbtn { height: 56px; min-width: 64px; border: 0; border-radius: 16px; background: var(--amber); color: #3b2a05; font-weight: 900; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 4px; cursor: pointer; box-shadow: 0 3px 0 #c98a17, var(--shadow); }
.ffbtn.on { background: #ffcf5a; }
.ffbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #c98a17; }
.lanes-row { align-items: center; }
.lanes-row .lbl { font-weight: 800; font-size: 13px; color: var(--ink-soft); }
.sheet { max-height: calc(100vh - 220px); overflow-y: auto; }
.sheet .tabs { align-self: flex-start; }
.jrow { display: flex; gap: 10px; align-items: flex-start; }
.schematic { width: 140px; height: 140px; flex: none; }
.jside { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.hint-mini { display: flex; gap: 6px; align-items: center; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.hint-mini svg { width: 16px; height: 16px; color: var(--amber); flex: none; }
.lanes { display: flex; gap: 6px; }
.lanecol { display: flex; flex-direction: column; gap: 4px; align-items: center; background: #5b5e63; padding: 6px 4px; border-radius: 10px; }
.lanehead { color: #fff; font-size: 11px; font-weight: 800; opacity: .8; }
.lanebtn { width: 40px; height: 36px; border: 0; border-radius: 8px; background: rgba(255,255,255,.14); color: rgba(255,255,255,.45); display: flex; align-items: center; justify-content: center; gap: 1px; cursor: pointer; }
.lanebtn svg { width: 18px; height: 18px; }
.lanebtn b { font-size: 10px; }
.lanebtn.on { background: #fff; color: var(--ink); }
.phases { gap: 6px; }
.phase { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; background: rgba(38,53,58,.05); border-radius: 12px; padding: 5px; }
.phn { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.phap { display: flex; gap: 3px; }
.apchip { min-width: 30px; height: 30px; border: 0; border-radius: 8px; background: #fff; font-weight: 800; cursor: pointer; box-shadow: inset 0 0 0 1.5px var(--line); display: grid; place-items: center; }
.apchip svg { width: 16px; height: 16px; }
.apchip.on { background: var(--good); color: #fff; box-shadow: none; }
.apchip.del { background: transparent; box-shadow: none; opacity: .5; }
.phase .stepper { height: 30px; }
.phase .stepper button { width: 24px; height: 24px; font-size: 15px; }
.routes .rlist { display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow-y: auto; }
.rgroup { background: rgba(38,53,58,.05); border-radius: 14px; padding: 8px 10px; cursor: pointer; }
.rgroup.focus { box-shadow: inset 0 0 0 2px var(--teal); }
.rfrom { display: flex; gap: 6px; align-items: center; font-weight: 800; margin-bottom: 4px; }
.rfrom i, .rrow i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; flex: none; }
.rrow { display: flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 700; padding: 2px 0 2px 6px; }
.rrow .nm { flex: 1; }
.rrow .rate { color: var(--ink-soft); font-size: 12px; }
.rrow .st { width: 16px; font-weight: 900; }
.rrow.ok .st { color: var(--good); }
.rrow.bad { color: var(--bad); }
.banner { cursor: pointer; }
.logo-icon { width: clamp(46px, 11vw, 64px); height: clamp(46px, 11vw, 64px); border-radius: 16px; box-shadow: 0 6px 18px rgba(30,45,50,.2); }
@media (orientation: landscape) and (min-width: 720px) {
  .optrow { flex-direction: column; align-items: stretch; }
  .optrow .sep { width: auto; height: 1px; margin: 3px 6px; }
  .testrow { flex-direction: column; }
}

/* ---------- tutorial coach ---------- */
.coach { position: absolute; inset: 0; pointer-events: none !important; z-index: 6; }
.coach.idle .hand, .coach.idle .spot { display: none !important; }
.coach .trail { position: absolute; inset: 0; width: 100%; height: 100%; }
.coach .trail path { fill: none; stroke: #ffd84a; stroke-width: 6; stroke-linecap: round; stroke-dasharray: 2 12; filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); }
.coach .hand { position: absolute; left: 0; top: 0; transition: transform .08s linear; filter: drop-shadow(0 4px 8px rgba(0,0,0,.35)); }
.coach .hand svg { width: 56px; height: 56px; }
.coach .spot { position: absolute; border-radius: 18px; box-shadow: 0 0 0 4px #ffd84a, 0 0 24px 6px rgba(255,216,74,.7); animation: spot 1s ease-in-out infinite; }
@keyframes spot { 50% { box-shadow: 0 0 0 7px #ffd84a, 0 0 34px 10px rgba(255,216,74,.5); } }
.coach .coachbar { position: absolute; top: calc(72px + var(--safe-t)); right: calc(10px + var(--safe-r)); display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; pointer-events: auto; }
.coach .coachbar .clbl { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.coach .coachbar .skip { width: auto !important; padding: 0 10px !important; border-radius: 16px !important; font-size: 12px; font-weight: 800; white-space: nowrap; }
.coach .dots { display: flex; gap: 5px; }
.coach .dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.coach .dots i.on { background: var(--amber); }
.coach .skip { width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(38,53,58,.08); font-weight: 900; cursor: pointer; }
.chapter { grid-column: 1 / -1; font-weight: 900; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin-top: 8px; }

/* ---------- lane cross-section widget ---------- */
.lanew { display: inline-flex; align-items: center; gap: 6px; padding: 4px; border-radius: 14px; background: rgba(38,53,58,.06); user-select: none; flex: none; }
.lanew .road { display: flex; height: 34px; min-width: 20px; background: #5b5e63; border-radius: 4px; overflow: hidden; box-shadow: inset 0 0 0 2px #d8cfbf; padding: 0 2px; }
.lanew .ln { width: 16px; display: grid; place-items: center; border-left: 1px dashed rgba(255,255,255,.55); }
.lanew .ln:first-child, .lanew .mid + .ln { border-left: 0; }
.lanew .ln svg { width: 9px; height: 13px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lanew .mid { width: 8px; position: relative; }
.lanew .mid.two::before, .lanew .mid.two::after { content: ''; position: absolute; top: 3px; bottom: 3px; width: 2px; background: #efc451; }
.lanew .mid.two::before { left: 1px; } .lanew .mid.two::after { right: 1px; }
.lw-step { display: flex; align-items: center; gap: 2px; background: #fff; border-radius: 11px; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.lw-step button { width: 38px; height: 38px; border: 0; background: transparent; font-size: 22px; font-weight: 800; color: var(--ink); cursor: pointer; border-radius: 10px; line-height: 1; }
.lw-step button:active { background: rgba(38,53,58,.1); }
.lw-step button[disabled] { opacity: .25; cursor: default; }
.lw-n { min-width: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 2px; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.lw-n svg { width: 9px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lw-n small { font-size: 10.5px; line-height: 1.05; text-align: center; color: var(--ink-soft); max-width: 46px; white-space: normal; }
.lanew.compact .lw-step button { width: 34px; height: 34px; }
.lanew.compact .road { height: 30px; }

/* ---------- transitions ---------- */
.wipe { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; pointer-events: all;
  background: radial-gradient(120% 90% at 50% 30%, #fdf6e9 0%, var(--sky) 60%, #b9dbe8 100%);
  opacity: 0; transition: opacity .26s ease; }
.wipe img { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 10px 30px rgba(30,45,50,.2); transform: scale(.85); transition: transform .5s cubic-bezier(.2,1.4,.4,1); }
.wipe.in { opacity: 1; }
.wipe.in img { transform: scale(1); }
.wipe.out { opacity: 0; transition: opacity .5s ease; }
.wipe.out img { transform: scale(1.15); }
/* night: the page behind the map and the loading wipe follow the night sky (no pale halo round the edges) */
body.night { background: radial-gradient(120% 90% at 50% 0%, #2b3554 0%, #1b2339 58%, #121827 100%); }
body.night .wipe { background: radial-gradient(120% 90% at 50% 30%, #2e3858 0%, #1c243a 60%, #131a2a 100%); }
body.night .wipe img { box-shadow: 0 10px 34px rgba(0,0,0,.45); }
.title-screen .logo { animation: drop .7s cubic-bezier(.2,1.2,.4,1) both; }
@keyframes drop { from { transform: translateY(-30px); opacity: 0; } }
.menu { animation: rise .45s ease-out both .1s; }
.menu > * { animation: rise .4s ease-out both; }
.menu > *:nth-child(1) { animation-delay: .15s; } .menu > *:nth-child(2) { animation-delay: .22s; }
.menu > *:nth-child(3) { animation-delay: .29s; } .menu > *:nth-child(4) { animation-delay: .36s; }
.levels { animation: rise .35s ease-out both; }
.lvl { animation: cardin .35s ease-out both; animation-delay: calc(var(--i, 0) * 22ms); }
@keyframes cardin { from { transform: translateY(14px) scale(.96); opacity: 0; } }
.topbar { animation: slidedown .45s ease-out both .25s; }
.bottom { animation: rise .45s ease-out both .3s; }
@keyframes slidedown { from { transform: translateY(-20px); opacity: 0; } }
.screen.dim .modal { animation: pop .32s cubic-bezier(.2,1.4,.4,1); }

/* ---------- real places + leaderboard ---------- */
.places h2 { display: flex; align-items: center; gap: 8px; }
.psearch { display: flex; gap: 6px; }
.psearch input, .pname { flex: 1; min-width: 0; height: 44px; border-radius: 12px; border: 1.5px solid var(--line); padding: 0 12px; font: inherit; font-weight: 700; background: #fff; }
.pname { flex: 0 1 170px; height: 38px; }
.presults, .psaved { display: flex; flex-direction: column; gap: 4px; }
.prow { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 10px; border: 0; border-radius: 12px; background: rgba(38,53,58,.05); font: inherit; font-weight: 700; text-align: left; cursor: pointer; }
.prow > span:nth-child(2) { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow.tall { min-height: 56px; padding: 8px 10px 8px 12px; gap: 10px; }
.prow > svg { flex: none; width: 20px; height: 20px; opacity: .75; }
.prow .pinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.prow .prname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.2; }
.prow .prmeta { font-size: .78em; font-weight: 600; opacity: .6; line-height: 1.3; white-space: normal; overflow-wrap: anywhere; }
.prow .pstars { flex: none; color: #e9b12f; letter-spacing: 1px; font-size: .9em; }
.prow .pchip { flex: none; padding: 5px 10px; border-radius: 999px; font-size: .78em; font-weight: 800; background: rgba(38,53,58,.08); color: var(--ink); white-space: nowrap; }
.prow.ready .pchip { background: var(--teal); color: #fff; }
.prow.failed .pchip { background: rgba(239,106,89,.16); color: var(--coral); }
.prow.ready { background: rgba(42,157,143,.10); box-shadow: inset 0 0 0 1px rgba(42,157,143,.35); }
/* the remove button: its own clearly separate 44 px target at the end of the row (a divider, a tinted
   square), so a tap on the place itself never lands on it and a tap meant for it never opens the place */
.prow .del { flex: none; position: relative; display: grid; place-items: center; width: 44px; height: 44px; margin: -4px -6px -4px 8px; border-radius: 12px; background: rgba(214, 69, 65, .09); color: var(--bad); opacity: 1; transition: background .15s ease, transform .15s ease; }
.prow .del::before { content: ''; position: absolute; left: -9px; top: 8px; bottom: 8px; width: 1px; background: currentColor; opacity: .18; }
.prow .del svg { width: 16px; height: 16px; }
.prow .del:active { transform: scale(.92); background: rgba(214, 69, 65, .2); }
body.night .prow .del { background: rgba(255, 120, 110, .12); }
.prow.pask { background: rgba(239,106,89,.12); box-shadow: inset 0 0 0 1px rgba(239,106,89,.35); cursor: default; }
.prow .paskq { flex: 1; min-width: 0; font-size: .9em; }
.prow .pbtn { flex: none; padding: 7px 12px; border-radius: 999px; font-size: .82em; font-weight: 800; cursor: pointer; }
.prow .pbtn.no { background: rgba(38,53,58,.08); }
.prow .pbtn.yes { background: var(--coral); color: #fff; }
body.night .prow .pbtn.no { background: rgba(255,255,255,.1); }
.prow .spin { flex: none; }
.ppending { margin-bottom: 8px; }
body.night .prow { background: rgba(255,255,255,.05); }
body.night .prow .pchip { background: rgba(255,255,255,.1); }
body.night .prow.ready .pchip { background: var(--teal); color: #fff; }
.small-title { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; margin: 6px 0 2px; }
.pbusy { display: flex; gap: 8px; align-items: center; font-weight: 700; color: var(--ink-soft); }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--teal); animation: spin 0.8s linear infinite; will-change: transform; transform: translateZ(0); /* (its own layer: it keeps turning while the page is busy) */ }
@keyframes spin { from { transform: translateZ(0) rotate(0deg); } to { transform: translateZ(0) rotate(360deg); } }
.perr { color: var(--bad); font-weight: 700; }
.attrib { font-size: 11px; color: var(--ink-soft); font-weight: 600; }
.pmap { position: relative; width: 100%; aspect-ratio: 1; border-radius: 16px; overflow: hidden; touch-action: none; }
.pmap canvas { width: 100%; height: 100%; display: block; cursor: grab; }
.pframe { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border: 3px solid var(--coral); border-radius: 6px; box-shadow: 0 0 0 999px rgba(30,45,50,.28); pointer-events: none; }
.lboard { background: rgba(38,53,58,.05); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
.lbh { display: flex; gap: 6px; align-items: center; font-weight: 800; }
.lbh svg { width: 18px; height: 18px; color: var(--amber); }
.lbrow { display: grid; grid-template-columns: 22px 1fr auto 32px; gap: 6px; font-size: 13px; font-weight: 700; }
.lbrow.me { color: var(--teal-dark); }
.lbrow.top { padding: 10px; border: 2px solid var(--amber); border-radius: 12px; background: rgba(255,195,75,.16); font-size: 15px; }
.lbrow.top svg { width: 20px; height: 20px; color: var(--amber); }
.lbrow.top.me { background: var(--teal-dark); color: #fff; box-shadow: 0 4px 16px rgba(30,90,80,.25); }
.lbrow.just-made { animation: record-pop .65s ease-out; }
.big-score.new-best { padding: 14px; border: 2px solid var(--amber); border-radius: 18px; background: rgba(255,195,75,.14); animation: record-pop .65s ease-out; }
.record-badge { display: flex; justify-content: center; align-items: center; gap: 7px; margin-bottom: 10px; font: 800 15px var(--font); letter-spacing: 0; }
.record-badge svg { width: 23px; height: 23px; color: var(--amber); }
@keyframes record-pop { from { transform: scale(.92); } 60% { transform: scale(1.04); } to { transform: scale(1); } }
.lbrow .st { color: var(--amber); }
.lbrow .sc { text-align: right; font-variant-numeric: tabular-nums; }

.pprog { display: flex; flex-direction: column; gap: 6px; }
.pprog .pl { display: flex; justify-content: space-between; font-weight: 800; font-size: 13px; color: var(--ink-soft); }
.pprog .bar { height: 10px; border-radius: 6px; background: rgba(38,53,58,.08); overflow: hidden; }
.pprog .bar i { display: block; height: 100%; background: var(--teal); border-radius: 6px; transition: width .3s ease; }
.places .seg button { padding: 8px 9px; }

/* =================== in-game HUD v3: calm glass layout =================== */
.glass { background: rgba(255, 251, 243, 0.84); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid rgba(255,255,255,.7); box-shadow: 0 8px 28px rgba(30,45,50,.14), 0 1px 2px rgba(30,45,50,.08); }
.topbar.glass { left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); top: calc(8px + var(--safe-t)); height: 54px; padding: 0 4px;
  border-radius: 18px; display: flex; align-items: center; gap: 2px; pointer-events: auto; position: absolute; overflow: hidden; }
.tb-btn { position: relative; width: 44px; height: 44px; flex: none; border: 0; border-radius: 13px; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--ink); }
.tb-btn:active { background: rgba(38,53,58,.08); }
.tb-btn .badge { position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--coral); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.topbar.glass .title { flex: 1; min-width: 0; padding: 0 6px; cursor: pointer; background: none; box-shadow: none; }
.topbar.glass .title .nm { font-size: 14.5px; }
.topbar.glass .title .sub { font-size: 11.5px; }
.tb-stat { display: flex; flex-direction: column; align-items: flex-end; padding: 0 8px; border-left: 1px solid var(--line); }
.tb-stat .k { font-size: 9.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-soft); }
.tb-stat .v { font-size: 15px; font-weight: 900; font-variant-numeric: tabular-nums; }
.tb-stat .v.bad { color: var(--bad); }
.tb-stat.score .v { color: var(--teal-dark); }
button.tb-stat.routes { background: transparent; border-top: 0; border-right: 0; border-bottom: 0; font: inherit; color: var(--ink); cursor: pointer; border-radius: 0 12px 12px 0; padding-right: 10px; }
button.tb-stat.routes:active { background: rgba(38,53,58,.08); }
.tb-stat.routes .v { display: flex; align-items: center; gap: 4px; color: var(--teal-dark); }
.tb-stat.routes .v svg { width: 17px; height: 17px; }
.tb-stat.routes .v.bad { color: var(--coral); }
.tb-stat.routes .badge { font-weight: 900; }
.topbar.glass .progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; }
.fabs { position: absolute; right: calc(12px + var(--safe-r)); bottom: calc(96px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.fabs > * { pointer-events: auto; }
.fab { width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(255,255,255,.7); background: rgba(255, 251, 243, 0.86);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: 0 6px 18px rgba(30,45,50,.16); display: grid; place-items: center;
  font-weight: 900; font-size: 13px; color: var(--ink); cursor: pointer; }
.fab svg { width: 20px; height: 20px; }
.fab:active { transform: scale(.94); }
.fab.on { background: var(--amber); color: #3b2a05; }
.bottom { left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); }
.bottom .dock.glass { display: flex; align-items: center; gap: 2px; padding: 5px; border-radius: 22px; flex: none; }
.bottom .dock .tool { flex: 1; max-width: none; min-width: 0; height: 58px; border-radius: 16px; }
.bottom .dock .tool.on { background: var(--ink); color: #fff; }
.bottom .dock .testbtn { flex: none; height: 58px; padding: 0 18px; margin-left: 4px; border-radius: 17px; box-shadow: 0 2px 0 #c9503f; }
.bottom .options.glass { border-radius: 18px; align-self: stretch; padding: 6px; }
.banner { display: none !important; }
@media (orientation: landscape) and (min-width: 720px) {
  .bottom { top: auto; left: calc(10px + var(--safe-l)); right: auto; width: min(560px, 60vw); flex-direction: column; align-items: stretch; }
  body.lefty .bottom { left: auto; right: calc(10px + var(--safe-r)); flex-direction: column; }
  .bottom .options.glass .optrow { flex-direction: row; }
  .bottom .dock.glass { flex-direction: row; }
  .bottom .options.glass { flex-direction: column; align-self: stretch; }
  .fabs { bottom: calc(14px + var(--safe-b)); }
  .topbar.glass { right: auto; width: min(640px, 70vw); }
}

/* Panels reserve the actual toolbar height, including road options and text scaling. */
@media (orientation: portrait), (min-height: 521px) {
  .sheet { bottom: calc(var(--dock-height, 68px) + 20px + var(--safe-b)); max-height: calc(100% - var(--dock-height, 68px) - 110px - var(--safe-t) - var(--safe-b)); }
}
.logo-trigger { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; letter-spacing: inherit; text-shadow: inherit; cursor: pointer; }
.logo-trigger:focus-visible { outline: 3px solid var(--teal); outline-offset: 8px; border-radius: 16px; }
.logo-party .logo-icon { animation: logo-spin 1s ease-in-out 6; }
.logo-parade { position: absolute; inset: auto 0 12%; height: 36px; overflow: hidden; pointer-events: none; }
.logo-parade i { position: absolute; left: -48px; color: var(--teal-dark); animation: logo-drive 4s linear both; animation-delay: calc(var(--i) * .25s); }
.logo-parade svg { width: 36px; height: 36px; }
@keyframes logo-spin { 50% { transform: rotate(360deg) scale(1.15); } to { transform: rotate(360deg); } }
@keyframes logo-drive { to { left: calc(100% + 48px); } }
@media (max-width: 400px) {
  .bottom .dock .tool .lbl { font-size: 9.5px; }
  .bottom .dock .testbtn { padding: 0 12px; }
  .tb-stat { padding: 0 5px; }
}

.lboard .namerow { display: flex; gap: 8px; margin-top: 6px; }
.lboard .namerow .pname { flex: 1; height: 42px; }
.lboard .namerow .btn { flex: none; height: 42px; }
.lboard .nerr { min-height: 16px; font-size: 12px; }
.lboard .nerr.bad { color: var(--bad); font-weight: 800; }

/* ---------- text size (Settings) ---------- */
#ui { zoom: var(--fs, 1); }
.plabel, .problem, .issue { zoom: var(--fs, 1); }

/* ---------- place signs: colour + shape ---------- */
.plabel svg.dot { width: 14px; height: 14px; flex: none; filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #fff); }
.legend span svg.lg, .rfrom svg.lg, .rrow svg.lg { width: 14px; height: 14px; flex: none; }
.setting span svg, .setting span .ico { width: 18px; height: 18px; vertical-align: -3px; margin-right: 6px; color: var(--ink-soft); }
.setting > span { display: inline-flex; align-items: center; }
.setting select { font: inherit; font-weight: 700; padding: 8px 10px; border-radius: 10px; border: 0; background: rgba(38,53,58,.07); color: var(--ink); }
.seg.wrap { flex-wrap: wrap; justify-content: flex-end; }
.seg .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.settings .setting, .sbsetup .setting { flex-wrap: wrap; row-gap: 6px; }
.muted.small, .small { font-size: 12.5px; }
.kicker { font-weight: 800; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.hintchip { opacity: .75; font-weight: 700; }
.hidden { display: none !important; }

/* ---------- bonus goals ---------- */
.goals, .trouble, .beforeafter { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 14px; background: rgba(38,53,58,.05); }
.gh { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.gh svg { width: 17px; height: 17px; }
.goal { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.goal .ck { width: 20px; height: 20px; border-radius: 6px; flex: none; display: grid; place-items: center; background: #fff; box-shadow: inset 0 0 0 1.5px var(--line); font-size: 13px; font-weight: 900; color: #fff; }
.goal.on .ck { background: var(--good); box-shadow: none; }
.lvl .medals { display: flex; gap: 2px; position: absolute; right: 10px; bottom: 10px; }
.lvl .medals i { width: 17px; height: 17px; color: #e0d7c6; display: grid; }
.lvl .medals i.on { color: var(--amber); }
.lvl .medals svg { width: 17px; height: 17px; }

/* ---------- trouble spots ---------- */
.tspot { display: flex; align-items: center; gap: 10px; text-align: left; border: 0; background: #fff; border-radius: 12px; padding: 8px 10px; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.08); font: inherit; color: inherit; }
.tspot .n, .issue .n { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--bad); color: #fff; font-weight: 900; font-size: 13px; }
.tspot .tx { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.tspot .tx b { font-size: 14px; }
.tspot .tx small { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; line-height: 1.3; }
.tspot .go svg { width: 18px; height: 18px; color: var(--ink-soft); }
.issue { position: absolute; left: 0; top: 0; display: flex; align-items: flex-start; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); font-size: 12.5px; max-width: 220px; cursor: pointer; pointer-events: auto; animation: bob 1.6s ease-in-out infinite; }
.issue .tx { display: flex; flex-direction: column; padding-top: 3px; }
.issue .tx small { display: none; font-weight: 600; color: var(--ink-soft); line-height: 1.3; margin-top: 2px; }
.issue.open .tx small { display: block; }
#labels .issue { pointer-events: auto; }

/* ---------- before / after ---------- */
.ba { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ba figure { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.ba canvas { width: 100%; aspect-ratio: 1; border-radius: 10px; display: block; background: #a9cc78; }
.ba figcaption { font-size: 12px; font-weight: 700; color: var(--ink-soft); text-align: center; }
.ba figcaption b { color: var(--teal-dark); }
.btn.share { background: var(--amber); color: #3b2a05; }

/* ---------- achievements ---------- */
.achlist { display: flex; flex-direction: column; gap: 6px; }
.ach { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: rgba(38,53,58,.05); position: relative; }
.ach .ai, .achtoast .ai { width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center; background: #e7e1d4; color: #fff; }
.ach .ai svg, .achtoast .ai svg { width: 20px; height: 20px; }
.ach.on .ai, .achtoast .ai { background: var(--amber); color: #3b2a05; }
.ach:not(.on) { opacity: .6; }
.ach > div { display: flex; flex-direction: column; flex: 1; }
.ach small, .achtoast small { color: var(--ink-soft); font-weight: 600; font-size: 12.5px; }
.ach .lockico svg { width: 16px; height: 16px; color: var(--ink-soft); }
.achtoast { position: fixed; z-index: 20; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 10px 16px 10px 10px; animation: drop .4s cubic-bezier(.2,1.4,.4,1); transition: opacity .4s, transform .4s; zoom: var(--fs, 1); }
.achtoast > div { display: flex; flex-direction: column; }
.achtoast.out { opacity: 0; transform: translate(-50%, -20px); }
@keyframes drop { from { transform: translate(-50%, -30px); opacity: 0; } }

/* ---------- real places preview: big map on phones ---------- */
.pzoom { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; }
.pzoom button { width: 42px; height: 42px; border: 0; border-radius: 12px; background: var(--paper-solid); box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; color: var(--ink); }
.pzoom svg { width: 20px; height: 20px; }
@media (max-width: 560px) {
  .screen.pscreen { padding: calc(6px + var(--safe-t)) 6px calc(6px + var(--safe-b)); }
  .pview { width: 100%; max-height: 100%; padding: 12px; gap: 10px; border-radius: 16px; }
  .pview h2 { font-size: 19px; }
  .pview .pmap { width: 100%; aspect-ratio: 1; flex: none; border-radius: 12px; }
  .pview .setting { flex-wrap: wrap; }
  .pview .seg { width: 100%; justify-content: space-between; }
}

/* achievements: the list scrolls, the buttons stay at the bottom */
.modal.achs { overflow: hidden; }
.achs .achlist { overflow-y: auto; flex: 1 1 auto; min-height: 0; margin: 0 -6px; padding: 0 6px; }
.achs .actions { flex: none; padding-top: 4px; }

/* compact lane row: never wider than the rows above it */
.optrow.lanes-row { flex-wrap: nowrap; gap: 6px; }
.lanew.compact { gap: 4px; padding: 3px; }
.lanew.compact .lw-step button { width: 30px; height: 32px; font-size: 19px; }
.lanew.compact .lw-n { min-width: 26px; font-size: 14px; }
.lanew.compact .lw-n small { font-size: 9.5px; max-width: 36px; }
.lanew.compact .road { height: 28px; }
.lanew.compact .ln { width: 11px; }
.lanew.compact.many .ln { width: 8px; }
.lanew.compact .ln svg { width: 7px; height: 11px; }
.costtag { height: 38px; padding: 0 10px; font-size: 13px; flex-direction: row; align-items: center; justify-content: center; gap: 2px; line-height: 1; }
.costtag small { font-size: 11px; text-transform: none; letter-spacing: 0; line-height: 1; position: relative; top: 1px; }

/* ---------- typography: soft serif titles ---------- */
.logo h1, .boot-logo, .modal h2, .levels h2, .sheet h3, .big-score, .achtoast b {
  font-family: var(--font-title);
  font-variation-settings: 'SOFT' 100, 'WONK' 0;
  font-optical-sizing: auto;
}
.logo h1 { font-weight: 700; letter-spacing: -0.035em; }
.boot-logo { font-weight: 700; }
.modal h2, .levels h2 { font-weight: 700; letter-spacing: -0.015em; }
.sheet h3 { font-weight: 650; }
.big-score { font-weight: 800; letter-spacing: -0.02em; }
.big-score small { font-family: var(--font); }
.logo p { font-weight: 700; letter-spacing: .01em; }

/* ---------- level select: map previews ---------- */
.levels header .totstars { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; color: var(--ink-soft); }
.levels header .totstars svg, .chapter .chstars svg { width: 16px; height: 16px; color: var(--amber); }
.level-grid { grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 12px; }
.chapter { display: flex; align-items: center; justify-content: space-between; }
.chapter .chstars { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; letter-spacing: 0; text-transform: none; }
.lvl { padding: 0; min-height: 172px; gap: 0; justify-content: flex-start; }
.lvl .swatch { display: none; }
.lvl .thumb { position: relative; height: 108px; flex: none; overflow: hidden; background: #b8d28a; }
.lvl .thumb img { width: 100%; height: 145%; object-fit: cover; object-position: center; display: block; transform: translateY(-15%); transition: transform .3s; }
.lvl:hover .thumb img { transform: translateY(-15%) scale(1.05); }
.lvl .num { position: absolute; left: 8px; top: 8px; width: 28px; height: 28px; font-size: 14px; }
.lvl .info { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.lvl .nm { margin: 0; font-size: 14.5px; }
.lvl .medals { position: absolute; right: 8px; bottom: 9px; }
.lvl.done .thumb::after { content: ''; position: absolute; inset: auto 0 0 0; height: 4px; background: var(--amber); }
.lvl.locked { opacity: 1; }
.lvl.locked .thumb img { filter: grayscale(.85) brightness(.9); opacity: .55; }
.lvl .unlock { display: flex; align-items: center; gap: 5px; font-size: 11.5px; line-height: 1.25; }
.lvl .unlock svg { width: 14px; height: 14px; flex: none; }
.lvl.locked .lockico { display: none; }

/* ---------- phones held sideways: slim tool rail on the left, the map gets the screen ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  .topbar.glass { top: calc(6px + var(--safe-t)); left: calc(76px + var(--safe-l)); right: auto; width: min(560px, 62vw); min-height: 0; padding: 4px; }
  .topbar .tb-btn { width: 38px; height: 38px; }
  .topbar .title .nm { font-size: 14px; }
  .topbar .title .sub { font-size: 11px; }
  .tb-stat .k { font-size: 9px; }
  .tb-stat .v { font-size: 14px; }
  #ui .bottom { left: calc(6px + var(--safe-l)); right: auto; top: calc(6px + var(--safe-t)); bottom: calc(6px + var(--safe-b)); width: auto; flex-direction: row-reverse; align-items: flex-end; gap: 6px; }
  .bottom .dock.glass { flex-direction: column; align-items: center; flex: none; width: 64px; height: 100%; padding: 4px; gap: 2px; justify-content: flex-start; overflow-y: auto; scrollbar-width: none; }
  .dock::-webkit-scrollbar { display: none; }
  .bottom .dock .tool { width: 56px; height: 46px; min-width: 0; max-width: none; flex: none; font-size: 9.5px; }
  .bottom .dock .tool svg { width: 20px; height: 20px; }
  .bottom .dock .testbtn { margin: auto 0 0 0; width: 56px; height: 54px; padding: 0; flex-direction: column; justify-content: center; gap: 2px; font-size: 11px; }
  .bottom .options.glass { align-self: flex-end; flex: none; max-width: min(540px, 60vw); padding: 4px; }
  .options .chip { height: 34px; padding: 0 9px; font-size: 12px; }
  .lanew.compact .lw-step button { width: 28px; height: 28px; }
  .costtag { height: 32px; }
  .hint { left: auto; right: calc(70px + var(--safe-r)); bottom: calc(8px + var(--safe-b)); width: min(340px, 42vw); transform: none; font-size: 12.5px; padding: 9px 11px; }
  .sheet { left: calc(76px + var(--safe-l)); right: auto; width: min(380px, 48vw); bottom: calc(6px + var(--safe-b)); max-height: calc(100vh - 70px); margin: 0; }
  .fabs { bottom: calc(8px + var(--safe-b)) !important; right: calc(8px + var(--safe-r)); }
  .fab { width: 44px; height: 44px; }
  .toasts { top: calc(56px + var(--safe-t)); }
  .modal { max-height: calc(100vh - 16px); padding: 16px; }
  body.lefty .bottom { left: auto; right: calc(6px + var(--safe-r)); flex-direction: row; }
  body.lefty .topbar.glass { left: auto; right: calc(76px + var(--safe-r)); }
  body.lefty .fabs { right: auto; left: calc(8px + var(--safe-l)); }
}

.pview .seg button:disabled { opacity: .45; cursor: default; }

/* real-place download running in the background: a small pill under the top bar */
.dlpill { position: fixed; z-index: 45; left: 50%; top: calc(74px + var(--safe-t, 0px)); transform: translateX(-50%); display: flex; align-items: center; gap: 8px; max-width: min(92vw, 420px); padding: 7px 14px 7px 10px; border: 0; border-radius: 999px; background: rgba(255,255,255,.94); color: var(--ink); box-shadow: var(--shadow); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; animation: dlin .35s cubic-bezier(.2,1.2,.4,1); }
.dlpill.hidden { display: none; }
.dlpill .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dlpill b { flex: none; color: var(--teal-dark); font-weight: 900; }
.dlpill svg { width: 18px; height: 18px; flex: none; }
.dlpill .spin { width: 14px; height: 14px; flex: none; }
.dlpill.ready { background: var(--teal); color: #fff; }
.dlpill.ready b { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
.dlpill.failed b { color: var(--coral); }
body.night .dlpill:not(.ready) { background: rgba(36,44,66,.94); color: #eef1f8; }
@keyframes dlin { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }
/* the tutorial bar sits under the top bar too: the download pill goes just below it */
body:has(.coach) .dlpill { top: calc(122px + var(--safe-t, 0px)); }
/* a dialog or screen open over the game: the tutorial waits underneath */
body:has(#ui .screen) .coach { display: none; }

.boot-help { max-width: 280px; text-align: center; font-size: 13px; font-weight: 600; color: var(--ink-soft); line-height: 1.4; }
.boot-help button { margin-top: 10px; border: 0; border-radius: 12px; padding: 10px 18px; background: var(--teal); color: #fff; font: inherit; font-weight: 800; }

.pchoose .pundo { min-height: 36px; width: 40px; padding: 0; flex: none; }
.pchoose .pundo svg { width: 18px; height: 18px; }
.pchoose .pundo:disabled { opacity: .35; }

/* ---------- level rail: bridge / ground / tunnel at the right edge ---------- */
.levelrail { --stop: 54px; position: absolute; z-index: 6; right: calc(10px + var(--safe-r)); top: calc(132px + var(--safe-t)); width: 60px; height: calc(var(--n) * var(--stop) + 12px); border-radius: 30px; padding: 0; touch-action: none; user-select: none;
  box-shadow: 0 8px 22px rgba(30,45,50,.22), inset 0 0 0 2px rgba(255,255,255,.75); transition: transform .45s cubic-bezier(.2,.8,.2,1), opacity .3s; }
.levelrail.hidden { display: none; }
body.testing .levelrail { opacity: 0; transform: translateX(90px); pointer-events: none; }
/* the little world it is cut through: sky over the ground line, earth below */
.lr-scene { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; }
.lr-scene i { position: absolute; left: 0; right: 0; display: block; }
.lr-sky { top: 0; height: calc(6px + (var(--g) + 0.5) * var(--stop)); background: linear-gradient(180deg, #a9d8ef 0%, #d7eef3 100%); }
.lr-cloud { top: 12px; left: 9px !important; right: auto !important; width: 26px; height: 9px; border-radius: 9px; background: rgba(255,255,255,.9); box-shadow: 10px -4px 0 -1px rgba(255,255,255,.9); opacity: calc(min(1, var(--g))); animation: lrcloud 9s ease-in-out infinite alternate; }
.lr-grass { top: calc(6px + (var(--g) + 0.5) * var(--stop) - 4px); height: 9px; background: linear-gradient(180deg, #8fca62, #6aa94a); box-shadow: 0 -2px 0 #a8d97a inset; }
.lr-earth { top: calc(6px + (var(--g) + 0.5) * var(--stop) + 5px); bottom: 0; background: linear-gradient(180deg, #b48a5f 0%, #93694a 60%, #7a563c 100%); }
.lr-pebbles { top: calc(6px + (var(--g) + 0.5) * var(--stop) + 14px); bottom: 0; background: radial-gradient(circle at 20% 30%, rgba(255,255,255,.22) 0 2px, transparent 3px), radial-gradient(circle at 70% 55%, rgba(0,0,0,.14) 0 2.5px, transparent 3.5px), radial-gradient(circle at 40% 80%, rgba(255,255,255,.16) 0 1.8px, transparent 2.8px); background-size: 30px 26px; }
@keyframes lrcloud { from { transform: translateX(-3px); } to { transform: translateX(6px); } }
.lr-stop { position: absolute; left: 7px; top: calc(6px + var(--i) * var(--stop) + 4px); width: 46px; height: 46px; border: 0; border-radius: 16px; background: transparent; display: grid; place-items: center; cursor: pointer; color: rgba(38,53,58,.55); transition: transform .2s, color .2s; }
.lr-stop svg { width: 22px; height: 22px; }
.lr-stop.tunnel, .lr-stop.ground + .lr-stop.tunnel { color: rgba(255,255,255,.75); }
.lr-stop:active { transform: scale(.9); }
.lr-stop.on { color: transparent; }
/* the knob: springs to the chosen level with a little overshoot */
.lr-knob { position: absolute; left: 7px; top: calc(6px + var(--k) * var(--stop) + 4px); width: 46px; height: 46px; border-radius: 16px; display: grid; place-items: center; color: #fff; pointer-events: none;
  box-shadow: 0 5px 12px rgba(20,30,35,.32), inset 0 -3px 0 rgba(0,0,0,.18), inset 0 2px 0 rgba(255,255,255,.35);
  transition: top .52s cubic-bezier(.34,1.56,.64,1), background .35s, transform .2s; }
.lr-knob.ground { background: linear-gradient(180deg, #4b5a60, #2f3c41); }
.lr-knob.bridge { background: linear-gradient(180deg, #5d8ddf, #3c66b8); }
.lr-knob.high { background: linear-gradient(180deg, #8a7fe6, #6256c4); }
.lr-knob.tunnel { background: linear-gradient(180deg, #8c6c4f, #644a33); }
.levelrail.sliding .lr-knob { transform: scale(1.1); }
.lr-knob.land { animation: lrland .55s cubic-bezier(.3,1.4,.5,1); }
@keyframes lrland { 0% { transform: scale(1.08, .9); } 35% { transform: scale(.92, 1.1); } 70% { transform: scale(1.04, .97); } 100% { transform: scale(1); } }
.lr-ic { display: grid; place-items: center; }
.lr-ic svg { width: 24px; height: 24px; }
.lr-ic.flip { animation: lrflip .45s cubic-bezier(.2,1.3,.4,1); }
@keyframes lrflip { from { transform: rotateY(90deg) scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
/* the level's name slides out to the left of the rail for a moment */
.lr-label { position: absolute; right: 68px; top: calc(6px + var(--k, 0) * var(--stop) + 13px); padding: 5px 11px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 800; white-space: nowrap; pointer-events: none; opacity: 0; transform: translateX(12px); transition: opacity .25s, transform .35s cubic-bezier(.2,1.3,.4,1); }
.lr-label.show { opacity: 1; transform: none; }
.lr-label.bridge { background: #3c66b8; } .lr-label.high { background: #6256c4; } .lr-label.tunnel { background: #644a33; }
body.night .lr-sky { background: linear-gradient(180deg, #1e2a4a, #34456b); }
body.night .lr-cloud { opacity: .25; }
@media (orientation: landscape) and (max-height: 520px) { .levelrail { top: calc(64px + var(--safe-t)); --stop: 48px; } .lr-stop, .lr-knob { width: 42px; height: 42px; left: 6px; } .levelrail { width: 54px; } }

/* the level rail sits at the right of the road options panel */
.bottom .options.glass.has-rail { display: flex; flex-direction: row; align-items: stretch; gap: 6px; }
.options .optcol { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.options .levelrail { --stop: 42px; position: relative; right: auto; top: auto; flex: none; width: 52px; height: calc(var(--n) * var(--stop) + 8px); align-self: center; border-radius: 22px; z-index: auto; }
.options .levelrail .lr-sky { height: calc(4px + (var(--g) + 0.5) * var(--stop)); }
.options .levelrail .lr-grass { top: calc(4px + (var(--g) + 0.5) * var(--stop) - 4px); }
.options .levelrail .lr-earth { top: calc(4px + (var(--g) + 0.5) * var(--stop) + 5px); }
.options .levelrail .lr-pebbles { top: calc(4px + (var(--g) + 0.5) * var(--stop) + 12px); }
.options .lr-stop { left: 5px; width: 42px; height: 38px; border-radius: 13px; top: calc(4px + var(--i) * var(--stop) + 2px); }
.options .lr-knob { left: 5px; width: 42px; height: 38px; border-radius: 13px; top: calc(4px + var(--k) * var(--stop) + 2px); }
.options .lr-stop svg { width: 20px; height: 20px; }
.options .lr-ic svg { width: 21px; height: 21px; }
.options .lr-cloud { top: 8px; left: 6px !important; width: 20px; height: 7px; }
.options .lr-label { right: 60px; top: calc(4px + var(--k, 0) * var(--stop) + 8px); }

/* level rail at night: moonlit colours, icons light enough to read on the dark sky, a moon for the cloud */
body.night .levelrail { box-shadow: 0 8px 22px rgba(0,0,0,.4), inset 0 0 0 2px rgba(200,212,240,.35); }
body.night .lr-sky { background: linear-gradient(180deg, #1b2540 0%, #2c3b5e 100%); }
body.night .lr-cloud { width: 9px; height: 9px; border-radius: 50%; opacity: calc(min(1, var(--g))); background: #f4ecc8; box-shadow: 0 0 8px 2px rgba(244,236,200,.45); animation: none; }
body.night .options .lr-cloud { width: 8px; height: 8px; }
body.night .lr-grass { background: linear-gradient(180deg, #557f45, #3e6234); box-shadow: 0 -2px 0 #6b9658 inset; }
body.night .lr-earth { background: linear-gradient(180deg, #6e5640 0%, #574332 60%, #463527 100%); }
body.night .lr-stop { color: rgba(226,232,246,.72); }
body.night .lr-knob { box-shadow: 0 5px 12px rgba(0,0,0,.45), inset 0 -3px 0 rgba(0,0,0,.2), inset 0 2px 0 rgba(255,255,255,.3), 0 0 0 1.5px rgba(226,232,246,.5); }
body.night .lr-knob.ground { background: linear-gradient(180deg, #6f7f8c, #4d5a66); }
body.night .lr-knob.bridge { background: linear-gradient(180deg, #6f9cec, #4a75c8); }
/* in the options panel the level name pops up above the rail, clear of the price tag */
.options .lr-label { right: 0; top: -36px; transform: translateY(8px); opacity: 0; background: rgba(38,53,58,.82); backdrop-filter: blur(4px); }
.options .lr-label.show { opacity: 1; transform: none; }
.options .lr-label.bridge { background: rgba(60,102,184,.85); } .options .lr-label.high { background: rgba(98,86,196,.85); } .options .lr-label.tunnel { background: rgba(100,74,51,.85); }
@media (orientation: landscape) and (min-width: 720px) { .options .lr-label { right: 60px; top: calc(4px + var(--k, 0) * var(--stop) + 8px); transform: translateX(12px); } }

/* ---------- night: the whole interface turns to moonlit dark panels ---------- */
body.night {
  --ink: #e8ecf4; --ink-soft: #a9b4c6; --line: rgba(214, 224, 244, 0.16);
  --paper: rgba(29, 37, 57, 0.93); --paper-solid: #232c43;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.4);
  --night-on: #4d6ea6;
  color: var(--ink);
}
body.night .glass { background: rgba(27, 35, 54, 0.86); }
body.night .fab { background: rgba(27, 35, 54, 0.88); border-color: rgba(200, 212, 240, 0.22); color: var(--ink); }
/* selected / dark chips used the ink colour as background: at night they take a moonlit blue */
body.night :is(.chip.on, .banner.test, .options .chip.level.on, .wchip.jtarget, .wchip.jadd.ok, .tool.on, .bottom .dock .tool.on,
  .seg-choice .chip.on, .toast, .tooltip, .phn, .levelseg .lvbtn.ground.on, .lr-label:not(.bridge):not(.high):not(.tunnel)) { background: var(--night-on); color: #fff; }
body.night .testbtn.running { background: var(--night-on); box-shadow: 0 3px 0 #233a63, var(--shadow); }
/* white controls become raised dark tiles */
body.night :is(.problem b, .wchip.jlane button.on, .wchip.jdot, .lvl .num, .seg button.on, .stepper button, .apchip, .lw-step, .goal .ck, .tspot, .wchip.jsign, .pzoom button) {
  background: #2f3a56; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(214, 224, 244, 0.1);
}
body.night .banner.warn { background: #4a3c17; color: #ffd98a; }
body.night :is(input, select, textarea, .psearch input, .pname) { background: #1b2234; color: var(--ink); border-color: var(--line); }
body.night .screen.dim { background: rgba(6, 10, 20, 0.5); }
body.night .ach .ai, body.night .achtoast .ai { background: #3a4560; }
body.night .reportpic { background: #2a3347; }
body.night ::placeholder { color: #7f8aa0; }

/* studio credit: a quiet line under the title menu and at the foot of the settings */
.credit { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 11.5px; font-weight: 700; color: var(--ink-soft); opacity: .72; letter-spacing: .01em; text-shadow: 0 1px 6px rgba(255,255,255,.6); pointer-events: none; user-select: none; }
.credit b { font-weight: 800; color: var(--ink); opacity: .85; }
.credit .tq-mark { width: 15px; height: 13px; flex: none; }
/* pinned under everything, so the menu keeps its place at the bottom and the map stays in view */
.title-screen .credit { position: absolute; left: 0; right: 0; bottom: calc(4px + var(--safe-b)); margin: 0; }
.title-screen { padding-bottom: calc(26px + var(--safe-b)); }
.credit.in-modal { margin-top: -4px; text-shadow: none; }
body.night .credit { text-shadow: 0 1px 6px rgba(0,0,0,.5); }
.shape-ic { width: 15px; height: 15px; vertical-align: -3px; margin-right: 4px; flex: none; }

/* Undo with nothing left to undo but a redo waiting (long press): quieter; while held, it turns round */
.tool[data-a=undo].dim { opacity: .55; }
.tool[data-a=undo] svg { transition: transform .45s cubic-bezier(.3,.7,.3,1); }
.tool[data-a=undo].holding svg { transform: scaleX(-1) rotate(-20deg); }
@media (prefers-reduced-motion: reduce) { .tool[data-a=undo] svg { transition: none; } }

/* ---------- guided road drawing: draft handles and the build bar ---------- */
.gd-layer { position: absolute; inset: 0; pointer-events: none; transition: opacity .2s; }
.gd-layer.off { opacity: 0; }
.gd-lift { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.gd-lift line { stroke: #fff; stroke-width: 2; stroke-dasharray: 3 4; stroke-linecap: round; opacity: 0; filter: drop-shadow(0 1px 1px rgba(0,0,0,.35)); }
.gd-h { position: absolute; left: 0; top: 0; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; background: #fff; will-change: transform;
  box-shadow: 0 0 0 2.5px var(--ink), 0 4px 12px rgba(0,0,0,.32); scale: 1; opacity: 1;
  transition: scale .26s cubic-bezier(.2,1.5,.4,1), opacity .2s, box-shadow .2s; }
.gd-h::after { content: ''; position: absolute; inset: 7px; border-radius: 50%; background: var(--teal); transition: background .2s, inset .2s; }
.gd-h.snap::after { background: var(--amber); inset: 5px; }
.gd-h.bad::after { background: var(--bad); }
.gd-h.m { width: 24px; height: 24px; margin: -12px 0 0 -12px; background: rgba(255,255,255,.9); box-shadow: 0 0 0 2px rgba(38,53,58,.75), 0 3px 8px rgba(0,0,0,.25); }
.gd-h.m::after { inset: 8px; background: var(--ink); opacity: .45; }
.gd-h.m.bent::after { inset: 6px; background: var(--teal); opacity: 1; }
.gd-h.drag { scale: 1.32; box-shadow: 0 0 0 3px #fff, 0 0 0 5.5px var(--ink), 0 8px 18px rgba(0,0,0,.35); }
.gd-h.off { opacity: 0; scale: .4; }
@starting-style { .gd-h { opacity: 0; scale: .3; } }
body.night .gd-h { box-shadow: 0 0 0 2.5px #0f1524, 0 4px 14px rgba(0,0,0,.6); }

.planbar { position: absolute; left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); bottom: 200px;
  display: flex; flex-direction: column; gap: 6px; padding: 6px; border-radius: 20px; box-shadow: var(--shadow);
  transition: bottom .35s cubic-bezier(.2,.8,.2,1), opacity .25s, transform .3s cubic-bezier(.2,.8,.2,1); }
@starting-style { .planbar { opacity: 0; transform: translateY(16px) scale(.97); } }
.planbar.leaving { animation: pbout .2s ease-in forwards !important; }
@keyframes pbout { to { opacity: 0; transform: translateY(16px) scale(.97); } }
.planbar.bump { animation: pbbump .42s cubic-bezier(.3,1.6,.5,1); }
@keyframes pbbump { 30% { transform: translateY(-7px); } 65% { transform: translateY(2px); } }
.pb-main { display: flex; align-items: center; gap: 6px; }
.pb-x { width: 46px; height: 46px; flex: none; border: 0; border-radius: 14px; background: rgba(38,53,58,.08); display: grid; place-items: center; cursor: pointer; transition: transform .12s, background .2s; }
.pb-x:active { transform: scale(.92); }
.pb-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.22; padding: 0 2px; }
.pb-info b { font-size: 14.5px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-info span { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); font-variant-numeric: tabular-nums; transition: color .2s; }
.planbar.bad .pb-info span { color: var(--bad); }
.pb-go { min-height: 46px; padding: 0 18px; flex: none; gap: 6px; transition: transform .12s, background .2s, box-shadow .2s, opacity .2s; }
.pb-go svg { width: 22px; height: 22px; stroke-width: 2.6; }
.pb-go[disabled] { background: rgba(38,53,58,.18); box-shadow: none; color: var(--ink-soft); opacity: 1; }
.pb-go.pulse { animation: pbpulse 1.5s ease-in-out infinite; }
@keyframes pbpulse { 0%, 100% { box-shadow: 0 3px 0 var(--teal-dark), 0 0 0 0 rgba(35,165,151,.55); } 55% { box-shadow: 0 3px 0 var(--teal-dark), 0 0 0 10px rgba(35,165,151,0); } }
.pb-kinds { display: flex; flex-wrap: wrap; gap: 4px; animation: swapin .3s cubic-bezier(.2,.8,.2,1); }
.pb-kinds::-webkit-scrollbar { display: none; }
.pb-kinds.hidden { display: none; }
.pb-kinds .chip { flex: none; height: 38px; background: rgba(38,53,58,.07); transition: background .2s, color .2s, transform .12s; }
.pb-kinds .chip:active { transform: scale(.95); }
.pb-kinds .chip.on { background: var(--ink); color: #fff; }
.chip.gd-how { opacity: .7; font-weight: 700; pointer-events: none; }
body.night .pb-x, body.night .pb-kinds .chip { background: rgba(255,255,255,.1); }
body.night .pb-kinds .chip.on { background: var(--night-on); color: #fff; }
body.night .pb-go[disabled] { background: rgba(255,255,255,.12); }
.planbar.land { right: auto !important; left: calc(76px + var(--safe-l)) !important; width: min(440px, 60vw); bottom: calc(12px + var(--safe-b)); }
body.lefty .planbar.land { left: auto !important; right: calc(76px + var(--safe-r)) !important; }
@media (orientation: landscape) and (min-width: 720px) and (min-height: 521px) {
  .planbar { right: auto; width: min(440px, 60vw); }
  body.lefty .planbar { left: auto; right: calc(10px + var(--safe-r)); }
}

/* while a guided road waits to be built the floating buttons step aside (they come back after) */
.fabs { transition: opacity .25s, transform .3s cubic-bezier(.2,.8,.2,1), bottom .35s cubic-bezier(.2,.8,.2,1); }
body.gd-drafting .fabs { opacity: 0; transform: translateX(14px) scale(.9); }
body.gd-drafting .fabs, body.gd-drafting .fabs > * { pointer-events: none !important; }
body.lefty.gd-drafting .fabs { transform: translateX(-14px) scale(.9); }
/* a dialog or sheet (pause menu, settings, road inspector) covers the build bar: it steps away until closed */
#ui:has(> .screen:not(.leaving)) .planbar, #ui:has(> .sheet:not(.leaving)) .planbar { opacity: 0; transform: translateY(16px) scale(.97); pointer-events: none; }
/* guided road panel: what is being made (road / lane / ramp), a segmented choice */
.intentseg { display: flex; gap: 3px; padding: 3px; border-radius: 13px; background: rgba(38,53,58,.07); flex: none; }
.intentseg .chip { height: 38px; transition: background .2s, color .2s, transform .12s; }
.intentseg .chip:active { transform: scale(.95); }
.intentseg .chip.on { background: var(--ink); color: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
body.night .intentseg { background: rgba(255,255,255,.08); }
body.night .intentseg .chip.on { background: var(--night-on); }
.chip.gd-how { white-space: normal; height: auto; min-height: 34px; padding: 6px 10px; line-height: 1.25; flex: 1 1 auto; }
/* a long dialog (many saved places) scrolls under its buttons: the closing row stays at the bottom */
.modal > .actions:last-child { position: sticky; bottom: -22px; margin: 0 -22px -22px; padding: 12px 22px 22px; z-index: 2;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--paper-solid) 0%, transparent), var(--paper-solid) 14px); }
@media (orientation: landscape) and (max-height: 520px) {
  .modal > .actions:last-child { bottom: -16px; margin: 0 -16px -16px; padding: 10px 16px 16px; }
}
