:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #38bdf8;
  --primary-hover: #0284c7;
  --accent-elnino: #f87171;
  --accent-lanina: #60a5fa;
  --accent-neutral: #a3e635;
  --card-bg: #1e293b;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --card-bg: #ffffff;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  padding: 1.5rem 1rem 3rem;
  max-width: 56rem;
  margin: 0 auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--surface-border);
  margin-bottom: 2rem;
}

h1 { font-size: 1.6rem; font-weight: 700; color: var(--text); }
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.2rem; }

.who {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.who-badge {
  padding: 0.2rem 0.6rem;
  background: var(--surface-border);
  border-radius: 9999px;
  font-weight: 500;
  color: var(--text);
}

.card-section {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section-header h2 { font-size: 1.25rem; font-weight: 600; }

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.public-badge { background: rgba(56, 189, 248, 0.15); color: var(--primary); }
.member-badge { background: rgba(168, 85, 247, 0.15); color: #c084fc; }

.muted { color: var(--text-muted); font-size: 0.9rem; }
.small-text { font-size: 0.82rem; }

/* Weather Grid */
.weather-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.city-card {
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 0.5rem;
  padding: 1.25rem;
}

.city-title h3 { font-size: 1.05rem; font-weight: 600; }
.city-title .coords { font-size: 0.78rem; color: var(--text-muted); }

.weather-metrics {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.metric { display: flex; flex-direction: column; }
.metric-label { font-size: 0.75rem; color: var(--text-muted); }
.metric-val { font-size: 1.1rem; font-weight: 600; }
.text-val { font-size: 0.95rem; }

.main-metric {
  grid-column: span 2;
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 0.25rem;
}
.main-metric .metric-val { font-size: 2.2rem; font-weight: 700; color: var(--primary); }
.main-metric .metric-unit { font-size: 1.2rem; color: var(--text-muted); }

/* ENSO Display */
.enso-summary-card {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 0.5rem;
  padding: 1.25rem;
  margin-top: 1rem;
  align-items: center;
}

.enso-state-box { min-width: 180px; }
.enso-state-box .label { font-size: 0.8rem; color: var(--text-muted); }

.phase-display {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin: 0.4rem 0;
}

.phase-badge {
  font-size: 1.2rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 0.375rem;
  background: var(--surface-border);
}
.phase-elnino { background: rgba(248, 113, 113, 0.2); color: var(--accent-elnino); }
.phase-lanina { background: rgba(96, 165, 250, 0.2); color: var(--accent-lanina); }
.phase-neutral { background: rgba(163, 230, 53, 0.2); color: var(--accent-neutral); }

.anomaly-val { font-size: 1.5rem; font-weight: 700; }

.enso-legend { flex: 1; min-width: 260px; font-size: 0.85rem; }
.enso-legend h4 { font-size: 0.88rem; margin-bottom: 0.4rem; color: var(--text); }
.enso-legend ul { list-style: none; display: flex; flex-direction: column; gap: 0.3rem; }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.4rem; }
.el-nino-dot { background: var(--accent-elnino); }
.neutral-dot { background: var(--accent-neutral); }
.la-nina-dot { background: var(--accent-lanina); }

.table-container { margin-top: 1.5rem; overflow-x: auto; }
.table-container h3 { font-size: 0.95rem; margin-bottom: 0.75rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--surface-border); }
th { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
td { font-variant-numeric: tabular-nums; }

/* Gate / Lock Panel */
.lock-panel {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--bg);
  border: 1px dashed var(--surface-border);
  border-radius: 0.5rem;
  margin-top: 1rem;
}
.lock-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.lock-panel h3 { font-size: 1.2rem; margin-bottom: 0.5rem; }
.lock-panel p { max-width: 32rem; margin: 0 auto 1.5rem; color: var(--text-muted); font-size: 0.92rem; }

.btn {
  display: inline-block;
  padding: 0.55rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 0.375rem;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s ease;
}
.btn:hover { background: var(--surface-border); }

.primary-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: #0f172a;
}
.primary-btn:hover { background: var(--primary-hover); }

/* Analysis Panel */
.analysis-panel { margin-top: 1rem; }
.summary-banner {
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.summary-banner h4 { font-size: 0.95rem; color: #c084fc; margin-bottom: 0.3rem; }
.summary-text { font-size: 0.92rem; }

.corr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.corr-card {
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 0.5rem;
  padding: 1.25rem;
}
.corr-card h4 { font-size: 1rem; margin-bottom: 0.75rem; font-weight: 600; }
.corr-stats { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; }
.corr-item { display: flex; justify-content: space-between; align-items: baseline; }
.corr-label { font-size: 0.85rem; color: var(--text-muted); }
.corr-value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Notes */
.notes-container {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--surface-border);
}
.notes-container h3 { font-size: 1.05rem; margin-bottom: 0.75rem; }
.notes-list { list-style: none; margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.notes-list li {
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 0.375rem;
  font-size: 0.9rem;
}
.note-form { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.note-form input {
  flex: 1;
  padding: 0.55rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 0.375rem;
  color: var(--text);
  font-size: 0.9rem;
}
.error-msg { color: #f87171; font-size: 0.85rem; }
