:root,
[data-theme="dark"] {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface2: #1c1c26;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --muted: #8888a8;
  --lineA: #3eb4e8;
  --lineB: #e83e3e;
  --lineC: #1a5fb4;
  --lineD: #2ec653;
  --lineE: #9b59b6;
  --lineH: #f5c518;
  --ok: #2ec653;
  --warn: #f5a623;
  --danger: #e83e3e;
  --noise-opacity: 0.4;
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface2: #eeeef0;
  --border: #d4d4d8;
  --text: #18181b;
  --muted: #71717a;
  --lineA: #2196d3;
  --lineB: #d32f2f;
  --lineC: #1558a8;
  --lineD: #1b9e3e;
  --lineE: #8338b3;
  --lineH: #d4a817;
  --ok: #1b9e3e;
  --warn: #d4870f;
  --danger: #d32f2f;
  --noise-opacity: 0.15;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Geist Mono', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px 40px;
  position: relative;
  overflow-x: hidden;
}

/* Noise texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
  opacity: var(--noise-opacity);
}

/* Header */
header {
  width: 100%;
  max-width: 520px;
  padding: 32px 0 24px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-label {
  font-family: 'Geist', sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--muted);
}

.brand-title {
  font-family: 'Geist', sans-serif;
  font-size: 36px;
  font-weight: 900;
  letter-spacing: -1px;
  line-height: 1;
  color: var(--text);
}

.brand-title span {
  color: var(--lineA);
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--text);
  color: var(--text);
}

/* Main content */
main {
  width: 100%;
  max-width: 520px;
  position: relative;
  z-index: 1;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.status-dot.loading {
  background: var(--warn);
  animation: pulse 1s infinite;
}

.status-dot.ok { background: var(--ok); }
.status-dot.error { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Nearest station card */
.station-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}

.station-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--line-color, var(--lineA));
  border-radius: 4px 0 0 4px;
}

.station-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 4px;
}

.station-name {
  font-family: 'Geist', sans-serif;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  color: var(--text);
}

.distance-badge {
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
  margin-top: 4px;
}

.line-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.line-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line-color, var(--lineA));
  flex-shrink: 0;
}

.line-name {
  font-family: 'Geist', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}

/* Trains section */
.section-title {
  font-family: 'Geist', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.trains-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.train-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: border-color 0.2s;
}

.train-card:hover {
  border-color: var(--line-color, var(--lineA));
}

.train-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.train-direction {
  font-family: 'Geist', sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text);
}

.train-direction .arrow {
  color: var(--muted);
  font-size: 12px;
}

.train-time-label {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 1px;
}

.train-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.arrival-time {
  font-family: 'Geist Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.delay-badge {
  font-size: 10px;
  letter-spacing: 1px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 700;
}

.delay-ok {
  background: color-mix(in srgb, var(--ok) 15%, transparent);
  color: var(--ok);
  border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
}

.delay-warn {
  background: color-mix(in srgb, var(--warn) 15%, transparent);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
}

.delay-danger {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}

/* Refresh bar */
.refresh-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
}

.refresh-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 10px;
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}

.refresh-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

/* Station picker */
.station-picker {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.picker-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.picker-label {
  font-family: 'Geist', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--muted);
}

.picker-location-btn {
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}

.picker-location-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

.picker-search {
  font-family: 'Geist Mono', monospace;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  width: 100%;
  transition: border-color 0.2s;
  letter-spacing: 0.5px;
}

.picker-search::placeholder {
  color: var(--muted);
}

.picker-search:focus {
  outline: none;
  border-color: var(--lineA);
}

.picker-line-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}

.picker-line-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--line-color);
  border-radius: 4px 0 0 4px;
}

.picker-line-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.picker-line-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.picker-line-name {
  font-family: 'Geist', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
}

.picker-stations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.picker-station {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
}

.picker-station:hover {
  border-color: var(--line-color);
  background: color-mix(in srgb, var(--line-color) 10%, var(--surface2));
}

.picker-station:active {
  transform: scale(0.96);
}

/* Station meta row */
.station-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.change-station-btn {
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}

.change-station-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

/* Error state */
.error-card {
  background: color-mix(in srgb, var(--danger) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
  border-radius: 12px;
  padding: 20px;
  font-size: 13px;
  color: var(--danger);
  line-height: 1.6;
  letter-spacing: 0.5px;
}

.countdown {
  font-variant-numeric: tabular-nums;
}

/* Subte map */
.subte-map {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
}

.map-header {
  margin-bottom: 8px;
}

.map-title {
  font-family: 'Geist', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--muted);
}

.map-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
}

.map-line-label {
  font-family: 'Geist', sans-serif;
  font-size: 13px;
  font-weight: 900;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.map-track-container {
  flex: 1;
  position: relative;
  height: 24px;
  display: flex;
  align-items: center;
}

.map-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 2px;
  opacity: 0.4;
}

.map-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  border: 2px solid var(--surface);
  transform: translateX(-50%);
  z-index: 2;
  cursor: default;
}

.map-dot-selected {
  width: 12px;
  height: 12px;
  background: var(--text);
  border: 2px solid var(--lineA);
  z-index: 3;
}

.map-dot-label {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  margin-bottom: 4px;
  pointer-events: none;
  z-index: 10;
}

.map-dot:hover .map-dot-label,
.map-dot-selected .map-dot-label {
  display: block;
}

.map-train {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  transform: translateX(-50%);
  z-index: 4;
  animation: train-pulse 2s infinite;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.2);
  cursor: default;
}

.map-train-label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  pointer-events: none;
  z-index: 10;
}

.map-train-label-top {
  bottom: 100%;
  margin-bottom: 4px;
}

.map-train-label-bottom {
  top: 100%;
  margin-top: 4px;
}

@keyframes train-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.map-legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.map-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.map-legend-train {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--lineA);
}

.map-legend-selected {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--lineA);
}

/* Responsive */
@media (max-width: 400px) {
  .station-name { font-size: 22px; }
  .arrival-time { font-size: 18px; }
}
