/* Metro Weave — Mini Metro feel, Apple HIG / Swiss typographic discipline. */

:root {
  --bg: #f4f2ee;            /* warm paper, Mini Metro daylight */
  --surface: #ffffff;
  --ink: #1c1c1e;
  --ink-2: #6e6e73;
  --ink-3: #a1a1a6;
  --hair: rgba(0, 0, 0, 0.12);
  --hair-strong: rgba(0, 0, 0, 0.22);
  --node-fill: #ffffff;
  --node-stroke: #1c1c1e;
  --ghost: #d8d5cf;         /* unfinished lines on the network map */
  --accent: #1c1c1e;        /* a single restrained accent: ink */
  --danger: #d0342c;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Inter, system-ui, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --surface: #1f1f1f;
    --ink: #f2f2f2;
    --ink-2: #a1a1a6;
    --ink-3: #6e6e73;
    --hair: rgba(255, 255, 255, 0.14);
    --hair-strong: rgba(255, 255, 255, 0.26);
    --node-fill: #161616;
    --node-stroke: #f2f2f2;
    --ghost: #3a3a3a;
    --accent: #f2f2f2;
    --danger: #ff5b52;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; }
h1, h2, h3, p, dl { margin: 0; }
.hidden { display: none !important; }

/* ---------- Home ---------- */
.screen { min-height: 100%; }
#home { padding: 40px 32px 48px; max-width: 1280px; margin: 0 auto; }

.masthead h1 {
  font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.05;
}
.masthead .sub { margin-top: 8px; color: var(--ink-2); font-size: 17px; }

.home-grid {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.85fr);
  gap: 24px; margin-top: 32px; align-items: start;
}
@media (max-width: 860px) {
  #home { padding: 28px 16px 40px; }
  .masthead h1 { font-size: 32px; }
  .home-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
}
.map-card { padding: 16px; }
#netmap { display: block; width: 100%; aspect-ratio: 1.15; }
@media (max-width: 860px) { #netmap { aspect-ratio: 1; } }

.caption { color: var(--ink-2); font-size: 13px; }
.map-card .caption { margin-top: 12px; }

.lines-card { padding: 8px 0 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 20px 8px; }
.card-head h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }

.lines { list-style: none; margin: 0; padding: 0; }
.lines li + li { border-top: 1px solid var(--hair); }
.line-btn {
  width: 100%; display: grid; grid-template-columns: 36px 1fr auto; column-gap: 14px; align-items: center;
  padding: 12px 20px; min-height: 60px; background: none; border: 0; text-align: left; cursor: pointer;
}
.line-btn:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.line-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.line-btn .swatch-line { width: 36px; height: 8px; border-radius: 4px; }
.line-btn.is-branch .swatch-line { height: 5px; width: 28px; margin-left: 4px; }
.line-btn .name { font-weight: 600; font-size: 15px; }
.line-btn .ends { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.line-btn .meta { text-align: right; color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.line-btn .meta .best { color: var(--ink); font-weight: 500; }
.line-btn .meta .star { letter-spacing: 1px; }

.settings { margin: 16px 20px 0; border-top: 1px solid var(--hair); padding-top: 12px; }
.setting { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.setting-label { font-size: 14px; }
.segmented { display: inline-flex; border: 1px solid var(--hair-strong); border-radius: 8px; overflow: hidden; }
.segmented button {
  background: none; border: 0; padding: 0 14px; min-height: 34px; font-size: 13px; cursor: pointer; color: var(--ink-2);
}
.segmented button + button { border-left: 1px solid var(--hair-strong); }
.segmented button[aria-checked="true"] { background: var(--ink); color: var(--bg); }
.text-btn { background: none; border: 0; min-height: 44px; padding: 0 4px; color: var(--ink-2); cursor: pointer; font-size: 14px; }
.text-btn:hover { color: var(--ink); }
.footnote { margin: 12px 20px 0; }

/* ---------- Play ---------- */
#play { position: relative; display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.playbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--hair); background: var(--surface); min-height: 56px;
}
.icon-btn {
  display: inline-flex; align-items: center; gap: 2px; background: none; border: 0; min-height: 44px; padding: 0 8px 0 2px;
  border-radius: 8px; cursor: pointer; justify-self: start; font-size: 15px;
}
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.play-title { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; white-space: nowrap; }
.play-title .swatch { width: 22px; height: 8px; border-radius: 4px; background: var(--ink-3); display: inline-block; }
.stats { display: flex; gap: 20px; justify-self: end; }
.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.stat-k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-2); }
.stat-v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .playbar { grid-template-columns: auto 1fr auto; gap: 8px; }
  .play-title { font-size: 14px; }
  .play-title #lineName { overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
  .stats { gap: 12px; }
  .icon-btn span { display: none; }
}

#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; user-select: none; -webkit-user-select: none; }
#map.dragging { cursor: grabbing; }
#map.pointing { cursor: pointer; }

.map-tools { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 8px; }
.tool {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--hair); border-radius: 10px; cursor: pointer; color: var(--ink);
}
.tool:hover { border-color: var(--hair-strong); }

/* SVG parts */
.rail { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.node { fill: var(--node-fill); stroke: var(--node-stroke); stroke-width: 3; }
.node.inter { stroke-width: 3.5; }
.node { transform-box: fill-box; transform-origin: center; }
.node.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.node-g { transform-box: fill-box; transform-origin: center; }
.label {
  font-family: var(--font); font-size: 12px; font-weight: 500; fill: var(--ink); paint-order: stroke;
  stroke: var(--bg); stroke-width: 3.5px; stroke-linejoin: round; pointer-events: none;
}
.label.dim { fill: var(--ink-2); font-weight: 400; }
.label.head { font-weight: 700; }
.ghost { fill: none; stroke: var(--ghost); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.ghost-node { fill: var(--bg); stroke: var(--ghost); stroke-width: 1.5; }
.mini-node { fill: var(--node-fill); stroke: var(--node-stroke); stroke-width: 1.6; }
.train { stroke: none; }

.statusbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--hair); background: var(--surface); min-height: 60px;
}
.msg { font-size: 15px; color: var(--ink); }
.msg.err { color: var(--danger); }
.actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn {
  min-height: 40px; padding: 0 16px; border-radius: 9px; border: 1px solid var(--hair-strong); background: var(--surface);
  cursor: pointer; font-size: 14px; font-weight: 500;
}
.btn:hover { border-color: var(--ink-3); }
.btn.subtle { border-color: transparent; color: var(--ink-2); }
.btn.subtle:hover { color: var(--ink); border-color: var(--hair); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Completion sheet */
.sheet {
  position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center;
  padding: 16px; pointer-events: none;
}
.sheet-card {
  pointer-events: auto; width: min(420px, 100%); background: var(--surface); border: 1px solid var(--hair);
  border-radius: 14px; padding: 20px 20px 18px; margin-bottom: 72px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  animation: rise 0.35s cubic-bezier(.2,.7,.2,1);
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-2); }
.sheet h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.015em; margin-top: 4px; }
.stars { margin-top: 8px; font-size: 18px; letter-spacing: 3px; color: var(--ink); }
.stars .off { color: var(--ink-3); }
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--hair); }
.results dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-2); }
.results dd { margin: 2px 0 0; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.sheet .caption { margin-top: 10px; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
  .node.shake, .sheet-card { animation: none; }
}
