:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #172033;
  --muted: #61708a;
  --border: #d9e0eb;
  --primary: #3558c9;
  --primary-soft: #e7edff;
  --oxidation: #d45b22;
  --oxidation-soft: #fff0e8;
  --reduction: #167a63;
  --reduction-soft: #e7f7f1;
  --danger: #b63d4c;
  --success: #18754e;
  --shadow: 0 14px 38px rgba(31, 45, 75, .09);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111724;
  --surface: #192131;
  --surface-2: #222c3f;
  --text: #edf2fb;
  --muted: #aab7cc;
  --border: #334159;
  --primary: #91a8ff;
  --primary-soft: #28365d;
  --oxidation: #ff9b68;
  --oxidation-soft: #4a2c24;
  --reduction: #6bd4b5;
  --reduction-soft: #173e37;
  --danger: #ff8b98;
  --success: #79d7ad;
  --shadow: 0 16px 40px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  line-height: 1.55;
}

button, select, input { font: inherit; }
button, select { min-height: 42px; }

.site-header {
  color: #fff;
  background:
    radial-gradient(circle at 86% 20%, rgba(255,255,255,.18), transparent 25%),
    linear-gradient(125deg, #263e9b, #6142a6 58%, #943e79);
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 24px 28px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(1.7rem, 4vw, 2.7rem); line-height: 1.12; }
h2 { margin-bottom: 10px; font-size: clamp(1.35rem, 3vw, 2rem); }
h3 { margin-bottom: 8px; }
.subtitle { margin: 0; opacity: .88; }
.eyebrow { display: block; margin-bottom: 7px; font-size: .78rem; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }

.icon-btn {
  width: 44px;
  border: 1px solid rgba(255,255,255,.45);
  border-radius: 50%;
  background: rgba(255,255,255,.13);
  color: #fff;
  cursor: pointer;
}

.section-nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  overflow-x: auto;
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.nav-btn {
  flex: 0 0 auto;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.nav-btn.active { color: var(--text); background: var(--primary-soft); border-color: var(--border); font-weight: 700; }

main { max-width: 1120px; margin: 0 auto; padding: 28px 24px 46px; }
.content-section { display: none; }
.content-section.active { display: block; }

.hero, .balance-layout, .transfer-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
  gap: 22px;
  align-items: stretch;
}

.hero { margin-bottom: 22px; align-items: center; }
.hero > div:first-child { padding: 12px 0; }
.formula-card, .panel, .rule, .atom-card, .task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.formula-card { padding: 26px; text-align: center; background: var(--primary-soft); }
.formula-card strong { display: block; font-size: 1.5rem; margin-bottom: 7px; }
.formula-card span { color: var(--muted); }

.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.rule { padding: 22px; border-top: 5px solid; }
.rule.oxidation { border-top-color: var(--oxidation); background: linear-gradient(var(--oxidation-soft), var(--surface)); }
.rule.reduction { border-top-color: var(--reduction); background: linear-gradient(var(--reduction-soft), var(--surface)); }
.rule-mark { float: right; font-size: 1.35rem; font-weight: 800; }
.oxidation .rule-mark { color: var(--oxidation); }
.reduction .rule-mark { color: var(--reduction); }

.rules-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; }
.rules-strip div { padding: 14px; border-radius: 14px; background: var(--surface-2); text-align: center; }
.rules-strip strong, .rules-strip span { display: block; }
.rules-strip strong { font-size: 1.22rem; }
.rules-strip span { color: var(--muted); font-size: .9rem; }

.section-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 22px; }
.section-title h2 { margin-bottom: 0; }
.select-label { display: grid; gap: 5px; color: var(--muted); font-size: .88rem; }
select, input[type="number"] { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); padding: 8px 10px; }

.reaction-line { margin: 0 auto 26px; padding: 15px 18px; max-width: 760px; border-radius: 14px; background: var(--surface-2); text-align: center; font-size: clamp(1.05rem, 3vw, 1.45rem); font-weight: 700; }
.transfer-stage { grid-template-columns: 1fr 150px 1fr; align-items: center; }
.atom-card { padding: 24px; text-align: center; min-height: 220px; }
.atom-card.oxidation { background: linear-gradient(150deg, var(--oxidation-soft), var(--surface)); }
.atom-card.reduction { background: linear-gradient(150deg, var(--reduction-soft), var(--surface)); }
.role-label { color: var(--muted); font-size: .88rem; }
.state-change { display: flex; justify-content: center; align-items: center; gap: 13px; margin: 18px 0; font-size: 1.55rem; font-weight: 800; }
.electron-arrow { text-align: center; color: var(--primary); font-weight: 800; }
.electron-arrow span { display: block; color: var(--muted); font-size: .85rem; }
.electron-arrow div { font-size: 1.7rem; }

.balance-layout { grid-template-columns: .8fr 1.2fr; }
.panel { padding: 22px; }
.half-reactions { display: grid; gap: 12px; }
.half-row { padding: 14px; border-radius: 12px; background: var(--surface-2); font-size: 1.05rem; }
.hint { color: var(--muted); margin: 16px 0 0; }
.coefficient-editor { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 16px 0 20px; font-size: 1.1rem; }
.coefficient-item { display: inline-flex; align-items: center; gap: 5px; }
.coefficient-item input { width: 62px; text-align: center; font-weight: 700; }
.operator { color: var(--muted); font-weight: 700; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

.btn { padding: 9px 15px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); cursor: pointer; }
.btn.primary { background: var(--primary); color: var(--bg); border-color: transparent; font-weight: 700; }
[data-theme="light"] .btn.primary { color: #fff; }
.btn.danger { margin-top: 18px; color: var(--danger); }
.feedback { margin: 18px 0 0; padding: 13px 15px; border-radius: 12px; }
.feedback.neutral { background: var(--surface-2); color: var(--muted); }
.feedback.correct { background: var(--reduction-soft); color: var(--success); }
.feedback.wrong { background: var(--oxidation-soft); color: var(--danger); }

.score-badge { padding: 9px 14px; border-radius: 999px; background: var(--primary-soft); font-weight: 700; white-space: nowrap; }
.task-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.task-card { padding: 20px; box-shadow: none; }
.task-number { color: var(--muted); font-size: .82rem; font-weight: 700; text-transform: uppercase; }
.task-card h3 { margin-top: 5px; font-size: 1.05rem; }
.option-list { display: grid; gap: 8px; }
.option { min-height: 42px; padding: 9px 12px; text-align: left; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); cursor: pointer; }
.option.correct { border-color: var(--success); background: var(--reduction-soft); }
.option.wrong { border-color: var(--danger); background: var(--oxidation-soft); }
.option:disabled { cursor: default; opacity: 1; }
.task-feedback { min-height: 44px; margin: 10px 0 0; color: var(--muted); font-size: .9rem; }

footer { padding: 22px; text-align: center; color: var(--muted); border-top: 1px solid var(--border); }

button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  .header-inner { padding: 24px 18px; }
  main { padding: 22px 16px 38px; }
  .hero, .balance-layout, .rule-grid, .task-grid { grid-template-columns: 1fr; }
  .rules-strip { grid-template-columns: 1fr 1fr; }
  .transfer-stage { grid-template-columns: 1fr; }
  .electron-arrow { transform: rotate(90deg); margin: -8px 0; }
  .section-title { align-items: stretch; flex-direction: column; }
  .section-nav { justify-content: flex-start; }
}

@media (prefers-reduced-motion: no-preference) {
  .content-section.active { animation: appear .22s ease-out; }
  @keyframes appear { from { opacity: 0; transform: translateY(5px); } }
}
