/* Pixel Earth Lab v0.5.0 — white/pop story UI with expressive pixel motion. */
:root {
  color-scheme: light;
  --ink: #173452;
  --ink-strong: #102d49;
  --muted: #5f7690;
  --paper: #ffffff;
  --cream: #fff8ed;
  --cream-2: #fffdf8;
  --line: #d7e5ef;
  --line-strong: #9fc5df;
  --blue: #4da3ff;
  --blue-soft: #eaf5ff;
  --blue-dark: #196fc6;
  --yellow: #ffd75e;
  --yellow-soft: #fff5c9;
  --yellow-dark: #ba7100;
  --mint: #70ddb9;
  --mint-soft: #e6fbf4;
  --mint-dark: #137b60;
  --coral: #ff8279;
  --coral-soft: #fff0ed;
  --coral-dark: #b63d37;
  --violet: #9a85ff;
  --violet-soft: #f0edff;
  --orange: #ff9f50;
  --orange-soft: #fff1df;
  --shadow-xs: 0 3px 0 rgb(31 74 111 / 10%);
  --shadow-sm: 0 7px 0 rgb(31 74 111 / 10%), 0 16px 30px rgb(39 91 128 / 8%);
  --shadow-md: 0 10px 0 rgb(31 74 111 / 13%), 0 24px 46px rgb(39 91 128 / 12%);
  --radius-sm: 14px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --ease-pop: cubic-bezier(.2, 1.25, .34, 1);
  --ease-smooth: cubic-bezier(.2, .75, .25, 1);
  --mission: var(--blue);
  --mission-soft: var(--blue-soft);
  --focus: #0d68c6;
}

* { box-sizing: border-box; }

html {
  min-width: 300px;
  background: var(--cream);
  scroll-behavior: smooth;
  scroll-padding-top: 92px;
}

body {
  min-width: 300px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 5%, rgb(255 215 94 / 34%) 0 80px, transparent 81px),
    radial-gradient(circle at 95% 11%, rgb(77 163 255 / 15%) 0 120px, transparent 121px),
    linear-gradient(180deg, #fffdf8 0%, #fff8ed 55%, #f8fbff 100%);
  font-family:
    ui-rounded, "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI",
    "Yu Gothic", system-ui, sans-serif;
  font-weight: 650;
  line-height: 1.55;
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button, input, output { font: inherit; }
button { color: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }
button:not(:disabled) { cursor: pointer; }
button:disabled { cursor: not-allowed; }

button:focus-visible,
input:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

button {
  border: 0;
}

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

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 500;
  top: 8px;
  left: 8px;
  padding: 12px 18px;
  border: 3px solid var(--ink-strong);
  border-radius: 14px;
  color: var(--ink-strong);
  background: var(--yellow);
  box-shadow: 0 5px 0 var(--ink-strong);
  font-weight: 900;
  transform: translateY(-150%);
  transition: transform 160ms ease;
}
.skip-link:focus { transform: translateY(0); outline: 4px solid var(--focus); outline-offset: 3px; }

/* Background decoration --------------------------------------------------- */
.background-toys {
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.toy {
  position: absolute;
  display: block;
  animation: toy-float 7s ease-in-out infinite alternate;
}
.toy-star { left: 3%; top: 18%; color: rgb(255 215 94 / 32%); font-size: 42px; }
.toy-ring {
  right: 4%; top: 35%; width: 74px; height: 74px;
  border: 12px solid rgb(112 221 185 / 18%); border-radius: 50%; animation-delay: -1s;
}
.toy-diamond { left: 9%; bottom: 5%; color: rgb(255 130 121 / 18%); font-size: 46px; animation-delay: -5s; }
.toy-dot { right: 15%; top: 2%; color: rgb(255 215 94 / 30%); font-size: 28px; animation-delay: -3s; }

/* Main frame -------------------------------------------------------------- */
.app-shell {
  width: min(1800px, 100%);
  margin: 0 auto;
  padding: 14px clamp(10px, 1.7vw, 28px) 30px;
}
body[data-app-ready="true"] .app-shell { animation: app-rise 520ms var(--ease-smooth); }
.topbar-slot { display: contents; }

.topbar {
  position: sticky;
  z-index: 80;
  top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 86px;
  margin-bottom: 18px;
  padding: 12px 14px 12px 16px;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgb(255 255 255 / 96%);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(16px) saturate(1.1);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}
.brand-mark {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 13px);
  grid-template-rows: repeat(2, 13px);
  gap: 3px;
  padding: 9px;
  border: 3px solid var(--ink-strong);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 5px 0 var(--ink-strong);
  transform: rotate(-3deg);
}
.brand-mark::after {
  position: absolute;
  right: -7px;
  bottom: -7px;
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border: 2px solid var(--ink-strong);
  border-radius: 50%;
  color: var(--ink-strong);
  background: var(--yellow);
  content: "★";
  font-size: 12px;
  line-height: 1;
}
.brand-mark span { border-radius: 4px; background: var(--blue); }
.brand-mark span:nth-child(2), .brand-mark span:nth-child(5) { background: var(--yellow); }
.brand-mark span:nth-child(3), .brand-mark span:nth-child(4) { background: var(--mint); }
.brand-mark span:nth-child(6) { background: var(--coral); }
.brand-copy { min-width: 0; }
.eyebrow {
  margin: 0 0 2px;
  color: var(--blue-dark);
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: .16em;
  line-height: 1.2;
  text-transform: uppercase;
}
.brand h1 {
  margin: 0;
  color: var(--ink-strong);
  font-size: clamp(22px, 2vw, 31px);
  font-weight: 1000;
  line-height: 1.08;
  white-space: nowrap;
}
.brand-subtitle { margin: 3px 0 0; color: var(--muted); font-size: 12px; font-weight: 800; }
.brand-tag {
  flex: 0 0 auto;
  margin-left: 4px;
  padding: 7px 11px;
  border: 2px dashed var(--coral);
  border-radius: 14px;
  color: var(--coral-dark);
  background: var(--coral-soft);
  font-size: 10px;
  font-weight: 1000;
  line-height: 1.05;
  text-align: center;
  transform: rotate(3deg);
}

.top-actions {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 7px;
  min-width: 0;
}
.primary-action,
.icon-button,
.notebook-button,
.inspect-button,
.wide-action,
.secondary-action,
.hint-button,
.choice-button,
.material-button,
.mission-card,
.modal-close,
.danger-link {
  min-height: 44px;
  border: 2px solid var(--line);
  border-radius: 15px;
  background: #fff;
  box-shadow: var(--shadow-xs);
  transition:
    transform 150ms var(--ease-pop),
    box-shadow 150ms ease,
    border-color 150ms ease;
}
.primary-action:not(:disabled):hover,
.icon-button:not(:disabled):hover,
.notebook-button:not(:disabled):hover,
.inspect-button:not(:disabled):hover,
.wide-action:not(:disabled):hover,
.secondary-action:not(:disabled):hover,
.hint-button:not(:disabled):hover,
.choice-button:not(:disabled):hover,
.material-button:not(:disabled):hover,
.mission-card:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 0 rgb(31 74 111 / 15%);
}
button:not(:disabled):active { transform: translateY(1px) scale(.985); box-shadow: 0 1px 0 rgb(31 74 111 / 12%); }
button:disabled { color: #9aabba; background: #f1f6f9; border-color: #dce7ed; box-shadow: none; opacity: .82; }

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 126px;
  padding: 8px 14px;
  color: var(--ink-strong);
  background: var(--mint-soft);
  border-color: #9be8d0;
  font-size: 14px;
  font-weight: 1000;
}
.primary-action > span:first-child {
  display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: 50%; color: #fff; background: var(--ink); font-size: 13px;
}
body[data-running="true"] .primary-action { color: #fff; background: var(--mint-dark); border-color: var(--mint-dark); }
body[data-running="true"] .primary-action > span:first-child { color: var(--mint-dark); background: #fff; }

.icon-button {
  display: grid;
  place-items: center;
  grid-template-rows: 23px auto;
  min-width: 58px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 900;
}
.icon-button > span:first-child { font-size: 17px; line-height: 1; }
.button-label { font-size: 9px; white-space: nowrap; }

.notebook-button {
  display: grid;
  grid-template-columns: 27px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-width: 154px;
  padding: 6px 9px;
  color: var(--ink-strong);
  background: var(--yellow-soft);
  border-color: #f4bd20;
  font-size: 13px;
  font-weight: 1000;
}
.notebook-button > span:nth-child(2) { white-space: nowrap; }
.notebook-icon {
  display: grid; place-items: center; width: 27px; height: 31px;
  border: 2px solid var(--ink-strong); border-radius: 8px; background: #fff; transform: rotate(-4deg);
}
.notebook-button strong {
  min-width: 34px;
  padding: 4px 7px;
  border-radius: 999px;
  color: #fff;
  background: var(--ink-strong);
  font-size: 10px;
  text-align: center;
}

/* Workspace --------------------------------------------------------------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(220px, .78fr) minmax(520px, 2.1fr) minmax(290px, .95fr);
  grid-template-areas:
    "missions lab predict"
    "missions lab learn";
  align-items: start;
  gap: 18px;
}
.mission-rail { grid-area: missions; position: sticky; top: 112px; display: grid; gap: 12px; min-width: 0; }
.lab-column { grid-area: lab; display: grid; gap: 18px; min-width: 0; }
.prediction-rail { grid-area: predict; min-width: 0; }
.learning-rail { grid-area: learn; display: grid; gap: 14px; min-width: 0; }

.rail-heading,
.mission-heading,
.material-deck,
.learning-card,
.model-card,
.method-card,
.footer-note {
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  background: rgb(255 255 255 / 96%);
  box-shadow: var(--shadow-sm);
}
.rail-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 14px 15px;
}
.rail-heading h2 { margin: 0; color: var(--ink-strong); font-size: 20px; font-weight: 1000; line-height: 1.12; }
.rail-helper { margin: 3px 0 0; color: var(--muted); font-size: 10px; font-weight: 800; }
.mastery-pill {
  display: grid; place-items: center; width: 58px; height: 58px;
  border: 3px solid var(--mint-dark); border-radius: 50%;
  color: var(--mint-dark); background: var(--mint-soft);
  box-shadow: 0 5px 0 rgb(19 123 96 / 20%); font-size: 14px; font-weight: 1000;
}
.mission-list { display: grid; gap: 10px; min-width: 0; }
.mission-card {
  --card: var(--blue);
  --card-soft: var(--blue-soft);
  position: relative;
  display: grid;
  grid-template-columns: 43px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 76px;
  padding: 9px 10px;
  overflow: hidden;
  border-color: var(--line);
  border-left: 7px solid var(--card);
  text-align: left;
}
.mission-card::after {
  position: absolute; right: -20px; bottom: -26px; width: 64px; height: 64px;
  border-radius: 50%; background: var(--card-soft); content: ""; z-index: 0;
}
.mission-card[aria-current="true"] {
  border-color: var(--card);
  background: var(--card-soft);
  box-shadow: 0 7px 0 color-mix(in srgb, var(--card) 30%, transparent), 0 16px 30px rgb(39 91 128 / 9%);
  transform: translateY(-1px);
}
.mission-card[data-complete="true"] .mission-state { color: #fff; background: var(--mint-dark); border-color: var(--mint-dark); }
.mission-card-number,
.mission-card-icon,
.mission-state,
.mission-card-copy { position: relative; z-index: 1; }
.mission-card-number {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 2px solid var(--card); border-radius: 13px; color: var(--ink-strong); background: #fff;
  font-size: 12px; font-weight: 1000;
}
.mission-card-copy { display: grid; min-width: 0; }
.mission-card-copy strong { color: var(--ink-strong); font-size: 13px; font-weight: 1000; line-height: 1.18; }
.mission-card-copy small { overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.mission-card-icon {
  display: grid; place-items: center; width: 36px; height: 36px;
  border-radius: 12px; background: var(--card-soft); font-size: 21px;
}
.mission-state {
  position: absolute; top: 7px; right: 7px;
  display: grid; place-items: center; width: 20px; height: 20px;
  border: 2px solid var(--line-strong); border-radius: 50%; color: var(--card); background: #fff;
  font-size: 10px; font-weight: 1000;
}

.method-card { padding: 14px; overflow: hidden; }
.method-card h3 { margin: 0 0 10px; color: var(--ink-strong); font-size: 16px; font-weight: 1000; }
.method-card ol { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.method-card li {
  display: grid; grid-template-columns: 30px 48px minmax(0, 1fr); align-items: center; gap: 7px;
  padding: 6px 8px; border-radius: 11px; background: var(--blue-soft); font-size: 10px;
}
.method-card li:nth-child(2) { background: var(--yellow-soft); }
.method-card li:nth-child(3) { background: var(--mint-soft); }
.method-card li:nth-child(4) { background: var(--coral-soft); }
.method-card li:nth-child(5) { background: var(--violet-soft); }
.method-card li > span { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 9px; color: #fff; background: var(--ink-strong); font-weight: 1000; }
.method-card li strong { color: var(--ink-strong); font-weight: 1000; }
.method-card li small { color: var(--muted); font-size: 9px; }

/* Mission and stage ------------------------------------------------------- */
.mission-heading {
  position: relative;
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr) 86px;
  align-items: center;
  gap: 14px;
  min-height: 132px;
  padding: 18px 20px;
  overflow: hidden;
  border-color: color-mix(in srgb, var(--mission) 52%, var(--line));
  background:
    radial-gradient(circle at 100% 100%, color-mix(in srgb, var(--mission-soft) 88%, transparent) 0 110px, transparent 111px),
    #fff;
}
.mission-heading::before,
.mission-heading::after {
  position: absolute; color: color-mix(in srgb, var(--mission) 28%, transparent); content: "✦";
}
.mission-heading::before { right: 118px; top: 18px; font-size: 30px; }
.mission-heading::after { right: 145px; top: 57px; font-size: 17px; }
.mission-icon {
  position: relative; z-index: 1; display: grid; place-items: center;
  width: 64px; height: 64px; border: 3px solid var(--ink-strong); border-radius: 22px;
  background: var(--mission-soft); box-shadow: 0 6px 0 var(--ink-strong); font-size: 33px;
}
.mission-copy { min-width: 0; }
.mission-kicker-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 3px; }
.mission-kicker,
.phase-chip {
  display: inline-flex; align-items: center; min-height: 25px; padding: 3px 9px;
  border: 2px solid var(--mission); border-radius: 999px; color: var(--blue-dark); background: #fff;
  font-size: 10px; font-weight: 1000;
}
.phase-chip { color: var(--ink-strong); background: var(--yellow-soft); border-color: #e8b220; }
.phase-chip[data-phase="experiment"] { background: var(--mint-soft); border-color: var(--mint-dark); color: var(--mint-dark); }
.phase-chip[data-phase="explain"], .phase-chip[data-phase="complete"] { background: var(--violet-soft); border-color: var(--violet); color: #5944bb; }
.mission-heading h2 { margin: 0; color: var(--ink-strong); font-size: clamp(29px, 3.1vw, 46px); font-weight: 1000; line-height: 1.04; letter-spacing: -.04em; }
.mission-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; font-weight: 800; }
.mission-score {
  position: relative; z-index: 1; display: grid; place-items: center; align-content: center;
  width: 82px; height: 82px; border: 3px solid color-mix(in srgb, var(--mission) 65%, #fff);
  border-radius: 50%; background: #fff; box-shadow: 0 7px 0 color-mix(in srgb, var(--mission) 22%, transparent);
}
.mission-score::before {
  position: absolute; inset: 5px; border-radius: 50%;
  background: conic-gradient(var(--mission) var(--progress, 0%), #eaf0f5 0); content: "";
}
.mission-score::after { position: absolute; inset: 11px; border-radius: 50%; background: #fff; content: ""; }
.mission-score > span:not(.progress-orbit), .mission-score strong { position: relative; z-index: 2; }
.mission-score > span:not(.progress-orbit) { color: var(--muted); font-size: 8px; font-weight: 900; }
.mission-score strong { color: var(--ink-strong); font-size: 18px; font-weight: 1000; }
.progress-orbit {
  position: absolute; z-index: 3; right: -4px; top: -8px; display: grid; place-items: center;
  width: 25px; height: 25px; border: 2px solid var(--ink-strong); border-radius: 50%;
  color: var(--ink-strong); background: var(--yellow); font-size: 11px;
}

.safety-banner {
  display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: center; gap: 10px;
  padding: 9px 13px; border: 2px solid var(--coral); border-radius: 16px; color: var(--coral-dark); background: var(--coral-soft); box-shadow: var(--shadow-xs);
}
.safety-banner[hidden] { display: none; }
.safety-banner span { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: #fff; background: var(--coral-dark); font-weight: 1000; }
.safety-banner p { margin: 0; font-size: 11px; font-weight: 900; }

.stage-frame {
  position: relative;
  width: calc(100% - 24px);
  margin: 4px auto 8px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 22px;
  background: #091827;
  box-shadow:
    0 0 0 5px #fff,
    0 0 0 9px var(--ink-strong),
    0 10px 0 rgb(19 45 72 / 15%),
    0 23px 42px rgb(19 45 72 / 20%);
  isolation: isolate;
  transition: box-shadow 220ms ease, transform 220ms var(--ease-pop);
}
.stage-frame[data-running="true"] {
  box-shadow:
    0 0 0 5px #fff,
    0 0 0 9px var(--mint-dark),
    0 10px 0 rgb(23 120 95 / 16%),
    0 23px 42px rgb(23 120 95 / 20%);
}
.stage-frame:focus-visible { outline-offset: 12px; }
#world-canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}
.fx-canvas,
.effects-canvas {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: auto;
}
.stage-grid { position: absolute; z-index: 4; inset: 0; pointer-events: none; background-image: linear-gradient(rgb(255 255 255 / 3%) 1px, transparent 1px), linear-gradient(90deg, rgb(255 255 255 / 3%) 1px, transparent 1px); background-size: 16px 16px; }
.stage-label,
.pause-badge,
.changed-badge,
.stage-corner,
.pointer-inspector {
  position: absolute; z-index: 8; border: 1px solid rgb(255 255 255 / 55%); color: #fff; background: rgb(8 24 39 / 84%); backdrop-filter: blur(6px);
}
.stage-label { left: 14px; top: 13px; padding: 5px 10px; border-radius: 999px; font-size: 9px; font-weight: 1000; letter-spacing: .04em; }
.pause-badge { left: 50%; top: 13px; min-width: 120px; padding: 5px 11px; border-radius: 999px; font-size: 9px; font-weight: 1000; text-align: center; transform: translateX(-50%); }
.pause-badge[data-running="true"] { color: #dffcf4; border-color: var(--mint); animation: running-pulse 1.45s ease-in-out infinite; }
.changed-badge { right: 13px; top: 13px; padding: 5px 10px; border-radius: 999px; color: #dffcf4; border-color: var(--mint); font-size: 9px; font-weight: 1000; }
.stage-corner { bottom: 10px; padding: 3px 7px; border: 0; color: #b9cddd; background: rgb(8 24 39 / 72%); font-size: 8px; font-weight: 800; }
.stage-corner-left { left: 11px; }
.stage-corner-right { right: 11px; }
.pointer-inspector { max-width: 190px; padding: 5px 8px; border-radius: 9px; pointer-events: none; font-size: 9px; }
.pointer-inspector[hidden], .changed-badge[hidden] { display: none; }
.keyboard-cursor { position: absolute; z-index: 7; width: 12px; height: 12px; border: 2px solid var(--yellow); border-radius: 3px; box-shadow: 0 0 0 1px var(--ink-strong); transform: translate(-50%, -50%); opacity: 0; pointer-events: none; }
.stage-frame[data-keyboard="true"] .keyboard-cursor { opacity: 1; }
.guide-layer { position: absolute; z-index: 6; inset: 0; pointer-events: none; }
.guide-region { position: absolute; border: 2px dashed var(--yellow); border-radius: 8px; background: rgb(255 215 94 / 12%); animation: guide-breathe 1.6s ease-in-out infinite; }
.guide-region[data-kind="target"] { border-color: #56ead0; background: rgb(86 234 208 / 12%); }
.guide-region span { position: absolute; left: 50%; bottom: calc(100% + 4px); padding: 3px 6px; border-radius: 7px; color: #fff; background: rgb(8 24 39 / 88%); font-size: 7px; font-weight: 900; white-space: nowrap; transform: translateX(-50%); }

/* Material deck ----------------------------------------------------------- */
.material-deck { overflow: hidden; padding: 17px 18px 16px; border-color: color-mix(in srgb, var(--mission) 42%, var(--line)); background: linear-gradient(145deg, #fff, var(--mission-soft)); }
.deck-header { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.deck-header h3 { margin: 0; color: var(--ink-strong); font-size: 23px; font-weight: 1000; line-height: 1.1; }
.section-help { margin: 3px 0 0; color: var(--muted); font-size: 10px; font-weight: 800; }
.inspect-button { min-width: 100px; padding: 8px 12px; color: var(--blue-dark); font-size: 12px; font-weight: 1000; }
.inspect-button[aria-pressed="true"] { color: #fff; background: var(--blue-dark); border-color: var(--blue-dark); }
.material-palette { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 10px; }
.material-button {
  position: relative; display: grid; place-items: center; gap: 2px; min-height: 82px; padding: 7px 5px;
  color: var(--muted); font-size: 10px; font-weight: 1000;
}
.material-button[aria-pressed="true"] { color: var(--ink-strong); border-color: var(--blue-dark); background: var(--blue-soft); box-shadow: 0 6px 0 rgb(25 111 198 / 32%); transform: translateY(-2px); }
.material-key { position: absolute; right: 6px; top: 5px; display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: #fff; font-size: 8px; }
.material-swatch { display: grid; place-items: center; width: 40px; height: 40px; border: 3px solid rgb(16 45 73 / 45%); border-radius: 14px; background: var(--material-color); box-shadow: inset 0 0 0 4px rgb(255 255 255 / 34%); color: rgb(16 45 73 / 62%); font-size: 13px; }
.brush-row { display: grid; grid-template-columns: auto minmax(80px, 1fr) 42px; align-items: center; gap: 11px; margin-top: 12px; padding-top: 12px; border-top: 2px dashed color-mix(in srgb, var(--mission) 45%, var(--line)); }
.brush-row label { font-size: 11px; font-weight: 1000; }
.brush-row input { width: 100%; min-height: 44px; height: 44px; margin: 0; accent-color: var(--mission); touch-action: manipulation; cursor: pointer; }
.brush-row input[type="range"] { appearance: none; -webkit-appearance: none; background: transparent; padding: 0; }
.brush-row input[type="range"]::-webkit-slider-runnable-track { height: 10px; border: 2px solid color-mix(in srgb, var(--mission) 55%, #ffffff); border-radius: 999px; background: linear-gradient(90deg, color-mix(in srgb, var(--mission) 22%, #ffffff), #ffffff); box-shadow: inset 0 1px 2px rgba(25, 50, 94, 0.12); }
.brush-row input[type="range"]::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 28px; height: 28px; margin-top: -11px; border: 3px solid #ffffff; border-radius: 50%; background: var(--mission); box-shadow: 0 3px 0 color-mix(in srgb, var(--mission) 70%, #17335f), 0 5px 12px rgba(25, 50, 94, 0.24); }
.brush-row input[type="range"]::-moz-range-track { height: 8px; border: 2px solid color-mix(in srgb, var(--mission) 55%, #ffffff); border-radius: 999px; background: linear-gradient(90deg, color-mix(in srgb, var(--mission) 22%, #ffffff), #ffffff); box-shadow: inset 0 1px 2px rgba(25, 50, 94, 0.12); }
.brush-row input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; border: 3px solid #ffffff; border-radius: 50%; background: var(--mission); box-shadow: 0 3px 0 color-mix(in srgb, var(--mission) 70%, #17335f), 0 5px 12px rgba(25, 50, 94, 0.24); }
.brush-row input[type="range"]:disabled { cursor: not-allowed; opacity: 0.58; }
.brush-row output { display: grid; place-items: center; width: 40px; height: 40px; border: 2px solid var(--mission); border-radius: 12px; color: var(--blue-dark); background: #fff; font-weight: 1000; }
.material-help { grid-column: 1 / -1; color: var(--muted); font-size: 9px; font-weight: 750; }

/* Learning cards ---------------------------------------------------------- */
.learning-card, .model-card { padding: 16px; overflow: hidden; }
.prediction-card { border-color: #efb300; background: radial-gradient(circle at 100% 0, rgb(255 215 94 / 36%) 0 70px, transparent 71px), #fffdf5; }
.experiment-card { border-color: #7dbaf8; background: #f8fcff; }
.observation-card { border-color: #73d9bb; background: #f8fffc; }
.card-step { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--ink-strong); font-size: 11px; font-weight: 1000; }
.card-step span { display: grid; place-items: center; width: 31px; height: 31px; border: 2px solid var(--ink-strong); border-radius: 11px; color: var(--ink-strong); background: var(--yellow); font-size: 12px; }
.experiment-card .card-step span { background: var(--blue-soft); }
.observation-card .card-step span { background: var(--mint-soft); }
.learning-card h2 { margin: 0 0 10px; color: var(--ink-strong); font-size: 18px; font-weight: 1000; line-height: 1.35; }
.choice-list { display: grid; gap: 8px; }
.choice-button { position: relative; width: 100%; padding: 11px 14px 11px 45px; color: var(--ink); text-align: left; font-size: 12px; font-weight: 900; }
.choice-button::before { position: absolute; left: 12px; top: 50%; width: 24px; height: 24px; border: 2px solid var(--line-strong); border-radius: 50%; background: #fff; content: ""; transform: translateY(-50%); }
.choice-button[aria-pressed="true"] { border-color: var(--blue); background: var(--blue-soft); box-shadow: 0 5px 0 rgb(77 163 255 / 32%); }
.choice-button[aria-pressed="true"]::before { border: 7px solid var(--blue-dark); }
.choice-button[data-result="correct"] { border-color: var(--mint-dark); background: var(--mint-soft); }
.choice-button[data-result="incorrect"] { border-color: var(--coral); background: var(--coral-soft); }
.feedback { margin-top: 9px; padding: 9px 11px; border: 2px solid #e4c253; border-radius: 12px; color: #725000; background: var(--yellow-soft); font-size: 10px; font-weight: 850; }
.feedback[hidden] { display: none; }
.feedback[data-result="correct"] { color: var(--mint-dark); border-color: var(--mint); background: var(--mint-soft); }
.feedback[data-result="incorrect"] { color: var(--coral-dark); border-color: var(--coral); background: var(--coral-soft); }
.wide-action { width: 100%; margin-top: 12px; padding: 10px 16px; color: var(--ink-strong); border-color: #e0ad10; background: var(--yellow); box-shadow: 0 6px 0 var(--ink-strong); font-size: 12px; font-weight: 1000; }
.wide-action:not(:disabled):hover { box-shadow: 0 8px 0 var(--ink-strong); }
.learning-goal { margin: 0 0 9px; color: var(--ink); font-size: 11px; font-weight: 850; }
.progress-track { height: 13px; margin: 9px 0; overflow: hidden; border: 2px solid #b5d5ed; border-radius: 999px; background: #fff; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--mint)); transition: width 320ms var(--ease-smooth); }
.mission-metric { display: block; margin: 5px 0; color: var(--ink-strong); font-size: 12px; font-weight: 1000; }
.mission-hint, .scaffold-hint { margin: 7px 0; color: var(--muted); font-size: 10px; font-weight: 800; }
.scaffold-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.hint-button { padding: 8px 11px; color: var(--blue-dark); font-size: 10px; font-weight: 1000; }
#hint-level { color: var(--muted); font-size: 9px; }
.observation-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.observation-heading h2 { margin: 0; }
#world-tick { padding: 4px 7px; border-radius: 999px; color: var(--mint-dark); background: var(--mint-soft); font-size: 9px; font-weight: 1000; }
.observation-log { display: grid; gap: 7px; max-height: 300px; margin: 10px 0 0; padding: 0; overflow: auto; list-style: none; }
.observation-log li { position: relative; padding: 9px 10px 9px 34px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); font-size: 10px; font-weight: 800; }
.observation-log li::before { position: absolute; left: 10px; top: 10px; display: grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; color: #fff; background: var(--mint-dark); content: "✓"; font-size: 8px; }
.observation-log .empty-observation { color: var(--muted); background: #f4f8fa; }
.observation-log .empty-observation::before { content: "?"; background: #a8bac8; }
.model-card { background: linear-gradient(145deg, #fff, var(--violet-soft)); }
.model-card strong { color: var(--ink-strong); font-size: 12px; font-weight: 1000; }
.model-card p, .model-card li { color: var(--muted); font-size: 9px; font-weight: 750; }
.model-card p { margin: 6px 0; }
.model-card details { border-top: 1px dashed #cfc5ff; padding-top: 7px; }
.model-card summary { color: #5944bb; cursor: pointer; font-size: 10px; font-weight: 1000; }
.model-card ul { margin: 7px 0 0; padding-left: 18px; }

.footer-note { display: flex; justify-content: space-between; gap: 16px; margin-top: 18px; padding: 12px 15px; }
.footer-note p { margin: 0; color: var(--muted); font-size: 9px; font-weight: 750; }
.footer-note strong { color: var(--ink-strong); }
#offline-status { color: var(--mint-dark); font-weight: 1000; }

/* Dialogs ----------------------------------------------------------------- */
.modal { width: min(670px, calc(100vw - 22px)); max-height: calc(100dvh - 22px); padding: 0; border: 0; background: transparent; overflow: visible; }
.modal::backdrop { background: rgb(14 38 60 / 50%); backdrop-filter: blur(7px); }
.modal-shell {
  position: relative; max-height: calc(100dvh - 22px); padding: 25px 24px 24px;
  overflow-y: auto; border: 3px solid var(--ink-strong); border-radius: 30px;
  background: #fff; box-shadow: 0 12px 0 var(--ink-strong), 0 30px 70px rgb(10 33 53 / 28%);
  animation: dialog-in 300ms var(--ease-pop) both;
}
.modal-close { position: absolute; z-index: 10; right: 15px; top: 15px; display: grid; place-items: center; width: 45px; height: 45px; border-color: var(--ink-strong); color: var(--ink-strong); background: #fff; box-shadow: 0 4px 0 var(--ink-strong); font-size: 24px; font-weight: 1000; }
.modal h2 { margin: 8px 52px 12px; color: var(--ink-strong); font-size: 30px; font-weight: 1000; text-align: center; }
.success-medal, .notebook-cover { display: grid; place-items: center; width: 78px; height: 78px; margin: 0 auto; border: 3px solid var(--ink-strong); border-radius: 25px; color: var(--ink-strong); background: var(--yellow); box-shadow: 0 7px 0 var(--ink-strong); font-size: 39px; transform: rotate(-3deg); }
.success-modal .eyebrow, .notebook-modal .eyebrow { margin-top: 13px; text-align: center; }
.success-evidence, .notebook-intro { margin: 0 auto 13px; color: var(--muted); font-size: 11px; font-weight: 800; text-align: center; }
.prediction-review, .reflection-area { margin-top: 12px; padding: 14px; border: 2px solid var(--line); border-radius: 17px; background: var(--blue-soft); }
.prediction-review strong { color: var(--ink-strong); font-size: 12px; }
.prediction-review p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.reflection-area { background: var(--violet-soft); }
.reflection-area h3 { margin: 0 0 10px; color: var(--ink-strong); font-size: 17px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr 1.15fr; gap: 9px; margin-top: 14px; }
.secondary-action { padding: 9px 11px; color: var(--blue-dark); font-size: 11px; font-weight: 1000; }
.modal-actions .wide-action { margin: 0; }
.success-burst { position: absolute; z-index: -1; inset: 5px; pointer-events: none; }
.success-burst span { position: absolute; width: 10px; height: 36px; border-radius: 999px; background: var(--coral); animation: burst-ray 550ms var(--ease-pop) both; }
.success-burst span:nth-child(1) { left: 12%; top: 8%; rotate: -35deg; }
.success-burst span:nth-child(2) { right: 13%; top: 10%; rotate: 38deg; background: var(--blue); }
.success-burst span:nth-child(3) { right: 8%; bottom: 22%; rotate: 76deg; background: var(--mint); }
.notebook-modal { width: min(820px, calc(100vw - 22px)); }
.notebook-shell { width: auto; }
.notebook-entries { display: grid; gap: 9px; margin-top: 13px; }
.notebook-entry { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; align-items: center; gap: 11px; padding: 11px; border: 2px solid var(--line); border-radius: 16px; background: #fff; }
.notebook-entry[data-complete="true"] { border-color: var(--mint); background: var(--mint-soft); }
.notebook-entry-number { display: grid; place-items: center; width: 44px; height: 44px; border: 2px solid var(--ink-strong); border-radius: 14px; color: var(--ink-strong); background: var(--yellow); font-size: 12px; font-weight: 1000; }
.notebook-entry h3 { margin: 0; color: var(--ink-strong); font-size: 13px; }
.notebook-entry p { margin: 3px 0 0; color: var(--muted); font-size: 9px; }
.notebook-replay-button { min-height: 44px; padding: 7px 10px; border: 2px solid var(--blue); border-radius: 12px; color: var(--blue-dark); background: #fff; font-size: 9px; font-weight: 1000; }
.notebook-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 15px; padding-top: 13px; border-top: 2px dashed var(--line); }
.notebook-footer-actions { display: flex; gap: 9px; }
.notebook-footer .wide-action { width: auto; margin: 0; }
.danger-link { padding: 8px 10px; color: var(--coral-dark); background: var(--coral-soft); border-color: var(--coral); font-size: 10px; font-weight: 1000; }

.toast { position: fixed; z-index: 300; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); max-width: min(360px, calc(100vw - 28px)); padding: 12px 16px; border: 3px solid var(--ink-strong); border-radius: 17px; color: var(--ink-strong); background: var(--mint-soft); box-shadow: 0 7px 0 var(--ink-strong), 0 18px 40px rgb(19 45 72 / 20%); font-size: 11px; font-weight: 1000; animation: toast-enter 260ms var(--ease-pop) both; }
.toast[hidden] { display: none; }

/* Motion states ----------------------------------------------------------- */
.attention-pop { animation: attention-pop 440ms var(--ease-pop) both; }
.mission-enter { animation: mission-enter 420ms var(--ease-smooth) both; }
.observation-log li[data-new="true"] { animation: observation-in 420ms var(--ease-pop) both; }
body[data-running="true"] .progress-orbit { animation: orbit-bob 1.1s ease-in-out infinite alternate; }
body[data-running="true"] .mission-icon { animation: mascot-work 1.4s ease-in-out infinite alternate; }
body[data-phase="complete"] .mission-heading { box-shadow: 0 8px 0 rgb(112 221 185 / 25%), 0 18px 36px rgb(39 91 128 / 9%); }

/* Responsive -------------------------------------------------------------- */
@media (max-width: 1370px) {
  .workspace { grid-template-columns: minmax(210px, .74fr) minmax(480px, 2fr) minmax(270px, .9fr); gap: 14px; }
  .brand-tag { display: none; }
  .top-actions { gap: 5px; }
  .icon-button { min-width: 50px; }
}

@media (max-width: 1190px) {
  .topbar { flex-wrap: wrap; }
  .top-actions { width: 100%; justify-content: flex-start; overflow-x: auto; padding: 2px 1px 5px; scrollbar-width: thin; }
  .workspace {
    grid-template-columns: minmax(0, 1.7fr) minmax(280px, .9fr);
    grid-template-areas: "missions missions" "lab predict" "lab learn";
  }
  .mission-rail { position: static; grid-template-columns: minmax(220px, .8fr) minmax(0, 2.2fr); align-items: stretch; }
  .rail-heading { min-height: 100%; }
  .mission-list { grid-template-columns: repeat(3, minmax(155px, 1fr)); align-content: start; }
  .mission-card { grid-template-columns: 38px minmax(0, 1fr) 33px; min-height: 70px; }
  .mission-card-number { width: 36px; height: 36px; }
  .mission-card-icon { width: 32px; height: 32px; font-size: 19px; }
  .method-card { grid-column: 1 / -1; }
  .method-card ol { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .method-card li { grid-template-columns: 30px minmax(0, 1fr); }
  .method-card li small { grid-column: 2; }
}

@media (max-width: 900px) {
  html { scroll-padding-top: 84px; }
  .app-shell { padding: 8px 9px 22px; }
  .topbar { top: 4px; margin-bottom: 13px; padding: 10px; border-radius: 22px; }
  .brand-mark { grid-template-columns: repeat(3, 10px); grid-template-rows: repeat(2, 10px); padding: 7px; border-radius: 15px; }
  .brand h1 { font-size: 20px; }
  .brand-subtitle { font-size: 10px; }
  .top-actions { margin-inline: -1px; padding-bottom: 6px; }
  #notebook-button { order: -3; }
  #play-button { order: -2; }
  #undo-button { order: -1; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "missions" "predict" "lab" "learn"; gap: 13px; }
  .mission-rail { grid-template-columns: 1fr; gap: 10px; }
  .mission-list { display: grid; grid-template-columns: repeat(6, minmax(150px, 1fr)); overflow-x: auto; padding: 2px 1px 9px; scroll-snap-type: x proximity; scrollbar-width: thin; }
  .mission-card { scroll-snap-align: start; }
  .method-card { display: none; }
  .mission-heading { grid-template-columns: 56px minmax(0, 1fr) 72px; min-height: 108px; padding: 14px; border-radius: 23px; }
  .mission-icon { width: 54px; height: 54px; font-size: 28px; }
  .mission-heading h2 { font-size: clamp(23px, 7.5vw, 34px); }
  .mission-score { width: 69px; height: 69px; }
  .mission-score strong { font-size: 17px; }
  .stage-frame { width: calc(100% - 18px); border-radius: 19px; }
  .material-deck, .learning-card, .model-card { border-radius: 22px; }
  .material-palette { grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); }
  .learning-rail { gap: 11px; }
  .observation-log { max-height: none; }
  .footer-note { display: grid; }
}

@media (max-width: 560px) {
  :root { --radius-md: 18px; --radius-lg: 22px; }
  html { scroll-padding-top: 76px; }
  .app-shell { padding-inline: 7px; }
  /* The slot preserves document flow while the compact command deck floats. */
  .topbar-slot { display: block; position: relative; z-index: 80; min-height: 176px; margin-bottom: 13px; }
  body:not([data-scrolled="true"]) .topbar { position: relative; top: 0; }
  .topbar { width: 100%; margin-bottom: 0; border-width: 1px; transition: box-shadow 220ms var(--ease-smooth), transform 220ms var(--ease-smooth); }
  .brand { width: 100%; max-height: 70px; gap: 9px; overflow: hidden; opacity: 1; transition: max-height 220ms var(--ease-smooth), opacity 160ms ease, margin 220ms var(--ease-smooth); }
  .brand-copy .eyebrow, .brand-subtitle { display: none; }
  .brand h1 { font-size: 18px; white-space: normal; }
  .top-actions { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; width: 100%; overflow: visible; padding: 1px 0 4px; }
  .top-actions .icon-button { min-width: 0; width: 100%; }
  #notebook-button { grid-column: span 3; order: 1; width: 100%; min-width: 0; }
  #play-button { grid-column: span 3; order: 2; width: 100%; min-width: 0; }
  #undo-button { order: 3; }
  #step-button { order: 4; }
  #speed-button { order: 5; }
  #diff-button { order: 6; }
  #reset-button { grid-column: span 2; order: 7; }
  .rail-heading { padding: 14px; }
  .rail-heading h2 { font-size: 18px; }
  .mastery-pill { width: 52px; height: 52px; }
  .mission-list { grid-template-columns: repeat(6, minmax(146px, 1fr)); }
  .mission-heading { grid-template-columns: 52px minmax(0, 1fr); gap: 10px; }
  .mission-icon { width: 50px; height: 50px; }
  .mission-score { grid-column: 1 / -1; display: flex; justify-content: center; width: 100%; height: 44px; border-radius: 14px; gap: 7px; }
  .mission-score::before, .mission-score::after, .progress-orbit { display: none; }
  .mission-heading::after { display: none; }
  .mission-score strong { font-size: 16px; }
  .stage-frame { width: calc(100% - 14px); margin-top: 7px; box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--ink-strong), 0 9px 0 rgb(19 45 72 / 15%), 0 18px 34px rgb(19 45 72 / 18%); }
  .stage-frame[data-running="true"] { box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--mint-dark), 0 9px 0 rgb(23 120 95 / 16%), 0 18px 34px rgb(23 120 95 / 18%); }
  .stage-label { display: none; }
  .pause-badge { left: 11px; min-width: 0; max-width: calc(100% - 110px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transform: none; }
  .changed-badge { right: 11px; }
  .stage-corner { bottom: 10px; font-size: 7px; }
  .material-deck, .learning-card, .model-card { padding: 14px; }
  .deck-header h3 { font-size: 18px; }
  .section-help { display: none; }
  .material-palette { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
  .material-button { min-height: 72px; padding-inline: 3px; }
  .material-swatch { width: 34px; height: 34px; }
  .brush-row { grid-template-columns: auto minmax(70px, 1fr) 38px; }
  .learning-card h2, .reflection-area h3 { font-size: 16px; }
  .modal-shell { padding: 18px 14px 20px; border-radius: 23px; }
  .modal h2 { margin-inline: 42px; font-size: 24px; }
  .success-medal, .notebook-cover { width: 64px; height: 64px; font-size: 32px; }
  .modal-actions { grid-template-columns: 1fr; }
  .notebook-entry { grid-template-columns: 40px minmax(0, 1fr); gap: 9px; }
  .notebook-entry-number { width: 39px; height: 39px; }
  .notebook-entry > :last-child { grid-column: 1 / -1; width: 100%; }
  .notebook-footer { align-items: stretch; flex-direction: column; }
  .notebook-footer-actions { display: grid; grid-template-columns: 1fr; }
  .notebook-footer .wide-action { width: 100%; }
  .toast { right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); max-width: calc(100vw - 20px); }

  /* One-row compact command strip after intentional scrolling. */
  body[data-scrolled="true"] .topbar { position: fixed; top: 4px; right: 7px; left: 7px; width: auto; min-height: 68px; gap: 0; padding: 6px 7px; border-radius: 18px; box-shadow: 0 7px 0 rgb(19 45 72 / 14%), 0 14px 30px rgb(19 45 72 / 18%); }
  body[data-scrolled="true"] .brand { max-height: 0; margin: 0; opacity: 0; pointer-events: none; }
  body[data-scrolled="true"] .top-actions { display: flex; align-items: center; gap: 5px; height: 54px; overflow-x: auto; padding: 1px 1px 5px; scrollbar-width: none; }
  body[data-scrolled="true"] .top-actions::-webkit-scrollbar { display: none; }
  body[data-scrolled="true"] .top-actions button { height: 48px; min-height: 48px; align-self: center; }
  body[data-scrolled="true"] #notebook-button { flex: 0 0 154px; order: -3; grid-template-columns: 24px minmax(0, 1fr) 28px; gap: 4px; padding: 4px 6px; font-size: 11px; }
  body[data-scrolled="true"] .notebook-icon { width: 24px; height: 28px; font-size: 12px; }
  body[data-scrolled="true"] .notebook-button strong { min-width: 28px; height: 24px; padding-inline: 4px; font-size: 9px; }
  body[data-scrolled="true"] #play-button { flex: 0 0 104px; order: -2; padding-inline: 8px; font-size: 11px; }
  body[data-scrolled="true"] #undo-button { flex: 0 0 52px; order: -1; }
  body[data-scrolled="true"] .top-actions .icon-button { flex: 0 0 52px; }
}

@media (max-width: 360px) {
  .app-shell { padding-inline: 5px; }
  body[data-scrolled="true"] .topbar { right: 5px; left: 5px; }
  .brand-mark { display: none; }
  .brand h1 { font-size: 17px; }
  .mission-list { grid-template-columns: repeat(6, minmax(138px, 1fr)); }
  .mission-heading { grid-template-columns: 46px minmax(0, 1fr); padding: 12px; }
  .mission-icon { width: 45px; height: 45px; border-radius: 16px; font-size: 24px; }
  .mission-heading h2 { font-size: 22px; }
  .mission-heading p { font-size: 10px; }
  .material-palette { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pause-badge, .changed-badge { top: 9px; padding: 4px 7px; font-size: 8px; }
  body[data-scrolled="true"] #notebook-button { flex-basis: 145px; }
}

/* Keyframes --------------------------------------------------------------- */
@keyframes app-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toy-float { from { translate: 0 -3px; rotate: -4deg; } to { translate: 0 12px; rotate: 7deg; } }
@keyframes attention-pop { 0% { transform: scale(1); } 42% { transform: scale(1.04) rotate(-.6deg); } 72% { transform: scale(.985) rotate(.4deg); } 100% { transform: scale(1); } }
@keyframes toast-enter { from { opacity: 0; transform: translateY(22px) scale(.94); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(18px) scale(.94) rotate(-.4deg); } to { opacity: 1; transform: translateY(0) scale(1) rotate(0); } }
@keyframes mission-enter { from { opacity: .35; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes observation-in { from { opacity: 0; transform: translateX(16px) scale(.98); } to { opacity: 1; transform: translateX(0) scale(1); } }
@keyframes running-pulse { 0%, 100% { transform: translateX(-50%) scale(1); box-shadow: 0 4px 0 rgb(0 0 0 / 18%); } 50% { transform: translateX(-50%) scale(1.04); box-shadow: 0 4px 0 rgb(0 0 0 / 18%), 0 0 18px rgb(112 221 185 / 55%); } }
@keyframes guide-breathe { 0%, 100% { opacity: .72; filter: brightness(1); } 50% { opacity: 1; filter: brightness(1.18); } }
@keyframes orbit-bob { from { transform: translateY(-1px) rotate(-8deg); } to { transform: translateY(3px) rotate(8deg); } }
@keyframes mascot-work { from { transform: rotate(-4deg) translateY(0); } to { transform: rotate(2deg) translateY(-3px); } }
@keyframes burst-ray { from { opacity: 0; scale: .2; } 55% { opacity: 1; scale: 1.18; } to { opacity: .82; scale: 1; } }

@media (max-width: 560px) {
  @keyframes running-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
}

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

/* v0.5 story layer and expressive simulation ---------------------------- */
.story-map-card,
.story-strip,
.story-reward {
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  background: rgb(255 255 255 / 97%);
  box-shadow: var(--shadow-sm);
}

.mission-rail {
  max-height: calc(100vh - 126px);
  padding: 1px 3px 12px 1px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.story-map-card {
  position: relative;
  padding: 13px 14px 14px;
  overflow: hidden;
  background:
    radial-gradient(circle at 105% -20%, rgb(255 215 94 / 42%) 0 76px, transparent 77px),
    linear-gradient(145deg, #fff 0%, #f5fbff 100%);
}
.story-map-card::after {
  position: absolute;
  right: -18px;
  bottom: -30px;
  width: 86px;
  height: 86px;
  border: 10px solid rgb(112 221 185 / 18%);
  border-radius: 50%;
  content: "";
}
.story-map-heading {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.story-map-heading h3 {
  margin: 0;
  color: var(--ink-strong);
  font-size: 14px;
  font-weight: 1000;
  line-height: 1.18;
}
.story-map-card > p {
  position: relative;
  z-index: 1;
  margin: 9px 0 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}
.story-duo { display: flex; align-items: flex-end; min-width: 54px; }
.story-duo > :last-child { margin-left: -7px; }
.story-map {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: start;
  gap: 3px;
}
.story-map::before {
  position: absolute;
  top: 16px;
  right: 8%;
  left: 8%;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  content: "";
}
.story-node {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 7px;
  font-weight: 1000;
  text-align: center;
}
.story-node-dot {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 3px solid var(--line-strong);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 0 rgb(31 74 111 / 10%);
  font-size: 15px;
}
.story-node[data-current="true"] .story-node-dot {
  border-color: var(--node-accent, var(--blue));
  box-shadow: 0 4px 0 color-mix(in srgb, var(--node-accent, var(--blue)) 30%, transparent);
  transform: translateY(-2px) scale(1.06);
}
.story-node[data-complete="true"] .story-node-dot {
  border-color: var(--mint-dark);
  color: #fff;
  background: var(--mint-dark);
}
.story-node small {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.story-strip {
  --story-accent: var(--blue);
  position: relative;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 116px;
  padding: 15px 16px;
  overflow: hidden;
  border-color: color-mix(in srgb, var(--story-accent) 42%, var(--line));
  background:
    linear-gradient(100deg, color-mix(in srgb, var(--story-accent) 10%, #fff) 0%, #fff 60%),
    #fff;
}
.story-strip::before {
  position: absolute;
  top: -42px;
  right: 92px;
  width: 132px;
  height: 132px;
  border: 18px solid color-mix(in srgb, var(--story-accent) 12%, transparent);
  border-radius: 50%;
  content: "";
}
.story-strip::after {
  position: absolute;
  right: 28%;
  bottom: 12px;
  color: color-mix(in srgb, var(--story-accent) 35%, transparent);
  content: "✦";
  font-size: 22px;
}
.story-strip-avatar {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border: 3px solid var(--ink-strong);
  border-radius: 24px;
  background: color-mix(in srgb, var(--story-accent) 14%, #fff);
  box-shadow: 0 6px 0 var(--ink-strong);
}
.story-strip-copy { position: relative; z-index: 1; min-width: 0; }
.story-strip-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.story-strip-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border: 2px solid color-mix(in srgb, var(--story-accent) 68%, var(--ink));
  border-radius: 999px;
  color: var(--ink-strong);
  background: #fff;
  font-size: 9px;
  font-weight: 1000;
}
.story-strip-meta span:last-child {
  border-color: #e8b220;
  background: var(--yellow-soft);
}
.story-strip h2 {
  margin: 0;
  color: var(--ink-strong);
  font-size: clamp(19px, 2vw, 27px);
  font-weight: 1000;
  line-height: 1.12;
  letter-spacing: -.025em;
}
.story-strip p { margin: 4px 0 0; color: var(--muted); font-size: 11px; font-weight: 850; }
.story-open-button {
  position: relative;
  z-index: 1;
  min-height: 46px;
  padding: 9px 13px;
  border: 2px solid var(--ink-strong);
  border-radius: 15px;
  color: var(--ink-strong);
  background: var(--yellow);
  box-shadow: 0 4px 0 var(--ink-strong);
  font-size: 10px;
  font-weight: 1000;
  white-space: nowrap;
  transition: transform 160ms var(--ease-pop), box-shadow 160ms var(--ease-pop);
}
.story-open-button:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink-strong); }
.story-open-button:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink-strong); }

/* CSS-only local pixel characters. */
.pixel-character {
  --character: var(--yellow);
  --character-dark: #b96d08;
  position: relative;
  display: inline-block;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 3px solid var(--ink-strong);
  border-radius: 14px;
  background: var(--character);
  box-shadow: inset 0 -6px 0 rgb(16 45 73 / 12%);
}
.pixel-character::before,
.pixel-character::after {
  position: absolute;
  top: 14px;
  width: 6px;
  height: 8px;
  border-radius: 3px;
  background: var(--ink-strong);
  content: "";
}
.pixel-character::before { left: 9px; }
.pixel-character::after { right: 9px; }
.pixel-character i {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 14px;
  height: 6px;
  border-bottom: 3px solid var(--ink-strong);
  border-radius: 50%;
  transform: translateX(-50%);
}
.pixel-character.pico::after { box-shadow: 2px -3px 0 #fff; }
.pixel-character.pico { --character: var(--yellow); --character-dark: #b96d08; }
.pixel-character.pico span { display: none; }
.pixel-character.pico::selection { background: transparent; }
.pixel-character.mina {
  --character: #6bc6ff;
  --character-dark: #1e74b0;
  border-radius: 52% 48% 48% 52% / 62% 62% 38% 38%;
  transform: rotate(2deg);
}
.pixel-character.mina i { transform: translateX(-50%) rotate(-2deg); }

.pixel-character.kai {
  --character: #66d6b0;
  --character-dark: #18785f;
  border-radius: 16px 16px 12px 12px;
}
.pixel-character.kai::before { box-shadow: -3px -8px 0 #1a6e5b; }
.pixel-character.hana {
  --character: #ff9e91;
  --character-dark: #b94d45;
  border-radius: 18px 18px 14px 14px;
}
.pixel-character.hana::after { box-shadow: 5px -9px 0 #ffd75e, 8px -5px 0 #fff; }
.pixel-character.toma {
  --character: #ff8c4c;
  --character-dark: #a94623;
  border-radius: 12px 18px 14px 18px;
}
.pixel-character.toma i { transform: translateX(-50%) rotate(5deg); }
.pixel-character.ao {
  --character: #a994ff;
  --character-dark: #6150aa;
  border-radius: 50% 50% 44% 44%;
}
.pixel-character.ao::before { box-shadow: -5px -7px 0 #e7e0ff; }
.pixel-character.ao::after { box-shadow: 5px -7px 0 #e7e0ff; }
.pixel-character.small { width: 31px; height: 31px; border-width: 2px; border-radius: 10px; }
.pixel-character.small::before, .pixel-character.small::after { top: 9px; width: 4px; height: 6px; }
.pixel-character.small::before { left: 7px; }
.pixel-character.small::after { right: 7px; }
.pixel-character.small i { bottom: 5px; width: 10px; height: 4px; border-bottom-width: 2px; }
.pixel-character.tiny { width: 28px; height: 28px; border-width: 2px; border-radius: 9px; }
.pixel-character.tiny::before, .pixel-character.tiny::after { top: 8px; width: 4px; height: 5px; }
.pixel-character.tiny::before { left: 6px; }
.pixel-character.tiny::after { right: 6px; }
.pixel-character.tiny i { bottom: 5px; width: 9px; height: 3px; border-bottom-width: 2px; }
.pixel-character.large { width: 70px; height: 70px; border-width: 4px; border-radius: 22px; }
.pixel-character.large::before, .pixel-character.large::after { top: 23px; width: 9px; height: 12px; }
.pixel-character.large::before { left: 15px; }
.pixel-character.large::after { right: 15px; }
.pixel-character.large i { bottom: 12px; width: 23px; height: 9px; border-bottom-width: 4px; }

.story-cue {
  position: absolute;
  z-index: 14;
  left: 50%;
  bottom: 18px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: min(470px, calc(100% - 40px));
  min-height: 52px;
  padding: 8px 12px 8px 9px;
  border: 3px solid #fff;
  border-radius: 18px;
  color: #fff;
  background: rgb(9 28 46 / 92%);
  box-shadow: 0 7px 0 rgb(0 0 0 / 28%), 0 16px 32px rgb(0 0 0 / 25%);
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
}
.story-cue[hidden] { display: none; }
.story-cue > span:last-child { display: grid; min-width: 0; }
.story-cue strong { color: #9cddff; font-size: 9px; font-weight: 1000; }
.story-cue #story-cue-text { font-size: 10px; font-weight: 850; line-height: 1.35; }
.story-cue[data-entering="true"] { animation: story-cue-in 420ms var(--ease-pop) both; }

.story-reward {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  padding: 12px;
  border-color: color-mix(in srgb, var(--story-accent, var(--blue)) 48%, var(--line));
  background: linear-gradient(115deg, color-mix(in srgb, var(--story-accent, var(--blue)) 12%, #fff), #fff);
  text-align: left;
}
.story-reward-icon {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: 3px solid var(--ink-strong);
  border-radius: 20px;
  background: var(--yellow-soft);
  box-shadow: 0 5px 0 var(--ink-strong);
  font-size: 30px;
}
.story-reward h3 { margin: 0; color: var(--ink-strong); font-size: 15px; font-weight: 1000; }
.story-reward p:last-child { margin: 4px 0 0; color: var(--muted); font-size: 10px; font-weight: 800; }

.story-shell { max-width: 610px; }
.story-dialog-header { display: grid; grid-template-columns: 88px minmax(0, 1fr); align-items: center; gap: 16px; text-align: left; }
.story-dialog-header h2 { margin: 0; font-size: clamp(24px, 5vw, 36px); line-height: 1.08; }
.story-dialog-avatar {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 27px;
  background: var(--blue-soft);
}
.story-scene {
  position: relative;
  min-height: 150px;
  margin: 18px 0 11px;
  padding: 26px 24px 22px;
  border: 3px solid var(--ink-strong);
  border-radius: 24px;
  background: linear-gradient(145deg, #fffdf8, #eef8ff);
  box-shadow: 0 7px 0 var(--ink-strong);
  text-align: left;
}
.story-scene::before {
  position: absolute;
  left: 40px;
  bottom: -15px;
  width: 24px;
  height: 24px;
  border-right: 3px solid var(--ink-strong);
  border-bottom: 3px solid var(--ink-strong);
  background: #f3faff;
  content: "";
  transform: rotate(45deg);
}
.story-speaker {
  display: inline-flex;
  min-height: 27px;
  margin-bottom: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--ink-strong);
  font-size: 10px;
  font-weight: 1000;
}
.story-scene p { margin: 0; color: var(--ink-strong); font-size: clamp(16px, 3vw, 20px); font-weight: 900; line-height: 1.65; }
.story-page-dots { display: flex; justify-content: center; gap: 7px; margin: 14px 0; }
.story-page-dot {
  width: 12px;
  height: 12px;
  padding: 0;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: #fff;
}
.story-page-dot[aria-current="true"] { width: 28px; border-color: var(--blue-dark); border-radius: 999px; background: var(--blue); }
.story-mission-bridge {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 17px;
  padding: 11px 13px;
  border: 2px dashed #e1ae1c;
  border-radius: 16px;
  background: var(--yellow-soft);
  text-align: left;
}
.story-mission-bridge > span { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 13px; background: #fff; font-size: 22px; }
.story-mission-bridge strong { color: var(--ink-strong); font-size: 11px; font-weight: 1000; }
.story-mission-bridge p { margin: 2px 0 0; color: var(--muted); font-size: 10px; font-weight: 800; }
.story-actions { grid-template-columns: minmax(110px, .45fr) minmax(170px, 1fr); }
.story-actions #story-start-button { grid-column: 2; }

body[data-running="true"] .story-strip-avatar .pixel-character,
.story-cue .pixel-character { animation: character-talk 780ms ease-in-out infinite alternate; }

@keyframes story-cue-in {
  from { opacity: 0; transform: translate(-50%, 18px) scale(.94); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
@keyframes character-talk {
  from { transform: translateY(1px) rotate(-2deg); }
  to { transform: translateY(-3px) rotate(2deg); }
}

@media (max-width: 1190px) {
  .mission-rail { max-height: none; overflow: visible; padding: 0; }
  .rail-heading { grid-column: 1; }
  .story-map-card { grid-column: 2; }
  .mission-list { grid-column: 1 / -1; }
  .method-card { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  .story-map-card { grid-column: auto; }
  .story-map-card > p { margin-bottom: 8px; }
  .story-strip { grid-template-columns: 64px minmax(0, 1fr) auto; min-height: 102px; padding: 13px; }
  .story-strip-avatar { width: 58px; height: 58px; border-radius: 20px; }
  .story-open-button { padding-inline: 10px; }
}

@media (max-width: 560px) {
  .story-map-card { padding: 12px; }
  .story-map-heading h3 { font-size: 13px; }
  .story-map-card > p { font-size: 9px; }
  .story-node small { display: none; }
  .story-node-dot { width: 32px; height: 32px; }
  .story-strip {
    grid-template-columns: 50px minmax(0, 1fr);
    gap: 10px;
    min-height: 0;
    padding: 12px;
    border-radius: 20px;
  }
  .story-strip-avatar { width: 48px; height: 48px; border-radius: 17px; box-shadow: 0 4px 0 var(--ink-strong); }
  .story-strip-avatar .pixel-character { transform: scale(.82); }
  .story-strip-meta { gap: 4px; }
  .story-strip-meta span { min-height: 22px; padding: 2px 7px; font-size: 8px; }
  .story-strip h2 { font-size: 18px; }
  .story-strip p { font-size: 10px; line-height: 1.45; }
  .story-open-button { grid-column: 1 / -1; width: 100%; min-height: 44px; }
  .story-cue { bottom: 12px; width: calc(100% - 24px); padding-right: 9px; }
  .story-cue #story-cue-text { font-size: 9px; }
  .story-dialog-header { grid-template-columns: 66px minmax(0, 1fr); gap: 10px; }
  .story-dialog-avatar { width: 62px; height: 62px; border-radius: 20px; }
  .story-dialog-avatar .pixel-character { transform: scale(.76); }
  .story-dialog-header h2 { margin: 0; font-size: 23px; }
  .story-scene { min-height: 138px; padding: 20px 16px; }
  .story-scene p { font-size: 16px; }
  .story-actions { grid-template-columns: 1fr; }
  .story-actions #story-start-button { grid-column: 1; }
  .story-reward { grid-template-columns: 52px minmax(0, 1fr); }
  .story-reward-icon { width: 50px; height: 50px; border-radius: 17px; font-size: 25px; }
}

/* v0.5.0 narrative + cinematic motion refinements ----------------------- */
#world-canvas {
  position: absolute;
  z-index: 1;
  inset: 0;
}
.effects-canvas {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  mix-blend-mode: normal;
}
.stage-grid { z-index: 4; }

.story-map-lumi {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  filter: drop-shadow(0 4px 0 rgb(16 45 73 / 16%));
}
.story-map-progress {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 2px dashed var(--line);
  color: var(--mint-dark);
  font-size: 9px;
  font-weight: 1000;
}
.story-map-progress > span {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  color: #fff;
  background: var(--mint-dark);
}

.story-strip-avatar img {
  display: block;
  width: 59px;
  height: 59px;
  object-fit: contain;
  transform-origin: 50% 82%;
}
body[data-running="true"] .story-strip-avatar img {
  animation: lumi-observe 1.25s ease-in-out infinite alternate;
}

.story-cue img {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
  filter: drop-shadow(0 2px 0 rgb(0 0 0 / 25%));
}

.story-dialog-heading-copy { min-width: 0; }
.story-dialog-role {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}
.story-dialog-avatar {
  overflow: hidden;
  border: 3px solid var(--ink-strong);
  box-shadow: 0 6px 0 var(--ink-strong);
}
.story-dialog-avatar img {
  display: block;
  width: 75px;
  height: 75px;
  object-fit: contain;
}
.story-dialog-avatar .story-character-emoji {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 42px;
}
.story-dialog-avatar[data-tone="blue"] { background: var(--blue-soft); }
.story-dialog-avatar[data-tone="mint"] { background: var(--mint-soft); }
.story-dialog-avatar[data-tone="yellow"] { background: var(--yellow-soft); }
.story-dialog-avatar[data-tone="coral"] { background: var(--coral-soft); }
.story-dialog-avatar[data-tone="violet"] { background: var(--violet-soft); }

.story-world-meter {
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 9px 12px;
  border: 2px solid var(--line);
  border-radius: 15px;
  color: var(--muted);
  background: #f8fcff;
  font-size: 9px;
  font-weight: 1000;
}
.story-world-track {
  height: 10px;
  overflow: hidden;
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
}
.story-world-track i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--mint));
  transition: width 420ms var(--ease-smooth);
}
.story-world-meter strong { color: var(--ink-strong); font-size: 11px; }

.story-scene[data-mood="concern"] { background: linear-gradient(145deg, #fff, var(--coral-soft)); }
.story-scene[data-mood="wonder"] { background: linear-gradient(145deg, #fff, var(--violet-soft)); }
.story-scene[data-mood="thinking"] { background: linear-gradient(145deg, #fff, var(--yellow-soft)); }
.story-scene[data-mood="resolve"] { background: linear-gradient(145deg, #fff, var(--blue-soft)); }
.story-scene[data-mood="celebrate"],
.story-scene[data-mood="warm"] { background: linear-gradient(145deg, #fff, var(--mint-soft)); }

.story-page-dot {
  min-height: 18px;
  min-width: 18px;
}
.story-page-dot[aria-current="true"] { min-width: 34px; }

@keyframes lumi-observe {
  from { transform: translateY(1px) rotate(-1.2deg); }
  to { transform: translateY(-3px) rotate(1.2deg); }
}

@media (max-width: 560px) {
  .story-map-lumi { width: 44px; height: 44px; }
  .story-strip-avatar img { width: 42px; height: 42px; }
  .story-open-button { display: flex; align-items: center; justify-content: center; gap: 7px; }
  .story-world-meter { grid-template-columns: auto minmax(55px, 1fr) auto; gap: 7px; padding-inline: 9px; }
  .story-dialog-avatar img { width: 56px; height: 56px; }
  .story-dialog-avatar .story-character-emoji { font-size: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  .effects-canvas { display: none; }
  body[data-running="true"] .story-strip-avatar img { animation: none !important; }
}
.story-cue-avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
}
.story-cue-avatar img { width: 32px; height: 32px; object-fit: contain; }
.story-cue-avatar .story-character-emoji { font-size: 23px; line-height: 1; }

/* v0.5 realistic-motion and story hardening */
.story-node {
  appearance: none;
  -webkit-appearance: none;
  min-width: 44px;
  min-height: 52px;
  margin: 0;
  padding: 4px 2px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
}
.story-node:hover { background: color-mix(in srgb, var(--node-accent) 10%, white); }
.story-node:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}
.story-node[data-current="true"] { background: color-mix(in srgb, var(--node-accent) 12%, white); }
.notebook-collectible {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin: 3px 0 7px;
  padding: 4px 8px;
  border: 2px solid color-mix(in srgb, var(--mission) 28%, var(--ink));
  border-radius: 999px;
  background: var(--mission-soft);
  color: var(--ink);
  font-size: 11px;
  font-weight: 900;
}
.effects-canvas {
  z-index: 3;
  mix-blend-mode: normal;
  filter: saturate(1.08) contrast(1.03);
}
.stage-grid { z-index: 4; }
.guide-layer { z-index: 5; }
.pause-badge,
.pointer-inspector,
.keyboard-cursor,
.changed-badge,
.story-cue,
.stage-corner { z-index: 6; }
body[data-running="true"] .stage-frame {
  box-shadow:
    0 24px 50px rgba(45, 72, 102, .18),
    0 0 0 3px color-mix(in srgb, var(--mission) 28%, white) inset;
}
body[data-running="true"] .stage-label::after {
  content: " · LIVE";
  color: var(--coral-dark);
}
.story-strip-avatar .pixel-character,
.story-dialog-avatar .pixel-character,
.story-cue .pixel-character {
  transform-origin: 50% 80%;
}
.story-dialog[open] .story-scene {
  animation: story-page-reveal 340ms var(--ease-out) both;
}
@keyframes story-page-reveal {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .story-dialog[open] .story-scene,
  body[data-running="true"] .story-strip-avatar .pixel-character,
  .story-cue .pixel-character { animation: none !important; }
  .effects-canvas { display: none; }
}


.effects-canvas {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: auto;
  mix-blend-mode: screen;
}
body[data-mission="sediment"] .effects-canvas { mix-blend-mode: normal; }

/* Story-map legibility and character acting. */
@media (min-width: 1191px) {
  .story-map {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px 5px;
  }
  .story-map::before { display: none; }
  .story-node small {
    min-height: 18px;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    line-height: 1.15;
  }
}
@media (max-width: 1190px) and (min-width: 561px) {
  .story-map { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
.story-page-swap { animation: story-page-swap 300ms var(--ease-out) both; }
@keyframes story-page-swap {
  from { opacity: .35; transform: translateY(8px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.story-dialog-avatar[data-mood="wonder"] .pixel-character { animation: character-wonder 620ms var(--ease-pop) both; }
.story-dialog-avatar[data-mood="resolve"] .pixel-character { animation: character-resolve 520ms var(--ease-pop) both; }
.story-dialog-avatar[data-mood="concern"] .pixel-character { animation: character-concern 760ms ease-in-out both; }
.story-dialog-avatar[data-mood="warm"] .pixel-character,
.story-dialog-avatar[data-mood="celebrate"] .pixel-character { animation: character-celebrate 680ms var(--ease-pop) both; }
@keyframes character-wonder {
  0% { transform: translateY(5px) scale(.92) rotate(-4deg); }
  55% { transform: translateY(-4px) scale(1.08) rotate(3deg); }
  100% { transform: translateY(0) scale(1) rotate(0); }
}
@keyframes character-resolve {
  0% { transform: translateX(-5px) rotate(-4deg); }
  60% { transform: translateX(3px) rotate(2deg); }
  100% { transform: translateX(0); }
}
@keyframes character-concern {
  0%, 100% { transform: translateX(0) rotate(0); }
  25% { transform: translateX(-2px) rotate(-2deg); }
  75% { transform: translateX(2px) rotate(2deg); }
}
@keyframes character-celebrate {
  0% { transform: translateY(5px) scale(.94); }
  45% { transform: translateY(-7px) scale(1.08) rotate(-4deg); }
  70% { transform: translateY(-2px) scale(1.02) rotate(3deg); }
  100% { transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .story-page-swap,
  .story-dialog-avatar .pixel-character { animation: none !important; }
}

/* Final accessibility override: this must follow the cinematic overlay rule. */
@media (prefers-reduced-motion: reduce) {
  .effects-canvas { display: none !important; }
}
