/* ==========================================================================
   全球热带气旋图集 — 浅灰主题 · 手机优先 · 纯静态
   ========================================================================== */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #ef4444;
  --accent-weak: #fef2f2;
  --accent-line: #fecaca;
  --sea: #e9eef5;
  --radius: 14px;
  --topbar-h: 62px;
  --yearbar-h: 57px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  padding-top: var(--topbar-h);
  padding-bottom: calc(var(--yearbar-h) + 14px + var(--safe-b));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: contain;
}

h1, h2, p, dl, dd, dt { margin: 0; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   顶部固定信息栏
   -------------------------------------------------------------------------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 7px;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 8px;
  align-items: center;
}

.tb-sep {
  background: var(--line);
  width: 1px;
  height: 32px;
  justify-self: center;
}

.tb-group { min-width: 0; }
.tb-group--right { padding-left: 2px; }

.tb-cap {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-cells {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 1px;
}

.metric {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.m-lab {
  font-size: 9px;
  line-height: 1.15;
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.m-val {
  font-size: clamp(11px, 3.2vw, 13px);
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.m-val i {
  font-style: normal;
  font-weight: 500;
  font-size: 8.5px;
  color: var(--muted);
  margin-left: 1px;
  letter-spacing: 0;
}

/* --------------------------------------------------------------------------
   页面主体
   -------------------------------------------------------------------------- */

.page {
  max-width: 1200px;
  margin: 0 auto;
}

.map-card {
  background: var(--card);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-top: 10px;
}

.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 12px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  color: var(--accent);
}

.brand-text { min-width: 0; }

.brand h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.3;
  white-space: nowrap;
}

.brand-sub {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1.4;
}

.map-head-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 0 1 auto;
}

.status-dot {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
}

.status-dot.is-wait {
  background: #f59e0b;
}

.map-status {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}

/* 图层胶囊按钮 */
.layerbar {
  display: flex;
  gap: 8px;
  padding: 4px 10px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.layerbar::-webkit-scrollbar { display: none; }

.pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.pill[aria-pressed="true"] {
  color: #b91c1c;
  border-color: var(--accent-line);
  background: var(--accent-weak);
}

.pill[hidden] { display: none; }

.pill--filter {
  color: #b91c1c;
  background: #fff;
  border-style: dashed;
}

.pill b { font-weight: 700; }

/* --------------------------------------------------------------------------
   地图画布
   -------------------------------------------------------------------------- */

.canvas-wrap {
  position: relative;
  background: var(--sea);
  overflow: hidden;
}

#map {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 1;
  touch-action: none;
  cursor: grab;
  background: var(--sea);
}

#map:active { cursor: grabbing; }

.map-hint {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font-size: 10px;
  color: #475569;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  pointer-events: none;
  white-space: nowrap;
}

.map-msg {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  text-align: center;
  background: rgba(244, 245, 247, 0.78);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.map-msg[hidden] { display: none; }
.map-msg p { font-size: 13px; color: var(--ink); }
.map-msg small { font-size: 11px; color: var(--muted); max-width: 280px; }

.map-msg .btn {
  height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* 风暴详情卡 */
.detail {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 6;
  background: rgba(255, 255, 255, 0.985);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
  padding: 10px 12px 12px;
  max-height: 72%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  animation: cardIn 0.16s ease-out;
}

.detail[hidden] { display: none; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.d-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.d-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding-top: 2px;
}

.d-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.d-title b {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.d-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.d-close {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin: -6px -6px 0 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px solid var(--line);
  background: #fff;
}

.d-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  margin-top: 8px;
}

.d-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.d-item.wide { grid-column: 1 / -1; }

.d-k {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.3;
}

.d-v {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.d-item.wide .d-v {
  white-space: normal;
  font-size: 11.5px;
  color: #374151;
}

@media (max-width: 759px) {
  .detail {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--yearbar-h) + 8px + var(--safe-b));
    z-index: 35;
    max-height: 46vh;
  }
}

/* 图例 */
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 8px 12px 12px;
  font-size: 10.5px;
  color: var(--muted);
}

.lg-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.lg-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}

.lg-shape { color: #64748b; flex: 0 0 auto; }

.lg-item em {
  font-style: normal;
  color: #94a3b8;
  font-size: 10px;
}

.note {
  padding: 0 12px 12px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}

.note[hidden] { display: none; }
.note b { color: #b91c1c; font-weight: 600; }

/* --------------------------------------------------------------------------
   热力图 / 年度统计
   -------------------------------------------------------------------------- */

.dash {
  display: grid;
  gap: 10px;
  padding: 10px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 6px;
}

.card-head h2 {
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.card-head span {
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
  line-height: 1.35;
}

.hm-scroll {
  overflow: auto;
  max-height: 420px;
  padding: 2px 10px 10px;
  -webkit-overflow-scrolling: touch;
}

.hm { display: grid; gap: 3px; min-width: 0; }

.hm-row {
  display: grid;
  grid-template-columns: 44px repeat(6, minmax(0, 1fr));
  gap: 3px;
  align-items: stretch;
  border-radius: 6px;
}

.hm-row.is-year { background: #f8fafc; }

.hm-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 5px;
  font-size: 10px;
  color: var(--muted);
  border: 0;
  background: transparent;
}

.hm-head .hm-cell {
  height: 20px;
  min-height: 20px;
  font-size: 9.5px;
  font-weight: 600;
  color: #94a3b8;
  letter-spacing: 0.03em;
}

.hm-corner {
  justify-content: flex-start;
  padding-left: 2px;
  font-size: 9px;
  color: #94a3b8;
}

.hm-year {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px;
}

.hm-year:hover { background: #f1f5f9; }
.hm-row.is-year .hm-year { color: var(--ink); font-weight: 700; }

.hm-val {
  position: relative;
  transition: box-shadow 0.12s ease, transform 0.12s ease;
}

.hm-val.is-zero { background: #f8fafc; }
.hm-val:active { transform: scale(0.95); }
.hm-val.is-basin { box-shadow: inset 0 0 0 1.5px rgba(31, 41, 51, 0.28); }
.hm-val.is-pick { box-shadow: inset 0 0 0 2px var(--ink); }

.hm-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px 12px;
  font-size: 10px;
  color: #94a3b8;
}

.hm-scale {
  flex: 0 0 78px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.05), rgba(239, 68, 68, 1));
  border: 1px solid var(--line);
}

/* 年度统计列表 */
.stat-list {
  max-height: 420px;
  overflow: auto;
  padding: 2px 12px 12px;
  -webkit-overflow-scrolling: touch;
}

.yr-row {
  padding: 7px 0;
  border-top: 1px solid #f1f3f6;
}

.yr-row:first-child { border-top: 0; }

.yr-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.yr-year {
  min-height: 30px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.yr-year:hover { background: #f1f5f9; }

.yr-storms {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.yr-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.yr-lab {
  flex: 0 0 26px;
  font-size: 9.5px;
  color: #94a3b8;
  white-space: nowrap;
}

.bar {
  flex: 1 1 auto;
  min-width: 20px;
  height: 7px;
  border-radius: 4px;
  background: #f1f3f6;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: 4px;
  background: var(--accent);
}

.bar--alt i { background: #94a3b8; }

.yr-val {
  flex: 0 0 auto;
  min-width: 62px;
  text-align: right;
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty {
  padding: 18px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   底部年份条
   -------------------------------------------------------------------------- */

.yearbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: rgba(244, 245, 247, 0.96);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 8px 0 calc(8px + var(--safe-b));
}

.yearbar-inner {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 10px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-padding-inline: 12px;
}

.yearbar-inner::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  height: 40px;
  min-width: 58px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.chip--all { min-width: 64px; color: #b91c1c; }
.chip--all[aria-pressed="true"] { color: #fff; }

/* 页脚 */
.foot {
  padding: 14px 12px 12px;
  text-align: center;
  font-size: 10.5px;
  line-height: 1.7;
  color: #94a3b8;
}

.foot p { margin: 0; }

.noscript {
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   桌面端自适应
   -------------------------------------------------------------------------- */

@media (min-width: 760px) {
  body { padding-bottom: calc(var(--yearbar-h) + 22px + var(--safe-b)); }

  .page { padding: 14px 16px 0; }

  .map-card {
    margin-top: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
  }

  .map-head { padding: 14px 16px 6px; }
  .brand h1 { font-size: 17px; }
  .brand-sub { font-size: 11.5px; }
  .layerbar { padding: 6px 16px 12px; }
  .legend { padding: 8px 16px 14px; font-size: 11px; }
  .note { padding: 0 16px 14px; }
  .map-hint { font-size: 11px; }
  .map-status { max-width: 260px; }

  .dash {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
    padding: 12px 0 0;
  }

  .hm-scroll, .stat-list { max-height: 460px; }
  .hm-row { grid-template-columns: 52px repeat(6, minmax(0, 1fr)); }
  .hm-cell { height: 30px; min-height: 30px; }
  .hm-head .hm-cell { height: 20px; min-height: 20px; }

  .topbar { padding-left: 16px; padding-right: 16px; }
  .tb-cells { gap: 14px; }
  .m-val { font-size: 14px; }
  .m-lab { font-size: 9.5px; }
  .tb-cap { font-size: 10.5px; }

  .yearbar-inner { padding: 0 16px; }
}

@media (min-width: 1024px) {
  .dash { grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr); }
}

/* --------------------------------------------------------------------------
   减少动效
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
