/* Styled after Norwegian platform displays: deep navy, white text, yellow for changes. */
:root {
  --bg: #0a1a33;
  --panel: #10264a;
  --panel-2: #163160;
  --line: #24406f;
  --text: #ffffff;
  --muted: #9fb3d4;
  --yellow: #ffd200;
  --red: #ff5a5a;
  --green: #3ccf7a;
  --orange: #ffa23a;
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Arial, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; display: flex; flex-direction: column; }

a { color: inherit; text-decoration: none; }
s { text-decoration-thickness: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: #061226;
  border-bottom: 2px solid var(--line);
}
.topbar-title {
  flex: 1; margin: 0; font-size: 1.25rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.clock { font-variant-numeric: tabular-nums; font-size: 1.15rem; font-weight: 600; letter-spacing: .02em; }
.back {
  appearance: none; border: 0; background: transparent; color: var(--text);
  font-size: 2rem; line-height: 1; padding: 0 8px 4px 0; cursor: pointer;
}

main { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; }

.footer {
  padding: 8px 16px calc(8px + var(--safe-bottom));
  font-size: .75rem; color: var(--muted); text-align: center;
  border-top: 1px solid var(--line);
}
.footer .error { color: var(--orange); }

/* ---------- Home ---------- */
.search { display: block; }
.search-label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .08em; }
input[type="search"] {
  width: 100%; padding: 14px 14px; font-size: 1.1rem;
  border-radius: var(--radius); border: 2px solid var(--line);
  background: var(--panel); color: var(--text); outline: none;
}
input[type="search"]:focus { border-color: var(--yellow); }

.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px; margin-bottom: 6px;
  background: var(--panel); border-radius: var(--radius);
}
.list-item:active { background: var(--panel-2); }
.li-main { font-weight: 600; font-size: 1.05rem; }
.li-sub { font-size: .85rem; color: var(--muted); }
.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 24px 0 8px; font-weight: 600; }
.hint { color: var(--muted); font-size: .9rem; line-height: 1.5; margin-top: 24px; }
.empty, .loading { color: var(--muted); padding: 16px 4px; list-style: none; }
.big { font-size: 1.1rem; text-align: center; padding: 48px 8px; }

/* ---------- Board ---------- */
.board-tools { display: flex; gap: 8px; margin-bottom: 10px; }
.board-tools input { flex: 1; font-size: 1rem; padding: 12px; }
.fav {
  appearance: none; border: 2px solid var(--line); background: var(--panel); color: var(--yellow);
  font-size: 1.4rem; width: 52px; border-radius: var(--radius); cursor: pointer;
}
.board-head {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) 52px; gap: 10px;
  padding: 6px 10px; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  border-bottom: 2px solid var(--line);
}
.r { text-align: right; }
.board-rows { list-style: none; margin: 0; padding: 0; }
.board-row {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) 52px; gap: 10px; align-items: center;
  padding: 12px 10px; border-bottom: 1px solid var(--line);
}
.board-row:active { background: var(--panel); }
.board-row.is-cancelled .br-to, .board-row.is-cancelled .br-time { color: var(--muted); text-decoration: line-through; }
.br-time { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.br-time.struck { text-decoration: line-through; text-decoration-color: var(--yellow); color: var(--muted); }
.br-dest { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.br-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.br-to { font-size: 1.15rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.br-meta b { color: var(--text); font-weight: 600; }
.br-meta { font-size: .8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.br-track {
  justify-self: end; min-width: 40px; height: 40px; padding: 0 6px;
  display: grid; place-items: center; font-size: 1.3rem; font-weight: 800;
  background: var(--text); color: var(--bg); border-radius: 6px;
}
.br-track.changed, .track.changed { background: var(--yellow); color: #000; }
.remark { font-weight: 700; padding: 1px 6px; border-radius: 4px; }
.remark.late { background: var(--yellow); color: #000; }
.remark.cancel { background: var(--red); color: #fff; }

.line-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.6em; padding: 2px 7px; border-radius: 5px;
  font-weight: 800; font-size: .95rem; letter-spacing: .02em; flex: none;
}

/* ---------- Situations / notices ---------- */
.situations { margin: 10px 0; display: flex; flex-direction: column; gap: 6px; }
.situation { background: #3a3000; border-left: 4px solid var(--yellow); border-radius: 6px; padding: 10px 12px; }
.situation summary { cursor: pointer; font-weight: 600; color: var(--yellow); }
.situation p { margin: 8px 0 0; line-height: 1.45; color: #f5ecc0; }
.notices { background: var(--panel); border-radius: var(--radius); padding: 4px 12px; margin: 10px 0; color: var(--muted); }

/* ---------- Train screen (platform display) ---------- */
.screen {
  background: #061226; border: 2px solid var(--line); border-radius: 14px;
  overflow: hidden;
}
.screen-top { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px; padding: 16px; position: relative; }
.track {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--text); color: var(--bg); border-radius: 10px;
  width: 84px; min-height: 96px; padding: 6px;
}
.track-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.track-no { font-size: 3rem; font-weight: 900; line-height: 1; }
.screen-main { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.screen-times { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }
.time-big { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.time-big.struck { font-size: 1.6rem; color: var(--muted); text-decoration: line-through; text-decoration-color: var(--yellow); }
.newtime { font-size: 1.6rem; font-weight: 800; color: #000; background: var(--yellow); padding: 2px 8px; border-radius: 5px; }
.newtime.cancel { background: var(--red); color: #fff; }
.screen-dest { display: flex; align-items: center; gap: 10px; min-width: 0; }
.screen-dest .line-badge { font-size: 1.15rem; }
.dest-name { font-size: 1.9rem; font-weight: 800; line-height: 1.1; overflow-wrap: anywhere; }
.screen-via { color: var(--muted); font-size: 1rem; }
.countdown {
  grid-column: 1 / -1;
  justify-self: start; font-size: 1.05rem; font-weight: 700;
  background: var(--panel-2); padding: 4px 10px; border-radius: 6px;
}
.screen.is-cancelled .dest-name { text-decoration: line-through; color: var(--muted); }

.banner { padding: 10px 16px; font-weight: 700; }
.banner.warn { background: var(--yellow); color: #000; }

.ticker {
  display: flex; align-items: stretch; background: var(--yellow); color: #000; overflow: hidden;
}
.ticker-label {
  flex: none; background: #000; color: var(--yellow); padding: 10px 12px;
  font-weight: 800; text-transform: uppercase; font-size: .8rem; letter-spacing: .06em;
  display: flex; align-items: center;
}
.ticker-track { flex: 1; overflow: hidden; display: flex; align-items: center; }
.ticker-text {
  display: inline-block; white-space: nowrap; padding-left: 100%;
  font-weight: 700; font-size: 1.05rem;
  animation: ticker 28s linear infinite;
  animation-delay: -7s; /* text visible immediately */
}
@keyframes ticker { from { transform: translateX(0); } to { transform: translateX(-100%); } }
@media (prefers-reduced-motion: reduce) {
  .ticker-text { animation: none; padding-left: 12px; white-space: normal; }
}

/* ---------- Facts grid ---------- */
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.fact {
  background: var(--panel); border-radius: var(--radius); padding: 12px;
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.fact.wide { grid-column: 1 / -1; }
.fact-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.fact-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.fact-value.pos { font-size: 1.2rem; }
.fact-sub { font-size: .85rem; color: var(--muted); }
.dim { color: var(--muted); }
.late-text { color: var(--yellow); }

/* ---------- Occupancy ---------- */
.occ { display: inline-flex; align-items: center; gap: 8px; }
.occ-people { display: inline-flex; gap: 2px; }
.person {
  width: 9px; height: 16px; position: relative; opacity: .25;
  background:
    radial-gradient(circle at 50% 3px, currentColor 3px, transparent 3.5px) top / 9px 7px no-repeat,
    linear-gradient(currentColor, currentColor) bottom / 9px 8px no-repeat;
  border-radius: 0 0 2px 2px;
}
.person.on { opacity: 1; }
.occ-1 { color: var(--green); }
.occ-2 { color: var(--yellow); }
.occ-3 { color: var(--orange); }
.occ-4 { color: var(--red); }
.occ-0 { color: var(--muted); }
.occ-label { font-size: .8rem; }
.occ-lg .person { width: 14px; height: 24px; background:
  radial-gradient(circle at 50% 4.5px, currentColor 4.5px, transparent 5px) top / 14px 10px no-repeat,
  linear-gradient(currentColor, currentColor) bottom / 14px 12px no-repeat; }
.occ-lg .occ-label { font-size: 1.1rem; font-weight: 700; color: var(--text); }

/* ---------- Stop list ---------- */
.stops { list-style: none; margin: 0; padding: 0; position: relative; }
.stop {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; grid-template-areas:
    "dot name time"
    "dot track time";
  column-gap: 10px; row-gap: 2px; padding: 10px 0; position: relative;
}
.stop::before {
  content: ""; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: var(--line);
}
.stop:first-child::before { top: 50%; }
.stop:last-child::before { bottom: 50%; }
.stop.passed::before { background: var(--muted); }
.stop-dot {
  grid-area: dot; align-self: center; justify-self: center; z-index: 1;
  width: 12px; height: 12px; border-radius: 50%; background: var(--bg); border: 2px solid var(--muted);
}
.stop.passed .stop-dot { background: var(--muted); }
.stop.current .stop-dot { background: var(--yellow); border-color: var(--yellow); box-shadow: 0 0 0 5px rgba(255,210,0,.25); }
.stop.here .stop-dot { width: 16px; height: 16px; border-color: var(--text); border-width: 3px; }
.stop.here { background: var(--panel); border-radius: var(--radius); }
.stop.here .stop-name { font-weight: 800; }
.stop-name { grid-area: name; font-size: 1rem; font-weight: 600; min-width: 0; }
.stop-name em { font-style: normal; color: var(--red); font-size: .85rem; }
.stop-name em.now { color: var(--yellow); }
.stop-time { grid-area: time; align-self: center; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; padding-right: 8px; }
.stop-track { grid-area: track; font-size: .8rem; color: var(--muted); }
.stop-track.changed { color: var(--yellow); font-weight: 700; }
.stop.passed .stop-name, .stop.passed .stop-time { color: var(--muted); }
.stop.cancelled .stop-name { text-decoration: line-through; }

/* Moving train marker between two stops */
.stop.train-after::after {
  content: "🚆"; position: absolute; left: 1px; bottom: -11px; z-index: 2; font-size: 15px;
  animation: bob 1.6s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(3px); } }

@media (min-width: 560px) {
  .facts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .fact.wide { grid-column: span 2; }
  .time-big { font-size: 3.2rem; }
  .dest-name { font-size: 2.4rem; }
}

/* ---------- Train formation ---------- */

/* Collapsible passed stops */
.stops.collapsed .stop.collapsible { display: none; }
.stop-toggle { position: relative; list-style: none; }
.stop-toggle::before {
  content: ""; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px;
  background: repeating-linear-gradient(var(--muted) 0 4px, transparent 4px 8px);
}
.stop-toggle button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 0; font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; text-align: left;
}
.stop-toggle .chev {
  flex: none; width: 22px; height: 22px; display: grid; place-items: center;
  position: relative; z-index: 1; font-size: .8rem; color: var(--text);
  background: var(--panel-2); border: 2px solid var(--line); border-radius: 50%;
  transition: transform .15s ease;
}
.stop-toggle button[aria-expanded="true"] .chev { transform: rotate(90deg); }
.stops.collapsed .toggle-hide, .stops:not(.collapsed) .toggle-show { display: none; }
