:root {
  --bg: #e9eef7;
  --panel: #f7f9ff;
  --muted: #5c6a86;
  --text: #1e2433;
  --accent: #2fbe82;
  --accent-2: #3b82f6;
  --border: #d6deeb;
  --danger: #d14343;
  --shadow: 0 14px 40px rgba(23, 43, 77, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 24px;
  font-family: "Inter", "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at 20% 20%, rgba(59, 130, 246, 0.12), transparent 25%),
    radial-gradient(circle at 80% 0%, rgba(47, 190, 130, 0.14), transparent 30%),
    var(--bg);
  color: var(--text);
}

header.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

h1,
h2 {
  margin: 4px 0 8px 0;
  font-weight: 700;
  letter-spacing: -0.4px;
}

h3 {
  margin: 4px 0 6px 0;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.tab-btn {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 10px 30px rgba(47, 190, 130, 0.25);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.status {
  padding: 10px 14px;
  background: rgba(47, 190, 130, 0.12);
  border: 1px solid rgba(47, 190, 130, 0.5);
  border-radius: 10px;
  color: var(--accent);
  min-width: 180px;
  text-align: center;
  box-shadow: var(--shadow);
}

.ghost-status {
  background: #ffffff;
  border: 1px dashed var(--border);
  color: var(--muted);
  box-shadow: none;
}

.panel {
  background: linear-gradient(135deg, #fdfdff, #f4f7ff);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 14px;
  color: var(--muted);
}

select,
input[type="file"],
button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
}

select:focus,
input[type="file"]:focus,
button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.pill {
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(91, 228, 168, 0.12);
  border: 1px solid rgba(91, 228, 168, 0.3);
  color: var(--accent);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.24);
  color: var(--accent-2);
  font-size: 12px;
}

button {
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease, box-shadow 0.2s ease;
}

button.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border: none;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(47, 190, 130, 0.25);
}

button.ghost {
  background: #ffffff;
  border: 1px dashed var(--border);
  color: var(--muted);
}

button:hover {
  transform: translateY(-1px);
}

.timeline {
  margin-top: 18px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.timeline-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  margin-bottom: 10px;
}

.slider {
  display: grid;
  gap: 8px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.chart-panel {
  padding-bottom: 8px;
}

.chart-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chart-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chart-card-header {
  color: var(--muted);
  font-size: 14px;
}

.chart-shell {
  position: relative;
  width: 100%;
  height: 260px;
}

.chart-shell canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.hint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  color: var(--muted);
}

code {
  background: #0c1224;
  padding: 2px 5px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--accent-2);
}

.typhoon-controls {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.typhoon-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
}

.typhoon-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.typhoon-guide {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.typhoon-guide-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.typhoon-guide img {
  width: 100%;
  height: auto;
  max-height: 240px;
  object-fit: contain;
  display: block;
  border-radius: 8px;
}

.map-shell {
  width: 100%;
  min-height: 520px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.typhoon-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.legend {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.legend-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.legend .swatch {
  width: 16px;
  height: 12px;
  border-radius: 4px;
  display: inline-block;
  border: 1px solid #e5e7eb;
}

.table-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.table-header {
  padding: 10px 12px;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.08);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.table-header-time {
  font-weight: 700;
  color: #111111;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table th,
table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

table tbody tr:nth-child(odd) {
  background: rgba(247, 249, 255, 0.6);
}

.table-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: #f8faff;
  font-size: 13px;
  color: var(--muted);
}

.pager-total {
  font-variant-numeric: tabular-nums;
}

.pager-btn {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-size: 12px;
}

.pager-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ranking-table--no-wind:not(.ranking-table--with-town) th:nth-child(4),
.ranking-table--no-wind:not(.ranking-table--with-town) td:nth-child(4) {
  display: none;
}

.ranking-table--no-wind.ranking-table--with-town th:nth-child(5),
.ranking-table--no-wind.ranking-table--with-town td:nth-child(5) {
  display: none;
}

.ranking-table--no-wind:not(.ranking-table--thi):not(.ranking-table--with-town) th:nth-child(5),
.ranking-table--no-wind:not(.ranking-table--thi):not(.ranking-table--with-town) th:nth-child(6),
.ranking-table--no-wind:not(.ranking-table--thi):not(.ranking-table--with-town) td:nth-child(5),
.ranking-table--no-wind:not(.ranking-table--thi):not(.ranking-table--with-town) td:nth-child(6) {
  display: none;
}

.ranking-table--no-wind.ranking-table--with-town:not(.ranking-table--thi) th:nth-child(6),
.ranking-table--no-wind.ranking-table--with-town:not(.ranking-table--thi) th:nth-child(7),
.ranking-table--no-wind.ranking-table--with-town:not(.ranking-table--thi) td:nth-child(6),
.ranking-table--no-wind.ranking-table--with-town:not(.ranking-table--thi) td:nth-child(7) {
  display: none;
}

.ranking-table--wind:not(.ranking-table--with-town) th:nth-child(5),
.ranking-table--wind:not(.ranking-table--with-town) th:nth-child(6),
.ranking-table--wind:not(.ranking-table--with-town) td:nth-child(5),
.ranking-table--wind:not(.ranking-table--with-town) td:nth-child(6) {
  display: none;
}

.ranking-table--wind.ranking-table--with-town th:nth-child(6),
.ranking-table--wind.ranking-table--with-town th:nth-child(7),
.ranking-table--wind.ranking-table--with-town td:nth-child(6),
.ranking-table--wind.ranking-table--with-town td:nth-child(7) {
  display: none;
}

.ranking-table--no-town.ranking-table--with-town th:nth-child(3),
.ranking-table--no-town.ranking-table--with-town td:nth-child(3) {
  display: none;
}

.ranking-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 16px;
  align-items: start;
}

.ranking-map .map-shell {
  min-height: 720px;
}

.ranking-table table tbody tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

.ranking-table table tbody tr:hover {
  background: var(--row-hover, rgba(47, 190, 130, 0.12));
}

.ranking-row--active {
  background: var(--row-hover, rgba(47, 190, 130, 0.2)) !important;
}

.town-tooltip {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
  box-shadow: var(--shadow);
}

.town-tooltip strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}

.wind-marker {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--arrow-fill, #8fd5ff);
  border: 1.5px solid rgba(0, 0, 0, 0.45);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.wind-arrow {
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 12px solid var(--arrow-color, #111);
  transform: rotate(var(--arrow-rotate, 0deg));
  transform-origin: 50% 60%;
  filter:
    drop-shadow(0 0 1px rgba(255, 255, 255, 0.9))
    drop-shadow(0 0 2px rgba(0, 0, 0, 0.35));
}

.colorbar-card {
  margin-top: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.colorbar-title {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.colorbar-vertical {
  display: flex;
  align-items: stretch;
  gap: 12px;
}

.colorbar-strip {
  height: 14px;
  border-radius: 999px;
  border: 1px solid #d1d9ea;
  overflow: hidden;
  background: #e5e7eb;
}

.colorbar-scale {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.colorbar-marks {
  position: relative;
  height: 6px;
}

.colorbar-marks span {
  position: absolute;
  width: 1px;
  height: 6px;
  background: #94a3b8;
}

.colorbar-strip.vertical {
  width: 18px;
  height: 260px;
  border-radius: 10px;
}

.colorbar-stops {
  display: grid;
  height: 100%;
}

.colorbar-stops.vertical {
  grid-auto-flow: row;
}

.colorbar-stops span {
  display: block;
  height: 100%;
}

.colorbar-ticks {
  position: relative;
  height: 16px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.colorbar-ticks.vertical {
  height: 260px;
  min-width: 44px;
  margin-top: 0;
}

.colorbar-ticks span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.colorbar-ticks.vertical span {
  transform: translateY(-50%);
  right: 0;
  left: auto;
}

.colorbar-ticks .tick-left {
  left: 0;
  transform: none;
}

.colorbar-ticks .tick-right {
  left: 100%;
  transform: translateX(-100%);
}

.colorbar-ticks.vertical .tick-bottom {
  bottom: 0;
  transform: translateY(0);
}

.colorbar-ticks.vertical .tick-top {
  top: 0;
  transform: translateY(-100%);
}

.colorbar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.colorbar-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.colorbar-swatch {
  width: 12px;
  height: 10px;
  border-radius: 4px;
  border: 1px solid #d1d9ea;
}

.realtime-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.realtime-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.realtime-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.alert-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: linear-gradient(135deg, #fdfdff, #f7faff);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
}

.alert-item.local-alert {
  background: linear-gradient(135deg, #fff2e0, #ffe7c2);
  border-color: rgba(255, 180, 100, 0.4);
}

.alert-item.local-alert.local-alert--aqi-orange {
  background: linear-gradient(135deg, #fff2e0, #ffe7c2);
  border-color: rgba(255, 180, 100, 0.5);
}

.alert-item.local-alert.local-alert--aqi-red {
  background: linear-gradient(135deg, #ffe6e6, #ffd1d1);
  border-color: rgba(220, 80, 80, 0.45);
}

.alert-item.local-alert.local-alert--aqi-purple {
  background: linear-gradient(135deg, #f1e6ff, #e5d2ff);
  border-color: rgba(140, 90, 200, 0.45);
}

.alert-item.local-alert.local-alert--aqi-maroon {
  background: linear-gradient(135deg, #f2e2e0, #e8c7c2);
  border-color: rgba(140, 70, 60, 0.5);
}

.alert-title {
  margin: 0 0 6px 0;
}

.alert-desc {
  margin: 6px 0 0 0;
  color: var(--text);
}

.alert-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.forecast-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.forecast-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.forecast-range {
  color: var(--muted);
  font-size: 13px;
}

.forecast-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--muted);
}

.data-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.data-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--muted);
}

.data-row strong {
  color: var(--text);
  font-weight: 600;
}

.small-map {
  min-height: 380px;
  margin-top: 10px;
}

.typhoon-live-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.typhoon-live-item {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
}

@media (max-width: 640px) {
  body {
    padding: 16px;
  }

  header.header {
    flex-direction: column;
  }

  .typhoon-layout {
    grid-template-columns: 1fr;
  }

  .map-shell {
    min-height: 360px;
  }

  .ranking-layout {
    grid-template-columns: 1fr;
  }
}
