@font-face {
  font-family: "Poppins";
  src: url("/static/assets/fonts/Poppins-Regular.ttf") format("truetype");
  font-weight: 400;
}

@font-face {
  font-family: "Poppins";
  src: url("/static/assets/fonts/Poppins-Bold.ttf") format("truetype");
  font-weight: 700;
}

@font-face {
  font-family: "Poppins";
  src: url("/static/assets/fonts/Poppins-ExtraBold.ttf") format("truetype");
  font-weight: 800;
}

:root {
  --ink: #172033;
  --muted: #5d6472;
  --paper: #fffaf0;
  --line: #273244;
  --lemon: #ffd54f;
  --leaf: #0b8d5b;
  --blue: #1b7fbd;
  --coral: #ef6f56;
  --panel: #f7f2e8;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: #111827;
  color: var(--ink);
  font-family: "Poppins", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 24% 20%, rgba(255, 213, 79, 0.18), transparent 28%),
    linear-gradient(135deg, #101827 0%, #243447 100%);
}

.stage-shell {
  position: relative;
  width: 1280px;
  height: 720px;
}

.game-stage {
  position: absolute;
  inset: 0;
  width: 1280px;
  height: 720px;
  overflow: hidden;
  display: none;
  transform-origin: top left;
  background: #7dc9f7;
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.game-stage.is-active {
  display: block;
}

.world {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.scene-img {
  position: absolute;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.sky-img {
  left: -1px;
  top: 0;
  width: 1296px;
  height: 641px;
  object-fit: contain;
}

.grass-img {
  left: -30px;
  top: 522px;
  width: 1343px;
  height: 200px;
  object-fit: contain;
}

.back-base {
  left: 777px;
  top: 370px;
  width: 212px;
  height: auto;
}

.front-base {
  left: 717px;
  top: 405px;
  width: 311px;
  height: auto;
  z-index: 9;
}

#setupObjects,
#chapterObjects {
  position: absolute;
  inset: 0;
  z-index: 7;
  touch-action: none;
}

.setup-character,
.chapter-character {
  left: 787px;
  top: 261px;
  width: 200px;
  height: 200px;
  object-fit: contain;
  z-index: 8;
}

.extra-img {
  left: 122px;
  top: 145px;
  width: 472px;
  height: 394px;
  object-fit: contain;
  z-index: 6;
}

.build-piece {
  position: absolute;
  width: 280px;
  height: 280px;
  object-fit: contain;
  z-index: 7;
  touch-action: none;
  pointer-events: none;
  transition: filter 160ms ease, transform 160ms ease;
}

.build-piece.is-enabled {
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.24));
}

.build-piece.is-dragging {
  transform: scale(1.04);
  z-index: 30;
}

.build-piece.sign-board {
  width: 375px;
  height: 134px;
}

.target-box {
  position: absolute;
  left: 676px;
  top: 126px;
  width: 404px;
  height: 422px;
  border: 4px dashed #d82c20;
  background: rgba(255, 255, 255, 0.1);
  opacity: 0;
  z-index: 5;
  pointer-events: none;
}

.target-box.is-visible {
  opacity: 1;
  animation: targetPulse 900ms ease-in-out infinite alternate;
}

@keyframes targetPulse {
  from {
    border-color: #d82c20;
    background: rgba(255, 255, 255, 0.05);
  }
  to {
    border-color: #ffcf33;
    background: rgba(255, 255, 255, 0.18);
  }
}

.painted-sky {
  position: absolute;
  inset: 0 0 120px;
  background:
    linear-gradient(180deg, #0f57b8 0%, #88bfd2 100%),
    #5fb1e3;
}

.welcome-grass {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1280px;
  height: 150px;
  background:
    linear-gradient(180deg, #185f35 0 22px, #0ba05a 22px 100%);
}

.snow-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.snowflake {
  position: absolute;
  top: -20px;
  width: var(--size);
  height: var(--size);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  animation: fall var(--duration) linear infinite;
  animation-delay: var(--delay);
}

@keyframes fall {
  to {
    transform: translate3d(var(--drift), 760px, 0);
  }
}

.welcome-logo {
  position: absolute;
  left: 315px;
  width: 650px;
  opacity: 0;
  filter: drop-shadow(0 0 55px rgba(255, 255, 255, 0.92));
  animation: logoArrive 2.8s ease forwards;
}

@keyframes logoArrive {
  0% {
    opacity: 0;
    transform: scale(0.55);
  }
  75% {
    opacity: 1;
    transform: scale(1.1);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.welcome-subtitle {
  position: absolute;
  right: 36px;
  bottom: 4px;
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  color: #111827;
}

.welcome-actions {
  position: absolute;
  left: 50%;
  bottom: 76px;
  display: grid;
  gap: 14px;
  transform: translateX(-50%);
}

.primary-action,
.secondary-action,
.choice-button,
.panel-toggle,
.validate-button,
.close-zoom {
  border: 2px solid var(--line);
  color: var(--ink);
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.primary-action,
.secondary-action {
  min-width: 220px;
  min-height: 60px;
  padding: 8px 24px;
  font-size: 30px;
  font-weight: 800;
}

.primary-action {
  background: var(--lemon);
}

.secondary-action {
  background: #ffffff;
}

.primary-action:hover,
.secondary-action:hover,
.choice-button:hover,
.panel-toggle:hover,
.validate-button:hover,
.close-zoom:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.2);
}

.panel-toggle {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 50;
  width: 141px;
  min-height: 62px;
  padding: 6px 12px;
  background: #101315;
  color: white;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0;
}

.side-panel {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 40;
  width: 502px;
  height: 720px;
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.98), rgba(244, 236, 219, 0.98)),
    var(--panel);
  border-right: 3px solid rgba(23, 32, 51, 0.28);
  box-shadow: 18px 0 42px rgba(23, 32, 51, 0.18);
  transform: translateX(-512px);
  transition: transform 260ms ease;
}

.side-panel.is-open {
  transform: translateX(0);
}

.locked-panel {
  display: grid;
  place-items: center;
}

.locked-word {
  margin: 0;
  color: rgba(23, 32, 51, 0.2);
  font-size: 66px;
  font-weight: 800;
  letter-spacing: 0;
}

.speech-bubble {
  position: absolute;
  left: 598px;
  top: 174px;
  z-index: 25;
  width: 188px;
  min-height: 191px;
  display: grid;
  place-items: stretch;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #111827;
  border-radius: 8px;
  box-shadow: 0 14px 0 rgba(23, 32, 51, 0.12), 0 22px 40px rgba(23, 32, 51, 0.18);
  transition: left 220ms ease;
}

.speech-bubble.shifted {
  left: 478px;
}

.speech-text {
  width: 100%;
  min-height: 185px;
  padding: 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 25px;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  white-space: normal;
}

.speech-text:focus-visible,
.choice-button:focus-visible,
.panel-toggle:focus-visible,
.validate-button:focus-visible,
.answer-input:focus-visible,
.brand-input:focus-visible {
  outline: 4px solid rgba(255, 213, 79, 0.95);
  outline-offset: 3px;
}

.brand-input {
  position: absolute;
  z-index: 35;
  height: 78px;
  padding: 0 8px;
  border: 0;
  outline: 0;
  background: transparent;
  color: #172033;
  font-size: 40px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.brand-input::placeholder {
  color: rgba(23, 32, 51, 0.42);
}

.chapter-brand {
  pointer-events: none;
}

.dialogue-controls {
  position: absolute;
  inset: 0;
  z-index: 28;
  pointer-events: none;
}

.dialogue-box {
  position: absolute;
  left: 600px;
  top: 508px;
  width: 520px;
  min-height: 96px;
  max-height: 118px;
  display: grid;
  place-items: center;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.97);
  border: 3px solid rgba(23, 32, 51, 0.72);
  border-radius: 8px;
  box-shadow: 0 10px 0 rgba(23, 32, 51, 0.14), 0 20px 34px rgba(23, 32, 51, 0.16);
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.18;
  overflow-wrap: anywhere;
  overflow-y: auto;
  text-align: center;
  pointer-events: auto;
}

.answer-input {
  position: absolute;
  left: 731px;
  top: 461px;
  z-index: 29;
  width: 279px;
  height: 62px;
  padding: 8px 14px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  pointer-events: auto;
}

.choice-row {
  position: absolute;
  left: 600px;
  top: 642px;
  width: 520px;
  display: flex;
  justify-content: center;
  gap: 16px;
  pointer-events: auto;
}

.choice-button {
  width: 154px;
  min-height: 50px;
  padding: 6px 12px;
  background: #fffaf0;
  font-size: 15px;
  font-weight: 800;
}

.choice-button:not(.back-choice):first-of-type,
#optionOne {
  background: var(--lemon);
}

.back-choice {
  width: 86px;
  background: #e8edf5;
}

.back-choice:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
}

.accounts-panel {
  display: flex;
  flex-direction: column;
  padding: 22px 14px 14px;
  gap: 12px;
}

.accounts-panel h2,
.accounts-panel h3 {
  margin: 0;
  text-align: center;
  color: var(--ink);
}

.accounts-panel h2 {
  padding-left: 138px;
  font-size: 34px;
  line-height: 1.1;
}

.accounts-panel h3 {
  font-size: 18px;
}

.accounting-workspace {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 8px 6px;
}

.empty-note {
  margin: 120px 18px 0;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.challenge-header {
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 4px 0 rgba(23, 32, 51, 0.1);
}

.challenge-header strong {
  display: block;
  font-size: 16px;
}

.challenge-header span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.sheet-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sheet-column {
  min-width: 0;
}

.sheet-heading {
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.drop-zone {
  min-height: 158px;
  padding: 7px;
  border: 2px dashed rgba(23, 32, 51, 0.5);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.74);
}

.drop-zone.is-hovered {
  border-color: var(--leaf);
  background: rgba(11, 141, 91, 0.12);
}

.account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 30px;
  gap: 4px;
  align-items: center;
  min-height: 42px;
  margin-bottom: 6px;
  padding: 6px;
  border: 1px solid rgba(23, 32, 51, 0.22);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 2px 0 rgba(23, 32, 51, 0.08);
}

.account-name {
  min-width: 0;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 800;
  line-height: 1.1;
}

.account-type {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.account-value {
  width: 72px;
  height: 30px;
  border: 1px solid rgba(23, 32, 51, 0.34);
  border-radius: 4px;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
}

.delete-row {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  background: #f1d6cd;
  color: #8a1f11;
  font-weight: 800;
}

.delete-row[disabled] {
  opacity: 0.28;
  cursor: not-allowed;
}

.sheet-total {
  margin: 6px 0 0;
  padding: 5px 8px;
  border-radius: 4px;
  background: #172033;
  color: white;
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.chip-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.account-chip {
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(180deg, #ffe27a, #ffd54f);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  user-select: none;
}

.account-chip.is-selected {
  outline: 3px solid var(--blue);
}

.validate-button {
  width: 100%;
  min-height: 46px;
  background: var(--leaf);
  color: white;
  font-size: 15px;
  font-weight: 800;
}

.feedback {
  margin-top: 8px;
  padding: 10px;
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
}

.feedback-list {
  margin: 0;
  padding-left: 18px;
}

.feedback-list li {
  margin-bottom: 4px;
}

.feedback-list li:last-child {
  margin-bottom: 0;
}

.feedback.is-success {
  color: #075f3d;
  background: #dff5e8;
}

.feedback.is-error {
  color: #7d1e11;
  background: #fde2da;
}

/* --- Journal (Dr/Cr) posting mode - chapters 6+ --- */

.journal-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.journal-column {
  min-width: 0;
}

.journal-zone {
  min-height: 120px;
  padding: 7px;
  border: 2px dashed rgba(23, 32, 51, 0.5);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.74);
}

.journal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px 26px;
  gap: 4px;
  align-items: center;
  margin-bottom: 6px;
  padding: 5px;
  border: 1px solid rgba(23, 32, 51, 0.22);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 2px 0 rgba(23, 32, 51, 0.08);
}

.journal-account {
  min-width: 0;
  height: 30px;
  border: 1px solid rgba(23, 32, 51, 0.34);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 700;
}

.journal-amount {
  width: 58px;
  height: 30px;
  border: 1px solid rgba(23, 32, 51, 0.34);
  border-radius: 4px;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
}

.journal-add {
  width: 100%;
  margin-top: 4px;
  padding: 5px;
  border: 2px dashed rgba(23, 32, 51, 0.4);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  transition: background 120ms ease, color 120ms ease;
}

.journal-add:hover {
  background: rgba(255, 213, 79, 0.4);
  color: var(--ink);
}

.journal-add:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* --- Chapter-end quiz --- */

.quiz-card {
  max-width: 640px;
}

.quiz-progress {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.quiz-question {
  margin: 0 0 18px;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.35;
  text-align: left;
}

.quiz-options {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.quiz-option {
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  text-align: left;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.quiz-option:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.16);
  background: #fff8e1;
}

.quiz-option:disabled {
  cursor: not-allowed;
}

.quiz-option.is-wrong {
  background: #fde2da;
  border-color: #b3402c;
  color: #7d1e11;
  opacity: 0.75;
  animation: quizShake 300ms ease;
}

.quiz-option.is-correct {
  background: #dff5e8;
  border-color: var(--leaf);
  color: #075f3d;
}

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

.quiz-explain {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--lemon);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
}

.quiz-next-button {
  font-size: 18px;
  padding: 10px 30px;
  min-height: 50px;
}

.lesson-strip {
  flex: 0 0 178px;
  border-top: 2px solid rgba(23, 32, 51, 0.34);
  padding-top: 8px;
}

.lesson-list {
  height: 132px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 4px 12px;
}

.lesson-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 154px;
  height: 100px;
  padding: 0;
  border: 3px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.lesson-thumb:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 rgba(23, 32, 51, 0.16);
}

.lesson-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lesson-thumb span {
  position: absolute;
  left: 4px;
  top: 4px;
  min-width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: white;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.zoom-view {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(7, 12, 20, 0.82);
}

.zoom-view img {
  max-width: 1120px;
  max-height: 660px;
  object-fit: contain;
  border: 4px solid white;
  background: white;
}

.close-zoom {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 100;
  min-width: 84px;
  min-height: 42px;
  background: #101315;
  color: white;
  font-weight: 800;
}

.chapter-overlay {
  position: absolute;
  inset: 0;
  z-index: 85;
  display: grid;
  place-items: center;
  background: rgba(5, 5, 5, 0.92);
  color: white;
  padding: 20px;
}

.chapter-overlay-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 22px;
  padding: 30px 40px;
  max-width: 560px;
  width: 100%;
  text-align: center;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.45);
  border: 4px solid var(--ink);
}

.chapter-overlay-title {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 800;
}

.chapter-overlay-subtitle {
  margin: 0 0 18px;
  font-size: 16px;
  color: var(--muted);
  font-weight: 600;
}

.chapter-overlay-heading {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
  text-align: left;
}

.chapter-overlay-goals {
  margin: 0 0 16px;
  padding-left: 22px;
  text-align: left;
  font-size: 15px;
  line-height: 1.55;
}

.chapter-overlay-goals li {
  margin-bottom: 6px;
}

.chapter-overlay-tip {
  margin: 0 0 22px;
  padding: 12px 14px;
  background: var(--lemon);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  line-height: 1.45;
}

.chapter-overlay-button {
  font-size: 18px;
  padding: 12px 32px;
}

.chapter-overlay p {
  margin: 0;
}

.is-hidden {
  display: none !important;
}

/* End Game Screen Styles */
.end-game-container {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 600px;
  text-align: center;
  z-index: 10;
}

.end-game-content {
  background: rgba(255, 255, 255, 0.95);
  padding: 60px 40px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.end-game-title {
  font-size: 48px;
  font-weight: 800;
  color: var(--ink);
  margin: 0 0 20px 0;
  animation: slideDown 0.6s ease-out;
}

.end-game-message {
  font-size: 24px;
  color: var(--ink);
  margin: 15px 0;
  animation: fadeIn 0.8s ease-out 0.2s both;
}

.coming-soon {
  font-size: 32px;
  font-weight: 700;
  color: var(--coral);
  margin: 25px 0 15px 0;
  animation: scaleIn 0.6s ease-out 0.4s both;
}

.end-game-subtitle {
  font-size: 18px;
  color: var(--muted);
  margin: 15px 0 30px 0;
  animation: fadeIn 0.8s ease-out 0.6s both;
}

.end-game-button {
  min-width: 280px;
  min-height: 60px;
  font-size: 28px;
  margin-bottom: 15px;
  animation: slideUp 0.6s ease-out 0.8s both;
}

.end-game-back-button {
  min-width: 150px;
  min-height: 50px;
  font-size: 16px;
  background: #f0f0f0 !important;
  animation: slideUp 0.6s ease-out 0.9s both;
}

.end-character {
  position: absolute;
  bottom: 50px;
  right: 60px;
  width: 300px;
  height: 300px;
  object-fit: contain;
  animation: popIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.5s both;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.5) translateX(100px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateX(0);
  }
}

/* --- Character emotions --- */

.setup-character,
.chapter-character {
  transform-origin: 50% 90%;
}

.emote-happy {
  animation: charBounce 700ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.emote-wow {
  animation: charPop 650ms cubic-bezier(0.34, 1.8, 0.64, 1);
}

.emote-sad {
  animation: charDroop 900ms ease;
}

.emote-thinking {
  animation: charTilt 1100ms ease-in-out;
}

.emote-piggy {
  animation: charJiggle 750ms ease;
}

.emote-explain {
  animation: charNod 800ms ease;
}

.emote-point {
  animation: charLean 700ms ease;
}

@keyframes charBounce {
  0% { transform: translateY(0); }
  30% { transform: translateY(-26px) scale(1.04); }
  55% { transform: translateY(0) scale(0.98); }
  75% { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}

@keyframes charPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

@keyframes charDroop {
  0% { transform: translateY(0) rotate(0deg); }
  40% { transform: translateY(10px) rotate(-3deg); }
  70% { transform: translateY(10px) rotate(3deg); }
  100% { transform: translateY(0) rotate(0deg); }
}

@keyframes charTilt {
  0% { transform: rotate(0deg); }
  30% { transform: rotate(-5deg); }
  65% { transform: rotate(4deg); }
  100% { transform: rotate(0deg); }
}

@keyframes charJiggle {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px) rotate(-2deg); }
  45% { transform: translateX(8px) rotate(2deg); }
  70% { transform: translateX(-4px); }
}

@keyframes charNod {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(8px) scale(1.02, 0.97); }
  60% { transform: translateY(-4px); }
}

@keyframes charLean {
  0%, 100% { transform: rotate(0deg) translateX(0); }
  40% { transform: rotate(3deg) translateX(10px); }
}

.emote-float {
  position: absolute;
  z-index: 26;
  font-size: 42px;
  pointer-events: none;
  animation: emoteRise 1.35s ease-out forwards;
}

@keyframes emoteRise {
  0% { opacity: 0; transform: translateY(14px) scale(0.6); }
  25% { opacity: 1; transform: translateY(-12px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-72px) scale(1); }
}

/* --- Chapter select (welcome screen) --- */

.chapter-select {
  position: absolute;
  left: 50%;
  bottom: 40px;
  width: max-content;
  max-width: 96%;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: rgba(255, 250, 240, 0.94);
  border: 3px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.18);
}

.chapter-select-heading {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: 0.5px;
}

.chapter-map {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  justify-content: center;
  gap: 10px;
  max-width: 880px;
}

.chapter-node {
  position: relative;
  min-height: 74px;
  display: grid;
  grid-template-rows: auto 1fr;
  place-items: center;
  gap: 2px;
  padding: 8px 6px 6px;
  border: 3px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--lemon);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.16);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.chapter-node-num {
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.chapter-node-title {
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
}

.chapter-node.is-done .chapter-node-title {
  color: rgba(255, 255, 255, 0.92);
}

.chapter-node.is-done {
  background: var(--leaf);
  color: #fff;
}

.chapter-node.is-done::after {
  content: "✓";
  position: absolute;
  right: -6px;
  top: -6px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #fff;
  color: var(--leaf);
  border: 2px solid var(--line);
  font-size: 13px;
}

.chapter-node:hover {
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 7px 0 rgba(0, 0, 0, 0.2);
}

/* --- Finale stats --- */

.end-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 24px 0 18px;
}

.end-stat {
  display: grid;
  gap: 2px;
  padding: 14px 8px;
  background: var(--paper);
  border: 3px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.12);
  animation: scaleIn 0.5s ease-out 0.5s both;
}

.end-stat-value {
  font-size: 30px;
  font-weight: 800;
  color: var(--leaf);
}

.end-stat:first-child .end-stat-value {
  color: var(--muted);
}

.end-stat-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.end-skills {
  margin: 0 0 26px;
  padding: 10px 14px;
  background: var(--lemon);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  animation: fadeIn 0.8s ease-out 0.7s both;
}

@media (max-width: 720px) {
  .app-shell {
    background: #111827;
  }
}
