/* Theme tokens. Light is the :root default; JS sets html[data-theme] explicitly
   (default dark, matching iOS) and index.html applies it pre-paint to avoid flash. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #0b1220;
  --muted: #6b7280;
  --accent: #1d4ed8;
  --accent-soft: #eaf0ff;
  --ok: #0a7d3b;
  --ok-soft: #e6f6ec;
  --ring: #e5e7eb;
  --warn: #fde68a;
  --warn-text: #7c2d12;
  --radius: 14px;
}
html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #151d2e;
  --text: #e6e9ef;
  --muted: #94a0b4;
  --accent: #6b93ff;
  --accent-soft: #1b2740;
  --ok: #5fd08a;
  --ok-soft: #16301f;
  --ring: #26314a;
  --warn: #3a2f12;
  --warn-text: #f5d98a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Noto Sans HK", "PingFang HK", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* App shell: fixed top bar + scrolling content + fixed bottom tab bar. */
#app {
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.topbar { flex: none; padding: calc(env(safe-area-inset-top) + 12px) 16px 8px; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px; }
.tabbar {
  flex: none; display: flex; border-top: 1px solid var(--ring);
  background: var(--surface); padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 0 6px; font-size: 11px; font-weight: 600;
  color: var(--muted); background: none; border: none; cursor: pointer;
}
.tab--on { color: var(--accent); }
.ic { width: 23px; height: 23px; }

/* Announcement banner (server maintenance notice). */
.banner {
  display: block; width: 100%; text-align: left; border: none; cursor: pointer;
  background: var(--warn); color: var(--warn-text); padding: 8px 16px; font-size: 13px; font-weight: 600;
}

/* Sticky page controls (date bars / filters) — the results scroll beneath them. */
.controls { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-top: 6px; }
.results { padding: 4px 0 20px; }
.results--busy { opacity: 0.55; }

.pick__l, .seg__l { font-size: 12px; color: var(--muted); padding: 2px 2px 0; }
.strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.strip::-webkit-scrollbar { display: none; }
.strip--seg { align-items: center; }
.strip--pad { padding: 10px 12px; }
.seg__l { flex: none; padding-right: 2px; }
.seg__sep { flex: none; width: 1px; height: 22px; background: var(--ring); margin: 0 2px; }

.chip {
  white-space: nowrap; border: 1px solid var(--ring); background: var(--surface);
  color: var(--text); border-radius: 999px; padding: 7px 14px; font-size: 14px;
  font-weight: 600; cursor: pointer; flex: none;
}
.chip--on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Page 1 result cards. */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--ring);
  border-radius: var(--radius); padding: 14px 16px; color: var(--text);
}
.card__top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card__city { font-size: 17px; font-weight: 700; }
.card__iata { color: var(--muted); font-weight: 600; font-size: 13px; }
.card__price { font-size: 17px; font-weight: 800; color: var(--accent); white-space: nowrap; }
.card__meta { color: var(--muted); font-size: 14px; margin-top: 4px; }
.card__tags { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.tag { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--accent-soft); border-radius: 6px; padding: 3px 8px; }

/* Page 2 calendar. */
.cal { padding-top: 2px; }
.cal__hd { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px; }
.cal__t { font-weight: 700; font-size: 16px; }
.nav { background: none; border: none; color: var(--accent); font-size: 24px; line-height: 1; padding: 4px 14px; cursor: pointer; }
.grid7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.grid7--wd { margin-bottom: 3px; }
.wd { text-align: center; font-size: 11px; color: var(--muted); padding: 4px 0; }
.day {
  min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border: none; border-radius: 8px; background: none; color: var(--text);
}
.day--pad { visibility: hidden; }
.day--data { background: var(--accent-soft); cursor: pointer; }
.day--cheap { background: var(--ok-soft); }
.day__n { font-size: 13px; }
.day__n--off { color: var(--muted); }
.day--cheap .day__n, .day--cheap .day__p { color: var(--ok); font-weight: 700; }
.day__p { font-size: 11px; color: var(--muted); }

/* Page 3 detail. */
.dhead { padding: 4px 0 2px; }
.back { background: none; border: none; color: var(--accent); font-size: 15px; padding: 4px 0; cursor: pointer; }
.dhead__city { font-size: 19px; font-weight: 800; margin-top: 2px; }
.dhead__dates { font-size: 14px; margin-top: 2px; }
.itins { display: flex; flex-direction: column; gap: 10px; }
.itin { background: var(--surface); border: 1px solid var(--ring); border-radius: var(--radius); padding: 12px 14px; }
.itin__hd { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.itin__car { font-weight: 700; }
.itin__price { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.leg { display: flex; gap: 10px; margin-top: 8px; }
.leg__lbl { flex: none; width: 30px; font-size: 12px; color: var(--muted); padding-top: 2px; }
.leg__times { font-size: 15px; }
.leg__times b { font-variant-numeric: tabular-nums; font-weight: 700; }
.leg__stops { font-size: 13px; margin-top: 2px; }
.legoff { color: #e08a00; font-size: 11px; margin-left: 2px; }
.book {
  position: sticky; bottom: 8px; display: block; text-align: center;
  margin: 14px 0 4px; padding: 14px; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 700; text-decoration: none;
}

/* Page 4 settings. */
.settings { padding-top: 6px; }
.grp { background: var(--surface); border: 1px solid var(--ring); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.grp > * + * { border-top: 1px solid var(--ring); }
.grp__hd { font-size: 12px; color: var(--muted); padding: 10px 14px 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.row { display: flex; align-items: center; justify-content: space-between; padding: 13px 14px; }
.row--link { color: var(--text); text-decoration: none; }
.toggle {
  flex: none; width: 46px; height: 28px; border: none; border-radius: 999px;
  background: var(--ring); position: relative; cursor: pointer; transition: background 0.15s;
}
.toggle--on { background: var(--accent); }
.toggle__k { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left 0.15s; }
.toggle--on .toggle__k { left: 21px; }

/* Shared empty / loading / error states. */
.empty { text-align: center; padding: 52px 16px; }
.empty__t { font-size: 16px; font-weight: 600; }
.empty__d { margin-top: 8px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.state { text-align: center; color: var(--muted); padding: 44px 0; font-size: 15px; }
.btn { margin-left: 8px; border: 1px solid var(--ring); background: var(--surface); color: var(--text); border-radius: 8px; padding: 6px 12px; font-weight: 600; cursor: pointer; }
.muted { color: var(--muted); }

/* Turnstile loading placeholder (also hosts the challenge widget if one appears).
   Created hidden; revealed only on a challenge or a slow mint (see turnstile.js). */
.ts-overlay { position: fixed; inset: 0; z-index: 9998; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.ts-overlay--hidden { display: none; }
.ts-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px; text-align: center; }
.ts-spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--ring); border-top-color: var(--accent); animation: ts-spin 0.8s linear infinite; }
@keyframes ts-spin { to { transform: rotate(360deg); } }
.ts-msg { font-size: 16px; font-weight: 600; }
.ts-sub { font-size: 13px; color: var(--muted); }
#ts-host:empty { display: none; }
