/* Takt: rail networks as strings.
   Colour tokens are written onto :root by src/js/theme.js so the canvas and the
   chrome can never drift apart. The values here are the light defaults. */

:root {
  --bg: #f3f5f7;
  --ink: #16232f;
  --muted: #5b6c7c;
  --line: rgba(22, 35, 47, .14);
  --chip: rgba(243, 245, 247, .90);
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Bricolage Grotesque", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  overflow: hidden;
  transition: background .2s, color .2s;
}
[hidden] { display: none !important; }

/* ---------- layout ---------- */
#wrap { display: flex; height: 100%; overflow: hidden; }
#main { flex: 1; min-width: 0; position: relative; }
#c {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; touch-action: none; cursor: crosshair;
}

#top {
  position: absolute; left: 28px; top: 22px; right: 28px;
  display: flex; justify-content: space-between; gap: 20px; pointer-events: none;
}
#top > * { pointer-events: auto; }
h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.01em; }

/* The logo: white on the dark theme, dark on the light one (theme.js swaps it). */
.brand { display: flex; align-items: center; gap: 7px; }
.brand .logo { flex-shrink: 0; display: block; }
.startlogo { display: block; margin: 0 auto 10px; }
#clock {
  font-size: clamp(52px, 7vw, 96px); font-weight: 300; line-height: .95;
  letter-spacing: -.03em; font-variation-settings: "opsz" 96; display: flex; margin-top: 4px;
}
#clock span { display: inline-block; width: .56em; text-align: center; }
#clock span.c { width: .28em; }
#tcount { font-size: 15px; margin-top: 4px; font-variant-numeric: tabular-nums; color: var(--muted); }
#tcountsub, #daynote { font-size: 13px; color: var(--muted); }
#daynote { margin-top: 2px; max-width: 42ch; }

/* Each mode shows only its own controls. */
body[data-mode="live"] [data-only="replay"],
body[data-mode="replay"] [data-only="live"] { display: none !important; }

.days { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.toprow { display: flex; gap: 6px; align-items: center; }
.ctry {
  display: flex; gap: 4px; background: var(--chip);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px;
}
.ctry button {
  font: inherit; font-size: 13.5px; border: 0; background: none; color: var(--ink);
  border-radius: 999px; padding: 5px 12px; cursor: pointer;
}
.ctry button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.ctry button:disabled { opacity: .5; cursor: default; }
#modes { margin-right: 4px; }
#startmodes { display: inline-flex; margin: 4px 0 2px; }
#startmodes button { font-size: 15px; padding: 6px 18px; }

/* Replay: the recorded days of a country, and a day bar you can scrub. */
#daybtns { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.dayb {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--chip);
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px;
  cursor: pointer; text-align: left; min-width: 230px;
}
.dayb b { display: block; font-weight: 600; }
.dayb small { color: var(--muted); }
.dayb[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.dayb[aria-pressed="true"] small { color: inherit; opacity: .7; }
body[data-mode="replay"] #bar { cursor: pointer; touch-action: none; }


/* ---------- theme switch ---------- */
#togtheme, #togfull {
  flex-shrink: 0; width: 34px; height: 34px; padding: 0;
  display: grid; place-items: center; border-radius: 999px;
  background: var(--chip); border: 1px solid var(--line); color: var(--ink); cursor: pointer;
}
#togtheme svg, #togfull svg { display: block; }
#togfull[hidden] { display: none; }
#togfull .leave, #togfull[aria-pressed="true"] .enter { display: none; }
#togfull[aria-pressed="true"] .leave { display: block; }
#togtheme .moon { display: none; }
:root[data-theme="dark"] #togtheme .sun { display: none; }
:root[data-theme="dark"] #togtheme .moon { display: block; }

/* Shown while the browser holds the sound back (after a call, the lock screen,
   or a tap that came too early): one tap brings it back. */
#tapsound {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 7;
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; font-size: 15px;
  background: var(--ink); color: var(--bg); border-color: var(--ink); box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
#tapsound[hidden] { display: none; }

/* ---------- bottom bar ---------- */
#bottom {
  position: absolute; left: 28px; right: 28px; bottom: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
#key {
  display: flex; flex-wrap: wrap; gap: 2px 12px;
  font-size: 11.5px; line-height: 1.5; color: var(--muted);
}
#key span { display: inline-flex; align-items: center; gap: 5px; }
#key i { display: inline-block; width: 13px; height: 3px; border-radius: 2px; }
#key i.grad { width: 40px; height: 4px; }
#key i.dot { width: 7px; height: 7px; border-radius: 50%; }
#key i.ring {
  width: 8px; height: 8px; border-radius: 50%;
  background: none !important; border: 1.4px solid var(--muted);
}
#key i.ring.dash { border-style: dashed; }

#bar { position: relative; height: 46px; }
#profile { position: absolute; left: 0; right: 0; top: 0; height: 22px; }
#profile svg { display: block; width: 100%; height: 100%; }
#profile path { fill: var(--line); }
#bar .track { position: absolute; left: 0; right: 0; top: 24px; height: 2px; background: var(--line); }
#bar .fill { position: absolute; left: 0; top: 24px; height: 2px; background: var(--ink); }
#bar .knob {
  position: absolute; top: 18px; width: 14px; height: 14px; margin-left: -7px;
  border-radius: 50%; background: var(--ink);
}
#bar .ticks {
  position: absolute; left: 0; right: 0; top: 30px; display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}

.ctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* The credit line sits under the buttons, centred. */
.ctl .foot { font-size: 12px; color: var(--muted); width: 100%; text-align: center; }
.ctl .foot a, #credits .foot { color: var(--muted); }
#credits .foot { font-size: 12px; margin-top: 28px; }
.b {
  white-space: nowrap; font: inherit; font-size: 14px; color: var(--ink);
  background: var(--chip); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 14px; cursor: pointer;
}
.b[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.b.icon { padding: 5px 10px; display: inline-flex; align-items: center; }
.ctl .b.icon { align-self: stretch; justify-content: center; }   /* as tall as the text buttons */
#play { font-size: 18px; padding: 5px 12px; }
.gap { flex: 1; }
#hint { font-size: 13px; color: var(--muted); }
button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible {
  outline: 2px solid #2b7bd6; outline-offset: 2px;
}

/* ---------- strings panel ---------- */
#side {
  width: 320px; flex-shrink: 0; will-change: width; background: var(--chip);
  border-left: 1px solid var(--line); color: var(--ink);
  display: flex; flex-direction: column; overflow: hidden; transition: width .25s;
}
#side.closed { width: 0; border: 0; }
#sidehead {
  display: flex; align-items: baseline; gap: 8px;
  padding: 12px 12px 6px; flex-shrink: 0;
}
#sidehead h2 { margin: 0; font-size: 15px; font-weight: 600; }
#scount { font-size: 12px; color: var(--muted); }
#sidehead .gap { flex: 1; }
#sidehead .b { font-size: 11px; padding: 2px 8px; }
#sidesearch { padding: 0 12px 8px; flex-shrink: 0; }
#ssearch {
  width: 100%; font: inherit; font-size: 13px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 6px;
  background: transparent; color: var(--ink); outline: none;
}
#slist { flex: 1; overflow-y: auto; overflow-x: hidden; font-size: 13px; }

.grp > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--line); background: var(--chip);
  position: sticky; top: 0; z-index: 1; user-select: none;
}
.grp > summary::-webkit-details-marker { display: none; }
.grp > summary::before {
  content: ""; width: 0; height: 0; flex-shrink: 0;
  border-left: 4px solid currentColor; border-top: 3.5px solid transparent;
  border-bottom: 3.5px solid transparent; transition: transform .15s;
}
.grp[open] > summary::before { transform: rotate(90deg); }
.grp > summary:hover { color: var(--ink); }
.grp .gname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp .gcount { font-variant-numeric: tabular-nums; opacity: .8; }

.sl {
  position: relative; display: grid; color: var(--ink);
  grid-template-columns: 10px 1fr 52px 40px; gap: 6px; align-items: center;
  padding: 5px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
  transition: background .15s;
}
.sl:hover, .sl.solo { background: var(--line); }
.sl i { width: 8px; height: 8px; border-radius: 50%; }
.sl .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.sl .op { opacity: .5; font-size: 11px; }
.sl .nt {
  font-variant-numeric: tabular-nums; text-align: right; font-size: 12px;
  color: var(--muted); white-space: nowrap;
}
.sl .bar {
  grid-column: 1 / 5; height: 3px; background: var(--line);
  border-radius: 2px; overflow: hidden; margin-top: -2px;
}
.sl .bar span { display: block; height: 100%; border-radius: 2px; }
.sl.muted { opacity: .2; }

/* ---------- advanced panel ---------- */
#adv {
  position: absolute; right: 28px; bottom: 116px; width: 286px;
  max-height: calc(100% - 200px); overflow-y: auto;
  background: var(--chip); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px 14px; display: none; color: var(--ink); font-size: 13px;
  backdrop-filter: blur(8px);
}
#adv.on { display: block; }
#adv header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#adv h3 { margin: 0; font-size: 14px; font-weight: 600; flex: 1; }
#adv h4 {
  margin: 12px 0 4px; font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
#adv label { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 5px 0; }
#adv input[type="range"] { width: 118px; accent-color: var(--ink); flex-shrink: 0; }
#adv .seg { display: flex; gap: 4px; }
#adv .seg .b { flex: 1; font-size: 12.5px; padding: 4px 8px; text-align: center; }
#adv .note { font-size: 11.5px; color: var(--muted); margin: 5px 0 0; line-height: 1.35; }
#adv .row { display: flex; gap: 6px; margin-top: 12px; }
#adv .row .b { flex: 1; font-size: 12.5px; text-align: center; }
#adv .toggle { display: flex; justify-content: space-between; align-items: center; margin: 5px 0; }
#adv .sub { margin: 8px 0 4px; }
#play .off { display: none; }
#pause .hold, #pause[data-playing="true"] .go { display: none; }
#pause[data-playing="true"] .hold { display: block; }
#play[aria-pressed="true"] .on { display: none; }
#play[aria-pressed="true"] .off { display: block; }
#adv .toggle .b { font-size: 12.5px; padding: 3px 12px; }
#adv input[type="number"] {
  width: 72px; font: inherit; font-size: 13px; color: var(--ink); background: var(--chip);
  border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; flex-shrink: 0;
}
#adv .oscrow { display: flex; align-items: center; gap: 10px; margin: 6px 0 0; }
#adv .oscrow .b { font-size: 12.5px; padding: 3px 12px; }
#oscstat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
#oscstat i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
#oscstat[data-s="on"] i { background: #2a9d55; }
#oscstat[data-s="connecting"] i, #oscstat[data-s="waiting"] i { background: #d9a400; }
#adv code { font-size: 11px; }

/* ---------- overlays ---------- */
#start {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: var(--bg); z-index: 10;
}
#start > div { max-width: 46ch; text-align: center; padding: 20px; }
#start p { color: var(--muted); margin: 8px 0 18px; }
#start .sub { font-size: 17px; margin: -4px 0 12px; font-weight: 400; }
#start button#go {
  font: inherit; font-size: 18px; font-weight: 600; color: var(--bg);
  background: var(--ink); border: 0; border-radius: 999px; padding: 12px 28px; cursor: pointer;
}
#start button#go:disabled { opacity: .6; cursor: default; }
#start .cred { font-size: 13px; margin-top: 14px; }
#start .cred a { color: var(--muted); }
#starterr { color: #d62839; font-size: 13px; min-height: 1.4em; margin-top: 10px; }

#credits {
  position: absolute; inset: 0; display: grid; place-items: start center;
  background: var(--bg); overflow-y: auto; z-index: 20; padding: 30px 0;
}
#credits > div { max-width: 58ch; padding: 10px 24px 40px; }
#credits h1 { margin: 0 0 12px; }
#credits h3 { margin: 18px 0 6px; font-size: 15px; }
#credits p, #credits li { font-size: 14px; color: var(--muted); line-height: 1.55; margin: 4px 0; }
#credits a { color: #2b7bd6; }
#credits ul { padding-left: 18px; }
#credits .b { margin-top: 20px; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  #side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 5; }
}
@media (max-width: 820px) {
  #adv { right: 14px; bottom: 104px; width: 240px; }
}
@media (max-width: 760px) {
  #top { left: 14px; right: 14px; top: 12px; flex-direction: column; gap: 10px; }
  /* Name and counts on the left, the clock beside them, so the map keeps the screen. */
  #top > div:first-child { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; }
  #clock { grid-column: 2; grid-row: 1 / span 3; font-size: 44px; margin: 0; }
  h1 { font-size: 18px; }
  #tcount { font-size: 13.5px; margin-top: 0; }
  #tcountsub { font-size: 12px; }
  .days { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; }
  .ctry button { font-size: 13px; padding: 4px 10px; }
  .toprow { flex-wrap: wrap; }
  .ctry button { white-space: nowrap; }
  /* The country and view pickers each get a line of their own and share it
     out, so five countries (replay) or five views (United States) fit on one line. */
  #ctry, #views { width: 100%; gap: 2px; }
  #ctry button, #views button { flex: 1 1 auto; padding: 4px 2px; font-size: 12px; }
  #daynote { display: none; }
  #daybtns { flex-direction: row; width: 100%; }
  .dayb { min-width: 0; flex: 1; padding: 6px 9px; font-size: 12.5px; }
  #togtheme, #togfull { width: 32px; height: 32px; }
  #bottom { left: 14px; right: 14px; bottom: 10px; gap: 6px; }
  #key { font-size: 11px; gap: 0 9px; }
  /* Every button on one line; the credit line goes underneath, centred. */
  .ctl { gap: 5px; }
  .b, .b.icon { padding: 4px 8px; font-size: 12.5px; }
  .ctl .foot { width: 100%; font-size: 11px; text-align: center; }
  #hint { display: none; }
  #side { width: 100%; }
  #adv { left: 10px; right: 10px; top: 10px; bottom: 10px; width: auto; max-height: none; z-index: 6; font-size: 14px; }
  #adv input[type="range"] { width: 45%; }
}
/* The narrowest phones: a little less room around each button keeps replay's
   seven on one line. */
@media (max-width: 380px) {
  .ctl { gap: 4px; }
  .b, .b.icon { padding: 4px 6px; font-size: 12px; }
  #ctry button, #views button { padding: 4px 2px; font-size: 11px; }
}
/* A phone held sideways: the header becomes a column on the left of the map. */
@media (max-height: 520px) and (orientation: landscape) {
  #top { left: 14px; right: auto; top: 10px; width: 200px; flex-direction: column; gap: 8px; }
  #top > div:first-child { display: block; }
  #clock { font-size: 40px; }
  .days { flex-direction: column; align-items: flex-start; }
  #daynote { display: none; }
  #daybtns { align-items: stretch; width: 100%; }
  .dayb { min-width: 0; padding: 5px 9px; font-size: 12px; }
  #key { display: none; }
  #bottom { left: 14px; right: 14px; bottom: 6px; gap: 2px; }
  #adv { left: auto; right: 10px; width: 320px; }
}

#views[hidden] { display: none; }
