:root {
  --ink: #f7f4ee;
  --ink-dim: #e8e8ee;
  --muted: #c0c0c8;
  --card: #faf6f0;
  --card-ink: #141414;
  --card-muted: #373737;
  --cta: #6b2d2d;
  --cta-text: #faf6f0;
  --banner: #ffcc33;
  --banner-ink: #1a0a00;
  --font: "Noto Sans TC", "PingFang HK", "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --sky: #1a8bc8;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--sky);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button {
  -webkit-tap-highlight-color: transparent;
}
input, textarea, select {
  user-select: text;
  -webkit-user-select: text;
}

/* Weather backdrop */
.wx {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: var(--sky);
  transition: background-color 1.2s ease;
}
.wx__sky { position: absolute; inset: 0; }
.wx--clear { --sky: #1a8bc8; }
.wx--partlycloudy { --sky: #3a92c4; }
.wx--cloudy { --sky: #5a7a94; }
.wx--overcast { --sky: #5a6570; }
.wx--lightrain { --sky: #4a6a80; }
.wx--rain { --sky: #3a5468; }
.wx--heavyrain { --sky: #2c4254; }
.wx--storm { --sky: #2a3540; }
.wx--fog { --sky: #7a8490; }
.wx--unknown { --sky: #1a8bc8; }

.wx__sun {
  position: absolute;
  top: 12%;
  right: 12%;
  width: 28vw;
  height: 28vw;
  max-width: 160px;
  max-height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe27a 0%, #ffc14a 42%, rgba(255, 193, 74, 0.15) 70%, transparent 74%);
  opacity: 0;
  filter: blur(0.5px);
  animation: sun-pulse 6s ease-in-out infinite;
}
.wx--clear .wx__sun,
.wx--partlycloudy .wx__sun { opacity: 1; }
.wx--lightrain .wx__sun { opacity: 0.35; }
@keyframes sun-pulse {
  0%, 100% { transform: scale(1); opacity: 0.92; }
  50% { transform: scale(1.08); opacity: 1; }
}

.wx__cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 40px;
  filter: blur(1px);
  opacity: 0;
  height: 42px;
}
.wx__cloud::before,
.wx__cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}
.wx__cloud::before { width: 44px; height: 44px; top: -20px; left: 18px; }
.wx__cloud::after { width: 56px; height: 56px; top: -28px; left: 48px; }
.wx__cloud--1 { width: 130px; top: 16%; left: -20%; animation: drift 42s linear infinite; }
.wx__cloud--2 { width: 160px; top: 26%; left: -30%; height: 48px; animation: drift 54s linear infinite 8s; }
.wx__cloud--3 { width: 110px; top: 10%; left: -25%; animation: drift 36s linear infinite 16s; }
.wx--partlycloudy .wx__cloud,
.wx--cloudy .wx__cloud,
.wx--overcast .wx__cloud,
.wx--lightrain .wx__cloud,
.wx--rain .wx__cloud,
.wx--heavyrain .wx__cloud,
.wx--storm .wx__cloud { opacity: 0.7; }
.wx--cloudy .wx__cloud,
.wx--overcast .wx__cloud { background: rgba(220, 226, 232, 0.7); opacity: 0.85; }
.wx--overcast .wx__cloud { background: rgba(170, 180, 190, 0.8); }
.wx--storm .wx__cloud { background: rgba(90, 100, 112, 0.75); }
@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(140vw); }
}

.wx__fog {
  position: absolute;
  inset: auto 0 0 0;
  height: 55%;
  background: linear-gradient(to top, rgba(220, 224, 228, 0.55), transparent);
  opacity: 0;
}
.wx--fog .wx__fog { opacity: 1; }

.wx__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.wx__flash {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: none;
}
.wx__flash.is-on { opacity: 1; }
.wx__scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(8, 16, 24, 0.28) 0%, rgba(8, 16, 24, 0.18) 40%, rgba(8, 16, 24, 0.42) 100%);
}

.night-dim {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: rgba(0, 0, 0, 0.38);
  pointer-events: none;
}
.leave-flash {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: #f4f0e8;
  mix-blend-mode: difference;
  opacity: 0.92;
}

.app {
  position: relative;
  z-index: 3;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(10px + var(--safe-t)) calc(18px + var(--safe-r)) calc(16px + var(--safe-b)) calc(18px + var(--safe-l));
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
}
.brand {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 1.05rem;
  text-shadow: 0 1px 8px rgba(0,0,0,0.35);
}
.settings-btn {
  appearance: none;
  border: 0;
  background: rgba(250, 246, 240, 0.95);
  color: #2a2420;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 10px 18px;
  min-height: 48px;
  min-width: 88px;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
}
.settings-btn:active { transform: scale(0.98); }

.banner {
  align-self: center;
  margin: 8px 0 0;
  background: var(--banner);
  color: var(--banner-ink);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 6px 14px;
  border-radius: 10px;
  text-align: center;
  max-width: 100%;
}
.offline-note {
  margin: 8px 0 0;
  text-align: center;
  color: #ffe08a;
  font-weight: 600;
  text-shadow: 0 1px 6px rgba(0,0,0,0.4);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 8px 0 12px;
}
.clock-block { text-align: center; width: 100%; }
.clock-time {
  margin: 0;
  font-size: clamp(72px, 22vw, 120px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 16px rgba(0,0,0,0.35);
}
.clock-date {
  margin: 8px 0 0;
  font-size: 1.25rem;
  color: var(--ink-dim);
  text-shadow: 0 1px 8px rgba(0,0,0,0.35);
}
.wx-line {
  margin: 10px 0 0;
  font-size: 1.35rem;
  font-weight: 600;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  text-shadow: 0 1px 8px rgba(0,0,0,0.35);
}

.bus-card {
  width: min(100%, 420px);
  background: var(--card);
  color: var(--card-ink);
  border-radius: 24px;
  padding: 18px 18px 16px;
  box-shadow: 0 16px 36px rgba(0,0,0,0.22);
}
.bus-card__head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.route-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  background: #e60012;
  color: #fff;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.route-badge.is-ctb { background: #ffb81c; color: #101010; }
.route-badge.is-lwb { background: #e87a12; color: #fff; }
.route-badge.is-nlb { background: #1f4d32; color: #fff; }
.bus-card__names { min-width: 0; flex: 1; }
.bus-dest {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.3;
}
.bus-stop {
  margin: 2px 0 0;
  font-size: 0.98rem;
  color: var(--card-muted);
  line-height: 1.3;
}
.eta-big {
  margin: 12px 0 0;
  font-size: clamp(2.4rem, 10vw, 3.2rem);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.01em;
}
.leave-line {
  margin: 6px 0 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: #282828;
  min-height: 1.3em;
}
.eta-next {
  margin: 4px 0 0;
  font-size: 1.05rem;
  color: #4a4a4a;
  min-height: 1.3em;
}
.bus-mark {
  margin: 6px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #c40010;
  min-height: 1.2em;
}
.bus-status {
  margin: 8px 0 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: #8a5a00;
  min-height: 1.2em;
}

body.is-bus .clock-time {
  font-size: clamp(52px, 16vw, 88px);
}
body.is-bus .main {
  justify-content: flex-start;
  padding-top: 8px;
}

.view-hint {
  margin: 0;
  text-align: center;
  font-size: 0.92rem;
  color: var(--muted);
  text-shadow: 0 1px 6px rgba(0,0,0,0.35);
  min-height: 1.2em;
}

/* Invert flash: lighten the whole UI except settings */
body.is-flash .wx,
body.is-flash .night-dim { visibility: hidden; }
body.is-flash { background: #f4f0e8; color: #101018; }
body.is-flash .brand,
body.is-flash .clock-time,
body.is-flash .clock-date,
body.is-flash .wx-line,
body.is-flash .view-hint { color: #101018; text-shadow: none; }
body.is-flash .bus-card { background: #101018; color: #f4f0e8; }
body.is-flash .bus-dest { color: #f4f0e8; }
body.is-flash .bus-stop,
body.is-flash .eta-next { color: #c8c8d0; }
body.is-flash .leave-line { color: #f4f0e8; }
body.is-flash .bus-mark { color: #3bffef; }
body.is-flash .bus-status { color: #7595ff; }
body.is-flash .banner { background: #0033cc; color: #e5f5ff; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #f3ebe0;
  color: #2a2420;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sheet[hidden] { display: none !important; }
.sheet__panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}
.sheet__bar {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 10px;
  border-bottom: 1px solid #d9cfc2;
  background: #faf6f0;
}
.sheet__back,
.sheet__spacer { min-height: 44px; }
.sheet__back {
  appearance: none;
  border: 0;
  background: transparent;
  color: #6b2d2d;
  font-weight: 700;
  text-align: left;
  padding: 8px 4px;
}
.sheet__title {
  margin: 0;
  font-size: 1.15rem;
  text-align: center;
  line-height: 1.3;
}
.sheet__body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px calc(28px + var(--safe-b));
}
.sheet__lead {
  margin: 0 0 16px;
  color: #5c534c;
  line-height: 1.5;
  font-size: 1.02rem;
}
.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.list button,
.field,
.row {
  width: 100%;
  text-align: left;
  background: #faf6f0;
  border: 1px solid #d9cfc2;
  border-radius: 16px;
  padding: 14px 16px;
  min-height: 56px;
  color: #2a2420;
}
.list button strong,
.row strong { display: block; font-size: 1.08rem; }
.list button span,
.row span { display: block; color: #5c534c; font-size: 0.95rem; margin-top: 2px; }
.list button.is-on { outline: 2px solid #6b2d2d; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.row > div { min-width: 0; }
.btn {
  appearance: none;
  border: 0;
  background: #6b2d2d;
  color: #faf6f0;
  font-weight: 700;
  border-radius: 999px;
  padding: 14px 22px;
  min-height: 52px;
  width: 100%;
  margin-top: 12px;
}
.btn:disabled { opacity: 0.45; }
.btn--ghost {
  background: transparent;
  color: #6b2d2d;
  border: 1px solid #d9cfc2;
}
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.btn-row .btn { margin-top: 0; }
.field input,
.field select {
  width: 100%;
  margin-top: 8px;
  border: 0;
  background: transparent;
  font-size: 1.25rem;
  outline: none;
  color: #2a2420;
}
.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}
.stepper button {
  width: 52px;
  height: 52px;
  border: 1px solid #d9cfc2;
  border-radius: 14px;
  background: #fff;
  font-size: 1.6rem;
  color: #2a2420;
  flex-shrink: 0;
}
.stepper b {
  font-size: 1.8rem;
  min-width: 3ch;
  text-align: center;
}
.toggle {
  appearance: none;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  border: 0;
  background: #cfc4b6;
  position: relative;
  flex-shrink: 0;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.toggle.is-on { background: #6b2d2d; }
.toggle.is-on::after { transform: translateX(20px); }
.link-buy {
  display: block;
  margin-top: 22px;
  text-align: center;
  color: #6b2d2d;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 16px;
  text-decoration: none;
}
.hint {
  color: #5c534c;
  font-size: 0.98rem;
  line-height: 1.5;
  margin: 0 0 14px;
}
.a2hs {
  background: #ebe1d3;
  border-radius: 16px;
  padding: 14px 16px;
  margin-top: 16px;
  color: #5c534c;
  line-height: 1.5;
}
.danger { color: #8a1020; }

@media (min-width: 720px) {
  .app { max-width: 480px; margin: 0 auto; }
  .sheet__panel { max-width: 480px; margin: 0 auto; box-shadow: 0 0 0 100vmax #e6ddd2; }
}
