/* ============================================================
   降雨機率預報追蹤器 — 深色主題設計系統
   ============================================================ */

/* --- Design Tokens --- */
:root {
  color-scheme: dark;

  /* 色彩 */
  --bg: #0a0e14;
  --bg-soft: #0f1520;
  --surface: #111927;
  --surface-2: #162032;
  --surface-3: #0d1219;

  --text: #edf2f8;
  --text-secondary: #a0b1c5;
  --muted: #6b7f96;

  --line: rgba(140, 165, 195, 0.12);
  --line-strong: rgba(140, 165, 195, 0.22);

  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.15);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.12);
  --yellow: #fbbf24;
  --yellow-soft: rgba(251, 191, 36, 0.12);
  --red: #f87171;

  /* 陰影 */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.35);

  /* 圓角 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 999px;

  /* 動畫 */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 0.15s var(--ease-out);
  --transition: 0.25s var(--ease-out);
}

/* --- Reset --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Noto Sans TC", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p {
  margin: 0;
}

/* --- Ambient Glow --- */
.page-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 600px 400px at 25% -5%, rgba(96, 165, 250, 0.08), transparent),
    radial-gradient(ellipse 500px 350px at 75% 105%, rgba(52, 211, 153, 0.05), transparent);
}

/* --- Typography --- */
h1 {
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  background: linear-gradient(135deg, #edf2f8, #a0b1c5);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
  color: var(--text);
}

p {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

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

/* --- Eyebrow & Labels --- */
.eyebrow-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.eyebrow,
.section-label {
  display: inline-block;
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px 2px 8px;
  border-radius: var(--radius-full);
  background: var(--green-soft);
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* --- Topbar --- */
.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(1100px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 22px;
}

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

/* --- Toolbar --- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  background: rgba(17, 25, 39, 0.85);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-sm);
}

.tool-button,
button {
  border: none;
  border-radius: var(--radius-full);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  transition: all var(--transition-fast);
}

.tool-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.tool-button:hover {
  background: var(--surface);
  color: var(--text);
  transform: translateY(-1px);
}

.tool-button.active {
  background: var(--accent);
  color: #0a0e14;
}

.tool-button.active svg {
  stroke: #0a0e14;
}

.refresh-btn {
  background: var(--yellow);
  color: #0a0e14;
}

.refresh-btn svg {
  stroke: #0a0e14;
}

.refresh-btn:hover {
  background: #f9cf47;
  color: #0a0e14;
  box-shadow: 0 0 20px rgba(251, 191, 36, 0.3);
}

.refresh-btn:active svg {
  animation: spin-once 0.5s var(--ease-out);
}

@keyframes spin-once {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* --- Main --- */
main {
  position: relative;
  z-index: 1;
  width: min(1100px, calc(100% - 40px));
  margin: 0 auto 40px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* --- Panels --- */
.panel,
.forecast-row {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(
    180deg,
    rgba(17, 25, 39, 0.92) 0%,
    rgba(15, 21, 32, 0.96) 100%
  );
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(8px);
}

.overview-panel {
  overflow: hidden;
}

.panel {
  padding: 22px;
}

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

.panel-header h2 {
  margin-top: 4px;
}

.panel-meta {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.section-label {
  display: inline-block;
  margin-bottom: 2px;
}

/* --- Section Heading --- */
.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin-top: 4px;
}

.section-heading p {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- Chart Containers --- */
.chart-wrap {
  position: relative;
  width: 100%;
  border: 1px solid rgba(140, 165, 195, 0.08);
  border-radius: var(--radius-md);
  background: linear-gradient(
    180deg,
    rgba(10, 14, 20, 0.5) 0%,
    rgba(10, 14, 20, 0.2) 100%
  );
}

.chart-wrap.large {
  height: 400px;
  padding: 14px 14px 8px;
}

.chart-wrap.detail {
  height: 280px;
  padding: 12px;
  background: rgba(10, 14, 20, 0.5);
}

.chart-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 0 2px;
  font-size: 12px;
  color: var(--muted);
}

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

.chart-legend-swatch {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 2px;
}

/* --- Forecast List --- */
.list-section {
  /* parent gap handles spacing */
}

.forecast-list {
  display: grid;
  gap: 8px;
}

.forecast-row {
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.forecast-row:hover {
  box-shadow: var(--shadow-lg);
}

.row-summary {
  display: grid;
  grid-template-columns: 148px 72px minmax(140px, 1fr) 42px;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.row-summary:hover {
  background: rgba(96, 165, 250, 0.04);
}

.forecast-time {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.latest-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  min-height: 28px;
  border: 1px solid rgba(52, 211, 153, 0.2);
  border-radius: 6px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* 依降雨機率動態上色 — JS 會加上 data-level */
.latest-value[data-level="low"] {
  border-color: rgba(52, 211, 153, 0.2);
  background: var(--green-soft);
  color: var(--green);
}
.latest-value[data-level="mid"] {
  border-color: rgba(251, 191, 36, 0.2);
  background: var(--yellow-soft);
  color: var(--yellow);
}
.latest-value[data-level="high"] {
  border-color: rgba(248, 113, 113, 0.2);
  background: rgba(248, 113, 113, 0.1);
  color: var(--red);
}

.sparkline-box {
  position: relative;
  display: block;
  height: 40px;
  min-width: 0;
}

.expand-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: end;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0;
  transition: all var(--transition-fast);
}

.expand-indicator::after {
  content: "";
  display: block;
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: transform var(--transition);
}

.row-summary[aria-expanded="true"] .expand-indicator {
  background: var(--accent);
  color: #0a0e14;
  border-color: transparent;
}

.row-summary[aria-expanded="true"] .expand-indicator::after {
  transform: rotate(-135deg) translate(-1px, -1px);
}

.row-detail {
  border-top: 1px solid var(--line);
  padding: 14px;
  background: linear-gradient(
    180deg,
    rgba(22, 32, 50, 0.9) 0%,
    rgba(13, 18, 25, 0.9) 100%
  );
}

/* --- Empty State --- */
.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: rgba(17, 25, 39, 0.5);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.empty::before {
  content: "📭";
  font-size: 20px;
}

/* --- Footer --- */
.site-footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--line);
  padding: 20px 0;
  text-align: center;
}

.site-footer p {
  font-size: 12px;
  color: var(--muted);
}

/* --- Loading Animation --- */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.loading .chart-wrap {
  background: linear-gradient(
    90deg,
    rgba(17, 25, 39, 0.6) 25%,
    rgba(22, 32, 50, 0.8) 50%,
    rgba(17, 25, 39, 0.6) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 720px) {
  .page-glow {
    background:
      radial-gradient(ellipse 350px 250px at 20% -6%, rgba(96, 165, 250, 0.08), transparent);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    width: min(100% - 28px, 640px);
    padding: 20px 0 16px;
  }

  .toolbar {
    align-self: flex-start;
  }

  main {
    width: min(100% - 28px, 640px);
    margin-bottom: 28px;
    gap: 20px;
  }

  .panel {
    padding: 14px;
  }

  .panel-header,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .section-heading p,
  .panel-meta {
    text-align: left;
  }

  .chart-wrap.large {
    height: 320px;
    padding: 8px;
  }

  .chart-wrap.detail {
    height: 240px;
    padding: 8px;
  }

  .row-summary {
    grid-template-columns: 1fr auto 36px;
    gap: 8px;
    min-height: 80px;
    padding: 10px;
  }

  .sparkline-box {
    grid-column: 1 / -1;
    grid-row: 2;
    height: 36px;
  }

  h1 {
    font-size: clamp(20px, 5vw, 26px);
  }
}
