:root {
  color-scheme: dark;
  --bg: #061018;
  --ink: #e8eef4;
  --soft: #9aabba;
  --faint: #6d8092;
  --line: rgba(214, 228, 240, 0.14);
  --glass: rgba(8, 16, 26, 0.72);
  --glass-strong: rgba(10, 18, 30, 0.88);
  --paper: rgba(255, 255, 255, 0.045);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --stale: #e0b27a;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Songti SC", "Noto Serif SC", serif;
  --sans: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-family: var(--sans);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
p { margin: 0; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#stage { position: relative; height: 100dvh; overflow: hidden; }
#map { position: absolute; inset: 0; background: #061018; }

.vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 46%, transparent 36%, rgba(2, 6, 12, 0.55) 100%),
    radial-gradient(ellipse at 12% 88%, rgba(18, 72, 92, 0.22), transparent 46%),
    radial-gradient(ellipse at 88% 12%, rgba(120, 36, 28, 0.12), transparent 40%);
}

.top, .foot, #panel, #hover, .banner, .maplibregl-ctrl { z-index: 3; }

.top {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 12px 14px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--glass);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(16px) saturate(1.2);
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--line);
  flex: none;
}
.kicker {
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--soft);
}
h1 {
  margin: 1px 0 0;
  font-family: var(--serif);
  font-weight: 560;
  font-size: 26px;
  letter-spacing: 0.01em;
  line-height: 1.05;
}
.sub { margin-top: 4px; color: var(--faint); font-size: 12px; line-height: 1.35; max-width: 36ch; }

.wwi {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 2px 8px 0 16px;
  border-left: 1px solid var(--line);
  min-width: 148px;
}
.wwi-label {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--soft);
}
.wwi-score {
  margin: 0;
  font-family: var(--serif);
  font-size: 46px;
  line-height: 0.9;
  font-weight: 560;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 24px color-mix(in srgb, currentColor 45%, transparent);
}

.tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.search { position: relative; color: var(--soft); }
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  pointer-events: none;
}
.search input {
  width: 230px;
  background: rgba(4, 10, 16, 0.55);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px 9px 34px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.search input::placeholder { color: var(--faint); }
.search input:focus {
  outline: none;
  border-color: rgba(234, 179, 8, 0.7);
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.16);
}
#suggest {
  position: absolute;
  z-index: 5;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--glass-strong);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  max-height: 260px;
  overflow: auto;
}
#suggest button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 9px;
  transition: background 0.15s ease;
}
#suggest button:hover, #suggest button:focus { background: rgba(255, 255, 255, 0.08); }

.lang {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(4, 10, 16, 0.4);
}
.lang button {
  background: transparent;
  border: 0;
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--soft);
  transition: background 0.2s ease, color 0.2s ease;
}
.lang button[aria-pressed="true"] { background: var(--ink); color: #10202c; }

#hover {
  position: fixed;
  z-index: 4;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
#hover[hidden] { display: none; }
.swatch {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
  flex: none;
}
.hover-meta { color: var(--soft); }

#panel {
  position: absolute;
  z-index: 6;
  top: 96px;
  right: 16px;
  bottom: 108px;
  width: min(400px, calc(100vw - 28px));
  overflow: auto;
  color: var(--ink);
  border-radius: 22px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(18, 32, 48, 0.92), rgba(8, 14, 22, 0.94));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(18px);
  padding: 18px 16px 22px;
  transform: translateX(18px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.34s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.34s ease;
}
#panel.is-open { transform: none; opacity: 1; pointer-events: auto; }
#panel[hidden] { display: none; }
.panel-glow {
  position: sticky;
  top: -18px;
  height: 0;
}
.panel-glow::before {
  content: "";
  position: absolute;
  left: 20%;
  right: 10%;
  top: -40px;
  height: 80px;
  background: radial-gradient(ellipse, rgba(239, 68, 68, 0.22), transparent 70%);
  pointer-events: none;
}
.panel-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.iso { letter-spacing: 0.18em; font-size: 11px; color: var(--soft); }
#panel h2 {
  margin: 2px 0 0;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 560;
  line-height: 1.05;
}
#panel-close {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  color: var(--ink);
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.15s ease;
}
#panel-close:hover { background: rgba(255, 255, 255, 0.12); transform: rotate(90deg); }

.stale-badge:not([hidden]) {
  display: inline-flex;
  align-items: center;
  margin: 10px 0 0;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(224, 178, 122, 0.14);
  color: var(--stale);
  border: 1px solid rgba(224, 178, 122, 0.35);
  font-size: 12px;
}
.rationale {
  margin-top: 14px;
  line-height: 1.55;
  font-size: 15px;
  color: #d5e0ea;
  border-left: 2px solid rgba(234, 179, 8, 0.75);
  padding-left: 12px;
}

#scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}
.meter {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 11px 12px;
}
.meter-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.meter-label { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--soft); }
.meter strong { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 620; letter-spacing: -0.03em; }
.track { height: 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

h3 {
  margin: 18px 0 8px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips a, .chips span {
  color: #d7e2ec;
  text-decoration: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  line-height: 1.35;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.chips a:hover { border-color: rgba(232, 238, 244, 0.45); background: rgba(255, 255, 255, 0.08); }
.empty-note { color: var(--soft); font-size: 13px; }

.history { display: flex; align-items: flex-end; gap: 8px; min-height: 72px; }
.history-col { display: flex; flex-direction: column; align-items: center; gap: 5px; width: 28px; }
.history-bar { width: 8px; border-radius: 99px; min-height: 4px; }
.history-col span { font-size: 10px; color: var(--faint); font-variant-numeric: tabular-nums; }

.banner {
  position: absolute;
  z-index: 5;
  left: 16px;
  bottom: 108px;
  max-width: min(440px, calc(100vw - 32px));
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.banner p { line-height: 1.45; color: #d5e0ea; }
.banner button {
  margin-top: 10px;
  background: var(--ink);
  color: #10202c;
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
}

.foot {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--glass);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(16px) saturate(1.15);
}
.legend { min-width: 240px; }
.legend-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 7px; }
#legend-label { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; }
.legend-note { color: var(--faint); font-size: 11px; }
.ramp-row { display: flex; align-items: center; gap: 8px; }
.tick { font-size: 11px; color: var(--soft); font-variant-numeric: tabular-nums; }
.ramp {
  width: 168px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green) 0%, var(--yellow) 50%, var(--red) 100%);
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.28), inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.disclaimer-wrap {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--soft);
  max-width: 640px;
}
.disclaimer-kicker {
  display: inline-block;
  margin-right: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 10px;
  color: #f0d48a;
}

.maplibregl-ctrl-bottom-left { bottom: 108px; left: 18px; }
.maplibregl-ctrl-attrib {
  background: rgba(6, 16, 24, 0.55) !important;
  color: var(--faint) !important;
  backdrop-filter: blur(8px);
}
.maplibregl-ctrl-attrib a { color: var(--soft) !important; }
.maplibregl-ctrl-group {
  background: rgba(8, 16, 24, 0.78) !important;
  border: 1px solid var(--line) !important;
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.maplibregl-ctrl-group button { filter: invert(0.92) hue-rotate(180deg); }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }

@media (prefers-reduced-motion: reduce) {
  #panel, .fill, #panel-close, .lang button, #suggest button { transition: none; }
}

@media (max-width: 860px) {
  .top, .foot { left: 8px; right: 8px; }
  .top { top: 8px; flex-direction: column; align-items: stretch; gap: 10px; padding: 10px; }
  h1 { font-size: 22px; }
  .wwi {
    align-items: flex-start;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 8px 2px 0;
    min-width: 0;
  }
  .wwi-score { font-size: 40px; }
  .tools { justify-content: space-between; }
  .search, .search input { width: 100%; }
  .foot { bottom: 8px; flex-direction: column; align-items: stretch; gap: 10px; }
  .ramp { width: 100%; }
  #panel {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: min(62dvh, 520px);
    transform: translateY(16px);
    border-radius: 18px 18px 14px 14px;
  }
  #panel.is-open { transform: none; }
  #panel h2 { font-size: 26px; }
  .banner { left: 8px; right: 8px; bottom: auto; top: 132px; max-width: none; }
  .maplibregl-ctrl-bottom-left { bottom: auto; top: 148px; left: 10px; }
}
