:root {
  --ink: #10213f;
  --muted: #65718a;
  --line: #dce3ed;
  --paper: #ffffff;
  --canvas: #f3f6fa;
  --navy: #102a56;
  --blue: #246bfd;
  --blue-deep: #1552cf;
  --cyan: #00a9a5;
  --cyan-soft: #e5f8f6;
  --amber: #f5a524;
  --amber-soft: #fff6df;
  --green: #1b8f65;
  --green-soft: #e9f7f1;
  --red: #c54545;
  --red-soft: #fff0f0;
  --shadow: 0 20px 60px rgba(22, 43, 78, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 90% 5%, rgba(36, 107, 253, 0.11), transparent 28rem),
    linear-gradient(180deg, #f8faff 0, var(--canvas) 34rem);
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(36, 107, 253, 0.28);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }

.topbar {
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 5vw, 72px);
  color: white;
  background: var(--navy);
  box-shadow: 0 8px 30px rgba(16, 42, 86, 0.2);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px 13px 13px 5px;
  font-weight: 900;
  letter-spacing: -0.05em;
  color: var(--navy);
  background: #69e0d7;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.02rem; letter-spacing: 0.01em; }
.brand small { margin-top: 2px; color: #b8c7e2; font-size: 0.78rem; }

.scoreboard {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px;
  color: #cbd6ea;
  font-size: .88rem;
}
.scoreboard b { color: white; font-size: 1rem; }
.score-divider { width: 1px; height: 18px; background: rgba(255,255,255,.2); }

.workspace {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 52px 0 72px;
}

.workspace-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(2rem, 4vw, 3.25rem); line-height: 1.03; letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: 1.28rem; letter-spacing: -.02em; }
.instruction { margin-bottom: 0; color: var(--muted); font-size: 1rem; line-height: 1.6; }

.ghost-button, .secondary-button, .primary-button, .icon-button {
  border: 0;
  border-radius: 12px;
  font-weight: 750;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.ghost-button:active, .secondary-button:active, .primary-button:active { transform: translateY(1px); }
.ghost-button {
  flex: 0 0 auto;
  padding: 12px 16px;
  border: 1px solid #c9d5e7;
  color: var(--navy);
  background: rgba(255,255,255,.72);
}
.ghost-button:hover { border-color: #9bb1d1; background: white; }

.control-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 14px;
}

label > span { display: block; margin-bottom: 7px; font-size: .8rem; font-weight: 800; color: var(--muted); }
select, .teacher-panel input {
  min-height: 45px;
  border: 1px solid #cbd6e5;
  border-radius: 10px;
  color: var(--ink);
  background: white;
}
select { min-width: 190px; padding: 0 38px 0 13px; }
.progress-copy { color: var(--muted); font-size: .9rem; }
.progress-copy strong { color: var(--ink); }

.question-card, .atom-check {
  border: 1px solid rgba(193, 205, 222, .8);
  background: rgba(255,255,255,.96);
  box-shadow: var(--shadow);
}
.question-card { padding: clamp(24px, 5vw, 52px); border-radius: 24px; }
.reaction-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .88rem; font-weight: 750; }
.difficulty-tag { padding: 5px 9px; border-radius: 999px; color: #7a5202; background: var(--amber-soft); }

.reaction {
  min-height: 180px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 15px;
  padding: 34px 8px 30px;
  font-size: clamp(1.6rem, 4vw, 3rem);
  font-weight: 760;
  letter-spacing: -.025em;
}
.reaction-part { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.coefficient-input {
  width: 54px;
  height: 58px;
  border: 2px solid #bcc9db;
  border-radius: 12px;
  color: var(--navy);
  background: #f8faff;
  text-align: center;
  font-size: 1.45rem;
  font-weight: 800;
  appearance: textfield;
}
.coefficient-input::-webkit-inner-spin-button { appearance: none; }
.coefficient-input:focus { border-color: var(--blue); background: white; }
.coefficient-input.correct { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.coefficient-input.incorrect { border-color: var(--red); color: var(--red); background: var(--red-soft); animation: nudge .28s ease; }
.formula sub { font-size: .58em; vertical-align: -0.28em; }
.state { font-size: .5em; font-weight: 650; color: var(--muted); }
.operator { color: #8190a8; font-weight: 500; }
.arrow { color: var(--blue); font-size: 1.15em; }

.feedback {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 15px;
  border: 1px solid #d9e2ef;
  border-radius: 12px;
  color: #56647c;
  background: #f7f9fc;
  line-height: 1.45;
}
.feedback-icon { width: 23px; height: 23px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: white; background: #7c8ba2; font-size: .78rem; font-weight: 900; }
.feedback.success { border-color: #b9e3d1; color: #176a4d; background: var(--green-soft); }
.feedback.success .feedback-icon { background: var(--green); }
.feedback.error { border-color: #f0c6c6; color: #9c3434; background: var(--red-soft); }
.feedback.error .feedback-icon { background: var(--red); }
.feedback.hint { border-color: #f4daa0; color: #735314; background: var(--amber-soft); }
.feedback.hint .feedback-icon { background: var(--amber); }

.actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 22px; }
.primary-actions { display: flex; gap: 10px; }
.secondary-button, .primary-button { min-height: 46px; padding: 0 18px; }
.secondary-button { border: 1px solid #cbd6e5; color: var(--navy); background: white; }
.secondary-button:hover { border-color: #9fb2cf; background: #f8faff; }
.primary-button { color: white; background: var(--blue); }
.primary-button:hover { background: var(--blue-deep); }
.next-button { min-width: 168px; }

.atom-check {
  display: flex;
  align-items: center;
  gap: clamp(30px, 6vw, 84px);
  margin-top: 18px;
  padding: 24px 30px;
  border-radius: 18px;
  box-shadow: 0 12px 36px rgba(22, 43, 78, .06);
}
.atom-check > div:first-child { flex: 0 0 auto; }
.atom-grid { display: grid; grid-template-columns: repeat(4, minmax(88px, 1fr)); gap: 10px; width: 100%; }
.atom-chip { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #f8faff; }
.atom-chip strong { display: block; color: var(--navy); }
.atom-chip small { display: block; margin-top: 3px; color: var(--muted); }
.atom-chip.balanced { border-color: #b9e3d1; background: var(--green-soft); }
.atom-chip.unbalanced { border-color: #f0c6c6; background: var(--red-soft); }

.teacher-panel {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  width: min(430px, 100%);
  height: 100vh;
  overflow: auto;
  padding: 34px;
  background: white;
  box-shadow: -20px 0 60px rgba(16, 33, 63, .18);
  animation: slide-in .22s ease both;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.teacher-panel > p { margin: 24px 0; color: var(--muted); line-height: 1.6; }
.icon-button { width: 40px; height: 40px; color: var(--muted); background: #f1f4f8; font-size: 1.6rem; font-weight: 400; }
.teacher-panel form { display: grid; gap: 20px; }
.teacher-panel input { width: 100%; padding: 0 13px; }
.example-box { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-radius: 10px; color: var(--muted); background: #f5f7fa; font-size: .82rem; }
.example-box strong { color: var(--ink); }
.form-error { min-height: 20px; margin: -5px 0; color: var(--red); font-size: .85rem; }
.full-button { width: 100%; }
.scrim { position: fixed; z-index: 15; inset: 0; background: rgba(10, 24, 50, .38); backdrop-filter: blur(2px); }

[hidden] { display: none !important; }

@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }
@keyframes nudge { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 72px; padding: 14px 20px; }
  .brand small { display: none; }
  .scoreboard { gap: 9px; padding: 8px 11px; }
  .workspace { width: min(100% - 24px, 1120px); padding-top: 34px; }
  .workspace-head { display: block; }
  .ghost-button { margin-top: 22px; }
  .question-card { padding: 22px 16px; border-radius: 18px; }
  .reaction { min-height: 210px; gap: 10px; padding-inline: 0; font-size: 1.65rem; }
  .coefficient-input { width: 45px; height: 50px; font-size: 1.25rem; }
  .actions { align-items: stretch; }
  .actions, .primary-actions { flex-direction: column; }
  .primary-actions { width: 100%; }
  .actions button { width: 100%; }
  .atom-check { display: block; padding: 22px 18px; }
  .atom-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
