:root {
  color-scheme: dark;
  --bg: #08131d;
  --bg-soft: #0d1b27;
  --panel: #122230;
  --panel-2: #172b3a;
  --text: #eaf4f8;
  --muted: #9bb2c1;
  --line: #294353;
  --primary: #55d2d0;
  --primary-strong: #168f97;
  --warm: #ffc866;
  --shadow: 0 18px 45px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 0%, rgba(42, 133, 143, .16), transparent 34rem),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Noto Sans TC", sans-serif;
}

body.light {
  color-scheme: light;
  --bg: #edf4f5;
  --bg-soft: #e3edef;
  --panel: #fff;
  --panel-2: #f6fafb;
  --text: #17313c;
  --muted: #526c78;
  --line: #c6d7dc;
  --primary: #087f86;
  --primary-strong: #086b74;
  --warm: #9b6500;
  --shadow: 0 18px 45px rgba(37, 73, 82, .10);
}

a { color: var(--primary); }

.site-toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 8px max(20px, calc((100vw - 1500px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(7, 18, 27, .87);
  color: var(--muted);
  font-size: 13px;
  backdrop-filter: blur(12px);
}

body.light .site-toolbar { background: rgba(255, 255, 255, .88); }
.site-toolbar a { color: inherit; text-decoration: none; }
.site-toolbar a:hover { color: var(--primary); }
.site-toolbar .site-home { color: var(--primary); font-weight: 900; letter-spacing: .02em; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px max(20px, calc((100vw - 1500px) / 2));
  background: linear-gradient(135deg, rgba(19, 44, 57, .94), rgba(11, 28, 39, .84));
  border-bottom: 1px solid var(--line);
  gap: 18px;
}

body.light header { background: linear-gradient(135deg, #fff, #edf7f7); }
header h1 { margin: 4px 0; font-size: clamp(24px, 2.7vw, 36px); letter-spacing: -.02em; }
header h1 small { margin-left: 7px; color: var(--warm); font-size: 12px; letter-spacing: .04em; }
header p { margin: 0; color: var(--muted); }
.eyebrow, .panel-kicker { margin: 0; color: var(--primary); font-size: 10px; font-weight: 900; letter-spacing: .16em; }
.header-actions, .toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

main {
  display: grid;
  gap: 16px;
  max-width: 1500px;
  margin: auto;
  padding: 20px;
}

.panel {
  min-width: 0;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, var(--panel), color-mix(in srgb, var(--panel) 93%, var(--primary) 7%));
  box-shadow: var(--shadow);
}

.panel h2 { margin: 0 0 10px; font-size: 18px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.fields { display: grid; grid-template-columns: repeat(3, minmax(115px, 1fr)); gap: 12px; margin-bottom: 13px; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
input, select, button { font: inherit; }
input[type="date"], select {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-soft);
  color: var(--text);
}

input[type="range"] { width: 100%; accent-color: var(--primary); }
button {
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, transform .15s, background .15s;
}

button:hover { border-color: var(--primary); transform: translateY(-1px); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }
button.primary { border-color: var(--primary-strong); background: var(--primary-strong); color: #fff; font-weight: 750; }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.status {
  padding: 4px 9px;
  border: 1px solid color-mix(in srgb, var(--primary) 55%, transparent);
  border-radius: 999px;
  color: var(--primary);
  font-size: 12px;
}

.muted, #feedback { color: var(--muted); font-size: 13px; }
.workspace { display: grid; grid-template-columns: minmax(360px, 1.12fr) minmax(360px, 1fr); gap: 16px; }

#map {
  height: 510px;
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #a7c5d7;
  z-index: 0;
  overflow: hidden;
}

.leaflet-container { font-family: inherit; }
.leaflet-container canvas { width: auto; height: auto; max-height: none; }
.inline-label { display: flex; flex-direction: row; align-items: center; gap: 7px; white-space: nowrap; }
.inline-label select { max-width: 165px; }
.inline-label input[type="range"] { width: 118px; }
.check-label { display: flex; flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }
.check-label input { accent-color: var(--primary); }

.legend { display: flex; gap: 15px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 4px; border-radius: 50%; }
.shallow { background: #2cb6b3; }
.medium { background: #e8b455; }
.deep { background: #e87985; }

.chart-wrap {
  display: flex;
  align-items: center;
  height: 510px;
  margin-top: 8px;
  border: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(57, 111, 128, .08), transparent 32%);
  overflow: hidden;
}

canvas { max-height: 100%; width: 100%; height: auto; background: transparent; cursor: crosshair; }
.camera-controls { margin-top: 10px; padding: 9px 10px; border-radius: 10px; background: var(--bg-soft); }
.time-panel input[type="range"] { margin-top: 12px; }
.bottom { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; }
.bottom ol { margin: 8px 0; padding-left: 24px; }
.event-layout { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: center; }
.event-layout p { margin: 7px 0; }
.mechanism-card { display: flex; align-items: center; gap: 12px; min-width: 285px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-soft); }
.mechanism-card canvas { width: 112px; height: 112px; flex: 0 0 112px; cursor: default; }
.mechanism-card .muted { max-width: 180px; margin: 4px 0 0; }

footer { padding: 25px; color: var(--muted); text-align: center; font-size: 13px; }
.mag-pillar { position: relative; border: 1px solid rgba(255,255,255,.68); border-radius: 4px 4px 0 0; background: linear-gradient(90deg, rgba(255,255,255,.42), transparent 35%), var(--pillar); box-shadow: 0 0 5px rgba(0,0,0,.42); cursor: pointer; }
.mag-pillar.selected { outline: 3px solid #fff; }
.section-band { stroke-dasharray: 6 6; }
.band-summary { margin: 8px 0; padding: 9px 11px; border-left: 3px solid var(--primary); background: var(--bg-soft); border-radius: 6px; font-size: 13px; }
#globe { position: relative; height: 590px; margin: 12px 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #030c1d; touch-action: none; cursor: grab; }
#globe:active { cursor: grabbing; }
#globe canvas { display: block; max-height: none; cursor: inherit; }
.globe-hint { position: absolute; bottom: 16px; left: 18px; z-index: 1; pointer-events: none; color: #a9c7dc; font-size: 12px; }
@media (max-width: 640px) { #globe { height: 420px; } }

dialog { max-width: 580px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); color: var(--text); }
dialog::backdrop { background: #0009; }

@media (max-width: 940px) {
  .workspace, .bottom { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 1fr 1fr; }
  #map { height: 430px; }
  .chart-wrap { height: 390px; }
}

@media (max-width: 640px) {
  .site-toolbar { overflow-x: auto; white-space: nowrap; }
  header { align-items: flex-start; flex-wrap: wrap; }
  main { padding: 11px; }
  .fields { grid-template-columns: 1fr 1fr; }
  .panel { padding: 12px; border-radius: 13px; }
  #map { height: 345px; }
  .chart-wrap { height: 310px; }
  .inline-label { white-space: normal; }
  .event-layout { grid-template-columns: 1fr; }
  .mechanism-card { min-width: 0; }
}

@media (max-width: 430px) {
  .fields { grid-template-columns: 1fr; }
  .title-row { align-items: flex-start; }
}

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