:root {
  --bg: #393939;
  --surface: #454545;
  --surface-raised: #505050;
  --text: #f2f2f2;
  --muted: #b8b8b8;
  --primary: #4da3ff;
  --primary-dark: #7bb8ff;
  --accent: #3dd68c;
  --orange-dark: #d44a07;
  --orange: #ff5a09;
  --orange-light: #ff8c42;
  --selected: var(--orange);
  --selected-text: #fff2c6;
  --border: #5c5c5c;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  --radius: 14px;
  --touch: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: "PingFang HK", "Microsoft JhengHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: calc(16px + var(--safe-bottom));
}

a {
  color: var(--primary);
  text-decoration: none;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(135deg, var(--orange-dark), var(--orange-light));
  color: var(--selected-text);
  padding: calc(10px + var(--safe-top)) calc(12px + var(--safe-right)) 10px calc(12px + var(--safe-left));
  box-shadow: 0 2px 12px rgba(255, 90, 9, 0.35);
}

.top-bar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: 640px;
  margin: 0 auto;
}

.top-bar-label {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.top-bar-sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  opacity: 0.88;
}

.live-clock {
  font-size: calc(0.88rem + 3px);
  font-variant-numeric: tabular-nums;
  background: rgba(255, 242, 198, 0.22);
  color: var(--selected-text);
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
}

.next-hero {
  background: linear-gradient(160deg, var(--orange-dark) 0%, var(--orange) 50%, var(--orange-light) 100%);
  color: var(--selected-text);
  border-radius: calc(var(--radius) + 2px);
  padding: 20px 18px 22px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}

.next-hero-route {
  margin: 0 0 4px;
  font-size: 0.9rem;
  opacity: 0.92;
  font-weight: 600;
}

.next-hero-time {
  margin: 0;
  font-size: clamp(3.2rem, 18vw, 4.5rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.next-hero-wait {
  margin: 10px 0 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
}

.next-hero-direction {
  margin: 8px 0 0;
  font-size: 0.95rem;
  opacity: 0.9;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.route-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.route-option,
.view-tab {
  border: 1.5px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  border-radius: 12px;
  min-height: var(--touch);
  padding: 12px 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font: inherit;
  touch-action: manipulation;
  user-select: none;
}

.route-option {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.route-option strong {
  font-size: 1rem;
}

.route-option span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.route-option.active,
.view-tab.active {
  border-color: var(--selected);
  background: var(--selected);
  color: var(--selected-text);
}

.route-option.active span {
  color: var(--selected-text);
  opacity: 0.95;
}

.view-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.view-tab {
  font-weight: 700;
  font-size: 0.92rem;
}

.upcoming-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upcoming-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 14px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
}

.upcoming-item.highlight {
  display: none;
}

.upcoming-time {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.upcoming-meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.upcoming-wait {
  text-align: right;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.timetable-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.time-cell {
  text-align: center;
  padding: 12px 4px;
  border-radius: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.95rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.time-cell.next {
  background: rgba(61, 214, 140, 0.2);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 214, 140, 0.25);
}

.time-cell.past {
  opacity: 0.38;
}

.time-cell.cancelled {
  opacity: 0.3;
  text-decoration: line-through;
  background: #333333;
}

#timetable-caption {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.remarks-details {
  padding: 0;
  overflow: hidden;
}

.remarks-details summary {
  padding: 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: var(--touch);
  display: flex;
  align-items: center;
  list-style: none;
}

.remarks-details summary::-webkit-details-marker {
  display: none;
}

.remarks-details summary::before {
  content: "▸";
  margin-right: 8px;
  color: var(--muted);
}

.remarks-details[open] summary::before {
  content: "▾";
}

.remarks-list {
  margin: 0;
  padding: 0 14px 0 28px;
  color: var(--muted);
  font-size: 0.88rem;
}

.remarks-list li + li {
  margin-top: 8px;
}

.footer-note {
  margin: 12px 14px 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.empty {
  color: var(--muted);
  margin: 0;
  text-align: center;
  padding: 20px 0;
}

@media (min-width: 480px) {
  .route-option span {
    font-size: 0.85rem;
  }

  .timetable-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.net-status {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #3a332c;
  color: var(--selected-text);
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
}

.install-hint {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(12px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(616px, calc(100% - 24px - var(--safe-left) - var(--safe-right)));
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--orange);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px 12px;
}

.install-hint-title {
  margin: 0;
  font-weight: 800;
  color: var(--orange-light);
}

.install-hint-text {
  margin: 6px 0 0;
  color: var(--text);
  font-size: 0.9rem;
}

.share-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin: 0 4px;
  vertical-align: -5px;
  color: var(--selected-text);
  background: var(--orange);
  border-radius: 6px;
}

.install-hint-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.install-hint-action {
  min-height: var(--touch);
  min-width: 96px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--orange);
  color: var(--selected-text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

body.has-install-hint {
  padding-bottom: calc(200px + var(--safe-bottom));
}

html.is-standalone body {
  min-height: 100dvh;
}

@media (min-width: 640px) {
  .page {
    padding-top: 16px;
  }

  .next-hero {
    padding: 28px 24px;
  }

  .panel {
    padding: 18px;
  }

  .timetable-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
