:root {
  --bg-gradient: radial-gradient(circle at 50% 0%, #1e293b 0%, #070c18 100%);
  --card-bg: rgba(15, 23, 42, 0.88);
  --card-border: rgba(255, 255, 255, 0.14);
  --text-main: #FFFFFF;
  --text-muted: #94A3B8;
  --focus-ring: #00E5FF;
}

[data-theme="high-contrast"] {
  --bg-gradient: #000000;
  --card-bg: #000000;
  --card-border: #FFFFFF;
  --text-main: #FFFFFF;
  --text-muted: #FFFF00;
  --focus-ring: #FFFF00;
}

[data-theme="light"] {
  --bg-gradient: #F8FAFC;
  --card-bg: #FFFFFF;
  --card-border: #CBD5E1;
  --text-main: #0F172A;
  --text-muted: #475569;
  --focus-ring: #0284C7;
}

body {
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
}

/* Visible keyboard focus in every theme. */
*:focus-visible {
  outline: 3px solid var(--focus-ring) !important;
  outline-offset: 4px !important;
}

.glass-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(20px);
}

@media (prefers-reduced-motion: reduce) {
  .animate-pulse, .animate-ping, .transition-all {
    animation: none !important;
    transition: none !important;
  }
}

/* Enhanced touch & click targets */
button, input, select {
  min-height: 48px;
}

/* High Contrast Mode Styles */

html[data-theme="high-contrast"] body {
    background: #000000 !important;
    color: #FFFFFF !important;
}

html[data-theme="high-contrast"] .text-slate-900,
html[data-theme="high-contrast"] .text-slate-800,
html[data-theme="high-contrast"] .text-slate-700,
html[data-theme="high-contrast"] .text-slate-600,
html[data-theme="high-contrast"] .text-slate-500,
html[data-theme="high-contrast"] .text-slate-400 {
    color: #FFFFFF !important;
}

html[data-theme="high-contrast"] h1,
html[data-theme="high-contrast"] h2,
html[data-theme="high-contrast"] h3,
html[data-theme="high-contrast"] p,
html[data-theme="high-contrast"] label,
html[data-theme="high-contrast"] footer {
    color: #FFFFFF;
}

html[data-theme="high-contrast"] .text-cyan-600,
html[data-theme="high-contrast"] .text-cyan-400,
html[data-theme="high-contrast"] .text-emerald-600,
html[data-theme="high-contrast"] .text-emerald-400,
html[data-theme="high-contrast"] .text-yellow-500,
html[data-theme="high-contrast"] .text-yellow-400 {
    color: #FFFF00 !important;
}

html[data-theme="high-contrast"] .glass-card {
    background: #000000 !important;
    color: #FFFFFF !important;
    border: 2px solid #FFFFFF !important;
}

html[data-theme="high-contrast"] input,
html[data-theme="high-contrast"] select {
    background: #000000 !important;
    color: #FFFFFF !important;
    border: 2px solid #FFFFFF !important;
}

html[data-theme="high-contrast"] input::placeholder {
    color: #FFFF00 !important;
    opacity: 1;
}

html[data-theme="high-contrast"] *:focus-visible {
    outline: 3px solid #FFFF00 !important;
    outline-offset: 4px !important;
}

html[data-theme="high-contrast"] button {
    color: #FFFFFF;
}

html[data-theme="high-contrast"] #arrivals-list {
    color: #FFFFFF;
}

html[data-theme="high-contrast"] #arrivals-list .text-slate-900,
html[data-theme="high-contrast"] #arrivals-list .text-slate-800,
html[data-theme="high-contrast"] #arrivals-list .text-slate-700,
html[data-theme="high-contrast"] #arrivals-list .text-slate-600,
html[data-theme="high-contrast"] #arrivals-list .text-slate-500,
html[data-theme="high-contrast"] #arrivals-list .text-slate-400 {
    color: #FFFFFF !important;
}

/* Reflow the interface instead of hiding overflow or disabling zoom. */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
}
.brand-logo-container { flex: 0 0 auto; }
.brand-logo { width: 6rem; height: 5rem; object-fit: contain; }
.brand-copy, .arrival-route, .arrival-destination { min-width: 0; }
.brand-title { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.brand-tagline { display: inline-block; max-width: 100%; }
.header-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
.theme-switcher { flex-wrap: wrap; }
.device-status { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
#connection-dot { flex-shrink: 0; }
#stop-title, #announcement-text, #last-updated, .arrival-destination, footer p {
  overflow-wrap: anywhere;
}
.stop-settings summary {
  cursor: pointer;
  min-height: 48px;
  padding: .75rem .25rem;
}
.stop-settings[open] summary { border-bottom: 1px solid var(--card-border); }
#stop-select { width: 100%; max-width: 100%; text-overflow: ellipsis; }
.route-filter { min-width: 0; }
#route-search { min-width: 0; }
.arrivals-heading { flex-wrap: wrap; gap: .5rem 1rem; }
.arrival-route { max-width: 100%; }
.arrival-card { overflow-wrap: anywhere; }

@media (max-width: 639px) {
  .site-header { gap: 1rem; }
  .brand { gap: .75rem; width: 100%; }
  .brand-logo { width: 3.75rem; height: 3.75rem; }
  .brand-title { font-size: 1.875rem; line-height: 1.15; }
  .brand-tagline {
    font-size: .625rem;
    line-height: 1.5;
    letter-spacing: .025em;
    padding-inline: .375rem;
  }
  .brand-copy > p { margin-top: .375rem; line-height: 1.5; }
  .header-controls, .theme-switcher { width: 100%; }
  .theme-switcher button { flex: 1 1 auto; padding-inline: .5rem; }
  .header-controls > button { justify-content: center; width: 100%; }
  .stop-card, .announcement-card { padding: 1rem; border-radius: 1rem; }
  .device-status { gap: .5rem; }
  #last-updated { font-size: .75rem; }
  .route-filter { flex-wrap: wrap; gap: .5rem; }
  .route-filter label { width: 100%; }
  #route-search { width: 100%; }
  /* 16px prevents automatic input zoom on iOS while preserving user zoom. */
  input, select { font-size: 1rem !important; }
  #switch-stop { width: 100%; }
  .arrival-route { align-items: flex-start; gap: .75rem; }
  .arrival-card { padding: 1rem; }
  .arrival-card h4 { font-size: 1.125rem; line-height: 1.5; }
}

/* Keep theme selection legible and expose its state to assistive technology. */
html[data-theme="light"] .theme-switcher button[aria-pressed="true"] {
  color: #0f172a !important;
}
html[data-theme="high-contrast"] .theme-switcher {
  background: #000;
  border-color: #fff;
}
html[data-theme="high-contrast"] .theme-switcher button {
  background: #000;
  color: #fff !important;
}
html[data-theme="high-contrast"] .theme-switcher button[aria-pressed="true"] {
  background: #ffff00;
  color: #000 !important;
}
html[data-theme="high-contrast"] .header-controls > button,
html[data-theme="high-contrast"] #switch-stop {
  color: #000;
}
