:root {
  --ink: #192230;
  --muted: #657080;
  --paper: #f5f7fa;
  --card: #ffffff;
  --line: #dfe4ea;
  --accent: #4455a5;
  --accent-dark: #303e83;
  --accent-soft: #eef0ff;
  --success: #176b45;
  --success-soft: #eaf7f0;
  --danger: #a33a3a;
  --danger-soft: #fff0f0;
  --warn: #7a5a00;
  --warn-soft: #fff7dc;
  --shadow: 0 12px 30px rgba(31, 42, 68, .08);
  --radius: 16px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font: 16px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: var(--accent-dark); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  padding: 10px clamp(18px, 4vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center;
  color: white; background: var(--accent); font-weight: 800; font-size: 20px;
}
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); font-size: 12px; font-weight: 500; }
nav { display: flex; gap: 6px; flex-wrap: wrap; }
nav a { text-decoration: none; padding: 9px 12px; border-radius: 9px; color: var(--muted); font-weight: 650; }
nav a.active, nav a:hover { background: var(--accent-soft); color: var(--accent-dark); }
main { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 42px 0 64px; min-height: calc(100vh - 160px); }
footer { border-top: 1px solid var(--line); padding: 22px 16px 36px; color: var(--muted); text-align: center; font-size: 13px; }
footer p { max-width: 900px; margin: auto; }
.hero { display: grid; grid-template-columns: 1.45fr .75fr; gap: 24px; align-items: stretch; margin-bottom: 30px; }
.hero-card, .summary-card, .module-card, .panel, .question-card, .level-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.hero-card { padding: clamp(26px, 4vw, 44px); }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .08em; font-weight: 800; font-size: 12px; margin: 0 0 8px; }
h1 { font-size: clamp(32px, 5vw, 52px); line-height: 1.05; letter-spacing: -.035em; margin: 0 0 16px; }
h2 { font-size: clamp(23px, 3vw, 32px); line-height: 1.18; margin: 0 0 12px; letter-spacing: -.02em; }
h3 { margin: 0; font-size: 19px; }
p { margin: 0 0 14px; }
.lead { font-size: 18px; color: #3d4959; max-width: 760px; }
.summary-card { padding: 24px; display: flex; flex-direction: column; justify-content: center; }
.big-stat { font-size: 46px; font-weight: 820; line-height: 1; letter-spacing: -.04em; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 5px; }
.stats-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 18px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 34px 0 16px; }
.section-head p { color: var(--muted); max-width: 700px; margin: 0; }
.module-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 18px; }
.module-card { padding: 23px; display: flex; flex-direction: column; gap: 16px; }
.module-card.primary { border-top: 4px solid var(--accent); }
.module-card.secondary { border-top: 4px solid #7984c8; }
.module-card.tertiary { border-top: 4px solid #a3abc9; }
.module-card p { color: var(--muted); }
.module-meta { display: flex; justify-content: space-between; gap: 12px; align-items: center; color: var(--muted); font-size: 13px; }
.progress-track { height: 8px; border-radius: 999px; overflow: hidden; background: #edf0f4; }
.progress-fill { height: 100%; background: var(--accent); border-radius: inherit; }
.btn { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 750; background: var(--accent); color: white; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: white; color: var(--accent-dark); border: 1px solid #b9c0e2; }
.btn.secondary:hover { background: var(--accent-soft); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.btn:disabled { cursor: not-allowed; opacity: .48; }
.level-list { display: grid; gap: 12px; }
.level-card { padding: 18px 20px; display: grid; grid-template-columns: 54px 1fr auto; gap: 16px; align-items: center; box-shadow: none; }
.level-number { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-dark); font-weight: 850; font-size: 18px; }
.level-card.locked { opacity: .68; }
.level-card.locked .level-number { background: #f0f1f3; color: #848b95; }
.level-card p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.badges { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 750; background: #f0f2f5; color: #586272; }
.badge.pass { background: var(--success-soft); color: var(--success); }
.badge.fail { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.practice-shell { max-width: 920px; margin: auto; }
.practice-top { margin-bottom: 18px; display: grid; gap: 10px; }
.breadcrumb { color: var(--muted); font-size: 13px; }
.question-progress { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); }
.question-card { padding: clamp(24px, 4vw, 38px); box-shadow: var(--shadow); }
.stimulus-label, .conclusion-label { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px; }
.stimulus { white-space: pre-line; font-size: 18px; padding: 18px 20px; border-left: 4px solid #cad0ef; background: #f8f9ff; border-radius: 0 10px 10px 0; margin-bottom: 24px; }
.conclusion { font-size: 20px; font-weight: 690; line-height: 1.45; margin-bottom: 20px; }
.instruction { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.answer-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.answer-btn { min-height: 58px; border-radius: 12px; border: 2px solid #cfd5de; background: white; color: var(--ink); font-size: 18px; font-weight: 800; }
.answer-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.answer-btn.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.answer-btn.correct { border-color: var(--success); background: var(--success-soft); color: var(--success); }
.answer-btn.wrong { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.feedback { margin-top: 22px; padding: 18px 20px; border-radius: 12px; }
.feedback.correct { background: var(--success-soft); border: 1px solid #a9d7c2; }
.feedback.wrong { background: var(--danger-soft); border: 1px solid #e7b7b7; }
.feedback h3 { margin-bottom: 6px; }
.feedback p:last-child { margin-bottom: 0; }
.feedback .rule { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(0,0,0,.09); font-size: 14px; }
.next-row { margin-top: 20px; display: flex; justify-content: flex-end; }
.result-card { max-width: 780px; margin: 20px auto; text-align: center; padding: 36px; background: white; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.score-ring { width: 128px; height: 128px; border-radius: 50%; display: grid; place-items: center; margin: 14px auto 20px; background: conic-gradient(var(--accent) var(--pct), #e8ebef 0); position: relative; }
.score-ring::after { content: ''; width: 96px; height: 96px; border-radius: 50%; background: white; position: absolute; }
.score-ring strong { position: relative; z-index: 1; font-size: 27px; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }
.panel { padding: 22px; box-shadow: none; }
.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 620px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.mistake-list { display: grid; gap: 12px; }
.mistake-item { padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.mistake-item p { margin: 5px 0; }
.mistake-item .meta { color: var(--muted); font-size: 12px; }
.control-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.file-label { position: relative; overflow: hidden; }
.file-label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.rule-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 18px; }
.rule-card { background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.rule-card code { display: block; padding: 10px 12px; background: #f4f5f8; border-radius: 8px; margin: 10px 0; color: #3c4760; }
.note { padding: 15px 17px; border-radius: 12px; background: var(--warn-soft); color: #604800; border: 1px solid #ead99e; }
.empty { color: var(--muted); padding: 24px 0; }
.small { font-size: 13px; color: var(--muted); }
.hide { display: none !important; }
@media (max-width: 900px) {
  .hero, .module-grid, .review-grid, .rule-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  nav { justify-content: flex-end; }
}
@media (max-width: 640px) {
  main { width: min(100% - 20px, 1180px); padding-top: 22px; }
  .topbar { position: static; flex-direction: column; gap: 8px; }
  nav { width: 100%; justify-content: flex-start; overflow-x: auto; }
  nav a { white-space: nowrap; }
  .level-card { grid-template-columns: 46px 1fr; }
  .level-card > :last-child { grid-column: 1 / -1; }
  .answer-row { grid-template-columns: 1fr; }
  .question-card { padding: 20px; }
  .stimulus { font-size: 16px; }
  .conclusion { font-size: 18px; }
}

.mistake-item summary { cursor: pointer; }
.mistake-item summary::marker { color: var(--accent); }


/* Animal mastery rewards */
.reward-home-strip {
  display: grid;
  grid-template-columns: 1.2fr auto auto;
  gap: 20px;
  align-items: center;
  padding: 20px 22px;
  background: linear-gradient(135deg, #fffaf0, #f2f7ff);
  border: 1px solid #e5dfcf;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.reward-home-strip h2, .reward-home-strip p { margin-bottom: 4px; }
.reward-home-animals { display: flex; align-items: center; }
.reward-home-animals span {
  width: 42px; height: 42px; margin-left: -7px; display: grid; place-items: center;
  background: white; border: 2px solid #efe6cc; border-radius: 50%; font-size: 24px;
  box-shadow: 0 3px 10px rgba(31,42,68,.08);
}
.reward-home-animals span:first-child { margin-left: 0; }
.level-card { grid-template-columns: 82px 1fr auto; }
.level-animal-wrap { display: grid; justify-items: center; gap: 4px; color: var(--muted); font-size: 11px; font-weight: 800; }
.animal-kicker { color: #94701a; font-size: 12px; font-weight: 850; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 1px; }
.animal-stage {
  width: 150px; height: 126px; position: relative; overflow: hidden; flex: 0 0 auto;
  border: 1px solid #dce5d0; border-radius: 18px; background: #dff2ff;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.04);
}
.animal-stage.compact { width: 72px; height: 62px; border-radius: 14px; }
.habitat-sky { position: absolute; inset: 0 0 38% 0; background: linear-gradient(#dff3ff, #f8fdff); }
.habitat-ground { position: absolute; inset: 62% 0 0; background: linear-gradient(#b9dc8d, #92bd67); }
.animal-stage::after {
  content: ''; position: absolute; width: 34px; height: 34px; border-radius: 50%; right: 10px; top: 9px;
  background: rgba(255,235,142,.82); box-shadow: 0 0 0 8px rgba(255,245,190,.3);
}
.animal-stage .pet {
  position: absolute; z-index: 2; left: 50%; bottom: 15px; transform: translateX(-50%);
  font-size: 58px; line-height: 1; filter: drop-shadow(0 4px 2px rgba(0,0,0,.08));
}
.animal-stage.compact .pet { font-size: 35px; bottom: 7px; }
.animal-stage .pet-item {
  position: absolute; z-index: 3; right: 11px; bottom: 10px; width: 42px; height: 42px;
  display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.92);
  border: 1px solid rgba(0,0,0,.07); font-size: 25px; box-shadow: 0 4px 10px rgba(31,42,68,.12);
}
.animal-stage.compact .pet-item { width: 26px; height: 26px; right: 4px; bottom: 4px; font-size: 16px; }
.animal-stage.mystery { background: #eceff3; border-color: #dde1e7; filter: grayscale(1); }
.animal-stage.mystery .habitat-sky { background: #eef0f2; }
.animal-stage.mystery .habitat-ground { background: #d9dde1; }
.animal-stage.mystery .pet { color: #949ba5; font: 850 38px/1 system-ui, sans-serif; bottom: 13px; }
.animal-stage.compact.mystery .pet { font-size: 26px; bottom: 11px; }
.reward-badge { background: #f5efff; color: #6442a5; }
.reward-wait { background: #fff0c9; color: #795600; }
.reward-button { background: #7c4db0; }
.reward-button:hover { background: #61378f; }
.reward-banner {
  margin-top: 24px; padding: 18px; display: grid; grid-template-columns: 150px 1fr auto;
  align-items: center; gap: 20px; text-align: left; border: 1px solid #dfd2ed; border-radius: 16px;
  background: linear-gradient(135deg, #fbf7ff, #fffaf0);
}
.reward-banner.waiting { border-color: #e3c66f; box-shadow: 0 8px 24px rgba(125,91,0,.08); }
.reward-banner h2 { margin-bottom: 5px; }
.reward-banner p:last-child { margin-bottom: 0; }
.sanctuary-section { margin-top: 34px; }
.sanctuary-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; margin-bottom: 13px; }
.sanctuary-heading h2 { margin: 0; }
.sanctuary-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 15px; }
.animal-card {
  background: white; border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
  box-shadow: 0 5px 16px rgba(31,42,68,.05);
}
.animal-card .animal-stage { width: 100%; height: 138px; border: 0; border-radius: 0; }
.animal-card.locked { opacity: .62; }
.animal-card-copy { padding: 16px; }
.animal-card-copy p { color: var(--muted); min-height: 44px; margin: 4px 0 13px; }
.animal-card-copy .eyebrow { min-height: auto; margin: 0 0 2px; color: var(--accent); }
.animal-card-copy .btn { width: 100%; }
.shop-shell { max-width: 1020px; margin: 0 auto; }
.shop-hero {
  margin-top: 14px; display: grid; grid-template-columns: 190px 1fr; gap: 28px; align-items: center;
  padding: 26px; background: white; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.shop-hero .animal-stage { width: 190px; height: 155px; }
.shop-hero h1 { margin-bottom: 10px; }
.shop-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }
.shop-item {
  min-height: 230px; padding: 20px; text-align: left; display: flex; flex-direction: column; align-items: flex-start;
  border: 2px solid var(--line); border-radius: 16px; background: white; color: var(--ink);
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.shop-item:hover { transform: translateY(-2px); border-color: #b79bd2; box-shadow: 0 9px 22px rgba(72,45,105,.1); }
.shop-item.selected { border-color: #7c4db0; background: #fbf8ff; box-shadow: 0 0 0 3px #efe4fa; }
.shop-item-emoji { font-size: 48px; line-height: 1.1; margin-bottom: 10px; }
.shop-category { color: #7c4db0; font-size: 11px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.shop-item strong { font-size: 18px; margin: 2px 0 7px; }
.shop-item > span:nth-of-type(3) { color: var(--muted); font-size: 13px; flex: 1; }
.shop-action { margin-top: 14px; padding: 6px 9px; border-radius: 8px; background: #f1ebf7; color: #694398; font-size: 12px; font-weight: 800; }
.shop-item.selected .shop-action { background: #7c4db0; color: white; }
.celebration {
  margin: 14px 0; padding: 11px 16px; display: flex; justify-content: center; align-items: center; gap: 12px;
  border: 1px solid #ecd17d; border-radius: 12px; background: #fff7d8; color: #624900;
  animation: reward-pop .35s ease-out;
}
.celebration span { font-size: 22px; }
@keyframes reward-pop { from { transform: scale(.97); opacity: .2; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 950px) {
  .sanctuary-grid { grid-template-columns: repeat(3,1fr); }
  .shop-grid { grid-template-columns: repeat(2,1fr); }
  .reward-banner { grid-template-columns: 130px 1fr; }
  .reward-banner > .btn { grid-column: 1 / -1; }
  .reward-banner .animal-stage { width: 130px; }
}
@media (max-width: 700px) {
  .reward-home-strip, .shop-hero { grid-template-columns: 1fr; }
  .reward-home-animals { order: 3; }
  .shop-hero .animal-stage { width: 100%; }
  .sanctuary-grid { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 520px) {
  .level-card { grid-template-columns: 72px 1fr; }
  .sanctuary-grid, .shop-grid { grid-template-columns: 1fr; }
  .reward-banner { grid-template-columns: 1fr; text-align: center; }
  .reward-banner .animal-stage { width: 100%; }
}
