:root {
  --ink: #0b1220;
  --ink-2: #121a2b;
  --ink-3: #1a2438;
  --line: rgba(232, 236, 244, 0.12);
  --line-strong: rgba(232, 236, 244, 0.22);
  --fg: #e8ecf4;
  --muted: #8b95a8;
  --amber: #e8a54b;
  --amber-dim: rgba(232, 165, 75, 0.18);
  --silver: #c8d0dc;
  --silver-dim: rgba(200, 208, 220, 0.16);
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Noto Sans TC", "PingFang HK", "Hiragino Sans CNS", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  min-height: 100vh;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
}

/* —— topbar —— */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: calc(0.55rem + var(--safe-t)) 1rem 0.4rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0e1626 0%, var(--ink) 100%);
  z-index: 2;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.mark {
  color: var(--amber);
  font-size: 1.15rem;
  line-height: 1;
}

.topbar-text h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.loc {
  margin: 0.1rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 11rem;
}

.topbar-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--ink-3);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.45rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:active { transform: translateY(1px); }

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.amber {
  background: var(--amber-dim);
  border-color: rgba(232, 165, 75, 0.45);
  color: var(--amber);
}

.btn.amber.on {
  background: var(--amber);
  color: #1a1208;
  border-color: var(--amber);
}

.btn.tiny {
  padding: 0.2rem 0.45rem;
  font-size: 0.68rem;
  color: var(--amber);
  background: transparent;
  border-color: rgba(232, 165, 75, 0.35);
}

/* —— mode bar —— */
.mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: var(--ink);
  flex-wrap: wrap;
}

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  overflow: hidden;
}

.mode-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.38rem 0.55rem;
  cursor: pointer;
  border-right: 1px solid var(--line);
}

.mode-btn:last-child { border-right: 0; }

.mode-btn.on {
  background: var(--ink-3);
  color: var(--fg);
}

.target-chips {
  display: flex;
  gap: 0.35rem;
}

.chip {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.35rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
}

.chip.sun.on {
  background: var(--amber-dim);
  border-color: rgba(232, 165, 75, 0.55);
  color: var(--amber);
}

.chip.moon.on {
  background: var(--silver-dim);
  border-color: rgba(200, 208, 220, 0.5);
  color: var(--silver);
}

/* —— sky —— */
.sky-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.5rem 0.15rem;
  position: relative;
  min-height: 0;
  background: radial-gradient(ellipse at 50% 40%, #0c1628 0%, #070b14 70%);
}

.sky-wrap {
  position: relative;
  width: min(100%, calc(100dvh - 19rem - var(--safe-t) - var(--safe-b)));
  max-width: 100%;
  aspect-ratio: 1;
}

#skyStage[data-view="finder"] .sky-wrap {
  width: 100%;
  max-width: 100%;
  aspect-ratio: auto;
  height: 100%;
  min-height: 18rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

#skyStage[data-view="finder"] #sky {
  width: min(100%, 100%);
  height: min(100%, calc(100dvh - 20rem));
  max-height: 100%;
}

#sky {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  touch-action: none;
  background: #0b1220;
}

#skyStage[data-view="finder"] #sky {
  border-radius: 6px;
  border: 1px solid var(--line);
}

.heading-chip {
  position: absolute;
  top: 4%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: center;
  background: rgba(11, 18, 32, 0.88);
  border: 1px solid var(--line-strong);
  padding: 0.28rem 0.55rem;
  border-radius: 3px;
  pointer-events: none;
  max-width: 92%;
}

.heading-deg {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: 0.02em;
}

.heading-card {
  font-size: 0.68rem;
  color: var(--amber);
  font-weight: 600;
}

.pitch-chip {
  font-size: 0.62rem;
  color: var(--muted);
  width: 100%;
  text-align: center;
  margin-top: 0.05rem;
}

#skyStage[data-view="map"] .pitch-chip {
  display: none;
}

.guide-banner {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  background: rgba(11, 18, 32, 0.9);
  border: 1px solid rgba(232, 165, 75, 0.45);
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.45rem 0.75rem;
  border-radius: 4px;
  pointer-events: none;
  text-align: center;
  max-width: 92%;
  z-index: 3;
}

.guide-banner.locked {
  border-color: rgba(232, 165, 75, 0.85);
  box-shadow: 0 0 18px rgba(232, 165, 75, 0.25);
  color: #f5d08a;
}

.guide-banner.moon-target {
  border-color: rgba(200, 208, 220, 0.5);
  color: var(--silver);
}

.guide-banner.moon-target.locked {
  border-color: rgba(200, 208, 220, 0.85);
  box-shadow: 0 0 18px rgba(200, 208, 220, 0.22);
  color: #eef2f8;
}

.guide-banner[hidden] { display: none; }

.sky-hint {
  display: none !important;
}

#skyStage[data-view="finder"] .guide-banner:not([hidden]) {
  bottom: 6%;
}

/* —— dock —— */
.dock {
  border-top: 1px solid var(--line);
  background: var(--ink-2);
  padding: 0.65rem 0.9rem calc(0.8rem + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.stats {
  display: none;
}


.timeline-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.timeline-head .label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.scrub-time {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--amber);
}

.slider-wrap {
  position: relative;
  margin-top: 0.35rem;
}

#timeline {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1.4rem;
  background: transparent;
  margin: 0;
  position: relative;
  z-index: 2;
  cursor: pointer;
}

#timeline:focus { outline: none; }

#timeline::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 2px;
}

#timeline::-moz-range-track {
  height: 3px;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 2px;
}

#timeline::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -7px;
  border-radius: 2px;
  background: var(--amber);
  border: 2px solid #1a1208;
  box-shadow: 0 0 10px rgba(232, 165, 75, 0.45);
}

#timeline::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 2px;
  background: var(--amber);
  border: 2px solid #1a1208;
  box-shadow: 0 0 10px rgba(232, 165, 75, 0.45);
}

.ticks {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 0;
  pointer-events: none;
  z-index: 1;
}

.tick {
  position: absolute;
  width: 2px;
  height: 8px;
  margin-left: -1px;
  margin-top: -4px;
  border-radius: 1px;
}

.tick.sun { background: var(--amber); opacity: 0.85; }
.tick.moon { background: var(--silver); opacity: 0.75; }

.timeline-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.62rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + var(--safe-b));
  transform: translateX(-50%);
  background: #1c2638;
  border: 1px solid var(--line-strong);
  color: var(--fg);
  font-size: 0.75rem;
  padding: 0.55rem 0.85rem;
  border-radius: 4px;
  z-index: 50;
  max-width: min(90vw, 20rem);
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media (min-width: 640px) {
  .app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}


/* Immersive finder — less chrome around the sphere */
.sky-stage[data-view="finder"] .heading-chip {
  background: rgba(8, 12, 20, 0.55);
  border-color: rgba(232, 236, 244, 0.1);
}
