@import url('https://fonts.googleapis.com/css2?family=Ma+Shan+Zheng&family=Noto+Sans+SC:wght@400;500;600;700;800;900&display=swap');

:root {
  --ink: #282643;
  --muted: #716f87;
  --paper: #fffdf8;
  --purple: #6454e8;
  --purple-deep: #4233b8;
  --yellow: #ffc845;
  --green: #41bb7a;
  --red: #f06b6b;
  --blue: #55a8eb;
  --line: rgba(44, 39, 91, .10);
  --shadow: 0 20px 55px rgba(53, 44, 117, .15);
  --radius: 26px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--ink);
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 5% 5%, rgba(255,255,255,.95) 0 3%, transparent 21%),
    linear-gradient(145deg, #f6f1ff 0%, #edf9ff 52%, #fff8e5 100%);
}

button, input, select { font: inherit; }
button { border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 4px solid rgba(100, 84, 232, .25);
  outline-offset: 3px;
}

.app-shell { min-height: 100vh; padding: 22px clamp(16px, 3vw, 42px) 42px; }
.page { max-width: 1180px; margin: 0 auto; animation: pageIn .35s ease both; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: 17px;
  color: white;
  background: linear-gradient(145deg, #7768f2, #4a38c4);
  box-shadow: 0 8px 0 #372a99, 0 14px 28px rgba(70, 51, 192, .22);
  font-size: 27px;
  transform: rotate(-4deg);
}

.brand h1 { margin: 0; font-size: clamp(18px, 2.2vw, 26px); line-height: 1.15; }
.brand small { color: var(--muted); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.pill {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border-radius: 999px;
  background: rgba(255,255,255,.88);
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(60, 50, 115, .10);
  font-weight: 800;
  white-space: nowrap;
}
.pill.coin { color: #9a6500; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,.9);
  font-size: 20px;
  box-shadow: 0 8px 22px rgba(60, 50, 115, .10);
}

.hero {
  min-height: 440px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, .72fr);
  align-items: stretch;
  overflow: hidden;
  border: 7px solid rgba(255,255,255,.75);
  border-radius: 38px;
  background-image: linear-gradient(90deg, rgba(28, 33, 70, .82) 0%, rgba(38, 35, 90, .62) 45%, rgba(38,35,90,.08) 70%), url("assets/adventure-world.png");
  background-size: cover;
  background-position: center;
  box-shadow: var(--shadow);
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(30px, 6vw, 70px);
  color: white;
}
.eyebrow {
  margin: 0 0 14px;
  color: #ffe17f;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .14em;
}
.hero h2 {
  margin: 0;
  font-family: "Ma Shan Zheng", "Noto Sans SC", sans-serif;
  font-size: clamp(42px, 6.8vw, 76px);
  line-height: 1;
  text-shadow: 0 5px 0 rgba(37, 24, 104, .35);
}
.hero-copy > p:not(.eyebrow) { max-width: 480px; margin: 20px 0 26px; color: rgba(255,255,255,.86); font-weight: 600; line-height: 1.8; }

.primary-btn, .secondary-btn, .danger-btn {
  min-height: 52px;
  padding: 0 23px;
  border-radius: 17px;
  font-weight: 900;
  transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}
.primary-btn {
  color: #403000;
  background: linear-gradient(180deg, #ffdc65, #ffbd36);
  box-shadow: 0 7px 0 #d78812, 0 13px 26px rgba(79, 53, 0, .24);
}
.primary-btn:hover { transform: translateY(-2px); filter: brightness(1.04); }
.primary-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 #d78812; }
.secondary-btn { color: #5040ca; background: #f0edff; box-shadow: inset 0 0 0 2px rgba(100,84,232,.10); }
.danger-btn { color: #b43d3d; background: #fff0f0; }
.wide-btn { width: 100%; }

.hero-side { display: flex; align-items: flex-end; justify-content: center; padding: 36px 30px; }
.hero-card {
  width: min(100%, 310px);
  padding: 24px;
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 26px;
  background: rgba(255,255,255,.87);
  backdrop-filter: blur(15px);
  box-shadow: 0 18px 42px rgba(33, 28, 77, .18);
}
.hero-card-top { display: flex; align-items: center; gap: 14px; }
.hero-card h3 { margin: 0 0 3px; font-size: 19px; }
.hero-card p { margin: 0; color: var(--muted); font-size: 13px; }
.avatar {
  --avatar-color: #7562ed;
  position: relative;
  width: 70px;
  height: 70px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 5px solid white;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--avatar-color), #3b2fa9);
  box-shadow: 0 7px 18px rgba(60,48,143,.25);
  font-size: 36px;
}
.avatar.small { width: 48px; height: 48px; border-width: 3px; font-size: 25px; }
.avatar.cape { --avatar-color: #e86767; }
.avatar.crown { --avatar-color: #f0a527; }
.avatar.starlight { --avatar-color: #4c9fdc; }
.progress-label { display: flex; justify-content: space-between; margin: 20px 0 8px; color: var(--muted); font-size: 13px; font-weight: 700; }
.progress-track { height: 11px; overflow: hidden; border-radius: 999px; background: #e8e5f3; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #6b57e6, #a66aed); transition: width .45s ease; }

.home-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 20px; }
.menu-card {
  min-height: 122px;
  padding: 19px;
  text-align: left;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 23px;
  background: rgba(255,255,255,.76);
  box-shadow: 0 10px 30px rgba(53,44,117,.09);
  transition: transform .2s ease, background .2s ease;
}
.menu-card:hover { transform: translateY(-4px); background: white; }
.menu-card .menu-icon { display: block; margin-bottom: 13px; font-size: 27px; }
.menu-card strong { display: block; font-size: 16px; }
.menu-card small { color: var(--muted); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin: 24px 0; }
.section-head h2 { margin: 0; font-size: clamp(25px, 4vw, 38px); }
.section-head p { margin: 6px 0 0; color: var(--muted); }
.back-btn { background: transparent; color: var(--ink); font-weight: 800; padding: 10px 0; }

.map-panel {
  position: relative;
  min-height: 610px;
  overflow: hidden;
  padding: 32px;
  border: 7px solid rgba(255,255,255,.75);
  border-radius: 36px;
  background: linear-gradient(rgba(31, 29, 72, .10), rgba(31,29,72,.2)), url("assets/adventure-world.png") center / cover;
  box-shadow: var(--shadow);
}
.map-panel::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, transparent 50%, rgba(31,29,72,.32)); }
.level-grid { position: relative; z-index: 1; height: 540px; }
.level-node {
  --node-color: #57bd72;
  position: absolute;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border: 5px solid white;
  border-radius: 50%;
  color: white;
  background: var(--node-color);
  box-shadow: 0 7px 0 color-mix(in srgb, var(--node-color), #000 24%), 0 12px 24px rgba(24,21,67,.22);
  font-size: 19px;
  font-weight: 900;
  transition: transform .2s ease;
  transform: translate(-50%, -50%);
}
.level-node:hover:not(:disabled) { transform: translate(-50%, -56%) scale(1.07); }
.level-node:disabled { filter: grayscale(.9); opacity: .72; cursor: not-allowed; }
.level-node.boss { width: 72px; height: 72px; background: #8f57d5; font-size: 23px; }
.level-node.done::after { content: "★"; position: absolute; right: -6px; top: -10px; color: #ffd75e; text-shadow: 0 2px 0 #865c00; }
.zone-label {
  position: absolute;
  z-index: 2;
  padding: 8px 13px;
  border-radius: 12px;
  color: white;
  background: rgba(29, 27, 67, .65);
  backdrop-filter: blur(7px);
  font-weight: 800;
  pointer-events: none;
}
.zone-forest { left: 4%; top: 3%; }
.zone-desert { left: 35%; top: 7%; }
.zone-snow { left: 64%; top: 8%; }
.zone-castle { right: 3%; top: 3%; }

.battle-page { max-width: 1060px; }
.battle-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; margin-bottom: 15px; }
.battle-title { text-align: center; }
.battle-title small { display: block; color: var(--muted); font-weight: 700; }
.battle-title strong { font-size: 21px; }
.stat-cluster { display: flex; gap: 8px; }
.stat-cluster.right { justify-content: flex-end; }
.battle-arena {
  --arena-image: url("assets/adventure-world.png");
  position: relative;
  min-height: 590px;
  overflow: hidden;
  border: 7px solid rgba(255,255,255,.75);
  border-radius: 36px;
  background-image: linear-gradient(180deg, rgba(21,25,55,.05), rgba(21,25,55,.34)), var(--arena-image);
  background-size: cover;
  background-position: var(--arena-position, left center);
  box-shadow: var(--shadow);
}
.battle-arena::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 52%; background: linear-gradient(transparent, rgba(24,22,59,.45)); pointer-events: none; }
.battle-stage { min-height: 310px; display: flex; align-items: center; justify-content: space-around; padding: 34px 6% 8px; }
.fighter { position: relative; z-index: 1; text-align: center; transition: transform .2s ease; }
.fighter-sprite { font-size: clamp(75px, 10vw, 125px); filter: drop-shadow(0 14px 10px rgba(22,17,53,.25)); }
.monster .fighter-sprite { animation: monsterFloat 2.3s ease-in-out infinite; }
@keyframes monsterFloat { 50% { transform: translateY(-9px) rotate(2deg); } }
.fighter-label { display: inline-block; padding: 7px 13px; border-radius: 999px; color: white; background: rgba(31,28,69,.68); backdrop-filter: blur(8px); font-weight: 800; }
.hp-bar { width: 150px; height: 12px; margin: 9px auto 0; overflow: hidden; border: 2px solid rgba(255,255,255,.75); border-radius: 999px; background: rgba(49,39,70,.48); }
.hp-fill { height: 100%; background: linear-gradient(90deg, #ef6e72, #ffb24b); transition: width .35s ease; }
.hit { animation: hit .38s ease; }
.attack { animation: attack .42s ease; }
@keyframes hit { 25% { transform: translateX(15px) rotate(4deg); filter: brightness(1.8); } 55% { transform: translateX(-9px) rotate(-3deg); } }
@keyframes attack { 45% { transform: translateX(55px) scale(1.08); } }

.question-card {
  position: relative;
  z-index: 3;
  width: min(92%, 720px);
  min-height: 245px;
  margin: -6px auto 28px;
  padding: 22px clamp(18px, 4vw, 34px) 26px;
  text-align: center;
  border: 1px solid rgba(255,255,255,.75);
  border-radius: 28px;
  background: rgba(255,255,255,.91);
  backdrop-filter: blur(18px);
  box-shadow: 0 20px 50px rgba(27,22,69,.24);
}
.question-meta { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 700; }
.timer { color: #e05b5b; font-variant-numeric: tabular-nums; }
.equation { margin: 6px 0 17px; font-size: clamp(38px, 7vw, 58px); font-weight: 900; letter-spacing: .04em; }
.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 11px; }
.choice-btn {
  min-height: 58px;
  border: 2px solid #ded9f5;
  border-radius: 17px;
  color: #4d3ec3;
  background: #f7f5ff;
  font-size: 21px;
  font-weight: 900;
  transition: transform .16s ease, border-color .16s ease;
}
.choice-btn:hover { transform: translateY(-3px); border-color: #8e81ed; }
.answer-form { display: flex; gap: 10px; justify-content: center; }
.answer-input { width: min(230px, 60%); height: 60px; border: 3px solid #d8d3f3; border-radius: 17px; text-align: center; color: #4738bd; background: white; font-size: 25px; font-weight: 900; }
.feedback {
  min-height: 24px;
  margin-top: 13px;
  color: var(--muted);
  font-weight: 700;
}
.feedback.correct { color: #228451; }
.feedback.wrong { color: #c44949; }

.panel-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 17px; }
.panel, .stat-card {
  padding: 24px;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: var(--radius);
  background: rgba(255,255,255,.78);
  box-shadow: 0 12px 35px rgba(53,44,117,.09);
}
.panel h3 { margin: 0 0 15px; }
.stat-card strong { display: block; margin-top: 10px; font-size: 32px; }
.stat-card small { color: var(--muted); font-weight: 700; }
.stat-icon { font-size: 27px; }
.list { display: grid; gap: 10px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px; border-radius: 16px; background: rgba(244,242,252,.85); }
.list-item strong { font-size: 18px; }
.list-item small { display: block; color: var(--muted); }
.empty { padding: 45px 20px; text-align: center; color: var(--muted); }
.empty-icon { display: block; margin-bottom: 10px; font-size: 46px; }

.shop-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
.shop-item { padding: 22px 16px; text-align: center; border-radius: 24px; background: rgba(255,255,255,.8); box-shadow: 0 12px 35px rgba(53,44,117,.09); }
.shop-item .avatar { margin: 0 auto 14px; }
.shop-item h3 { margin: 0 0 4px; }
.shop-item p { min-height: 40px; margin: 0 0 15px; color: var(--muted); font-size: 13px; }
.shop-item button { width: 100%; min-height: 44px; border-radius: 14px; color: white; background: var(--purple); font-weight: 800; }
.shop-item button:disabled { background: #d4d1df; color: #878491; cursor: default; }

.settings-card { max-width: 660px; margin: 0 auto; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 19px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border: 0; }
.setting-row strong { display: block; }
.setting-row small { color: var(--muted); }
.select { min-height: 44px; padding: 0 12px; border: 2px solid #e0dcf2; border-radius: 13px; color: var(--ink); background: white; }
.switch { position: relative; width: 54px; height: 31px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: #cfccd8; transition: .25s ease; }
.switch span::before { content: ""; position: absolute; left: 4px; top: 4px; width: 23px; height: 23px; border-radius: 50%; background: white; transition: .25s ease; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(23px); }

.modal-wrap { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(29,25,61,.55); backdrop-filter: blur(8px); }
.modal { width: min(100%, 480px); padding: 30px; border-radius: 30px; background: var(--paper); box-shadow: 0 30px 90px rgba(21,18,55,.35); animation: pop .28s ease; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.modal h2 { margin: 0 0 8px; font-size: 29px; }
.modal > p { margin: 0 0 20px; color: var(--muted); line-height: 1.7; }
.name-input { width: 100%; height: 56px; margin-bottom: 16px; padding: 0 17px; border: 2px solid #ded9f4; border-radius: 16px; background: white; }
.result-stars { margin: 10px 0; color: #ffbd2e; font-size: 40px; letter-spacing: 5px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 20px 0; }
.result-stat { padding: 13px 7px; border-radius: 15px; background: #f2effb; text-align: center; }
.result-stat strong { display: block; font-size: 19px; }
.result-stat small { color: var(--muted); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions > * { flex: 1; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: 28px; max-width: calc(100% - 30px); padding: 13px 20px; border-radius: 999px; color: white; background: #302b58; box-shadow: 0 12px 32px rgba(23,19,54,.3); font-weight: 800; opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: .25s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.confetti-layer { position: fixed; inset: 0; z-index: 90; overflow: hidden; pointer-events: none; }
.confetti { position: absolute; top: -20px; width: 10px; height: 18px; border-radius: 2px; animation: fall 1.8s linear forwards; }
@keyframes fall { to { transform: translate3d(var(--drift), 110vh, 0) rotate(680deg); } }

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

@media (max-width: 850px) {
  .hero { grid-template-columns: 1fr; min-height: 560px; }
  .hero-side { align-items: flex-end; justify-content: flex-start; padding-top: 0; }
  .home-grid, .shop-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid { grid-template-columns: 1fr 1fr; }
  .map-panel { min-height: 650px; padding: 18px; background-position: center; }
  .level-grid { height: 590px; }
  .zone-label { display: none; }
  .battle-stage { min-height: 300px; }
}

@media (max-width: 620px) {
  .app-shell { padding: 12px 12px 28px; }
  .topbar { margin-bottom: 14px; }
  .brand small { display: none; }
  .brand-mark { width: 43px; height: 43px; border-radius: 14px; font-size: 23px; }
  .top-actions .player-pill { display: none; }
  .hero { min-height: 610px; border-width: 4px; border-radius: 28px; background-position: 22% center; }
  .hero-copy { justify-content: flex-start; padding: 40px 24px 10px; }
  .hero-copy > p:not(.eyebrow) { margin: 16px 0 22px; }
  .hero-side { padding: 20px; }
  .home-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .menu-card { min-height: 112px; padding: 15px; }
  .section-head { align-items: flex-start; }
  .section-head .pill { display: none; }
  .map-panel { min-height: 570px; border-width: 4px; border-radius: 28px; background-position: center; }
  .level-grid { height: 520px; }
  .level-node { width: 53px; height: 53px; border-width: 4px; box-shadow: 0 6px 0 color-mix(in srgb, var(--node-color), #000 24%), 0 8px 16px rgba(24,21,67,.22); }
  .level-node.boss { width: 61px; height: 61px; }
  .battle-top { grid-template-columns: 1fr auto; }
  .battle-title { grid-column: 1 / -1; grid-row: 1; }
  .battle-top .stat-cluster:first-child { grid-row: 2; }
  .battle-top .stat-cluster.right { grid-row: 2; }
  .battle-arena { min-height: 610px; border-width: 4px; border-radius: 27px; }
  .battle-stage { min-height: 270px; padding-top: 28px; }
  .fighter-sprite { font-size: 75px; }
  .hp-bar { width: 110px; }
  .question-card { min-height: 290px; margin-bottom: 18px; padding: 18px 15px 22px; }
  .equation { margin: 10px 0 18px; }
  .choices { grid-template-columns: repeat(2, 1fr); }
  .panel-grid, .shop-grid { grid-template-columns: 1fr; }
  .result-stats { gap: 5px; }
  .modal { padding: 24px 20px; }
}

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