:root {
  color-scheme: light;
  --page: #eef1ff;
  --ink: #171b38;
  --subtle: #535a77;
  --blue: #3544db;
  --blue-dark: #2934ac;
  --blue-pale: #ebedff;
  --line: #d8dcef;
  --yellow: #ffdf6b;
  --success-bg: #e6f9df;
  --success-ink: #234822;
  --error-bg: #fff0ed;
  --error-ink: #8a3429;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  min-height: 100vh;
}

h1, h2, h3, p { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 4px;
}

.shell { width: min(100% - 72px, 1080px); margin-inline: auto; }
.intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  margin-block: 42px 24px;
}

.subject {
  color: var(--blue-dark);
  font-size: .875rem;
  font-weight: 760;
  margin-bottom: 7px;
}

h1 {
  font-size: clamp(2.15rem, 4.7vw, 3.6rem);
  line-height: 1.04;
  letter-spacing: -.063em;
}

.small-only { display: none; }

.mode {
  display: flex;
  flex: none;
  min-width: 0;
  gap: 4px;
  padding: 4px;
  margin: 0;
  border: 1px solid #c9ceeb;
  border-radius: 13px;
  background: #e2e6fa;
}

.mode label { cursor: pointer; position: relative; }
.mode input { position: absolute; opacity: 0; margin: 0; }
.mode span {
  display: block;
  text-align: center;
  border-radius: 9px;
  padding: 10px 13px;
  color: #454c6a;
  font-size: .875rem;
  font-weight: 730;
  white-space: nowrap;
}

.mode input:checked + span {
  background: white;
  color: var(--blue-dark);
  box-shadow: 0 1px 3px #1a254228;
}

.mode input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr);
  align-items: start;
  gap: 22px;
  padding-bottom: 42px;
}

.practice, .reference {
  border: 1px solid #d5d9ef;
  border-radius: 22px;
  box-shadow: 0 5px 0 #dee2f5;
}

.practice {
  background: white;
  padding: clamp(22px, 4vw, 42px);
  min-height: 515px;
}

.round > p {
  font-size: .875rem;
  font-weight: 760;
  color: var(--subtle);
}

.progress { display: flex; gap: 5px; margin-top: 9px; }
.progress span { flex: 1; height: 6px; border-radius: 3px; background: #e2e5f4; }
.progress .complete { background: #6a77ee; }
.progress .current { background: var(--blue); }

.equation {
  font-family: var(--mono);
  font-size: clamp(2.75rem, 7vw, 5.4rem);
  font-weight: 790;
  line-height: 1.07;
  letter-spacing: -.055em;
  font-variant-numeric: tabular-nums;
  margin-block: 28px 23px;
}

.equation:focus, .summary h2:focus { outline: none; }

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.field {
  display: grid;
  align-content: start;
  gap: 7px;
  width: min(100%, 125px);
  font-size: .875rem;
  font-weight: 720;
}

.field input {
  width: 100%;
  min-height: 57px;
  border: 2px solid #c6ccee;
  border-radius: 11px;
  background: #f6f7ff;
  color: var(--ink);
  padding: 4px 12px;
  font: 700 1.7rem/1.15 var(--mono);
  font-variant-numeric: tabular-nums;
}

.field input::placeholder { color: #727a9e; }
.field input[aria-invalid="true"] { border-color: #b85545; }

.support {
  margin-top: 10px;
  color: var(--subtle);
  font-size: .875rem;
  line-height: 1.45;
}

.step-title {
  font-size: 1.125rem;
  font-weight: 790;
  margin-bottom: 6px;
}

.step-copy { color: var(--subtle); max-width: 36ch; line-height: 1.45; margin-bottom: 14px; }
.step-math {
  margin-bottom: 11px;
  font-family: var(--mono);
  font-size: 1rem;
  line-height: 1.5;
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.primary, .quiet {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 17px;
  font-weight: 760;
  line-height: 1.3;
}

.primary {
  min-width: 122px;
  color: white;
  background: var(--blue);
  box-shadow: 0 3px 0 var(--blue-dark);
}

.primary:hover { background: var(--blue-dark); }
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--blue-dark); }
.quiet { background: #f2f3fc; color: var(--blue-dark); border-color: #e8eaf6; }
.quiet:hover { background: var(--blue-pale); }

.feedback, .hint, .callout {
  border-radius: 11px;
  padding: 12px 14px;
  margin-top: 14px;
  font-size: .9375rem;
  line-height: 1.5;
}

.feedback { background: var(--error-bg); color: var(--error-ink); }
.hint { background: #fff3be; color: #583e0c; }
.callout { background: var(--success-bg); color: var(--success-ink); margin-block: 0 20px; }
.callout strong { display: block; margin-bottom: 4px; }
.callout p + p { margin-top: 4px; }
.callout .check-equation { font-family: var(--mono); }

.summary { padding-block: 31px 12px; }
.summary h2 { font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.08; letter-spacing: -.055em; }
.summary > p { margin-top: 15px; line-height: 1.5; }

.reference { background: #f8f9ff; padding: 23px; }

.reference-heading { display: flex; gap: 13px; align-items: center; margin-bottom: 16px; }
.reference-heading h2 { font-size: 1.2rem; letter-spacing: -.025em; }

.division-mark {
  width: 39px;
  height: 37px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--yellow);
  color: var(--ink);
  font: 800 1.6rem/1 var(--mono);
}

.example-paper {
  padding: 15px 13px;
  border-radius: 11px;
  color: #202c78;
  background-color: #e6ebff;
  background-image: linear-gradient(#d7dfff 1px, transparent 1px), linear-gradient(90deg, #d7dfff 1px, transparent 1px);
  background-size: 17px 17px;
  font: 630 clamp(.95rem, 2vw, 1.22rem)/1.55 var(--mono);
}

.example-equation { font-weight: 800; padding-bottom: 7px; border-bottom: 1px solid #9ca9e9; }
.example-parts { padding-top: 7px; }
.example-parts p { white-space: pre; }
.example-parts p:nth-child(2) { margin-left: 1ch; }
.method { padding-left: 1.35rem; margin-block: 17px; font-size: .9375rem; line-height: 1.5; }
.method li + li { margin-top: 6px; }
.method li::marker { color: var(--blue-dark); font-weight: 760; }

.example-check {
  display: grid;
  gap: 4px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  font-size: .875rem;
  line-height: 1.4;
}

.example-check p:first-child { color: var(--blue-dark); font-weight: 750; }
.example-check strong { font: 700 1rem/1.4 var(--mono); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 850px) {
  .shell { width: min(100% - 44px, 1080px); }
  .intro { align-items: flex-start; flex-direction: column; gap: 15px; }
}

@media (max-width: 650px) {
  .shell { width: calc(100% - 28px); }
  .intro { margin-block: 25px 15px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .practice { min-height: 0; }
  .equation { margin-block: 21px 18px; }
  .reference { padding: 20px; }
}

@media (max-width: 400px) {
  .small-only { display: inline; }
  .practice { padding: 20px 17px; }
}

@media (max-width: 340px) {
  .mode { width: 100%; }
  .mode label { flex: 1; }
  .mode span { padding-inline: 6px; }
  .field { width: min(100%, 106px); }
}

.equation-solved {
  font-size: clamp(1.875rem, 5.2vw, 3.4rem);
  overflow-wrap: anywhere;
}

.mission-home { padding-block: clamp(24px, 5vw, 62px) 42px; }

.mission {
  --mission-ink: #17183c;
  --mission-yellow: #ffde66;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(18px, 5vw, 50px);
  min-height: 510px;
  padding: clamp(26px, 5vw, 60px);
  overflow: hidden;
  border: 1px solid #353260;
  border-radius: 28px;
  background: radial-gradient(ellipse at 90% 22%, #33328a 0%, transparent 59%), var(--mission-ink);
  color: white;
  box-shadow: 0 8px 0 #d9ddf5;
}

.mission-copy { position: relative; z-index: 1; }

.mission-subject {
  margin-bottom: 14px;
  color: #d3d2ff;
  font-size: .9rem;
  font-weight: 720;
}

.mission h1 {
  color: white;
  font-size: clamp(3.2rem, 7.2vw, 6.2rem);
  font-weight: 900;
  line-height: .93;
  letter-spacing: -.074em;
}

.mission h1 span { color: var(--mission-yellow); }

.mission-brief {
  max-width: 33ch;
  margin-top: 24px;
  color: #e3e3fb;
  font-size: clamp(1rem, 1.9vw, 1.125rem);
  line-height: 1.5;
}

.mission-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 27px;
}

.mission-actions :is(.mission-play, .mission-guide) {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 0 17px;
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.mission-actions a:focus-visible { outline-color: white; }

.mission-play {
  background: var(--mission-yellow);
  color: #242044;
  box-shadow: 0 4px 0 #b78024;
}
.mission-play:hover { background: #ffe88f; }

.mission-actions .mission-guide {
  border-color: #7778b2;
  background: #ffffff0d;
  color: #fff;
}
.mission-guide:hover { background: #ffffff20; }
.mission-actions a:active { transform: translateY(2px); }

.mission-rules {
  margin-top: 22px;
  color: #c9c9ec;
  font-size: .9rem;
  font-weight: 630;
}
.mission-rules span { margin-inline: .35em; }

.mission-art {
  width: 100%;
  max-width: 400px;
  margin-inline: auto;
}

.arcade-scene {
  position: relative;
  isolation: isolate;
  aspect-ratio: 1 / 1;
  width: 100%;
  overflow: hidden;
  border: 1px solid #8485d75e;
  border-radius: 24px;
  background:
    radial-gradient(ellipse at 58% 49%, #7864f38f 0, transparent 65%),
    radial-gradient(circle, #a9a6f878 1px, transparent 1.5px) center / 16px 16px,
    #25246a;
  box-shadow: inset 0 0 55px #15163588, 0 12px 38px #14132d66;
  container-type: inline-size;
}

.orbit {
  position: absolute;
  inset: 19% 14%;
  border: 1px solid #bdb1ff55;
  border-radius: 50%;
  transform: rotate(-27deg);
}
.orbit-inner { inset: 28% 9%; border-style: dashed; transform: rotate(29deg); }

.arcade-chip {
  position: absolute;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid #ffffff8a;
  border-radius: 18%;
  font: 900 12cqw / 1 var(--mono);
}

.chip-division {
  z-index: 1;
  top: 27%;
  left: 31%;
  width: 42%;
  transform: rotate(-9deg);
  background: #ffdd67;
  color: #24204b;
  box-shadow: inset 0 0 0 1.8cqw #ffed9a, 1.3cqw 2.8cqw 0 #a96830, 2.2cqw 5cqw 0 #15163470;
  font-size: 31cqw;
}

.chip-question {
  top: 15%;
  left: 12%;
  width: 22%;
  transform: rotate(12deg);
  background: #a499ff;
  color: #252044;
  box-shadow: inset 0 0 0 1.1cqw #c8bfff, .6cqw 1.5cqw 0 #5449a9;
}

.chip-check {
  right: 11%;
  bottom: 13%;
  width: 23%;
  transform: rotate(11deg);
  background: #8df1b7;
  color: #123d3c;
  box-shadow: inset 0 0 0 1.1cqw #c3ffda, .7cqw 1.6cqw 0 #46836d;
}

.spark {
  position: absolute;
  width: 5.5%;
  aspect-ratio: 1;
  background: #e0d6ff;
  clip-path: polygon(50% 0, 63% 37%, 100% 50%, 63% 63%, 50% 100%, 37% 63%, 0 50%, 37% 37%);
}
.spark-top { top: 14%; right: 22%; }
.spark-right { top: 45%; right: 10%; width: 3.9%; }
.spark-bottom { left: 24%; bottom: 17%; background: #ffde66; }

.chip-light {
  position: absolute;
  top: 23%;
  right: 12%;
  width: 2%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #8df1b7;
  box-shadow: 0 0 12px #8df1b7;
}

@media (max-width: 760px) {
  .mission { min-height: 0; }
  .mission h1 { font-size: clamp(2.85rem, 8vw, 4.8rem); }
  .mission-actions { gap: 10px; }
  .mission-brief { margin-top: 18px; }
}

@media (max-width: 575px) {
  .mission {
    grid-template-columns: minmax(0, 1fr);
    gap: 26px;
    padding: 24px;
    border-radius: 21px;
  }
  .mission h1 { font-size: clamp(2.75rem, 12.5vw, 4.15rem); }
  .mission-actions { margin-top: 22px; }
  .mission-art { max-width: 285px; }
  .arcade-scene { border-radius: 17px; }
}

@media (max-width: 375px) {
  .mission { padding: 20px; }
  .mission-actions a { width: 100%; }
}

.math-back {
  padding-block: 13px 0;
}

.math-back a {
  display: inline-flex;
  align-items: center;
  min-height: 35px;
  color: #4d5b66;
  font-size: .9rem;
  font-weight: 700;
  text-underline-offset: 3px;
}

.charkade-footer {
  margin-top: auto;
  border-top: 1px solid #a2d7ff;
  background: #5cb8ff;
  color: #374151;
}

body:has(.charkade-footer) {
  display: flex;
  flex-direction: column;
}

.footer-content, .footer-content nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
}

.footer-content {
  justify-content: space-between;
  padding-block: 14px;
  font-size: .875rem;
}

.footer-content a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  text-underline-offset: 3px;
}

.footer-content a:hover { color: var(--blue-dark); }
