:root {
  --bg-1: #eef4ff;
  --bg-2: #f5ecff;
  --bg-3: #e8fbf4;

  --surface: #ffffff;
  --surface-soft: #f7f9ff;
  --border: #e3e9f5;

  --text: #1f2a44;
  --text-soft: #6b7a99;
  --muted: #9aa6bf;

  --accent: #5a7cff;
  --accent-2: #7a5cff;

  --h2: #ff6b9d;      /* pink */
  --h2-soft: #ffd6e3;
  --o2: #31b6ff;      /* cyan/blue */
  --o2-soft: #cfeeff;
  --electron: #3b7cff;
  --proton: #ffb347;
  --water: #38c5c8;
  --bulb: #ffcb47;

  --shadow-sm: 0 2px 8px rgba(31, 42, 68, 0.06);
  --shadow-md: 0 8px 24px rgba(31, 42, 68, 0.08);
  --shadow-lg: 0 16px 40px rgba(31, 42, 68, 0.10);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--bg-2), transparent 60%),
    radial-gradient(1000px 600px at 110% 20%, var(--bg-3), transparent 60%),
    linear-gradient(180deg, var(--bg-1), #ffffff 70%);
  background-attachment: fixed;
}

/* TOP BAR */
.topbar {
  padding: 22px 28px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.logo-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: conic-gradient(from 180deg, var(--h2), var(--o2), var(--accent), var(--h2));
  box-shadow: 0 0 16px rgba(90, 124, 255, 0.35);
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.accent {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0 0 0 30px;
  color: var(--text-soft);
  font-size: 14px;
}

/* LAYOUT */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  gap: 20px;
  padding: 16px 24px 28px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 16px;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.2px;
}

/* CONTROLS */
.control {
  margin-bottom: 16px;
}

.control-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.control-head label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 500;
}

.control-head output {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 8px;
  min-width: 40px;
  text-align: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 22px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}

.pill-h2 { background: linear-gradient(135deg, #ff8ab3, #ff5b8f); }
.pill-o2 { background: linear-gradient(135deg, #5cc7ff, #2a9fe6); }
.pill-t  { background: linear-gradient(135deg, #ffc06b, #ff8a3b); }
.pill-r  { background: linear-gradient(135deg, #9c7cff, #6a4cff); }

/* RANGE */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  outline: none;
  opacity: 0.95;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 2px 8px rgba(90, 124, 255, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 2px 8px rgba(90, 124, 255, 0.35);
  cursor: pointer;
}

/* READOUTS */
.readouts {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.readout {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.readout-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.readout-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* STAGE */
.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.canvas-wrap {
  position: relative;
  background:
    radial-gradient(800px 400px at 50% 0%, #ffffff, transparent 70%),
    linear-gradient(160deg, #f6f8ff, #f0fbf6 60%, #fff3f9);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  aspect-ratio: 16 / 10;
  min-height: 420px;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: #1f2a44;
  color: #fff;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow-md);
  max-width: 220px;
  transform: translate(-50%, calc(-100% - 12px));
  z-index: 5;
}

.tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: #1f2a44;
}

.tooltip b { color: #ffcb47; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  font-size: 12px;
  color: var(--text-soft);
}

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

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-e { background: var(--electron); box-shadow: 0 0 8px rgba(59, 124, 255, 0.6); }
.dot-p { background: var(--proton); box-shadow: 0 0 8px rgba(255, 179, 71, 0.6); }
.dot-h { background: var(--h2); box-shadow: 0 0 8px rgba(255, 107, 157, 0.6); }
.dot-o { background: var(--o2); box-shadow: 0 0 8px rgba(49, 182, 255, 0.6); }
.dot-w { background: var(--water); box-shadow: 0 0 8px rgba(56, 197, 200, 0.6); }

/* RIGHT PANEL / INFO */
.info-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.step-num {
  flex: 0 0 26px;
  height: 26px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.step h3 {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 700;
}

.step p {
  margin: 0;
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.4;
}

.formula-card {
  background: linear-gradient(135deg, #eef2ff, #f3ecff);
  border: 1px solid #e0e4ff;
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 16px;
  text-align: center;
}

.formula {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  font-family: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace;
  margin-bottom: 6px;
}

.hint {
  font-size: 12px;
  color: var(--text-soft);
}

.tips {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.tips h4 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.tips ul {
  margin: 0;
  padding-left: 16px;
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.7;
}

/* RESPONSIVE */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 280px 1fr 300px;
    gap: 16px;
    padding: 12px 16px 20px;
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 12px 14px 24px;
  }
  .panel {
    position: static;
  }
  .panel-right { order: 3; }
  .stage { order: 2; }
  .panel-left { order: 1; }
  .canvas-wrap { min-height: 360px; }
  .readouts {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 560px) {
  .topbar { padding: 16px 14px 4px; }
  .topbar h1 { font-size: 20px; }
  .tagline { margin-left: 30px; font-size: 12px; }
  .readouts {
    grid-template-columns: repeat(2, 1fr);
  }
  .canvas-wrap { min-height: 280px; }
  .panel { padding: 16px; }
  .legend { font-size: 11px; gap: 10px; }
}
