:root {
  --bg: #05070f;
  --panel: rgba(13, 18, 34, 0.94);
  --panel-2: rgba(255, 255, 255, 0.05);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9edff;
  --muted: #98a3c7;
  --accent: #ffd27a;
  --accent-2: #86b6ff;
  --good: #8fe0a8;
  --warn: #ffb27a;
  --radius: 16px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#sky { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; z-index: 1; }
#cam { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; display: none; background: #000; }
body.ar #cam { display: block; }

/* ---------- 頂部列 ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 16px 18px;
  background: linear-gradient(to bottom, rgba(5, 7, 15, 0.85), rgba(5, 7, 15, 0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { flex: 1; min-width: 0; line-height: 1.25; }
.brand strong { display: block; font-size: 17px; letter-spacing: 0.04em; }
.brand small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
  font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip svg { width: 17px; height: 17px; }
.chip.sim { background: rgba(255, 210, 122, 0.18); border-color: rgba(255, 210, 122, 0.5); color: var(--accent); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
}
.icon-btn[aria-pressed="true"] { background: #b3261e; border-color: #ff6a5a; }

/* ---------- 畫面上的提示 ---------- */
.hud {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%);
  top: calc(64px + var(--safe-t));
  font-size: 12.5px; color: var(--muted);
  background: rgba(5, 7, 15, 0.55); padding: 3px 12px; border-radius: 999px;
  white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums;
}
.toast {
  position: fixed; z-index: 60; left: 50%; top: calc(98px + var(--safe-t));
  transform: translate(-50%, -8px); opacity: 0; transition: opacity .25s, transform .25s;
  background: rgba(20, 26, 48, 0.95); border: 1px solid var(--line);
  padding: 9px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); text-align: center;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.reticle {
  position: fixed; z-index: 5; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border: 1.5px solid rgba(255, 255, 255, 0.55); border-radius: 50%; pointer-events: none;
}
.reticle::after { content: ""; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: rgba(255, 255, 255, 0.8); }
.aim-label {
  position: fixed; z-index: 5; left: 50%; top: calc(50% + 34px); transform: translateX(-50%);
  background: rgba(5, 7, 15, 0.7); border: 1px solid var(--line); padding: 4px 12px; border-radius: 999px;
  font-size: 14px; pointer-events: auto; white-space: nowrap;
}

/* ---------- AR 校正 ---------- */
.calib {
  position: fixed; z-index: 25; left: 12px; right: 12px;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  max-width: 480px; margin: 0 auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.calib h2 { margin: 6px 0 4px; font-size: 19px; }
.calib p { margin: 0; font-size: 14px; }
.calib .calib-now { color: var(--muted); font-size: 12.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.calib-steps { display: flex; gap: 6px; font-size: 11.5px; color: var(--muted); }
.calib-steps span { padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.calib-steps span.on { color: #1a1406; background: var(--accent); border-color: transparent; font-weight: 700; }
.calib .btn-row { justify-content: space-between; }
.calib #calibOk { flex: 1; }
.reticle.big { width: 84px; height: 84px; margin: -42px 0 0 -42px; border: 2px solid var(--accent); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(255, 210, 122, 0.15); } }
.recal-btn {
  position: fixed; z-index: 8; right: 12px; top: calc(100px + var(--safe-t));
  padding: 7px 12px; border-radius: 999px; font-size: 13px;
  background: rgba(13, 18, 34, 0.75); border: 1px solid var(--line);
}

/* ---------- 地圖控制 ---------- */
.map-controls {
  position: fixed; z-index: 8; right: 12px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px;
}
.map-controls button, .dir-chips button {
  width: 42px; height: 42px; border-radius: 12px; font-size: 20px;
  background: rgba(13, 18, 34, 0.75); border: 1px solid var(--line);
}
.map-controls button.small { font-size: 12.5px; }
.dir-chips {
  position: fixed; z-index: 8; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  display: flex; gap: 8px;
}
.dir-chips button { width: 44px; height: 36px; font-size: 15px; border-radius: 999px; }
.dir-chips .play { display: grid; place-items: center; }
.dir-chips .play svg { width: 18px; height: 18px; }
.dir-chips .play.on { background: var(--accent); color: #1a1406; }
body.ar .map-controls, body.ar .dir-chips { display: none; }

/* ---------- 底部選單 ---------- */
.tabbar {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(8, 11, 22, 0.94); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.tabbar button {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11.5px; color: var(--muted);
}
.tabbar button.active { color: var(--accent); }

/* ---------- 底部面板 ---------- */
.sheet {
  position: fixed; z-index: 30; left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-b));
  max-height: min(62dvh, 560px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border-top: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 16px 20px;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  animation: up .22s ease-out;
  -webkit-user-select: text; user-select: text;
}
.sheet.tall { max-height: calc(100dvh - var(--tabbar-h) - var(--safe-b) - 60px - var(--safe-t)); }
@media (min-width: 720px) {
  .sheet { left: 50%; right: auto; width: 560px; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; animation: none; }
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-close {
  position: sticky; top: 0; float: right; margin: -6px -4px 0 8px;
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06);
  z-index: 1;
}
.sheet h2 { margin: 0 0 6px; font-size: 20px; }
.sheet h3 { margin: 20px 0 8px; font-size: 14px; color: var(--accent-2); letter-spacing: .06em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.warn { color: var(--warn); }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn-row button, button.primary, button.inline, .field select {
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07);
}
button.primary { background: var(--accent); color: #1a1406; border-color: transparent; font-weight: 700; }
button.block { width: 100%; padding: 12px; font-size: 16px; }
button.inline { padding: 3px 10px; margin-left: 8px; font-size: 13px; }

.field { display: block; margin: 12px 0; }
.field input[type="range"], .field input[type="datetime-local"], .field select { display: block; width: 100%; margin-top: 6px; }
.field input[type="datetime-local"] {
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--text); font: inherit;
}
.field select { color: var(--text); font: inherit; background: #151b30; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
.slider-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.time-now { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 6px 0 4px; }

.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toggles label {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 14px;
}
.toggles input { accent-color: var(--accent); width: 18px; height: 18px; }
@media (max-width: 360px) { .toggles { grid-template-columns: 1fr; } }

/* ---------- 資訊卡 ---------- */
.info .kicker { font-size: 12px; letter-spacing: .08em; color: var(--accent-2); }
.info h2 { margin: 2px 0 0; font-size: 22px; }
.info .sub { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0 12px; }
.fact { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.fact b { display: block; font-size: 15px; }
.fact span { font-size: 11.5px; color: var(--muted); }
.story { margin: 8px 0; }
.story-title { font-size: 13px; color: var(--accent); font-weight: 700; margin-top: 10px; }

/* ---------- 今晚星空 ---------- */
.card-block { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 10px 0; }
.row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.row:last-child { border-bottom: 0; }
.row .k { color: var(--muted); white-space: nowrap; }
.row .v { text-align: right; font-variant-numeric: tabular-nums; }
.rating { font-size: 15px; font-weight: 700; color: var(--good); }
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0;
}
.list-item .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 10px currentColor; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .main b { display: block; }
.list-item .main span { color: var(--muted); font-size: 13px; }
.list-item .go { color: var(--accent); font-size: 13px; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.const-chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); font-size: 14px;
}
.const-chip small { color: var(--muted); margin-left: 4px; }
.const-chip.star { border-color: rgba(255, 210, 122, 0.45); }
.const-chip.star::before { content: "★ "; color: var(--accent); }
.moon-icon { width: 44px; height: 44px; flex: none; }

/* ---------- 全螢幕說明 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(3, 5, 12, 0.82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.overlay .card {
  width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 22px 20px;
}
.overlay h2 { margin: 0 0 8px; }
.overlay ul { padding-left: 20px; margin: 10px 0; }
.overlay li { margin: 6px 0; }
.logo { font-size: 40px; color: var(--accent); text-align: center; line-height: 1; margin-bottom: 8px; text-shadow: 0 0 24px rgba(255, 210, 122, 0.7); }
.overlay .btn-row { justify-content: flex-end; }

/* ---------- 紅光夜視模式：用色彩相乘把整個畫面變成紅色 ---------- */
#redOverlay {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  background: #ff2200; mix-blend-mode: multiply; display: none;
}
body.red #redOverlay { display: block; }
