:root {
  --ink: #f8f5ff;
  --muted: #c8beda;
  --panel: rgba(16, 8, 41, .86);
  --panel-strong: rgba(12, 5, 31, .95);
  --line: rgba(232, 211, 255, .18);
  --purple: #8b5cf6;
  --purple-light: #bd9dff;
  --gold: #ffd76a;
  --gold-strong: #f5b93e;
  --emerald: #57e6ad;
  --danger: #ff6687;
  --shadow: 0 22px 70px rgba(3, 0, 14, .5);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  color-scheme: dark;
  background: #090319;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Tahoma", "Arial", sans-serif;
  overflow-x: hidden;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.world-bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  background:
    linear-gradient(180deg, rgba(5, 2, 20, .12), rgba(7, 2, 25, .78) 58%, #08021a 100%),
    url("assets/kingdom-bg.webp") center top / cover no-repeat;
}

.world-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 15%, transparent 0 18%, rgba(4, 1, 17, .2) 55%, rgba(4, 1, 17, .76) 100%);
}

.stars,
.stars::before,
.stars::after {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  content: "";
  background-image:
    radial-gradient(circle, rgba(255, 225, 142, .7) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(190, 164, 255, .55) 0 1px, transparent 1.5px);
  background-size: 92px 92px, 137px 137px;
  background-position: 0 0, 31px 47px;
  animation: drift 26s linear infinite;
  opacity: .42;
}

.stars::before { transform: scale(1.2); opacity: .2; animation-duration: 38s; }
.stars::after { transform: scale(.8); opacity: .28; animation-duration: 19s; }

@keyframes drift { to { background-position: 92px 92px, -106px 184px; } }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 62px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(7, 2, 24, .96), rgba(7, 2, 24, .58));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 215, 106, .12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--gold);
  font-size: 1.06rem;
  font-weight: 800;
  letter-spacing: .2px;
}

.mini-crown { font-size: 1.3rem; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  color: var(--ink);
  cursor: pointer;
}

.icon-btn:hover { background: rgba(255, 215, 106, .13); border-color: rgba(255, 215, 106, .38); }

.app-shell {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 30px 18px max(44px, env(safe-area-inset-bottom));
}

.screen { display: none; animation: reveal .42s ease both; }
.screen.active { display: block; }
.hidden { display: none !important; }

@keyframes reveal {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.glass-card {
  background: linear-gradient(145deg, rgba(31, 17, 67, .91), rgba(11, 6, 34, .88));
  border: 1px solid var(--line);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.07);
  backdrop-filter: blur(18px);
}

.intro-screen {
  min-height: calc(100vh - 120px);
  text-align: center;
  padding-top: clamp(28px, 8vh, 80px);
}

.hero-emblem {
  position: relative;
  width: 118px;
  height: 118px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 215, 106, .5);
  border-radius: 32px 32px 48px 48px;
  background: radial-gradient(circle at 50% 35%, rgba(172, 115, 255, .56), rgba(43, 15, 89, .92) 62%);
  box-shadow: 0 0 50px rgba(139, 92, 246, .4), inset 0 0 32px rgba(255, 215, 106, .09);
}

.hero-emblem::before,
.hero-emblem::after {
  content: "";
  position: absolute;
  inset: -9px;
  border: 1px solid rgba(190, 157, 255, .22);
  border-radius: 40px 40px 55px 55px;
  transform: rotate(8deg);
}

.hero-emblem::after { transform: rotate(-8deg); }
.hero-emblem .crown { position: absolute; top: -25px; color: var(--gold); font-size: 3rem; filter: drop-shadow(0 5px 8px #4d2600); }
.hero-x { font-family: Georgia, serif; font-weight: 900; font-size: 4.4rem; color: white; text-shadow: 0 0 20px #bc9cff; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: 1.5px;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin-bottom: 8px;
  font-size: clamp(2.35rem, 7vw, 4.2rem);
  line-height: 1;
  text-shadow: 0 4px 30px rgba(0,0,0,.6);
}

.hero-subtitle {
  max-width: 530px;
  margin: 0 auto 25px;
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.18rem);
  line-height: 1.9;
}

.start-card {
  width: min(100%, 470px);
  margin: 0 auto;
  padding: 24px;
  border-radius: 25px;
}

.start-card label {
  display: block;
  margin-bottom: 10px;
  text-align: right;
  color: #eee8ff;
  font-weight: 700;
}

.start-card input {
  width: 100%;
  min-height: 54px;
  margin-bottom: 14px;
  padding: 0 17px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  outline: none;
  background: rgba(4, 2, 17, .6);
  color: white;
  font-size: 1rem;
}

.start-card input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(255, 215, 106, .1);
}

.primary-btn,
.ghost-btn {
  width: 100%;
  min-height: 54px;
  border-radius: 15px;
  font-weight: 900;
  cursor: pointer;
  transition: transform .18s ease, filter .18s ease;
}

.primary-btn {
  border: 1px solid #ffe49b;
  background: linear-gradient(135deg, #ffe287, #e9a92e);
  color: #2c1600;
  box-shadow: 0 10px 28px rgba(242, 174, 48, .25);
}

.primary-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary-btn:active { transform: translateY(1px) scale(.99); }

.ghost-btn {
  margin-top: 10px;
  border: 1px solid rgba(208, 185, 255, .3);
  background: rgba(142, 91, 246, .1);
  color: #eee7ff;
}

.journey-promise {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 24px auto 14px;
  color: #ddd4ed;
  font-size: .84rem;
}

.journey-promise i { width: 4px; height: 4px; border-radius: 50%; background: var(--gold); }
.credit { color: rgba(239, 230, 255, .65); font-size: .78rem; }

.academy-screen {
  max-width: 820px;
  margin: 0 auto;
  padding-top: 16px;
}

.academy-heading {
  margin: 10px auto 20px;
  text-align: center;
}

.academy-heading h2 {
  margin-bottom: 8px;
  color: var(--gold);
  font-size: clamp(1.8rem, 5vw, 2.8rem);
}

.academy-heading > p:last-child {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.8;
}

.academy-progress {
  max-width: 700px;
  margin: 0 auto 17px;
}

.academy-card {
  max-width: 700px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 34px);
  border-radius: 28px;
}

.academy-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.academy-card h3 {
  margin: 22px 0 8px;
  text-align: center;
  color: #fff;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
}

.academy-instruction {
  max-width: 590px;
  margin: 0 auto 12px;
  color: #ddd4ed;
  text-align: center;
  font-size: 1rem;
  line-height: 1.9;
}

.academy-equation {
  margin-bottom: 16px;
  scroll-margin-top: 82px;
  font-size: clamp(1.65rem, 6vw, 2.35rem);
}

.academy-model {
  min-height: 96px;
  margin: 0 0 15px;
  padding: 14px;
  overflow: hidden;
  border: 1px solid rgba(189, 157, 255, .22);
  border-radius: 18px;
  background: radial-gradient(circle at 50% 0, rgba(139, 92, 246, .18), transparent 58%), rgba(2, 7, 25, .5);
  text-align: center;
}

.academy-model > p {
  margin: 0 0 11px;
  color: #d7cdea;
  font-size: .87rem;
  line-height: 1.6;
}

.token-equation,
.zero-pair,
.coefficient-model,
.rule-transform,
.sign-division,
.verify-model {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  direction: ltr;
}

.token-cluster { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; max-width: 250px; }
.unit-token {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 50%;
  color: #fff;
  font: 800 .75rem Tahoma, Arial, sans-serif;
  box-shadow: inset 0 1px 7px rgba(255,255,255,.14), 0 5px 14px rgba(0,0,0,.25);
  transition: opacity .5s ease, transform .5s ease, filter .5s ease;
}
.unit-token.positive { background: linear-gradient(145deg, #168d66, #0b493b); }
.unit-token.negative { background: linear-gradient(145deg, #bd3866, #681d46); }
.unit-token.cancelling { opacity: .22; transform: scale(.72); filter: grayscale(.8); text-decoration: line-through; }
.result-cluster { padding: 7px; border: 1px solid rgba(87,230,173,.28); border-radius: 14px; background: rgba(87,230,173,.06); }
.mystery-token, .side-operation, .answer-sign {
  min-width: 48px;
  min-height: 42px;
  display: inline-grid;
  place-items: center;
  padding: 5px 10px;
  border: 1px dashed rgba(255,215,106,.48);
  border-radius: 12px;
  color: var(--gold);
  background: rgba(255,215,106,.07);
  font-weight: 900;
}
.model-caption { margin-top: 10px; color: #bff8df; font-size: .85rem; line-height: 1.6; }
.rule-transform span, .sign-division span, .verify-model span { padding: 9px 12px; border-radius: 11px; background: rgba(255,255,255,.06); font: 800 1.14rem "Times New Roman", serif; }
.rule-transform .lit-rule, .verify-model .verified { color: #bff8df; box-shadow: inset 0 0 0 1px rgba(87,230,173,.35); }
.both-sides-model { display: grid; grid-template-columns: 50px 24px 1fr 24px 50px; align-items: center; gap: 5px; direction: ltr; }
.both-sides-model > div { display: flex; align-items: center; justify-content: space-around; gap: 8px; color: #d7cdea; font-size: .75rem; }
.both-sides-model > div b { color: var(--gold); font-size: 1.7rem; }
.operation-arrow { color: var(--emerald); font-weight: 900; }
.x-copies { display: flex; gap: 7px; }
.model-x { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 1px solid rgba(255,215,106,.5); border-radius: 13px; background: linear-gradient(145deg, #7541d8, #34136a); color: white; font: 900 1.35rem Georgia, serif; }
.gem-bank { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 180px; }
.model-gem { color: var(--gold); font-size: .72rem; filter: drop-shadow(0 1px 4px rgba(255,215,106,.35)); }
.x-groups { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.x-groups > span { max-width: 150px; padding: 8px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 3px; border: 1px solid rgba(87,230,173,.25); border-radius: 12px; background: rgba(87,230,173,.06); }
.answer-sign { border-style: solid; border-color: rgba(87,230,173,.45); color: #bff8df; }

.balance-board {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 90px 1fr;
  align-items: end;
  gap: 10px;
  margin: 17px 0;
  padding: 18px 14px 25px;
  border: 1px solid rgba(255, 215, 106, .2);
  border-radius: 20px;
  background:
    radial-gradient(circle at 50% 100%, rgba(255, 215, 106, .12), transparent 45%),
    rgba(2, 7, 25, .45);
}

.balance-pan {
  min-width: 0;
  text-align: center;
}

.balance-pan small {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .88rem;
}

.pan-content {
  min-height: 62px;
  padding: 14px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  border: 2px solid rgba(255, 215, 106, .46);
  border-radius: 12px 12px 26px 26px;
  background: linear-gradient(180deg, rgba(113, 65, 184, .38), rgba(29, 13, 64, .72));
  box-shadow: 0 9px 0 -5px rgba(255, 215, 106, .42);
  color: #fff;
  font: 700 clamp(1.1rem, 4vw, 1.45rem) "Times New Roman", serif;
  unicode-bidi: isolate;
}

.balance-center {
  display: grid;
  justify-items: center;
  gap: 4px;
  color: var(--gold);
}

.balance-center span {
  font-size: 2.6rem;
  filter: drop-shadow(0 5px 12px rgba(255, 190, 63, .28));
}

.balance-center b {
  font-size: .78rem;
}

.academy-choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 11px;
  margin-top: 17px;
}

.academy-choice {
  min-height: 60px;
  padding: 12px;
  border: 1px solid rgba(220, 203, 255, .25);
  border-radius: 16px;
  background: rgba(15, 22, 55, .78);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.academy-choice:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--gold);
}

.academy-choice.correct {
  border-color: var(--emerald);
  background: rgba(20, 92, 73, .55);
}

.academy-choice.wrong {
  border-color: var(--danger);
  background: rgba(102, 19, 49, .52);
  animation: nudge .28s ease;
}

@keyframes nudge {
  25% { transform: translateX(5px); }
  75% { transform: translateX(-5px); }
}

.academy-work {
  display: none;
  margin: 16px 0;
  padding: 16px;
  border: 1px solid rgba(87, 230, 173, .3);
  border-radius: 16px;
  background: rgba(12, 69, 56, .2);
}

.academy-work.visible {
  display: block;
  animation: reveal .4s ease both;
}

.academy-step-line {
  padding: 8px 6px;
  color: #fff;
  text-align: center;
  font: 700 clamp(1.02rem, 4vw, 1.28rem) "Times New Roman", serif;
  unicode-bidi: isolate;
}

.academy-step-line.math { direction: ltr; }

.academy-step-line + .academy-step-line {
  border-top: 1px dashed rgba(255, 255, 255, .13);
}

.academy-explain {
  margin: 9px 0 0;
  color: #d7f8ea;
  text-align: center;
  font-size: .94rem;
  line-height: 1.75;
}

.cancel-pair {
  color: var(--gold);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.academy-card > .primary-btn {
  margin-top: 15px;
}

.academy-laws {
  max-width: 700px;
  margin: 17px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.academy-laws p {
  margin: 0;
  padding: 13px 14px;
  border: 1px solid rgba(255, 215, 106, .18);
  border-radius: 15px;
  background: rgba(11, 5, 32, .72);
  color: #d9cfea;
  text-align: center;
  font-size: .9rem;
  line-height: 1.75;
}

.academy-laws strong {
  display: block;
  margin-bottom: 3px;
  color: var(--gold);
}
.map-academy-btn { max-width: 320px; }

.section-heading { margin: 16px 0 22px; text-align: center; }
.section-heading h2 { margin-bottom: 9px; font-size: clamp(1.55rem, 4vw, 2.3rem); }
.section-heading > p:last-child { color: var(--muted); }

.player-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 22px;
  padding: 15px 18px;
  border-radius: 19px;
  text-align: center;
}

.player-strip div { display: grid; gap: 5px; }
.player-strip small { color: var(--muted); font-size: .72rem; }
.player-strip strong { color: var(--gold); font-size: .92rem; }
.player-strip .rank { border-inline: 1px solid var(--line); }

.skill-map {
  margin-bottom: 22px;
  padding: 18px;
  border-radius: 20px;
}
.skill-map-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.skill-map-head h3 { margin: 0; font-size: 1.05rem; }
.mini-action { min-height: 40px; padding: 7px 12px; border: 1px solid rgba(255,215,106,.3); border-radius: 12px; background: rgba(255,215,106,.08); color: var(--gold); font-size: .78rem; font-weight: 900; cursor: pointer; }
.skill-bars { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 18px; }
.skill-row > div:first-child { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; color: #e9e2f4; font-size: .78rem; }
.skill-row b { color: var(--gold); }
.skill-track { height: 7px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.1); }
.skill-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #7b49e1, var(--emerald)); }
.skill-coach-text { margin: 14px 0 0; padding-top: 11px; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; line-height: 1.7; }

.realm-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: stretch;
  gap: 12px;
}

.realm-card {
  position: relative;
  min-height: 272px;
  padding: 18px 15px 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(49, 25, 97, .92), rgba(12, 6, 35, .95));
  color: var(--ink);
  box-shadow: 0 16px 45px rgba(2, 0, 12, .35);
  text-align: right;
  cursor: pointer;
  transition: transform .22s ease, border-color .22s ease;
}

.realm-card:hover:not([disabled]) { transform: translateY(-5px); border-color: rgba(255, 215, 106, .55); }
.realm-card[disabled] { cursor: not-allowed; filter: grayscale(.7); opacity: .58; }
.realm-card::after {
  content: "";
  position: absolute;
  width: 130px;
  height: 130px;
  left: -50px;
  bottom: -60px;
  border-radius: 50%;
  background: var(--realm-glow, rgba(139,92,246,.28));
  filter: blur(8px);
}

.realm-number {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 11px;
  background: rgba(255,255,255,.08);
  color: var(--gold);
  font-weight: 900;
}

.realm-icon { display: block; margin: 18px 0 12px; font-size: 2rem; }
.realm-card h3 { min-height: 48px; margin-bottom: 8px; font-size: 1rem; line-height: 1.5; }
.realm-card p { min-height: 55px; color: var(--muted); font-size: .75rem; line-height: 1.65; }
.realm-status { display: flex; align-items: center; justify-content: space-between; color: var(--gold); font-size: .73rem; font-weight: 800; }
.realm-stars { direction: ltr; color: #5e526c; letter-spacing: 1px; }
.realm-stars .lit { color: var(--gold); }
.realm-card.complete { border-color: rgba(87, 230, 173, .4); }
.realm-card.complete .realm-number { color: #052d21; background: var(--emerald); border-color: var(--emerald); }
.realm-card.current { box-shadow: 0 0 0 2px rgba(255,215,106,.15), 0 18px 50px rgba(2,0,12,.5); }

.royal-missions { margin-top: 30px; }
.mission-section-head { margin-bottom: 14px; text-align: center; }
.mission-section-head h3 { margin-bottom: 7px; font-size: 1.25rem; }
.mission-section-head > p:last-child { color: var(--muted); font-size: .88rem; }
.mission-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mission-map-card {
  min-height: 150px;
  display: grid;
  grid-template-columns: 38px 42px 1fr;
  align-items: start;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(32,18,69,.92), rgba(10,6,31,.95));
  color: white;
  text-align: right;
  cursor: pointer;
}
.mission-map-card:disabled { opacity: .5; filter: grayscale(.7); cursor: not-allowed; }
.mission-map-card.current { border-color: rgba(255,215,106,.42); box-shadow: 0 0 0 2px rgba(255,215,106,.08); }
.mission-map-card.complete { border-color: rgba(87,230,173,.38); }
.mission-map-number { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: rgba(255,255,255,.08); color: var(--gold); font-weight: 900; }
.mission-map-card.complete .mission-map-number { background: var(--emerald); color: #06281e; }
.mission-map-icon { color: var(--gold); font-size: 1.65rem; }
.mission-map-card h4 { margin: 2px 0 6px; font-size: .96rem; }
.mission-map-card p { margin: 0 0 8px; color: var(--muted); font-size: .76rem; line-height: 1.65; }
.mission-map-card small { color: var(--gold); font-size: .7rem; }

.mission-screen { max-width: 790px; margin: 0 auto; }
.mission-score { padding: 8px 13px; border: 1px solid rgba(255,215,106,.24); border-radius: 13px; color: var(--gold); font-weight: 900; direction: ltr; }
.mission-equation { font-size: clamp(1.45rem, 5vw, 2.15rem); }
.mission-work { display: grid; gap: 8px; margin: 0 0 17px; }
.mission-work-line { min-height: 48px; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; padding: 9px 12px; border-right: 3px solid rgba(255,215,106,.6); border-radius: 10px; background: rgba(2,8,28,.5); }
.mission-work-line span { direction: rtl; color: var(--gold); font: 700 .75rem Tahoma, Arial, sans-serif; }
.mission-work-line b { color: #fff; text-align: center; font: 700 1.07rem "Times New Roman", serif; unicode-bidi: isolate; }
.mission-choices { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; }
.mission-choice { min-height: 60px; padding: 11px; border: 1px solid rgba(220,203,255,.22); border-radius: 15px; background: rgba(14,21,54,.76); color: white; font-weight: 800; line-height: 1.6; unicode-bidi: plaintext; cursor: pointer; }
.mission-choice.correct { border-color: var(--emerald); background: rgba(20,92,73,.5); }
.mission-choice.wrong { border-color: var(--danger); background: rgba(102,19,49,.5); }
.mission-feedback { margin: 15px 0; padding: 14px; border-radius: 14px; line-height: 1.8; }
.mission-feedback.correct { border: 1px solid rgba(87,230,173,.32); background: rgba(20,92,73,.22); color: #c9fae6; }
.mission-feedback.wrong { border: 1px solid rgba(255,102,135,.32); background: rgba(102,19,49,.22); color: #ffd6df; }
.mission-card > .primary-btn { margin-top: 10px; }

.map-actions { margin-top: 22px; text-align: center; }
.text-btn { padding: 10px; border: 0; background: transparent; color: #bdb0d1; text-decoration: underline; cursor: pointer; }
.map-credit { margin-top: 14px; text-align: center; }

.quest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 17px 20px;
  border-radius: 19px;
}

.quest-header h2 { margin: 0; font-size: clamp(1.15rem, 3.5vw, 1.55rem); }
.quest-stats { display: flex; gap: 13px; color: var(--gold); font-weight: 900; white-space: nowrap; }
#heartStat { color: #ff7895; letter-spacing: 2px; }

.progress-wrap { margin: 18px 3px; }
.progress-meta { display: flex; justify-content: space-between; margin-bottom: 8px; color: #e0d7ee; font-size: .83rem; }
.progress-track { height: 8px; overflow: hidden; border-radius: 9px; background: rgba(255,255,255,.1); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--emerald), var(--gold)); transition: width .4s ease; }

.challenge-card {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 34px);
  border-radius: 28px;
}

.challenge-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.question-code { color: var(--emerald); font-weight: 900; font-size: .8rem; }
.difficulty-badge { padding: 5px 10px; border: 1px solid rgba(255,215,106,.25); border-radius: 999px; color: var(--gold); background: rgba(255,215,106,.08); font-size: .7rem; }
.question-prompt { margin: 20px 0 8px; color: #eee9f7; text-align: center; font-size: clamp(1rem, 3vw, 1.18rem); }

.equation {
  unicode-bidi: isolate;
  width: fit-content;
  min-width: min(100%, 330px);
  margin: 12px auto 20px;
  padding: 17px 24px;
  border: 1px solid rgba(255, 215, 106, .3);
  border-radius: 18px;
  background: rgba(2, 9, 28, .55);
  color: white;
  box-shadow: inset 0 0 28px rgba(139,92,246,.1);
  text-align: center;
  font-family: "Times New Roman", serif;
  font-size: clamp(1.85rem, 7vw, 2.7rem);
  font-weight: 700;
  letter-spacing: .5px;
}

.story-scaffold {
  min-height: 58px;
  margin: 0 auto 18px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  font-size: .86rem;
  line-height: 1.7;
}

.x-token {
  display: inline-grid;
  min-width: 37px;
  height: 37px;
  place-items: center;
  border: 1px solid rgba(255,215,106,.45);
  border-radius: 12px;
  background: linear-gradient(145deg, #6f3ed2, #35166d);
  color: #fff;
  font-family: Georgia, serif;
  font-weight: 900;
  box-shadow: 0 0 18px rgba(139,92,246,.28);
}

.guided-solver {
  margin: 2px 0 18px;
  padding: 16px;
  border: 1px solid rgba(87, 230, 173, .26);
  border-radius: 19px;
  background: linear-gradient(145deg, rgba(7, 45, 48, .35), rgba(15, 8, 41, .72));
}

.guided-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 13px;
  color: var(--emerald);
  font-size: .88rem;
  font-weight: 900;
}

.guided-head span:last-child {
  padding: 5px 9px;
  border: 1px solid rgba(87, 230, 173, .25);
  border-radius: 999px;
  background: rgba(87, 230, 173, .08);
}

.guided-history {
  display: grid;
  gap: 8px;
  margin-bottom: 15px;
}

.guided-line {
  padding: 10px 12px;
  border-right: 3px solid var(--gold);
  border-radius: 9px;
  background: rgba(1, 7, 25, .5);
  color: #fff;
  text-align: center;
  font: 700 clamp(1.05rem, 4vw, 1.3rem) "Times New Roman", serif;
  unicode-bidi: isolate;
  animation: reveal .35s ease both;
}

.guided-line.result {
  border-right-color: var(--emerald);
  color: #bff8df;
}

.guided-prompt {
  margin: 0 0 11px;
  color: #f3edfb;
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.75;
}

.guided-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
}

.guided-option {
  min-height: 56px;
  padding: 10px;
  border: 1px solid rgba(219, 204, 255, .22);
  border-radius: 14px;
  background: rgba(21, 27, 63, .78);
  color: #fff;
  font-size: .94rem;
  font-weight: 800;
  line-height: 1.6;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.guided-option:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--gold);
}

.guided-option.correct {
  border-color: var(--emerald);
  background: rgba(18, 91, 70, .55);
}

.guided-option.wrong {
  border-color: var(--danger);
  background: rgba(102, 19, 49, .52);
  animation: nudge .28s ease;
}

.guided-complete {
  padding: 13px;
  border: 1px solid rgba(255, 215, 106, .28);
  border-radius: 13px;
  background: rgba(255, 215, 106, .08);
  color: var(--gold);
  text-align: center;
  font-weight: 900;
}

.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.choice-btn {
  position: relative;
  min-height: 68px;
  padding: 12px 50px 12px 18px;
  border: 1px solid rgba(220, 203, 255, .2);
  border-radius: 17px;
  background: rgba(14, 21, 54, .72);
  color: #fff;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  transition: border-color .18s ease, transform .18s ease, background .18s ease;
  direction: ltr;
  unicode-bidi: isolate;
}

.choice-btn:hover:not(:disabled) { border-color: var(--gold); transform: translateY(-2px); background: rgba(64, 36, 109, .82); }
.choice-btn::before {
  content: attr(data-letter);
  position: absolute;
  right: 12px;
  top: 50%;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  transform: translateY(-50%);
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  color: var(--gold);
  font-family: Tahoma, Arial, sans-serif;
  font-size: .85rem;
}

.choice-btn:disabled { cursor: default; }
.choice-btn.eliminated { opacity: .18; pointer-events: none; text-decoration: line-through; }
.choice-btn.correct { border-color: var(--emerald); background: rgba(20, 92, 73, .48); }
.choice-btn.wrong { border-color: var(--danger); background: rgba(102, 19, 49, .46); }

.power-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.power-btn {
  min-height: 45px;
  border: 1px solid rgba(188, 157, 255, .25);
  border-radius: 13px;
  background: rgba(139, 92, 246, .08);
  color: #dcd1ee;
  cursor: pointer;
}
.power-btn span { color: var(--gold); }
.power-btn:disabled { opacity: .4; cursor: not-allowed; }

.result-screen,
.certificate-screen {
  max-width: 680px;
  margin: 0 auto;
  padding-top: clamp(45px, 10vh, 100px);
  text-align: center;
}

.result-emblem {
  width: 105px;
  height: 105px;
  margin: 0 auto 22px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,215,106,.45);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(139,92,246,.5), rgba(23,8,54,.95));
  color: var(--gold);
  font-size: 3rem;
  box-shadow: 0 0 45px rgba(139,92,246,.42);
}

.result-screen h2 { font-size: clamp(1.7rem, 5vw, 2.6rem); }
.result-screen > p:not(.eyebrow) { color: var(--muted); line-height: 1.8; }
.result-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin: 25px 0; padding: 20px; border-radius: 20px; }
.result-stats div { display: grid; gap: 6px; }
.result-stats span { color: var(--gold); font-size: 1.4rem; font-weight: 900; }
.result-stats small { color: var(--muted); }
.result-screen .primary-btn, .result-screen .ghost-btn, .certificate-actions { max-width: 420px; margin-inline: auto; }

.certificate {
  position: relative;
  overflow: hidden;
  padding: clamp(28px, 6vw, 55px);
  border: 2px solid var(--gold);
  border-radius: 7px;
  background:
    linear-gradient(rgba(18,7,43,.95), rgba(18,7,43,.96)),
    radial-gradient(circle, #5c2cb0, #12072b);
  box-shadow: 0 0 0 8px rgba(255,215,106,.1), var(--shadow);
}

.certificate::before {
  content: "";
  position: absolute;
  inset: 13px;
  border: 1px solid rgba(255,215,106,.35);
  pointer-events: none;
}

.certificate-crown { color: var(--gold); font-size: 3.2rem; }
.certificate h2 { color: var(--gold); font-size: clamp(1.8rem, 6vw, 3rem); }
.certificate h3 { margin: 18px 0; color: white; font-size: clamp(1.6rem, 5vw, 2.4rem); border-bottom: 1px solid rgba(255,215,106,.35); padding-bottom: 13px; }
.certificate p { color: #d8cee8; line-height: 1.85; }
.certificate-score { color: var(--gold); font-weight: 900; }
.seal { width: 65px; height: 65px; margin: 22px auto 12px; display: grid; place-items: center; border: 2px solid var(--gold); border-radius: 50%; color: var(--gold); font: 900 2rem Georgia, serif; box-shadow: inset 0 0 15px rgba(255,215,106,.15); }
.certificate-credit { font-size: .75rem; }
.certificate-actions { margin-top: 23px; display: grid; gap: 10px; }
.certificate-actions .primary-btn + .primary-btn { background: linear-gradient(135deg, #bd9dff, #7440d3); border-color: #d8c5ff; color: #16082e; box-shadow: 0 10px 28px rgba(139,92,246,.25); }

.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,0,13,.78); backdrop-filter: blur(8px); }
.modal-card {
  position: relative;
  z-index: 1;
  width: min(100%, 520px);
  max-height: min(90vh, 680px);
  overflow-y: auto;
  padding: 28px;
  border: 1px solid rgba(255,215,106,.26);
  border-radius: 25px;
  background: linear-gradient(155deg, #28134f, #0c061f 72%);
  box-shadow: 0 30px 90px rgba(0,0,0,.7);
  text-align: center;
}

.feedback-icon { width: 66px; height: 66px; margin: 0 auto 15px; display: grid; place-items: center; border-radius: 50%; color: #06271e; background: var(--emerald); font-size: 2rem; font-weight: 900; }
.feedback-icon.wrong { color: #360715; background: var(--danger); }
.modal-card h2 { margin-bottom: 7px; }
.modal-card > p { color: var(--muted); }
.solution-steps { margin: 18px 0; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(1,6,23,.48); }
.solution-line { padding: 7px; color: #fff; font: 700 1.17rem "Times New Roman", serif; unicode-bidi: isolate; }
.solution-line + .solution-line { border-top: 1px dashed rgba(255,255,255,.1); }
.concept-note { padding: 10px 13px; border-radius: 12px; background: rgba(255,215,106,.08); color: #f4dfaa !important; font-size: .85rem; line-height: 1.7; }

.toast {
  position: fixed;
  z-index: 150;
  left: 50%;
  bottom: 25px;
  max-width: calc(100% - 36px);
  padding: 12px 18px;
  border: 1px solid rgba(255,215,106,.3);
  border-radius: 13px;
  background: #19102e;
  color: white;
  box-shadow: 0 10px 35px rgba(0,0,0,.45);
  transform: translate(-50%, 25px);
  opacity: 0;
  pointer-events: none;
  transition: .25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 850px) {
  .realm-grid { grid-template-columns: repeat(2, 1fr); }
  .realm-card:last-child { grid-column: 1 / -1; min-height: 225px; }
  .mission-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .app-shell { padding: 18px 13px 35px; }
  .topbar { height: 58px; }
  .intro-screen { padding-top: 28px; }
  .hero-emblem { width: 96px; height: 96px; }
  .hero-emblem .crown { font-size: 2.45rem; top: -22px; }
  .hero-x { font-size: 3.6rem; }
  .start-card { padding: 19px; }
  .journey-promise { font-size: .72rem; gap: 7px; }
  .academy-card { padding: 18px 13px; }
  .academy-model { padding: 12px 7px; }
  .unit-token { width: 29px; height: 29px; font-size: .66rem; }
  .token-equation { gap: 5px; }
  .token-cluster { gap: 3px; }
  .both-sides-model { grid-template-columns: 45px 18px 1fr 18px 45px; }
  .both-sides-model > div { font-size: .62rem; }
  .x-groups { grid-template-columns: 1fr; width: 100%; }
  .x-groups > span { max-width: none; }
  .balance-board { grid-template-columns: 1fr 48px 1fr; gap: 5px; padding-inline: 8px; }
  .balance-center span { font-size: 2rem; }
  .balance-center b { display: none; }
  .pan-content { min-height: 58px; padding-inline: 4px; font-size: 1.02rem; }
  .academy-choices { grid-template-columns: 1fr; }
  .academy-laws { grid-template-columns: 1fr; }
  .player-strip { grid-template-columns: 1fr 1fr; }
  .player-strip .rank { grid-column: 1 / -1; grid-row: 2; padding-top: 10px; border-inline: 0; border-top: 1px solid var(--line); }
  .skill-map-head { align-items: flex-start; flex-direction: column; }
  .skill-bars { grid-template-columns: 1fr; }
  .mini-action { width: 100%; }
  .realm-grid { grid-template-columns: 1fr; }
  .realm-card, .realm-card:last-child { grid-column: auto; min-height: 195px; }
  .realm-icon { display: inline-block; margin: 15px 0 8px 8px; }
  .realm-card h3 { display: inline; min-height: 0; }
  .realm-card p { min-height: 0; margin-top: 8px; }
  .quest-header { align-items: flex-start; padding: 14px; }
  .quest-stats { flex-direction: column; align-items: flex-end; gap: 5px; font-size: .8rem; }
  .challenge-card { padding: 19px 14px; border-radius: 22px; }
  .choice-grid { gap: 9px; }
  .choice-btn { min-height: 62px; padding-right: 42px; font-size: 1.08rem; }
  .choice-btn::before { right: 8px; width: 29px; height: 29px; }
  .power-row { grid-template-columns: 1fr; }
  .guided-options { grid-template-columns: 1fr; }
  .mission-choices { grid-template-columns: 1fr; }
  .mission-work-line { grid-template-columns: 1fr; gap: 5px; }
  .result-stats { padding: 14px 7px; }
  .result-stats small { font-size: .65rem; }
  .modal-card { padding: 24px 18px; }
}

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

@media print {
  body { background: white; }
  .world-bg, .stars, .topbar, .certificate-actions { display: none !important; }
  .app-shell { width: 100%; padding: 0; }
  .screen { display: none !important; }
  #certificateScreen { display: block !important; padding: 0; }
  .certificate { color: #190c30; border-color: #8b641d; background: white; box-shadow: none; break-inside: avoid; }
  .certificate h2, .certificate-score, .certificate-crown, .seal { color: #6e4d11; }
  .certificate p, .certificate h3 { color: #190c30; }
}
