:root {
  --bg: #f3f0ea;
  --bg-elev: #fffcf7;
  --ink: #1a1916;
  --ink-soft: #5c5852;
  --line: rgba(26, 25, 22, 0.08);
  --teal: #0b6e5f;
  --teal-ink: #085247;
  --teal-soft: #e3f1ed;
  --indigo: #3f4a7a;
  --indigo-soft: #eceef6;
  --sand: #e8e2d6;
  --warn: #8a4b12;
  --warn-soft: #f8ecd9;
  --danger: #8f2d2d;
  --danger-soft: #f8e8e6;
  --star: #c4922a;
  --shadow: 0 1px 2px rgba(26, 25, 22, 0.04), 0 8px 24px rgba(26, 25, 22, 0.06);
  --radius: 20px;
  --tap: 44px;
  --font: "PingFang TC", "Noto Sans TC", "Hiragino Sans CNS",
    "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}

body {
  padding-bottom: var(--safe-bottom);
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

a {
  color: var(--teal);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-top) + 10px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.2) blur(16px);
  -webkit-backdrop-filter: saturate(1.2) blur(16px);
  border-bottom: 1px solid var(--line);
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
}

.brand-text h1 {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0.04em;
  line-height: 1.15;
}

.sub {
  color: var(--ink-soft);
  font-size: 12px;
  letter-spacing: 0.06em;
  margin-top: 1px;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--ink);
  flex-shrink: 0;
}

.icon-btn:active {
  background: var(--sand);
}

.icon-btn[hidden] {
  display: none;
}

.star-btn[aria-pressed="true"] {
  color: var(--star);
}

.star-btn[aria-pressed="true"] .star-icon path {
  fill: currentColor;
  stroke: currentColor;
}

.search-wrap {
  margin-top: 10px;
  position: relative;
}
.search-wrap input { padding-right: 48px !important; }
.search-wrap input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: color-mix(in srgb, var(--line) 70%, transparent); color: #5f5a52;
  display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.search-clear[hidden] { display: none; }
.search-clear:active { transform: translateY(-50%) scale(0.92); }

.search-wrap[hidden] {
  display: none;
}

.search-wrap input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  border-radius: 14px;
  padding: 0 14px;
  outline: none;
}

.search-wrap input::placeholder {
  color: #8a857c;
}

.search-wrap input:focus {
  border-color: color-mix(in srgb, var(--teal) 45%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 16%, transparent);
}

main {
  padding: 8px 16px 40px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  padding: 14px 4px 8px;
}

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

.station-row {
  display: flex;
  align-items: stretch;
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 64px;
  overflow: hidden;
}

.station-row.is-last .id-badge {
  box-shadow: inset 0 0 0 1.5px var(--teal);
}

.station-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px 12px 14px;
  text-align: left;
  min-width: 0;
  min-height: var(--tap);
}

.id-badge {
  flex-shrink: 0;
  min-width: 46px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal-ink);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.02em;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
}

.station-meta {
  min-width: 0;
}

.station-name {
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-town {
  color: var(--ink-soft);
  font-size: 12px;
  margin-top: 1px;
}

.row-flags {
  display: flex;
  gap: 6px;
  margin-top: 3px;
}

.chip {
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--sand);
  color: var(--ink-soft);
}

.chip.recent {
  background: var(--teal-soft);
  color: var(--teal-ink);
}

.star-btn.row-star {
  width: 52px;
  border-radius: 0;
  color: #b0aaa0;
}

.star-btn[aria-pressed="true"],
.star-btn.row-star[aria-pressed="true"] {
  color: var(--star);
}

.star-btn.row-star:active {
  background: var(--sand);
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 40px 16px;
}

/* Detail */

.detail-head {
  padding: 8px 4px 16px;
}

.detail-name {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.detail-kicker {
  color: var(--ink-soft);
  font-size: 13px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.board-card {
  background: var(--bg-elev);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 20px 20px 18px;
}

.board-card.shun {
  border-top: 4px solid var(--teal);
}

.board-card.ni {
  border-top: 4px solid var(--indigo);
}

.dir-label {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.16em;
}

.board-card.shun .dir-label {
  color: var(--teal-ink);
}

.board-card.ni .dir-label {
  color: var(--indigo);
}

.dir-hint {
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.4;
}

.eta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 12px;
  min-height: 88px;
}

.eta-num {
  font-size: 80px;
  font-weight: 600;
  letter-spacing: -0.05em;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}

.board-card.shun .eta-num {
  color: var(--teal-ink);
}

.board-card.ni .eta-num {
  color: var(--indigo);
}

.eta-unit {
  font-size: 20px;
  font-weight: 600;
  color: var(--ink-soft);
}

.eta-phrase {
  font-size: 36px;
  font-weight: 650;
  letter-spacing: 0.06em;
  align-self: center;
  line-height: 1;
}

.board-card.shun .eta-phrase {
  color: var(--teal-ink);
}

.board-card.ni .eta-phrase {
  color: var(--indigo);
}

.status-msg {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  background: var(--warn-soft);
  color: var(--warn);
}

.status-msg.is-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.fallback {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f6f3ed;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}

.fallback strong {
  color: var(--ink);
  font-weight: 600;
}

.refresh-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding: 0 4px;
  color: var(--ink-soft);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.refresh-btn {
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 600;
  color: var(--teal-ink);
}

.refresh-btn:disabled {
  opacity: 0.55;
}

.banner {
  margin: 8px 0 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 14px;
}

.banner.is-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.skeleton {
  height: 88px;
  border-radius: 24px;
  background: linear-gradient(
    90deg,
    var(--sand) 0%,
    #efeae1 45%,
    var(--sand) 90%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 80% 0;
  }
  100% {
    background-position: -80% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}
