:root {
  --bg: #fafbfc;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --ink: #1f2430;
  --ink-soft: #5b6473;
  --ink-faint: #98a0ad;
  --line: #e8eaee;
  --line-strong: #d6dae0;

  --p: #7b9cf2;   /* pastel blue */
  --i: #8fd3a8;   /* pastel green */
  --d: #f2b88c;   /* pastel peach */
  --sp: #c8a2e0;  /* pastel lilac */
  --pv: #5aa9c4;  /* pastel teal */
  --out: #ef9d9d; /* pastel rose */

  --sp-fill: rgba(200, 162, 224, 0.10);
  --pv-fill: rgba(90, 169, 196, 0.14);
  --out-fill: rgba(239, 157, 157, 0.10);

  --shadow-sm: 0 1px 2px rgba(40, 50, 70, 0.04), 0 1px 1px rgba(40, 50, 70, 0.02);
  --shadow: 0 4px 16px rgba(40, 50, 70, 0.06), 0 1px 3px rgba(40, 50, 70, 0.04);
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--p), var(--i) 55%, var(--d));
}
.brand-name { font-size: 16px; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.tab {
  border: 0;
  background: transparent;
  padding: 7px 18px;
  border-radius: 7px;
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.18s ease;
}
.tab:hover { color: var(--ink); }
.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* ---------- Layout ---------- */
main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 32px 64px;
}
.tab-panel { display: none; animation: fade 0.3s ease; }
.tab-panel.active { display: block; }
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Learn ---------- */
.hero { max-width: 640px; margin-bottom: 30px; }
.hero h1, .sim-header h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.lead { color: var(--ink-soft); margin: 0; }
.lead em { color: var(--ink); font-style: normal; font-weight: 500; }

.formula-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
}
.formula-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin-bottom: 10px;
}
.formula {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.formula sub { font-size: 0.62em; }
.formula-sub { color: var(--ink-soft); margin-top: 8px; font-size: 14px; }

.term-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}
.term-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.term-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
}
.p-card::before { background: var(--p); }
.i-card::before { background: var(--i); }
.d-card::before { background: var(--d); }

.term-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.term-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.term-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 13px;
  color: var(--surface);
  background: var(--ink-soft);
  flex-shrink: 0;
}
.p-card .term-tag, .p-group .term-tag { background: var(--p); }
.i-card .term-tag, .i-group .term-tag { background: var(--i); color: #2a4a36; }
.d-card .term-tag, .d-group .term-tag { background: var(--d); color: #6b4220; }

.term-card p { color: var(--ink-soft); margin: 0 0 14px; font-size: 14px; }
.mini-formula {
  font-family: 'Inter', monospace;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface-2);
  padding: 6px 10px;
  border-radius: 6px;
  display: inline-block;
  font-weight: 500;
}

.info-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}
.info-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.info-block h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.info-block p { margin: 0; color: var(--ink-soft); font-size: 14px; }

.tuning-note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
}
.tuning-note h3 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.tuning-note ul { margin: 0; padding-left: 0; list-style: none; }
.tuning-note li {
  padding: 7px 0;
  color: var(--ink-soft);
  border-bottom: 1px dashed var(--line);
}
.tuning-note li:last-child { border-bottom: 0; }
.tuning-note strong { color: var(--ink); font-weight: 600; }
.tuning-note strong sub { font-size: 0.7em; }

.cta-sim {
  text-align: center;
  padding: 24px;
}
.cta-sim p { margin: 0 0 14px; color: var(--ink-soft); }
.primary-btn {
  background: var(--ink);
  color: var(--surface);
  border: 0;
  padding: 12px 24px;
  border-radius: 10px;
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

/* ---------- Simulate ---------- */
.sim-header { margin-bottom: 24px; }

.sim-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}

.controls {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.control-group { display: flex; flex-direction: column; gap: 8px; }
.control-group:not(:last-child) {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.control-title { display: flex; align-items: center; gap: 8px; }
.control-title h3 { margin: 0; }
.control-group h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.slider-row { display: flex; align-items: center; gap: 12px; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--line-strong);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.18); }
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--ink-soft);
  cursor: pointer;
}

.p-group input[type="range"]::-webkit-slider-thumb { border-color: var(--p); }
.i-group input[type="range"]::-webkit-slider-thumb { border-color: var(--i); }
.d-group input[type="range"]::-webkit-slider-thumb { border-color: var(--d); }

.value-pill {
  min-width: 52px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

select {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  width: 100%;
}

.button-row { display: flex; gap: 8px; }
.ghost-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 0;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease;
}
.ghost-btn:hover { background: var(--surface-2); }

.readouts {
  display: flex;
  gap: 10px;
}
.readout {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.readout-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin-bottom: 3px;
}
.readout-value {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- Plot ---------- */
.plot-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.plot-legend { display: flex; gap: 18px; padding: 0 4px; flex-wrap: wrap; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
}
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.sp { background: var(--sp); }
.dot.pv { background: var(--pv); }
.dot.out { background: var(--out); }

#plot {
  width: 100%;
  height: 380px;
  display: block;
  border-radius: 8px;
}

.plot-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--ink-faint);
  padding: 0 4px;
}
.plot-foot #time-display {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-weight: 500;
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 24px;
  color: var(--ink-faint);
  font-size: 13px;
  border-top: 1px solid var(--line);
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .term-grid { grid-template-columns: 1fr; }
  .info-row { grid-template-columns: 1fr; }
  .sim-layout { grid-template-columns: 1fr; }
  .main { padding: 24px 18px; }
  #plot { height: 280px; }
}
@media (max-width: 540px) {
  main { padding: 24px 16px 48px; }
  .hero h1, .sim-header h1 { font-size: 24px; }
}
