:root {
  --ink: #221e18;
  --muted: #5f584c;
  --paper: #f6f1e7;
  --paper-2: #efe8db;
  --line: #ddd4c4;
  --rule: #221e18;
  --delay: #9c3419;
  --delay-soft: #f8e6dc;
  --ok: #1e5c40;
  --desk: #d4cbbd;
  --shadow: 0 18px 50px rgba(55, 40, 16, 0.12);
  --serif: "Fraunces", "Iowan Old Style", Palatino, serif;
  --sans: "Schibsted Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  background:
    radial-gradient(ellipse at 0% -10%, rgba(255, 252, 245, 0.9), transparent 46%),
    radial-gradient(ellipse at 100% 110%, rgba(80, 58, 28, 0.16), transparent 42%),
    var(--desk);
}

button, a { font: inherit; color: inherit; }

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

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

.sheet {
  width: min(1120px, calc(100% - 24px));
  margin: 16px auto 32px;
  padding: 22px 18px 18px;
  background: var(--paper);
  border: 1px solid #c9bfae;
  box-shadow: var(--shadow);
}

.masthead {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-end;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
  box-shadow: 0 3px 0 var(--paper), 0 4px 0 var(--rule);
}

.brand { display: flex; gap: 14px; align-items: center; }

.mark {
  position: relative;
  width: 22px;
  height: 42px;
  flex: none;
}

.mark::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 7px;
  bottom: 7px;
  width: 1.5px;
  background: var(--ink);
  transform: translateX(-50%);
}

.mark span {
  position: absolute;
  left: 50%;
  width: 8px;
  height: 8px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  transform: translateX(-50%);
}

.mark span:first-child { top: 0; }
.mark span:last-child { bottom: 0; background: var(--ink); }

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 7vw, 4.4rem);
  font-weight: 560;
  letter-spacing: -0.035em;
  line-height: 0.86;
}

.mast-meta { text-align: right; }

.clock, .pulse { margin: 0; }

.clock {
  font-family: var(--mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.clock-label {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.pulse {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.lede {
  max-width: 62ch;
  margin: 18px 0 0;
  font-size: 1.05rem;
}

.ranges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 18px;
}

.ranges button { flex: 1 1 calc(50% - 6px); }

.ranges button,
.toolbar-actions button,
.toolbar-actions a {
  border: 1px solid var(--line);
  background: transparent;
  padding: 7px 12px;
  text-decoration: none;
}

.ranges button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.tickets {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 16px;
}

.ticket {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-height: 118px;
  padding: 14px 14px 12px 16px;
  text-align: left;
  background: var(--paper-2);
  border: 1px solid var(--line);
  overflow: hidden;
}

.ticket::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--ticket, var(--ink));
}

.ticket[data-line="470"] { --ticket: #234237; }
.ticket[data-line="470E"] { --ticket: #24344d; }

.ticket[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.ticket[aria-pressed="true"]::before { background: #e6c27a; }

.ticket-top, .ticket-route, .ticket-stat { display: block; }

.ticket-top {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.line-badge {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  border: 1px solid currentColor;
  padding: 1px 6px;
}

.dir {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.ticket[aria-pressed="true"] .dir { color: #d9d0c2; }

.ticket-route {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 560;
  letter-spacing: -0.02em;
  line-height: 1.12;
}

.ticket-stat {
  margin-top: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.ticket[aria-pressed="true"] .ticket-stat { color: #d9d0c2; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 16px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.stats div {
  padding: 12px 14px 10px 0;
}

.stats div:nth-child(even) { padding-left: 14px; }

.stats span {
  display: block;
  margin-bottom: 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.stats strong {
  font-family: var(--serif);
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  font-weight: 560;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 16px;
  align-items: center;
  margin-top: 14px;
}

.summary { margin: 0; color: var(--muted); }

.toolbar-actions { display: flex; gap: 8px; }

.toolbar-actions button:disabled { opacity: 0.55; cursor: wait; }

#log { margin-top: 8px; }

.day-group { margin: 0 0 8px; }

.day-group h2 {
  margin: 18px 0 0;
  padding-top: 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.day-group ol { list-style: none; margin: 0; padding: 0; }

.entry {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "when delay"
    "route route"
    "meta meta";
  gap: 3px 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.when { grid-area: when; display: flex; align-items: center; gap: 8px; }

.entry time {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

.route { grid-area: route; }

.route strong { font-weight: 600; }

.sign {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.delay {
  grid-area: delay;
  justify-self: end;
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

.delay small {
  display: block;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.delay.late, .delay.cancel { color: var(--delay); }
.delay.ok { color: var(--ok); }
.delay.unknown { color: var(--muted); }

.meta {
  grid-area: meta;
  color: var(--muted);
  font-size: 13px;
}

.stamp {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border: 1px solid var(--delay);
  color: var(--delay);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.empty {
  margin: 28px 0;
  padding: 22px;
  border: 1px dashed #c9bfae;
  color: var(--muted);
}

.empty strong { display: block; margin-bottom: 4px; color: var(--ink); font-weight: 600; }

.error { border-style: solid; border-color: var(--delay); background: var(--delay-soft); }

footer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

footer p { margin: 0 0 6px; }

.foot-row a { color: var(--ink); }

@media (max-width: 699px) {
  .masthead { flex-direction: column; align-items: flex-start; gap: 14px; }
  .mast-meta { text-align: left; }
  .pulse { max-width: 28ch; }
}

@media (min-width: 700px) {
  .sheet { padding: 32px 32px 22px; margin-top: 28px; }
  .ranges button { flex: 0 0 auto; }
  .tickets { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stats div { padding-left: 16px; }
  .stats div:first-child { padding-left: 0; }
  .stats div + div { border-left: 1px solid var(--line); }
}

@media (min-width: 980px) {
  .sheet { margin-top: 40px; margin-bottom: 56px; }
  .tickets { grid-template-columns: repeat(4, 1fr); }
  .entry {
    grid-template-columns: 7.2rem minmax(0, 1fr) 9.5rem;
    grid-template-areas: "when route delay" "when meta delay";
    align-items: center;
    column-gap: 18px;
  }
  .delay small { display: inline; margin-left: 6px; }
}

@media (prefers-color-scheme: dark) {
  body { background: #231f1a; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

@media print {
  body { background: white; }
  .sheet { width: 100%; margin: 0; border: 0; box-shadow: none; }
  .ranges, .toolbar-actions, .foot-row a { display: none; }
  .ticket { break-inside: avoid; }
  .entry { break-inside: avoid; }
}
