:root {
  --bg-a: #f8fcff;
  --bg-b: #eaf4fa;
  --surface: rgba(255, 255, 255, 0.93);
  --surface-strong: rgba(255, 255, 255, 0.99);
  --line: rgba(33, 90, 128, 0.2);
  --text: #10293d;
  --muted: #517189;
  --accent: #1098ad;
  --accent-2: #0f6da4;
  --focus: rgba(16, 152, 173, 0.35);
  --p-color: #0f766e;
  --i-color: #ca8a04;
  --d-color: #1d4ed8;
  --total-color: #b45309;
  --resp-color: #0f6da4;
  --set-color: #f97316;
  --radius: 20px;
  --shadow: 0 20px 45px rgba(17, 63, 95, 0.13);
  --font-head: "Space Grotesk", "IBM Plex Sans", sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  line-height: 1.55;
  background:
    radial-gradient(circle at 8% 6%, rgba(16, 152, 173, 0.18), transparent 34%),
    radial-gradient(circle at 94% 2%, rgba(15, 109, 164, 0.16), transparent 30%),
    linear-gradient(180deg, var(--bg-a), var(--bg-b));
}

.page-shell {
  width: min(1320px, calc(100% - 2rem));
  margin: 0 auto 2rem;
  display: grid;
  gap: 1rem;
  position: relative;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1rem, 2.2vw, 1.7rem);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.hero h1,
h2,
h3,
h4,
h5,
label,
button {
  font-family: var(--font-head);
  letter-spacing: 0.01em;
}

.hero {
  margin-top: 0.8rem;
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  right: -52px;
  top: -52px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(16, 152, 173, 0.18), rgba(16, 152, 173, 0));
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 0.5rem;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-weight: 700;
  font-size: 0.76rem;
  font-family: var(--font-mono);
}

.note {
  margin-top: 0.7rem;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  background: rgba(16, 152, 173, 0.09);
  color: #0a5966;
  font-weight: 600;
}

.wip-banner {
  border-color: rgba(180, 83, 9, 0.28);
  background: rgba(255, 247, 237, 0.95);
  color: #9a3412;
  font-weight: 600;
}

.wip-banner p {
  margin: 0;
}

.tabs-wrap {
  padding: 0.8rem;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.tab-btn {
  border: 1px solid rgba(15, 109, 164, 0.24);
  background: #f7fbff;
  color: #194e6f;
  border-radius: 11px;
  padding: 0.7rem 0.8rem;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  color: #ffffff;
  background: linear-gradient(135deg, #0b7da2, #1098ad);
  border-color: transparent;
}

.tab-panel.hidden {
  display: none;
}

.section-head h2 {
  margin: 0.25rem 0 0.35rem;
}

.layout-two {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(332px, 390px) minmax(0, 1fr);
  align-items: start;
}

.control-panel {
  display: grid;
  gap: 0.9rem;
  position: sticky;
  top: 12px;
}

.control-panel h3,
.control-panel h4 {
  margin: 0;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  background: rgba(16, 152, 173, 0.09);
}

.mode-toggle {
  display: grid;
  gap: 0.35rem;
}

.mode-toggle label {
  color: #214962;
  font-size: 0.84rem;
}

.mode-toggle select {
  border: 1px solid rgba(15, 109, 164, 0.24);
  border-radius: 9px;
  background: #f8fcff;
  color: #174a69;
  padding: 0.45rem 0.55rem;
  font: 600 0.82rem var(--font-body);
}

.control-grid {
  display: grid;
  gap: 0.46rem;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.36rem 0.5rem;
  align-items: center;
  border: 1px solid rgba(15, 109, 164, 0.14);
  border-radius: 10px;
  padding: 0.4rem 0.5rem;
  background: rgba(255, 255, 255, 0.82);
}

.control-row label {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  color: #214962;
  font-size: 0.83rem;
  grid-column: 1 / span 2;
}

.control-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent-2);
}

.control-row output {
  min-width: 58px;
  text-align: right;
  font-family: var(--font-mono);
  color: #0c476d;
  font-size: 0.83rem;
}

.help-icon {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(15, 109, 164, 0.34);
  background: #ecf6fd;
  color: #0f5a87;
  font: 700 11px/1 var(--font-mono);
  cursor: pointer;
  padding: 0;
}

.toggle {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  color: #25495f;
  font-size: 0.9rem;
}

.toggle input {
  accent-color: var(--accent-2);
}

.button-row {
  display: flex;
  gap: 0.6rem;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.58rem 0.82rem;
  font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer;
}

.btn.primary {
  background: linear-gradient(135deg, #0b7da2, #1098ad);
  color: #ffffff;
}

.btn.secondary {
  background: #eef6fb;
  border-color: rgba(15, 109, 164, 0.25);
  color: #0c4e75;
}

.preset-grid {
  display: grid;
  gap: 0.45rem;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}

.preset-grid button {
  border: 1px solid rgba(15, 109, 164, 0.24);
  background: #f8fcff;
  color: #164866;
  border-radius: 9px;
  padding: 0.48rem 0.56rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.preset-grid button:hover {
  background: #e8f4fb;
}

.what-changed,
.equation-box {
  background: rgba(16, 152, 173, 0.08);
  border: 1px solid rgba(15, 109, 164, 0.21);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  color: #245675;
  font-size: 0.92rem;
}

.foundation-formula p {
  margin: 0.3rem 0;
}

.viz-panel {
  display: grid;
  gap: 0.75rem;
}

.chart-card {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.72rem;
}

.chart-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.chart-card h3 {
  margin: 0;
  font-size: 1rem;
}

.chart-card canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid rgba(15, 109, 164, 0.15);
  background: #ffffff;
}

.axis-label {
  margin: 0.34rem 0 0;
  color: #3f6886;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

.plot-note {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.legend {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  color: #386283;
  font-size: 0.82rem;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 0.18rem;
  vertical-align: middle;
}

.dot.setpoint {
  background: var(--set-color);
}

.dot.response {
  background: var(--resp-color);
}

.dot.low {
  background: #1d4ed8;
}

.dot.medium {
  background: #0f6da4;
}

.dot.high {
  background: #b91c1c;
}

.dot.pterm {
  background: var(--p-color);
}

.dot.iterm {
  background: var(--i-color);
}

.dot.dterm {
  background: var(--d-color);
}

.dot.total {
  background: var(--total-color);
}

.dot.vesc-est {
  background: #64748b;
}

.dot.vesc-iq-set {
  background: #0f766e;
}

.dot.vesc-iq {
  background: #0369a1;
}

.dot.vesc-duty {
  background: #7c3aed;
}

.stats-grid {
  display: grid;
  gap: 0.52rem;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.stats-grid article {
  border: 1px solid rgba(15, 109, 164, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  padding: 0.52rem 0.6rem;
}

.stats-grid h4 {
  margin: 0;
  font-size: 0.79rem;
  color: #3f6886;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-grid p {
  margin: 0.18rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.formula-inline {
  font-family: var(--font-mono);
  color: #0f4c73;
  background: rgba(15, 109, 164, 0.09);
  border: 1px solid rgba(15, 109, 164, 0.2);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  display: inline-block;
}

.help-popover {
  position: fixed;
  z-index: 60;
  max-width: 260px;
  border-radius: 10px;
  border: 1px solid rgba(15, 109, 164, 0.25);
  background: #ffffff;
  box-shadow: 0 12px 24px rgba(17, 63, 95, 0.22);
  padding: 0.5rem 0.58rem;
  color: #154a6d;
  font-size: 0.82rem;
  pointer-events: auto;
}

.btn:focus-visible,
.help-icon:focus-visible,
.tab-btn:focus-visible,
input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.reveal {
  opacity: 0;
  transform: translateY(10px);
  animation: riseIn 0.45s ease forwards;
}

.reveal:nth-child(2) {
  animation-delay: 0.06s;
}

.reveal:nth-child(3) {
  animation-delay: 0.1s;
}

.reveal:nth-child(4) {
  animation-delay: 0.14s;
}

@keyframes riseIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1100px) {
  .layout-two {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .tabs {
    grid-template-columns: 1fr;
  }

  .page-shell {
    width: min(1320px, calc(100% - 1rem));
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
