:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #162032;
  --border: rgba(16, 185, 129, 0.15);
  --border-soft: rgba(255, 255, 255, 0.06);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --s-color: #22d3ee;
  --i-color: #f87171;
  --r-color: #4ade80;
  --e-color: #facc15;
  --d-color: #a78bfa;
  --accent: #34d399;
}

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

body {
  font-family: "Avenir Next", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #06101d, #0b1424 40%, var(--bg));
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.sir-container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px;
}

header {
  margin-bottom: 18px;
  padding: 22px 24px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.96), rgba(15, 23, 42, 0.96));
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

header h1 {
  font-size: clamp(1.6rem, 2.8vw, 2.6rem);
  line-height: 1.1;
  background: linear-gradient(120deg, var(--i-color), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  max-width: 880px;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.6;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(290px, 320px) minmax(0, 1fr);
  gap: 18px;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control-section {
  padding: 16px;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.98), rgba(22, 32, 50, 0.98));
  border: 1px solid var(--border);
  border-radius: 16px;
}

.control-section h3 {
  font-size: 0.92rem;
  margin-bottom: 12px;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.mode-toggle {
  display: flex;
  gap: 6px;
}

.mode-btn {
  flex: 1;
  padding: 9px 8px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 150ms ease;
}

.mode-btn:hover { background: rgba(255, 255, 255, 0.08); }

.mode-btn.active {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.mode-hint {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
  padding: 8px 10px;
  background: rgba(16, 185, 129, 0.06);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
}

.control-group {
  margin-bottom: 12px;
}

.control-group:last-child { margin-bottom: 0; }

.control-group label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.control-group .val {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hint-text {
  margin-top: 4px;
  font-size: 0.72rem;
  color: #64748b;
  line-height: 1.4;
}

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

.btn-row {
  display: flex;
  gap: 8px;
}

.action-btn {
  flex: 1;
  padding: 9px 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 120ms ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border);
}

.action-btn.primary {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  border: none;
  font-weight: 700;
}

.action-btn.primary:hover { filter: brightness(1.1); }

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.83rem;
  padding: 5px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.04);
}

.stat-row:last-child { border-bottom: none; }

.stat-label { color: var(--muted); }

.stat-val {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

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

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

.swatch {
  display: inline-block;
  width: 22px;
  height: 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

.swatch.susceptible { background: var(--s-color); }
.swatch.infected { background: var(--i-color); }
.swatch.recovered { background: var(--r-color); }
.swatch.exposed { background: var(--e-color); }
.swatch.deaths { background: var(--d-color); }
.swatch.herd-line {
  background: none;
  border-top: 2px dashed rgba(255, 255, 255, 0.35);
  height: 0;
}

.display-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.canvas-card {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(5, 10, 18, 0.95), rgba(8, 14, 25, 0.95));
  border: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
}

.canvas-card.large { height: 460px; }

.canvas-card canvas {
  display: block;
  flex: 1;
  width: 100%;
  height: 100%;
}

.card-title {
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--accent);
  background: rgba(16, 185, 129, 0.06);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
}

.canvas-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.canvas-row .canvas-card { height: 280px; }

.education {
  margin-top: 18px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 9px 18px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 12px 12px 0 0;
  cursor: pointer;
  font-size: 0.88rem;
  transition: all 150ms ease;
}

.tab-btn:hover { background: rgba(255, 255, 255, 0.07); }

.tab-btn.active {
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.98), rgba(22, 32, 50, 0.98));
  color: var(--accent);
  border-color: var(--border);
  border-bottom-color: transparent;
}

.tab-pane {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.tab-pane.active { display: grid; }

.edu-card {
  padding: 18px;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.98), rgba(22, 32, 50, 0.98));
  border: 1px solid var(--border);
  border-radius: 16px;
}

.edu-card h3 {
  font-size: 0.96rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.edu-card p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.65;
}

@media (max-width: 1100px) {
  .canvas-row { grid-template-columns: 1fr; }
  .canvas-row .canvas-card { height: 240px; }
}

@media (max-width: 960px) {
  .main-layout { grid-template-columns: 1fr; }
  .canvas-card.large { height: 380px; }
}

@media (max-width: 640px) {
  .sir-container { padding: 10px; }
  .canvas-card.large { height: 320px; }
  .canvas-row .canvas-card { height: 220px; }
  .btn-row { flex-wrap: wrap; }
  .tab-pane { grid-template-columns: 1fr; }
}
