@font-face {
  font-family: "ABeeZee";
  src: url("assets/fonts/ABeeZee-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "ABeeZee";
  src: url("assets/fonts/ABeeZee-Italic.ttf") format("truetype");
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}

:root {
  --font: "ABeeZee", "Atkinson Hyperlegible", "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  --bg: #f7fbff;
  --ink: #172033;
  --muted: #536071;
  --panel: #ffffff;
  --panel-2: #fff8dc;
  --line: #243047;
  --button: #243047;
  --button-ink: #ffffff;
  --focus: #ffbf00;
  --success: #167047;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(31, 41, 55, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(36, 48, 71, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(36, 48, 71, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
}

body.dark-mode {
  --bg: #0e1424;
  --ink: #f7f9ff;
  --muted: #c7d0df;
  --panel: #182235;
  --panel-2: #26324b;
  --line: #d7e2ff;
  --button: #f7c948;
  --button-ink: #111827;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.36);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    var(--bg);
}

body.access-mode {
  --bg: #fff5bf;
  --ink: #101828;
  --muted: #263044;
  --panel: #fffdf0;
  --panel-2: #fff0a8;
  --line: #111827;
  font-size: 18px;
  line-height: 1.75;
}

body.access-mode.dark-mode {
  --bg: #101828;
  --ink: #fffbe6;
  --muted: #f2e8ba;
  --panel: #1f2937;
  --panel-2: #333b26;
  --line: #fffbe6;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--button);
  color: var(--button-ink);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.22);
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease, background-color 160ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: saturate(1.08) brightness(1.02);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.22), 0 8px 18px rgba(15, 23, 42, 0.14);
}

button:active {
  transform: translateY(1px);
  box-shadow: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

button.secondary {
  background: var(--panel);
  color: var(--ink);
}

button.success {
  background: #0f7b52;
  color: #ffffff;
}

button.warning {
  background: #f7c948;
  color: #111827;
}

button.danger {
  background: #b42318;
  color: #ffffff;
}

button.ghost {
  background: transparent;
  color: var(--ink);
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--panel);
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 18px;
  background: rgba(247, 251, 255, 0.94);
  border-bottom: 3px solid var(--line);
}

.dark-mode .topbar {
  background: rgba(14, 20, 36, 0.95);
}

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

.brand > div {
  min-width: 0;
}

.crest {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.wrap {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
  gap: 16px;
  align-items: start;
  animation: screenSlide 260ms ease both;
}

.quest-map,
.panel,
.question-panel,
.result-panel {
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: box-shadow 180ms ease, transform 180ms ease, border-color 180ms ease;
}

.quest-map {
  position: relative;
  min-height: 620px;
  overflow: hidden;
  background:
    radial-gradient(circle at 16% 16%, rgba(250, 204, 21, 0.42), transparent 18%),
    radial-gradient(circle at 82% 24%, rgba(236, 72, 153, 0.22), transparent 20%),
    radial-gradient(circle at 78% 78%, rgba(14, 165, 233, 0.3), transparent 22%),
    linear-gradient(180deg, #bfe8ff 0%, #d5f7dc 38%, #f9e4aa 100%);
}

.dark-mode .quest-map {
  background:
    linear-gradient(180deg, #17243c 0%, #183f3a 45%, #4b3c29 100%);
}

.map-title {
  position: absolute;
  left: 16px;
  top: 16px;
  max-width: calc(100% - 32px);
  padding: 12px 14px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
}

.map-title h2 {
  margin: 0;
  font-size: 1.45rem;
}

.map-title p {
  margin: 4px 0 0;
  color: var(--muted);
}

.path-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.path-line path {
  fill: none;
  stroke: rgba(36, 48, 71, 0.6);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 12 14;
}

.dark-mode .path-line path {
  stroke: rgba(255, 255, 255, 0.45);
}

.landmark {
  position: absolute;
  border: 2px solid rgba(36, 48, 71, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

.landmark.one {
  left: 4%;
  bottom: 8%;
  width: 28%;
  height: 19%;
}

.landmark.two {
  right: 5%;
  bottom: 12%;
  width: 22%;
  height: 32%;
}

.landmark.three {
  right: 18%;
  top: 13%;
  width: 20%;
  height: 16%;
}

.realm-pin {
  position: absolute;
  width: 116px;
  min-height: 94px;
  padding: 8px;
  overflow: hidden;
  background: var(--theme-gradient);
  color: var(--ink);
  text-align: center;
  transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
  animation: realmFloat 4.8s ease-in-out infinite;
}

.realm-pin::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.88);
  z-index: 0;
}

.dark-mode .realm-pin::before {
  background: rgba(15, 23, 42, 0.86);
}

.realm-pin > * {
  position: relative;
  z-index: 1;
}

.realm-pin em {
  display: grid;
  width: 34px;
  height: 34px;
  margin: 0 auto 5px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--theme-gradient);
  color: #ffffff;
  font-style: normal;
  font-weight: 900;
  font-size: 1rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.realm-pin strong {
  display: block;
  font-size: 1rem;
  line-height: 1.15;
}

.realm-pin span {
  display: block;
  margin-top: 3px;
  font-size: 1rem;
  color: var(--muted);
}

.realm-pin.done {
  border-color: var(--success);
  box-shadow: 0 0 0 4px rgba(22, 112, 71, 0.18), 0 0 28px rgba(34, 197, 94, 0.35);
}

.realm-pin:hover {
  transform: translateY(-4px) scale(1.03);
  filter: saturate(1.12);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.2);
}

.realm-pin[data-subject="english"] { left: 8%; top: 55%; }
.realm-pin[data-subject="history"] { left: 23%; top: 23%; }
.realm-pin[data-subject="mathematics"] { left: 38%; top: 64%; }
.realm-pin[data-subject="languages"] { left: 54%; top: 30%; }
.realm-pin[data-subject="geography"] { left: 70%; top: 62%; }
.realm-pin[data-subject="science"] { left: 84%; top: 24%; }

.companion {
  display: grid;
  gap: 16px;
}

.avatar-panel {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 14px;
  align-items: center;
  padding: 16px;
}

.avatar-panel img {
  width: 118px;
  height: 118px;
  object-fit: cover;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #eef5ff;
}

.side-avatar {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  margin-bottom: 12px;
}

.panel {
  padding: 16px;
}

.panel h2,
.panel h3,
.question-panel h2,
.result-panel h2 {
  margin: 0 0 8px;
  line-height: 1.2;
}

.panel p,
.question-panel p,
.result-panel p {
  margin: 0 0 10px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  text-align: center;
}

.stat strong {
  display: block;
  font-size: 1.35rem;
}

.daily-card {
  background:
    linear-gradient(var(--panel), var(--panel)) padding-box,
    linear-gradient(135deg, #0f7b52, #f7c948, #38bdf8) border-box;
  border-color: transparent;
}

.daily-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.daily-count {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #f7c948;
  color: #111827;
  font-weight: 900;
  font-size: 1.35rem;
}

.daily-plan {
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.language-mini {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.daily-language {
  max-width: 820px;
  margin: 0 auto;
}

.subject-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.55fr);
  gap: 16px;
}

.topic-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.topic-chip {
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 800;
}

.topic-mastery {
  margin-top: 16px;
}

.mastery-list {
  display: grid;
  gap: 10px;
}

.mastery-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.mastery-item div:first-child {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

.mastery-item strong,
.mastery-item span {
  font-size: 1rem;
}

.mini-track {
  height: 12px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.08);
}

.mini-track span {
  display: block;
  height: 100%;
  min-width: 8px;
  background: #f97316;
}

.mastery-item.building .mini-track span {
  background: #f7c948;
}

.mastery-item.strong .mini-track span {
  background: #38bdf8;
}

.mastery-item.mastered .mini-track span {
  background: #16a34a;
}

.subject-hero,
.intro-screen,
.result-hero {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.subject-hero {
  min-height: 420px;
  background: var(--theme-gradient);
}

.realm-art,
.intro-bg,
.result-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.subject-hero::before,
.intro-screen::before,
.result-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.2)),
    radial-gradient(circle at 80% 20%, rgba(250, 204, 21, 0.32), transparent 25%);
}

.dark-mode .subject-hero::before,
.dark-mode .intro-screen::before,
.dark-mode .result-hero::before {
  background:
    linear-gradient(90deg, rgba(15, 23, 42, 0.94), rgba(15, 23, 42, 0.76), rgba(15, 23, 42, 0.34)),
    radial-gradient(circle at 80% 20%, rgba(56, 189, 248, 0.18), transparent 25%);
}

.realm-hero-copy,
.intro-copy,
.result-copy {
  position: relative;
  z-index: 2;
  max-width: 720px;
  padding: 8px;
}

.intro-screen {
  display: grid;
  min-height: 620px;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 18px;
  align-items: end;
  padding: 28px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--theme-gradient);
  box-shadow: var(--shadow);
}

.portal-in {
  animation: portalIn 420ms ease both;
}

.boss-warning {
  animation: bossWarningIn 480ms ease both;
}

.intro-copy {
  align-self: center;
  padding: 18px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: #172033;
}

.dark-mode .intro-copy {
  background: rgba(24, 34, 53, 0.92);
  color: var(--ink);
}

.intro-copy h2,
.result-copy h2 {
  margin: 8px 0;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1.02;
}

.intro-character,
.result-character {
  position: relative;
  z-index: 2;
  width: min(100%, 340px);
  justify-self: center;
  align-self: end;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  animation: characterRise 520ms ease both;
}

.boss-warning .intro-character {
  animation: bossPulse 1.6s ease-in-out infinite;
}

.intro-small {
  margin-top: 14px;
  font-size: 1rem;
  font-weight: 800;
}

.result-hero {
  display: grid;
  min-height: 460px;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
  gap: 16px;
  align-items: center;
}

.result-copy {
  padding: 18px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.dark-mode .result-copy {
  background: rgba(24, 34, 53, 0.92);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.language-choice {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.language-door {
  padding: 16px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: left;
  color: var(--ink);
}

.progress-track {
  height: 16px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.08);
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #167047, #f7c948, #f28f3b);
  transition: width 420ms ease;
}

.question-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.72fr) minmax(300px, 0.28fr);
  gap: 16px;
}

.question-panel {
  position: relative;
  overflow: hidden;
  padding: 18px;
  background:
    linear-gradient(var(--panel), var(--panel)) padding-box,
    var(--theme-gradient) border-box;
  border-color: transparent;
}

.question-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.pill {
  display: inline-block;
  padding: 6px 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  font-weight: 900;
  font-size: 1rem;
}

.question-text {
  font-size: 1.28rem;
  font-weight: 900;
  margin: 12px 0;
}

.answer-area {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.choice-button {
  width: 100%;
  text-align: left;
  background: var(--panel);
  color: var(--ink);
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

.choice-button:hover {
  transform: translateX(3px);
}

.choice-button.selected,
.grid-button.selected,
.order-item.selected {
  box-shadow: 0 0 0 4px rgba(247, 201, 72, 0.55);
}

.choice-button.correct {
  background: #dff7ea;
  color: #064e3b;
  border-color: #064e3b;
}

.choice-button.wrong {
  background: #ffe4e1;
  color: #7a1f18;
  border-color: #7a1f18;
}

.dark-mode .choice-button.correct {
  background: #164d37;
  color: #e5fff4;
  border-color: #a7f3d0;
}

.dark-mode .choice-button.wrong {
  background: #5a1d1b;
  color: #fff1f0;
  border-color: #fecaca;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.5fr) minmax(160px, 0.5fr);
  gap: 10px;
  align-items: center;
}

.form-row label,
.form-row span {
  font-weight: 900;
}

.order-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.order-item {
  background: var(--panel);
  color: var(--ink);
}

.selected-sequence {
  min-height: 54px;
  padding: 10px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.selected-sequence span {
  display: inline-block;
  margin: 4px;
  padding: 6px 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-weight: 800;
}

.grid-choice {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.grid-button {
  background: var(--panel);
  color: var(--ink);
}

.feedback {
  margin-top: 14px;
  padding: 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 800;
}

.feedback.good {
  border-color: var(--success);
}

.feedback.bad {
  border-color: var(--danger);
}

.answer-spark {
  animation: answerSpark 560ms ease;
}

.mistake-soft-shake {
  animation: mistakeShake 360ms ease;
}

.side-visual {
  display: grid;
  gap: 16px;
}

.visual-box {
  padding: 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.visual-box img {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #eef5ff;
}

.realm-mini img {
  max-height: 190px;
  object-fit: cover;
}

.boss-meter {
  margin-top: 10px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(var(--panel), var(--panel)) padding-box,
    linear-gradient(135deg, #7c3aed, #f97316, #f7c948) border-box;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.16);
}

.boss-topline {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.boss-topline p {
  margin: 0;
}

.boss-topline span,
.boss-cues span {
  display: inline-block;
  padding: 5px 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 900;
}

.boss-cues {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.boss-track {
  height: 18px;
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(180, 35, 24, 0.18);
  margin-top: 10px;
}

.boss-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #b42318, #f97316, #f7c948);
  transition: width 460ms cubic-bezier(.2, .8, .2, 1);
}

.boss-meter.phase-two {
  animation: bossPhaseShift 420ms ease both;
}

.boss-meter.phase-three {
  animation: bossFinalPhase 720ms ease both;
}

.boss-event {
  margin-top: 10px;
  padding: 9px 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  font-weight: 900;
  animation: badgePop 240ms ease both;
}

.boss-event.hit {
  background: #dcfce7;
  color: #064e3b;
}

.boss-event.pressure {
  background: #ffedd5;
  color: #7c2d12;
}

.dark-mode .boss-event.hit {
  background: #164d37;
  color: #e5fff4;
}

.dark-mode .boss-event.pressure {
  background: #5a2d10;
  color: #fff7ed;
}

.boss-brief {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.boss-brief span {
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  font-weight: 900;
}

.calm-boss {
  background: var(--panel);
  box-shadow: none;
}

.diagram {
  width: 100%;
  max-width: 560px;
  margin: 8px auto 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.diagram svg {
  display: block;
  width: 100%;
  height: auto;
}

.dark-mode .diagram {
  background: #f8fafc;
  color: #111827;
}

.result-panel {
  padding: 20px;
}

.mistake-list {
  display: grid;
  gap: 10px;
}

.mistake-item {
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.mistake-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.mistake-topics span {
  padding: 7px 9px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 800;
}

.credits-list {
  display: grid;
  gap: 10px;
}

.credit-item {
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.calm-shell {
  min-height: 100vh;
  display: grid;
  align-content: start;
  gap: 16px;
  width: min(900px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 34px;
}

.calm-home {
  justify-self: start;
}

.calm-shell .question-panel {
  box-shadow: none;
  background: var(--panel);
  border-color: var(--line);
  overflow: visible;
}

.popup-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.24);
}

.quest-popup {
  width: min(520px, 100%);
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.28);
  animation: badgePop 360ms ease both;
}

.quest-popup img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.quest-popup h2 {
  margin: 0 0 4px;
  font-size: 1.28rem;
}

.quest-popup p {
  margin: 0 0 10px;
}

.quest-popup.badge,
.quest-popup.complete {
  background: linear-gradient(135deg, #fff7cc, #dcfce7);
  color: #172033;
}

.quest-popup.boss {
  background: linear-gradient(135deg, #fef3c7, #ede9fe);
  color: #172033;
}

.question-feedback-overlay {
  position: absolute;
  inset: 10px;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(2px);
}

.avatar-speech {
  width: min(820px, 100%);
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.3);
  animation: badgePop 300ms ease both;
}

.avatar-speech img {
  width: 150px;
  height: 150px;
  object-fit: cover;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.speech-bubble {
  position: relative;
  padding: 16px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.speech-bubble::before {
  content: "";
  position: absolute;
  left: -17px;
  top: 44px;
  width: 24px;
  height: 24px;
  transform: rotate(45deg);
  border-left: 3px solid var(--line);
  border-bottom: 3px solid var(--line);
  background: var(--panel-2);
}

.speech-bubble h2 {
  margin: 0 0 6px;
  font-size: 1.45rem;
}

.speech-bubble p {
  margin: 0 0 10px;
}

.avatar-speech.spark,
.avatar-speech.badge,
.avatar-speech.complete {
  border-color: #16a34a;
}

.avatar-speech.mistake {
  border-color: #f97316;
}

.avatar-speech.boss {
  border-color: #7c3aed;
}

.access-mode button {
  min-height: 52px;
  padding: 12px 16px;
}

.access-mode .question-text {
  font-size: 1.45rem;
}

.access-mode .panel,
.access-mode .question-panel,
.access-mode .result-panel,
.access-mode .visual-box {
  border-width: 4px;
}

.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;
}

.empty-note {
  padding: 14px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 800;
}

@keyframes realmFloat {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -5px; }
}

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

@keyframes portalIn {
  from { opacity: 0; transform: translateY(14px); filter: saturate(0.85); }
  to { opacity: 1; transform: translateY(0); filter: saturate(1); }
}

@keyframes bossWarningIn {
  from { opacity: 0; transform: scale(0.985); filter: saturate(0.8); }
  to { opacity: 1; transform: scale(1); filter: saturate(1.08); }
}

@keyframes characterRise {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bossPulse {
  0%, 100% { transform: translateY(0) scale(1); filter: saturate(1); }
  50% { transform: translateY(-4px) scale(1.02); filter: saturate(1.18); }
}

@keyframes bossPhaseShift {
  0% { box-shadow: var(--shadow); filter: saturate(1); }
  45% { box-shadow: 0 0 0 7px rgba(249, 115, 22, 0.25), var(--shadow); filter: saturate(1.16); }
  100% { box-shadow: var(--shadow); filter: saturate(1); }
}

@keyframes bossFinalPhase {
  0%, 100% { box-shadow: var(--shadow); }
  45% { box-shadow: 0 0 0 8px rgba(180, 35, 24, 0.24), 0 0 32px rgba(249, 115, 22, 0.28); }
}

@keyframes answerSpark {
  0% { box-shadow: 0 0 0 rgba(250, 204, 21, 0); }
  45% { box-shadow: 0 0 0 8px rgba(250, 204, 21, 0.45), 0 0 32px rgba(34, 197, 94, 0.35); }
  100% { box-shadow: var(--shadow); }
}

@keyframes mistakeShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes badgePop {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.access-mode .realm-pin,
.access-mode .portal-in,
.access-mode .boss-warning,
.access-mode .intro-character,
.access-mode .boss-warning .intro-character,
.access-mode .answer-spark,
.access-mode .mistake-soft-shake,
.access-mode .quest-popup,
.access-mode .avatar-speech,
.access-mode .boss-meter,
.access-mode .boss-event {
  animation: none;
}

@media (max-width: 920px) {
  .topbar,
  .map-layout,
  .subject-layout,
  .question-layout {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .quest-map {
    min-height: 760px;
  }

  .realm-pin {
    width: 132px;
  }

  .realm-pin[data-subject="english"] { left: 7%; top: 19%; }
  .realm-pin[data-subject="history"] { left: 52%; top: 22%; }
  .realm-pin[data-subject="mathematics"] { left: 15%; top: 42%; }
  .realm-pin[data-subject="languages"] { left: 58%; top: 45%; }
  .realm-pin[data-subject="geography"] { left: 10%; top: 67%; }
  .realm-pin[data-subject="science"] { left: 57%; top: 70%; }

  .intro-screen,
  .result-hero {
    grid-template-columns: 1fr;
  }

  .intro-character,
  .result-character {
    max-height: 320px;
    object-fit: cover;
  }

  .avatar-speech {
    grid-template-columns: 120px minmax(0, 1fr);
  }

  .avatar-speech img {
    width: 120px;
    height: 120px;
  }
}

@media (max-width: 620px) {
  .wrap {
    width: min(100% - 18px, 1180px);
  }

  .brand {
    align-items: flex-start;
  }

  .brand > div {
    width: min(280px, calc(100vw - 104px));
  }

  .brand p {
    white-space: normal;
  }

  .crest {
    width: 42px;
    height: 42px;
  }

  .brand h1 {
    font-size: 1.08rem;
  }

  .quest-map {
    min-height: 860px;
  }

  .realm-pin {
    left: 50% !important;
    transform: translateX(-50%);
    width: min(260px, calc(100% - 32px));
  }

  .realm-pin[data-subject="english"] { top: 120px; }
  .realm-pin[data-subject="history"] { top: 240px; }
  .realm-pin[data-subject="mathematics"] { top: 360px; }
  .realm-pin[data-subject="languages"] { top: 480px; }
  .realm-pin[data-subject="geography"] { top: 600px; }
  .realm-pin[data-subject="science"] { top: 720px; }

  .form-row {
    grid-template-columns: 1fr;
  }

  .grid-choice {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .daily-head,
  .language-mini,
  .boss-brief {
    grid-template-columns: 1fr;
  }

  .daily-count {
    width: 100%;
  }

  .question-feedback-overlay {
    inset: 6px;
    padding: 8px;
  }

  .avatar-speech,
  .quest-popup {
    grid-template-columns: 1fr;
  }

  .avatar-speech img,
  .quest-popup img {
    width: 118px;
    height: 118px;
    justify-self: center;
  }

  .speech-bubble::before {
    display: none;
  }
}
