:root {
  --paper: rgba(255, 250, 240, 0.9);
  --ink: #26303f;
  --muted: #6c7686;
  --line: rgba(38, 48, 63, 0.12);
  --accent: #ff6b4a;
  --live: #12a66a;
  --schedule: #d98a00;
  --simulated: #7d7aa8;
  --shadow: 0 10px 30px rgba(40, 50, 70, 0.18);
  font-family: ui-rounded, "SF Pro Rounded", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}
body[data-night="1"] {
  --paper: rgba(20, 30, 52, 0.88);
  --ink: #edf1fb;
  --muted: #9aa6c2;
  --line: rgba(237, 241, 251, 0.14);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a9dcd9; color: var(--ink); }
#map { position: fixed; inset: 0; }
#map canvas.agents { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.card {
  position: fixed; background: var(--paper); border-radius: 18px; box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line); transition: background 0.8s, color 0.8s;
}
.brand { top: 14px; left: 14px; padding: 12px 14px; width: 252px; z-index: 3; }
.brand-row { display: flex; gap: 10px; align-items: center; }
.brand h1 { margin: 0; font-size: 19px; letter-spacing: -0.02em; line-height: 1.1; }
.brand p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.brand select { font: inherit; color: inherit; background: transparent; border: 0; padding: 0; }
.clock {
  margin-top: 10px; width: 100%; display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  background: transparent; border: 0; border-top: 1px solid var(--line); padding: 9px 0 0; text-align: left;
}
#clock-time { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
#clock-wx { font-size: 13px; color: var(--muted); text-align: right; }
#dial { margin-top: 8px; font-size: 12px; color: var(--muted); }
#dial input { width: 100%; accent-color: var(--accent); margin: 6px 0 4px; }
.dial-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 26px; }
#dial-now { border: 0; background: var(--accent); color: #fff; border-radius: 999px; padding: 4px 11px; font-size: 12px; margin-left: auto; white-space: nowrap; }
body[data-preview="1"] #clock-time { color: var(--accent); }

.corner { position: fixed; top: 14px; right: 14px; display: flex; gap: 8px; z-index: 4; }
.round {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper);
  box-shadow: var(--shadow); font-weight: 700; font-size: 14px; backdrop-filter: blur(14px);
}
.round[aria-expanded="true"] { background: var(--accent); color: #fff; }

.chips {
  position: fixed; left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 3;
  display: flex; gap: 8px; padding: 4px 14px; overflow-x: auto; scrollbar-width: none; justify-content: safe center;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: flex; align-items: center; gap: 7px; padding: 8px 13px 8px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); font-size: 13.5px; font-weight: 600;
  backdrop-filter: blur(14px); transition: opacity 0.2s, transform 0.2s;
}
.chip:active { transform: scale(0.96); }
.chip[aria-pressed="false"] { opacity: 0.55; }
.chip[aria-pressed="false"] .dot { background: transparent !important; box-shadow: inset 0 0 0 2px var(--muted); animation: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.live { background: var(--live); animation: beat 1.8s ease-in-out infinite; }
.dot.schedule { background: var(--schedule); }
.dot.simulated { background: var(--simulated); }
.dot.down { background: #c0392b; animation: none; }
@keyframes beat { 0%, 100% { box-shadow: 0 0 0 0 rgba(18, 166, 106, 0.55); } 60% { box-shadow: 0 0 0 6px rgba(18, 166, 106, 0); } }

.panel { top: 64px; right: 14px; width: 318px; max-height: calc(100% - 140px); overflow-y: auto; padding: 4px 16px 12px; z-index: 4; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin: 14px 0 8px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.stats div { background: var(--line); border-radius: 12px; padding: 8px 10px; }
.stats dt { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.stats dd { margin: 2px 0 0; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats dd small { font-size: 12px; font-weight: 500; color: var(--muted); }
.layer-list, .credits { list-style: none; margin: 0; padding: 0; }
.layer-list li { padding: 9px 0; border-top: 1px solid var(--line); }
.layer-list li:first-child { border-top: 0; }
.layer-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14.5px; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff; margin-left: auto; }
.tag.live { background: var(--live); } .tag.schedule { background: var(--schedule); } .tag.simulated { background: var(--simulated); }
.layer-list p { margin: 4px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.layer-list .warn { color: #c0392b; }
.credits li { font-size: 12.5px; line-height: 1.5; padding: 3px 0; }
.credits a { color: inherit; }
.credits span { color: var(--muted); }
.fine { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin: 8px 0 0; }

#loading {
  position: fixed; inset: 0; z-index: 10; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: #f6efdf; color: #26303f; transition: opacity 0.6s; font-weight: 600;
}
#loading.done { opacity: 0; pointer-events: none; }
.pulse { width: 46px; height: 46px; border-radius: 14px; background: var(--accent); animation: rise 1.1s ease-in-out infinite alternate; }
@keyframes rise { from { transform: scaleY(0.35); transform-origin: bottom; } to { transform: scaleY(1); transform-origin: bottom; } }

.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: 58px; }
.maplibregl-ctrl-group { border-radius: 14px !important; overflow: hidden; }

@media (max-width: 640px) {
  .brand { width: auto; right: 112px; padding: 10px 12px; }
  #clock-time { font-size: 21px; }
  .panel { top: auto; left: 8px; right: 8px; bottom: 66px; width: auto; max-height: 58%; }
  .chips { justify-content: flex-start; }
}
@media (prefers-reduced-motion: reduce) { .dot.live, .pulse { animation: none; } }
