:root {
  --ink: #29262f;
  --muted: #716b76;
  --cream: #fff9ec;
  --paper: #fffdf6;
  --coral: #ff715f;
  --coral-dark: #df4e43;
  --mint: #9edfc0;
  --yellow: #ffd769;
  --violet: #a887e8;
  --line: rgba(41, 38, 47, 0.1);
  --shadow: 0 18px 50px rgba(83, 57, 44, 0.14);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: #f7f0df; color: var(--ink); }

body {
  font-family: "Noto Sans SC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 14%, rgba(255, 255, 255, .95) 0 3%, transparent 18%),
    radial-gradient(circle at 88% 80%, rgba(255, 215, 105, .16), transparent 27%),
    #f7f0df;
  overflow-x: hidden;
}

button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

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

.topbar {
  height: 84px;
  padding: 0 clamp(20px, 4vw, 68px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 246, .84);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 10;
}

.brand { appearance: none; border: 0; background: none; display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 0; }
.brand-mark { width: 45px; height: 45px; background: var(--coral); border-radius: 52% 48% 46% 54%; display: grid; place-items: center; transform: rotate(-8deg); box-shadow: inset 0 -5px 0 rgba(133, 35, 35, .13); position: relative; }
.brand-mark::after { content: ""; position: absolute; width: 22px; height: 12px; border-bottom: 3px solid #63352f; border-radius: 50%; bottom: 9px; left: 12px; transform: rotate(8deg); }
.brand-mark i { width: 5px; height: 6px; background: #63352f; border-radius: 50%; position: absolute; top: 13px; }
.brand-mark i:first-child { left: 12px; }
.brand-mark i:last-child { right: 12px; }
.brand > span:last-child { display: flex; flex-direction: column; align-items: flex-start; line-height: 1; }
.brand strong { font-size: 18px; font-weight: 800; }
.brand small { font: 700 9px/1.5 "Fredoka", sans-serif; letter-spacing: .25em; color: var(--coral-dark); }

.top-actions { display: flex; align-items: center; gap: 10px; }
.icon-button, .pause-button { border: 1px solid var(--line); background: var(--paper); border-radius: 50%; width: 44px; height: 44px; cursor: pointer; font: 700 20px/1 "Fredoka"; box-shadow: 0 5px 16px rgba(54, 43, 37, .08); }
.avatar-button { border: 1px solid var(--line); background: var(--paper); border-radius: 999px; display: flex; align-items: center; gap: 9px; height: 48px; padding: 4px 14px 4px 5px; font-size: 13px; font-weight: 800; cursor: pointer; box-shadow: 0 5px 16px rgba(54, 43, 37, .08); }
.mini-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--yellow) center/cover no-repeat; overflow: hidden; display: block; }

.play-stats { display: flex; gap: clamp(16px, 4vw, 54px); position: absolute; left: 50%; transform: translateX(-50%); }
.play-stats div { display: flex; align-items: baseline; gap: 8px; }
.play-stats span { color: var(--muted); font-size: 11px; font-weight: 700; }
.play-stats strong { font: 700 20px/1 "Fredoka", sans-serif; }
#shots-label { color: var(--coral); letter-spacing: 3px; font-size: 14px; }

.home-screen { max-width: 1380px; margin: 0 auto; min-height: calc(100vh - 84px); padding: clamp(44px, 7vh, 92px) clamp(24px, 6vw, 88px) 56px; display: grid; grid-template-columns: .9fr 1.1fr; gap: clamp(48px, 8vw, 120px); align-items: center; }
.hero-copy { max-width: 570px; }
.eyebrow { display: block; color: var(--coral-dark); font: 700 11px/1.2 "Fredoka", "Noto Sans SC"; letter-spacing: .18em; text-transform: uppercase; margin-bottom: 16px; }
.hero-copy h1 { font-size: clamp(52px, 6.5vw, 88px); line-height: .98; letter-spacing: -.06em; margin: 0 0 26px; font-weight: 800; }
.hero-copy h1 em { color: var(--coral); font-style: normal; display: inline-block; position: relative; transform: rotate(-8deg); text-shadow: 4px 5px 0 #ffd9c8; }
.hero-copy h1 em::after { content: ""; position: absolute; width: 18px; height: 18px; background: var(--yellow); border-radius: 4px 12px 5px 10px; right: -16px; top: -4px; transform: rotate(26deg); }
.hero-copy > p { color: var(--muted); font-size: clamp(14px, 1.3vw, 17px); line-height: 1.9; margin: 0 0 30px; }
.selected-card { width: min(100%, 430px); display: flex; align-items: center; gap: 15px; background: rgba(255,255,255,.62); border: 1px solid rgba(255,255,255,.9); padding: 9px 10px; border-radius: 22px; box-shadow: 0 13px 36px rgba(77, 53, 43, .09); }
.selected-art { width: 64px; height: 64px; border-radius: 17px; flex: 0 0 auto; background: #ffd8c5 center/cover no-repeat; }
.selected-card div { display: flex; flex-direction: column; flex: 1; }
.selected-card small { color: var(--muted); font-size: 10px; }
.selected-card strong { font-size: 18px; }
.selected-card span:last-child { color: var(--muted); font-size: 11px; }
.selected-card button { border: 0; background: var(--ink); color: white; border-radius: 13px; padding: 10px 15px; font-size: 12px; font-weight: 800; cursor: pointer; }

.level-section { background: rgba(255,253,246,.76); border: 1px solid rgba(255,255,255,.86); border-radius: 38px; padding: clamp(24px, 4vw, 44px); box-shadow: var(--shadow); }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 34px; }
.section-heading span { color: var(--coral-dark); font: 700 10px "Fredoka"; letter-spacing: .18em; }
.section-heading h2 { margin: 3px 0 0; font-size: 29px; }
.section-heading p { color: var(--muted); margin: 0; font: 600 13px "Fredoka", sans-serif; }
.section-heading b { color: var(--ink); font-size: 22px; }
.level-map { display: grid; gap: 28px; }
.chapter-block { display: grid; gap: 13px; }
.chapter-block + .chapter-block { border-top: 1px dashed rgba(41,38,47,.16); padding-top: 24px; }
.chapter-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.chapter-heading div { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 10px; }
.chapter-heading span { grid-column: 1 / -1; color: var(--coral-dark); font: 700 9px "Fredoka"; letter-spacing: .16em; }
.chapter-heading strong { font-size: 18px; }
.chapter-heading small { color: var(--muted); font-size: 10px; }
.chapter-heading b { color: var(--muted); font: 600 11px "Fredoka"; white-space: nowrap; }
.chapter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; }
.level-card { min-height: 135px; border: 1px solid var(--line); background: rgba(255,255,255,.68); border-radius: 23px; padding: 16px; position: relative; text-align: left; cursor: pointer; overflow: hidden; transition: transform .2s, box-shadow .2s, border-color .2s; }
.level-card:not(:disabled):hover { transform: translateY(-4px); box-shadow: 0 14px 30px rgba(59, 42, 35, .12); border-color: rgba(255,113,95,.35); }
.level-card:disabled { cursor: not-allowed; filter: grayscale(.5); opacity: .62; }
.level-number { display: block; color: var(--coral-dark); font: 700 11px "Fredoka"; letter-spacing: .08em; margin-bottom: 33px; }
.level-card strong { display: block; font-size: 15px; position: relative; z-index: 1; }
.level-card small { color: #b6aeb1; font-size: 16px; letter-spacing: 2px; }
.level-card small.filled { color: #f5af35; }
.level-orbit { position: absolute; width: 64px; height: 64px; right: -12px; top: -9px; border: 2px solid rgba(41,38,47,.09); border-radius: 50%; }
.level-orbit::before, .level-orbit::after { content: ""; position: absolute; border-radius: 50%; background: var(--level-color, var(--coral)); }
.level-orbit::before { width: 28px; height: 28px; left: -8px; top: 20px; box-shadow: inset 0 -5px 0 rgba(70,40,40,.1); }
.level-orbit::after { width: 9px; height: 9px; right: 2px; bottom: 6px; }
.level-lock { position: absolute; right: 18px; top: 17px; font-size: 14px; }
.tip-card { display: flex; align-items: center; gap: 13px; border-top: 1px dashed rgba(41,38,47,.15); margin-top: 25px; padding-top: 19px; }
.tip-card span { background: var(--yellow); color: #5c481e; border-radius: 8px; padding: 5px 7px; font: 700 9px "Fredoka"; }
.tip-card p { margin: 0; color: var(--muted); font-size: 11px; }

.game-screen { height: calc(100vh - 84px); background: #d8f2df; display: grid; place-items: center; padding: 18px; }
.game-frame { aspect-ratio: 16/9; width: min(100%, calc((100vh - 120px) * 16/9)); position: relative; border-radius: 30px; overflow: hidden; background: #bcebd9; box-shadow: 0 20px 55px rgba(37, 85, 68, .18); border: 5px solid rgba(255,255,255,.85); }
#game-canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#game-canvas.dragging { cursor: grabbing; }
.pause-button { position: absolute; right: 18px; top: 18px; background: rgba(255,255,255,.78); backdrop-filter: blur(7px); }
.level-intro { position: absolute; inset: 0; background: rgba(38, 40, 48, .56); color: white; display: grid; place-content: center; text-align: center; transition: opacity .35s, visibility .35s; pointer-events: none; backdrop-filter: blur(3px); }
.level-intro.hidden { opacity: 0; visibility: hidden; }
.level-intro span { font: 700 11px "Fredoka"; letter-spacing: .22em; color: #ffe07f; }
.level-intro strong { font-size: clamp(28px, 4vw, 54px); margin: 8px 0; }
.level-intro p { margin: 0; opacity: .8; }
.level-intro small { margin-top: 12px; color: #ffe9a5; font-size: 11px; letter-spacing: .03em; }
.module-panel { position: absolute; left: 18px; top: 18px; z-index: 4; width: min(310px, 35%); padding: 10px 12px 9px; border: 1px solid rgba(255,255,255,.62); border-radius: 18px; background: rgba(41,38,47,.78); color: white; backdrop-filter: blur(9px); transition: opacity .2s; }
.module-label { display: block; margin-bottom: 7px; color: #ffe07f; font: 700 9px "Fredoka"; letter-spacing: .14em; }
.module-options { display: flex; gap: 7px; }
.module-button { min-width: 0; flex: 1; border: 1px solid rgba(255,255,255,.18); border-radius: 12px; background: rgba(255,255,255,.08); color: white; padding: 6px 7px; cursor: pointer; display: flex; align-items: center; gap: 6px; text-align: left; }
.module-button span { flex: 0 0 auto; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.12); color: #ffe07f; font-size: 15px; }
.module-button strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.module-button.selected { border-color: #ffe07f; background: rgba(255,224,127,.17); }
.module-button.spent { opacity: .5; filter: grayscale(.7); }
.module-panel p { margin: 7px 0 0; color: rgba(255,255,255,.75); font-size: 9px; line-height: 1.45; }
.module-panel.locked .module-button { cursor: not-allowed; }
.module-panel.used p::after { content: " · 本发已使用"; color: #ffe07f; }
.game-hint { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 9px; background: rgba(41,38,47,.82); color: white; border-radius: 999px; padding: 10px 16px; font-size: 11px; pointer-events: none; transition: opacity .3s; }
.game-hint i { width: 8px; height: 8px; background: var(--yellow); border-radius: 50%; box-shadow: 10px 0 0 rgba(255,215,105,.55), 20px 0 0 rgba(255,215,105,.25); margin-right: 20px; }
.game-hint.hidden { opacity: 0; }

.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(42, 36, 40, .48); backdrop-filter: blur(9px); display: grid; place-items: center; padding: 24px; }
.modal { width: min(660px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: var(--paper); border-radius: 30px; padding: 35px; box-shadow: 0 30px 100px rgba(46, 31, 32, .25); position: relative; }
.modal-close { position: absolute; right: 20px; top: 17px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: #f2ede4; font-size: 22px; cursor: pointer; }
.modal h2 { margin: 0 0 7px; font-size: 30px; }
.modal > p { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.avatar-choice { border: 2px solid transparent; background: #f6f1e7; border-radius: 20px; padding: 10px 8px 12px; cursor: pointer; text-align: center; transition: .2s; }
.avatar-choice:hover { transform: translateY(-3px); }
.avatar-choice.selected { border-color: var(--coral); background: #fff1e9; }
.avatar-choice span { display: block; aspect-ratio: 1; border-radius: 16px; margin-bottom: 7px; background: var(--avatar-bg, #ffd9cb) center/cover no-repeat; }
.avatar-choice strong { font-size: 13px; }
.avatar-choice small { display: block; font-size: 9px; color: var(--muted); margin-top: 2px; }
.upload-card { margin-top: 15px; min-height: 74px; border: 1.5px dashed rgba(41,38,47,.22); border-radius: 18px; display: grid; grid-template-columns: 42px 1fr; grid-template-rows: 1fr 1fr; column-gap: 10px; align-items: center; padding: 10px 16px; cursor: pointer; }
.upload-card input { display: none; }
.upload-card > span { grid-row: 1/3; width: 42px; height: 42px; display: grid; place-items: center; background: var(--mint); border-radius: 13px; font-size: 24px; }
.upload-card strong { align-self: end; font-size: 13px; }
.upload-card small { align-self: start; color: var(--muted); font-size: 9px; }

.crop-modal { width: min(500px, 100%); text-align: center; }
.crop-stage { width: min(320px, 72vw); aspect-ratio: 1; margin: 10px auto 18px; border-radius: 50%; overflow: hidden; box-shadow: 0 0 0 7px #fff, 0 0 0 9px var(--coral), 0 12px 30px rgba(50,30,30,.18); background: #eee; touch-action: none; }
#crop-canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.zoom-control { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 10px; max-width: 350px; margin: 0 auto 20px; }
.zoom-control input { flex: 1; accent-color: var(--coral); }
.primary-button, .secondary-button { border: 0; border-radius: 15px; min-height: 48px; padding: 0 24px; font-weight: 800; cursor: pointer; }
.primary-button { background: var(--coral); color: white; box-shadow: 0 7px 0 #d85045; }
.secondary-button { background: #eee9df; color: var(--ink); }
.crop-modal .primary-button { width: min(350px, 100%); }

.result-modal { width: min(450px, 100%); text-align: center; overflow: visible; }
.result-kicker { display: inline-block; background: var(--mint); color: #245e49; border-radius: 999px; padding: 6px 11px; font: 700 10px "Fredoka"; letter-spacing: .13em; }
.result-modal h2 { font-size: 36px; margin: 14px 0 4px; }
.result-stars { color: #f5af35; font-size: 45px; letter-spacing: 4px; text-shadow: 0 4px 0 rgba(161, 101, 27, .12); }
.result-criteria { display: grid; gap: 6px; max-width: 310px; margin: 13px auto 0; text-align: left; }
.result-criteria div { display: flex; align-items: center; gap: 9px; border-radius: 11px; padding: 7px 11px; background: #f3eee5; color: #9b9298; }
.result-criteria div.met { background: #edf8f1; color: #2f765c; }
.result-criteria span { color: #b9b0b3; }
.result-criteria .met span { color: #f2ad37; }
.result-criteria p { margin: 0; font-size: 11px; font-weight: 700; }
.result-score { margin: 13px auto 22px; display: flex; flex-direction: column; }
.result-score span { color: var(--muted); font-size: 10px; }
.result-score strong { font: 700 36px "Fredoka"; }
.result-score small { color: var(--muted); font-size: 10px; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 18px); z-index: 80; background: var(--ink); color: white; border-radius: 999px; padding: 10px 17px; font-size: 11px; opacity: 0; pointer-events: none; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.rotate-notice { display: none; }

@media (max-width: 880px) {
  .home-screen { grid-template-columns: 1fr; padding-top: 42px; }
  .hero-copy { max-width: none; }
  .hero-copy h1 { font-size: clamp(49px, 12vw, 76px); }
  .level-section { margin-bottom: 35px; }
  .play-stats { position: static; transform: none; margin-left: auto; }
  .play-stats div:first-child { display: none; }
}

@media (max-width: 600px) {
  .topbar { height: 70px; padding: 0 14px; }
  .brand strong { font-size: 15px; }
  .brand-mark { width: 39px; height: 39px; }
  .avatar-button > span:last-child, .icon-button { display: none; }
  .avatar-button { padding: 4px; border: 0; background: none; }
  .play-stats { gap: 12px; }
  .play-stats span { display: none; }
  .home-screen { min-height: calc(100vh - 70px); padding: 35px 16px; gap: 34px; }
  .level-section { border-radius: 28px; padding: 22px 16px; }
  .chapter-grid { grid-template-columns: repeat(2, 1fr); }
  .level-card { min-height: 120px; }
  .modal { padding: 30px 20px 24px; }
  .avatar-grid { grid-template-columns: repeat(2, 1fr); }
  .game-screen { height: calc(100vh - 70px); padding: 8px; }
  .game-frame { border-radius: 17px; border-width: 3px; }
  .module-panel { left: 8px; top: 8px; width: 42%; padding: 7px; }
  .module-label, .module-panel p { display: none; }
  .module-button { justify-content: center; padding: 4px; }
  .module-button strong { display: none; }
}

@media (orientation: portrait) and (max-width: 700px) {
  body.game-active .rotate-notice { display: flex; position: fixed; inset: 0; z-index: 100; background: var(--cream); align-items: center; justify-content: center; flex-direction: column; }
  .rotate-notice span { font-size: 42px; color: var(--coral); }
  .rotate-notice strong { font-size: 22px; }
  .rotate-notice small { color: var(--muted); margin-top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
