:root {
  --bg: #0a1420;
  --bg-elevated: #122335;
  --bg-elevated-2: #17293d;
  --border: #223a52;
  --border-soft: #1a2e42;
  --text: #f2f7fb;
  --text-dim: #8ea3b6;
  --text-faint: #5f7d92;
  --accent: #4fb0e8;
  --accent-dim: #1c3a4d;
  --green: #35d488;
  --green-dim: #0f2e21;
  --green-glow: rgba(53, 212, 136, 0.18);
  --yellow: #f5c451;
  --yellow-dim: #3a2f10;
  --yellow-glow: rgba(245, 196, 81, 0.16);
  --red: #f0564f;
  --red-dim: #3a1414;
  --red-glow: rgba(240, 86, 79, 0.18);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.25), 0 4px 16px rgba(0, 0, 0, 0.28);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(680px 420px at 50% -8%, rgba(79, 176, 232, 0.09), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 2.5rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.35rem 1.1rem 0.6rem;
}

.topbar h1 {
  font-size: 1.2rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: 0.01em;
}

.icon-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: scale(0.92); }

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.3rem;
  margin: 0.4rem 1.1rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
}

.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0.55rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.tab.active {
  color: #06222f;
  background: var(--accent);
  box-shadow: 0 4px 14px rgba(79, 176, 232, 0.35);
}

main {
  padding: 0 1.1rem;
}

.panel { display: none; }
.panel.active {
  display: block;
  animation: fadeIn 0.28s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.gauge {
  border-radius: var(--radius-lg);
  padding: 2rem 1.25rem;
  text-align: center;
  margin-bottom: 1.1rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
  position: relative;
  overflow: hidden;
}

.gauge::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 100% at 50% 0%, rgba(255, 255, 255, 0.05), transparent 55%);
  pointer-events: none;
}

.gauge--neutral { background: var(--bg-elevated); }

.gauge--green {
  background: linear-gradient(180deg, var(--green-dim), var(--bg-elevated) 75%);
  border-color: var(--green);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--green-glow), 0 0 32px -8px var(--green-glow);
}

.gauge--yellow {
  background: linear-gradient(180deg, var(--yellow-dim), var(--bg-elevated) 75%);
  border-color: var(--yellow);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--yellow-glow), 0 0 32px -8px var(--yellow-glow);
}

.gauge--red {
  background: linear-gradient(180deg, var(--red-dim), var(--bg-elevated) 75%);
  border-color: var(--red);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--red-glow), 0 0 32px -8px var(--red-glow);
}

.gauge-eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  position: relative;
}

.gauge-value {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-top: 0.3rem;
  position: relative;
  white-space: nowrap;
}

.gauge--green .gauge-value { color: var(--green); }
.gauge--yellow .gauge-value { color: var(--yellow); }
.gauge--red .gauge-value { color: var(--red); }

.gauge-sub {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  position: relative;
}

.gauge--green .gauge-sub { color: var(--green); border-color: rgba(53, 212, 136, 0.4); }
.gauge--yellow .gauge-sub { color: var(--yellow); border-color: rgba(245, 196, 81, 0.4); }
.gauge--red .gauge-sub { color: var(--red); border-color: rgba(240, 86, 79, 0.4); }

.banner {
  background: var(--yellow-dim);
  border: 1px solid var(--yellow);
  color: var(--yellow);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  font-size: 0.85rem;
  line-height: 1.4;
  margin-bottom: 1.1rem;
  animation: fadeIn 0.25s ease;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 1.1rem;
}

.option-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.option-item:active { transform: scale(0.99); }

.option-item--selected {
  border-color: var(--accent);
  background: var(--bg-elevated-2);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--accent);
}

.option-item--green { border-left-color: var(--green); }
.option-item--yellow { border-left-color: var(--yellow); }
.option-item--red { border-left-color: var(--red); }

.option-main { min-width: 0; }

.option-times {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.option-arrow { color: var(--text-faint); font-weight: 400; margin: 0 0.1rem; }

.option-sub {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

.option-recommended {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.option-status {
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.option-status--green { color: var(--green); }
.option-status--yellow { color: var(--yellow); }
.option-status--red { color: var(--red); }

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 1.1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 1.1rem 1rem 0.2rem;
  box-shadow: var(--shadow-1);
}

.tl-item {
  display: flex;
  gap: 0.85rem;
  align-items: stretch;
}

.tl-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 2.1rem;
  flex-shrink: 0;
}

.tl-icon {
  font-size: 1.05rem;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  z-index: 1;
}

.tl-line {
  position: relative;
  width: 3px;
  flex: 1;
  min-height: 26px;
  margin: 3px 0;
  background: var(--border);
  border-radius: 2px;
}

.tl-line-fill {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: height 0.5s ease;
}

.tl-marker {
  position: absolute;
  left: 50%;
  top: 0;
  width: 1.5rem;
  height: 1.5rem;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  line-height: 1;
  box-shadow: 0 0 0 4px var(--bg-elevated), 0 0 12px rgba(79, 176, 232, 0.5);
  transition: top 0.5s ease;
}

.tl-marker--moving { animation: markerPulse 1.6s ease-in-out infinite; }

@keyframes markerPulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--bg-elevated), 0 0 12px rgba(79, 176, 232, 0.5); }
  50% { box-shadow: 0 0 0 4px var(--bg-elevated), 0 0 20px rgba(79, 176, 232, 0.85); }
}

.tl-body {
  flex: 1;
  min-width: 0;
  padding-bottom: 1.15rem;
}

.tl-live-note {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 600;
  margin-top: 0.3rem;
}

.tl-live-note--muted {
  color: var(--text-faint);
  font-weight: 500;
  font-style: italic;
}

.tl-time {
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}

.tl-time .live-tag {
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 6px;
  padding: 0.08rem 0.35rem;
  margin-left: 0.4rem;
  vertical-align: middle;
  letter-spacing: 0.03em;
}

.tl-time .delay-tag {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--red);
  margin-left: 0.4rem;
}

.tl-desc {
  font-size: 0.84rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

.meta-row {
  font-size: 0.75rem;
  color: var(--text-faint);
  text-align: center;
  margin-top: 0.6rem;
}

.section-title {
  font-size: 1rem;
  color: var(--text-dim);
  font-weight: 700;
  margin: 0.6rem 0 1rem;
}

.map-shell {
  position: relative;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  height: min(70vh, 600px);
}

#mapView {
  width: 100%;
  height: 100%;
  background: var(--bg-elevated);
}

.map-live-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: rgba(10, 20, 32, 0.75);
  color: var(--text-dim);
  font-size: 0.75rem;
  line-height: 1;
  pointer-events: none;
}

.map-live-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.map-live-badge--stale::before {
  background: var(--red);
}

/* Vehicle markers reposition on every poll; a short transform transition
   makes them glide to the new fix instead of teleporting. */
.leaflet-marker-icon {
  transition: transform 0.9s linear;
}

.map-train-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  box-shadow: 0 0 10px rgba(79, 176, 232, 0.6);
}

.map-train-icon--late {
  border-color: var(--red);
  box-shadow: 0 0 10px rgba(240, 86, 79, 0.6);
}

/* Leaflet ships light-themed chrome by default; retint to match the app. */
.leaflet-container {
  background: var(--bg-elevated);
  font-family: inherit;
}

.leaflet-control-zoom a {
  background: var(--bg-elevated-2) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.leaflet-control-attribution {
  background: rgba(10, 20, 32, 0.75) !important;
  color: var(--text-dim) !important;
}

.leaflet-control-attribution a { color: var(--accent) !important; }

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--bg-elevated-2);
  color: var(--text);
}

.leaflet-popup-content { font-size: 0.85rem; }

.board {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.board-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.1rem;
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.board-item:active { transform: scale(0.99); }

.board-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.board-item .board-time {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.board-item .board-sub {
  font-size: 0.76rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

.board-item .board-wait {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  white-space: nowrap;
}

.board-detail {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-soft);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
}

.board-divider {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin: 0.3rem 0;
}

.empty-state {
  color: var(--text-dim);
  text-align: center;
  padding: 2.5rem 1rem;
  font-size: 0.9rem;
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

/* settings sheet */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 14, 0.65);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  z-index: 20;
  animation: overlayIn 0.2s ease;
}

.sheet[hidden] {
  display: none;
}

@keyframes overlayIn {
  from { background: rgba(3, 8, 14, 0); }
  to { background: rgba(3, 8, 14, 0.65); }
}

.sheet-inner {
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1.1rem 1.3rem 1.6rem;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4);
  animation: sheetUp 0.28s cubic-bezier(0.2, 0.7, 0.3, 1);
}

@keyframes sheetUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-inner::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 0 auto 0.9rem;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.sheet-header h2 { margin: 0; font-size: 1.15rem; font-weight: 800; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1.1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 600;
}

.field select,
.field input[type="time"],
.field input[type="number"] {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field select:focus,
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 176, 232, 0.2);
}

.field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.65rem;
}

.field.checkbox span { color: var(--text); font-weight: 500; }

.field.checkbox input {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--accent);
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: -0.55rem 0 1.1rem;
}

.preset-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.preset-chip.active {
  border-color: var(--accent);
  color: #06222f;
  background: var(--accent);
}

.primary-btn {
  width: 100%;
  background: var(--accent);
  color: #06222f;
  border: none;
  padding: 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  margin-top: 0.3rem;
  box-shadow: 0 6px 18px rgba(79, 176, 232, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary-btn:active {
  transform: scale(0.98);
  box-shadow: 0 3px 10px rgba(79, 176, 232, 0.25);
}

@media (max-width: 380px) {
  .gauge-value { font-size: 2rem; }
  .gauge { padding: 1.6rem 1rem; }
}
