@font-face {
  font-family: 'Overpass';
  src: url('../vendor/fonts/overpass-latin.woff2') format('woff2');
  font-weight: 300 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: 'Overpass';
  src: url('../vendor/fonts/overpass-latin-ext.woff2') format('woff2');
  font-weight: 300 800;
  font-display: swap;
  unicode-range: U+0100-024F, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --concrete: #e7e9e6;
  --concrete-2: #f2f3f1;
  --graphite: #24292e;
  --graphite-2: #31383e;
  --steel: #6b7780;
  --line: rgba(36, 41, 46, 0.14);
  --signal: #c8102e;
  --amber: #f4b942;
  --ink-soft: #4c565d;
  --r-panel: 14px;
  --r-ctl: 8px;
  --shadow: 0 10px 30px rgba(18, 22, 26, 0.18), 0 1px 0 rgba(255, 255, 255, 0.6) inset;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-family: 'Overpass', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--graphite);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1c2024; overscroll-behavior: none; }
body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; width: 100%; height: 100%; outline: none; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* ---------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--r-ctl);
  border: 1px solid var(--line); background: var(--concrete-2); cursor: pointer;
  font-weight: 600; letter-spacing: 0.01em; white-space: nowrap;
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(1px); }
.btn-accent { background: var(--signal); color: #fff; border-color: transparent; }
.btn-accent:hover { background: #a90d27; }
.btn-danger { color: var(--signal); }
.btn-icon { width: 36px; padding: 0; font-size: 20px; line-height: 1; }
.btn svg { width: 17px; height: 17px; }
.linkish { background: none; border: 0; padding: 0; color: var(--graphite); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; text-align: left; }

.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: rgba(36, 41, 46, 0.1); border: 1px solid var(--line); }
.seg-btn { height: 30px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-weight: 600; color: var(--ink-soft); }
.seg-btn.is-on { background: var(--graphite); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px; padding: 0 11px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; cursor: pointer; font-weight: 600; font-size: 13px; color: inherit;
}
.chip.is-on { background: var(--graphite); color: #fff; border-color: var(--graphite); }

/* ---------------------------------------------------------------- top bar */
#topbar {
  position: fixed; top: calc(12px + var(--safe-t)); left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r));
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; pointer-events: none; z-index: 20;
}
#topbar > * { pointer-events: auto; }
.brand {
  display: flex; flex-direction: column; align-items: flex-start; text-align: left;
  padding: 9px 14px 8px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--concrete); box-shadow: var(--shadow); cursor: pointer; min-width: 150px;
}
.brand-title { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.brand-sub { font-size: 12.5px; color: var(--ink-soft); font-weight: 500; }
.brand-sub::after { content: ''; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor; transform: translateY(-3px) rotate(45deg); }
.brand-sub.is-custom { color: var(--signal); }
.top-actions { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 12px; background: var(--concrete); border: 1px solid var(--line); box-shadow: var(--shadow); }

/* ---------------------------------------------------------------- popovers & sheets */
.popover {
  position: fixed; top: calc(70px + var(--safe-t)); right: calc(12px + var(--safe-r)); width: 280px; z-index: 30;
  background: var(--concrete); border: 1px solid var(--line); border-radius: var(--r-panel); box-shadow: var(--shadow);
  padding: 8px 14px 12px;
}
.popover .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.popover label.row { justify-content: flex-start; }
.popover .row input[type=range] { width: 130px; accent-color: var(--graphite); }
.popover input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--graphite); }
.popover .fine { font-size: 11.5px; color: var(--steel); padding-top: 10px; }

.sheet {
  position: fixed; z-index: 40; background: var(--concrete); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: 0 24px 60px rgba(10, 14, 18, 0.35); padding: 18px;
}
.sheet-left { top: calc(76px + var(--safe-t)); left: calc(12px + var(--safe-l)); width: 380px; max-height: calc(100% - 180px); overflow: auto; }
.sheet-center { top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(620px, calc(100% - 24px)); max-height: calc(100% - 40px); overflow: auto; }
.sheet-head, .panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sheet h2, .panel h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.sheet h3 { font-size: 15px; font-weight: 700; margin: 4px 0 6px; }
.sheet p { color: var(--ink-soft); margin-bottom: 8px; max-width: 62ch; }
.sheet-note { font-size: 13px; }
.close { background: transparent; border-color: transparent; }
.wide { width: 100%; margin-top: 10px; height: 42px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.credits-body { font-size: 13px; color: var(--ink-soft); display: grid; gap: 4px; }
.credits-body b { color: var(--graphite); font-weight: 700; }

.preset-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.preset {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; text-align: left;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--concrete-2); cursor: pointer;
}
.preset:hover { background: #fff; }
.preset.is-on { border-color: var(--graphite); box-shadow: inset 0 0 0 1px var(--graphite); }
.preset-name { font-weight: 800; font-size: 15px; }
.preset-time { font-variant-numeric: tabular-nums; color: var(--steel); font-weight: 600; font-size: 12.5px; }
.preset-blurb { grid-column: 1 / -1; color: var(--ink-soft); font-size: 13px; }

/* ---------------------------------------------------------------- panels */
.panel {
  position: fixed; z-index: 15; background: var(--concrete); border: 1px solid var(--line);
  border-radius: var(--r-panel); box-shadow: var(--shadow); padding: 14px;
}
.panel-left { top: calc(84px + var(--safe-t)); left: calc(12px + var(--safe-l)); width: 300px; bottom: calc(160px + var(--safe-b)); display: flex; flex-direction: column; }
.panel-right { top: calc(84px + var(--safe-t)); right: calc(12px + var(--safe-r)); width: 280px; }
.cat-items { list-style: none; margin: 12px -4px 0; padding: 0 4px; overflow: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-content: start; }
.cat-item {
  width: 100%; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--concrete-2);
  cursor: pointer; text-align: left; display: grid; gap: 4px;
}
.cat-item:hover { background: #fff; border-color: rgba(36, 41, 46, 0.3); }
.cat-thumb { aspect-ratio: 1; border-radius: 7px; background-color: #e2e5e2; background-repeat: no-repeat; }
.cat-name { font-weight: 700; font-size: 13px; line-height: 1.2; }
.cat-size { font-size: 11.5px; color: var(--steel); font-variant-numeric: tabular-nums; }
.fab { position: fixed; left: calc(12px + var(--safe-l)); top: calc(84px + var(--safe-t)); z-index: 14; box-shadow: var(--shadow); height: 40px; }

.dims { color: var(--steel); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 2px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.15); cursor: pointer; padding: 0; background-size: cover; }
.swatch.is-on { box-shadow: 0 0 0 2px var(--concrete), 0 0 0 4px var(--graphite); }
.variant-name { font-size: 12.5px; color: var(--ink-soft); min-height: 18px; margin-bottom: 8px; }
.ins-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ins-actions .btn { width: 100%; }

/* ---------------------------------------------------------------- departure board */
.board {
  position: fixed; left: calc(12px + var(--safe-l)); bottom: calc(12px + var(--safe-b)); z-index: 16;
  width: 330px; color: #e9ecea; background: var(--graphite); border-radius: 14px;
  box-shadow: 0 14px 40px rgba(8, 10, 12, 0.35); overflow: hidden;
  border: 1px solid #3a4248;
}
.board-main { display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 14px 10px; background: none; border: 0; cursor: pointer; text-align: left; color: inherit; }
.board-time { font-size: 40px; font-weight: 800; color: var(--amber); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1; display: flex; align-items: baseline; gap: 4px; }
.board-ampm { font-size: 14px; font-weight: 700; color: #cfd5d2; letter-spacing: 0.02em; }
.board-meta { display: grid; gap: 1px; }
.board-day { font-weight: 700; font-size: 14px; }
.board-sky { font-size: 12.5px; color: #aab3b0; }
.board-trains { list-style: none; margin: 0; padding: 0 14px 10px; display: grid; gap: 3px; }
.board-trains li { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 8px; font-size: 13px; padding: 5px 0 3px; border-top: 1px solid #3a4248; }
.tr-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--amber); }
.tr-dest { color: #e9ecea; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-kind { font-size: 11.5px; font-weight: 700; padding: 1px 7px 0; border-radius: 4px; background: #48525a; color: #fff; }
.tr-kind.limited { background: var(--amber); color: var(--graphite); }
.tr-kind.express { background: var(--signal); }
.board-more { padding: 4px 14px 14px; border-top: 1px solid #3a4248; }
.board-more input[type=range] { width: 100%; accent-color: var(--amber); margin: 10px 0 0; }
.board-ticks { display: flex; justify-content: space-between; font-size: 11px; color: #8d9894; margin: 0 2px 8px; font-variant-numeric: tabular-nums; }
.board-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.board .chip { border-color: #4a545b; color: #dfe4e1; height: 28px; font-size: 12.5px; background: transparent; }
.board .chip.is-on { background: var(--amber); color: var(--graphite); border-color: var(--amber); }
.board select.chip { padding-right: 8px; }
.board select.chip option { color: var(--graphite); }

/* ---------------------------------------------------------------- walk HUD */
.hint {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 12;
  padding: 8px 14px 6px; border-radius: 999px; background: rgba(36, 41, 46, 0.86); color: #fff; font-weight: 600; font-size: 13.5px;
  pointer-events: none; white-space: nowrap;
}
.crosshair { position: fixed; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.9); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35); pointer-events: none; z-index: 11; }
.joystick { position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(36, 41, 46, 0.25); border: 1.5px solid rgba(255, 255, 255, 0.55); z-index: 11; pointer-events: none; }
.joystick .stick { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); }
.carry-bar { position: fixed; left: 50%; bottom: calc(70px + var(--safe-b)); transform: translateX(-50%); z-index: 13; display: flex; gap: 6px; padding: 6px; border-radius: 12px; background: var(--concrete); border: 1px solid var(--line); box-shadow: var(--shadow); }

.toast {
  position: fixed; left: 50%; top: calc(84px + var(--safe-t)); transform: translate(-50%, -8px); z-index: 50;
  padding: 9px 16px 7px; border-radius: 999px; background: var(--graphite); color: #fff; font-weight: 600;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- loader */
#loader { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--concrete); transition: opacity 0.7s ease; }
#loader.done { opacity: 0; pointer-events: none; }
.loader-inner { width: min(460px, 86vw); display: grid; justify-items: start; gap: 6px; }
#loader-plan { width: 100%; height: auto; margin-bottom: 16px; overflow: visible; }
#loader-plan .wall { fill: var(--graphite); opacity: 0; }
#loader-plan .outline { fill: none; stroke: var(--graphite); stroke-width: 0.35; }
#loader-plan .win { stroke: var(--concrete); stroke-width: 0.6; }
#loader-plan .label { font: 700 2.3px 'Overpass', sans-serif; fill: #e0612f; letter-spacing: 0.02em; }
#loader-plan .dim { font: 500 1.7px 'Overpass', sans-serif; fill: var(--graphite); }
.loader-title { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.loader-sub { color: var(--ink-soft); font-size: 15px; }
.loader-bar { width: 100%; height: 3px; background: rgba(36, 41, 46, 0.12); border-radius: 3px; margin-top: 18px; overflow: hidden; }
.loader-bar span { display: block; height: 100%; width: 0; background: var(--signal); transition: width 0.25s; }
.loader-status { color: var(--steel); font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- responsive */
.only-touch { display: none; }
@media (pointer: coarse) { .only-touch { display: block; } .only-desk { display: none; } }

@media (max-width: 760px) {
  :root { font-size: 13.5px; }
  #topbar { top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); }
  .brand { min-width: 0; padding: 7px 11px 6px; }
  .brand-title { font-size: 15px; }
  .top-actions { gap: 5px; padding: 4px; }
  .seg-btn { padding: 0 10px; }
  #share { padding: 0 10px; }
  .board { left: calc(8px + var(--safe-l)); bottom: calc(8px + var(--safe-b)); width: auto; max-width: calc(100% - 16px); }
  .board-main { padding: 8px 12px 7px; gap: 10px; }
  .board-time { font-size: 28px; }
  .board-trains { display: none; }
  .board.expanded { right: calc(8px + var(--safe-r)); }
  body.sheet-open .board, body.sheet-open .fab { display: none; }
  .board.expanded .board-trains { display: grid; }
  .panel-left, .panel-right, .sheet-left {
    top: auto; left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); bottom: calc(8px + var(--safe-b)); width: auto;
    max-height: 56%; border-radius: 16px;
  }
  .panel-left { height: 56%; }
  .panel-right { padding: 12px; }
  .ins-actions { grid-template-columns: repeat(4, 1fr); }
  .ins-actions .btn span { font-size: 12.5px; }
  .ins-actions .btn { padding: 0 6px; }
  .fab { top: auto; left: auto; right: calc(8px + var(--safe-r)); bottom: calc(8px + var(--safe-b)); }
  .help-cols { grid-template-columns: 1fr; gap: 6px; }
  .popover { top: calc(62px + var(--safe-t)); right: calc(8px + var(--safe-r)); }
  .hint { bottom: calc(76px + var(--safe-b)); font-size: 12.5px; }
  .toast { top: calc(66px + var(--safe-t)); }
}

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