:root {
  color-scheme: dark;
  --ink: #061117;
  --ink-2: #0a2026;
  --paper: #e7f3ed;
  --muted: #8bb0ac;
  --jade: #7de0c3;
  --jade-2: #2fa58e;
  --ice: #8edcff;
  --gold: #eacb76;
  --red: #e65d55;
  --line: rgba(153, 218, 202, .22);
  --glass: rgba(5, 22, 27, .78);
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--ink); }

body {
  color: var(--paper);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  user-select: none;
}

button, a { font: inherit; }

#app { position: relative; width: 100%; height: 100%; isolation: isolate; background: #07161a; }

#game-canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

.hidden, [hidden] { display: none !important; }

.glass {
  background: linear-gradient(145deg, rgba(10, 35, 40, .9), rgba(3, 15, 20, .75));
  border: 1px solid var(--line);
  box-shadow: 0 12px 35px rgba(0, 0, 0, .32), inset 0 1px rgba(255, 255, 255, .04);
  backdrop-filter: blur(9px);
}

.glass-heavy {
  background:
    linear-gradient(135deg, rgba(10, 35, 39, .97), rgba(3, 13, 19, .96)),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(255, 255, 255, .014) 3px 4px);
  border: 1px solid rgba(151, 224, 202, .28);
  box-shadow: 0 35px 110px rgba(0, 0, 0, .65), inset 0 1px rgba(255, 255, 255, .05);
  backdrop-filter: blur(14px);
}

.hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; padding: max(16px, env(safe-area-inset-top)) 18px max(16px, env(safe-area-inset-bottom)); }
.hud-top { display: grid; grid-template-columns: minmax(235px, 300px) minmax(240px, 400px) minmax(200px, 280px); justify-content: space-between; align-items: start; gap: 14px; }
.hero-panel, .wave-panel, .run-panel { border-radius: 12px; min-height: 78px; }
.hero-panel { display: flex; gap: 11px; align-items: center; padding: 8px 12px 8px 7px; }
.hero-portrait { width: 63px; height: 63px; flex: 0 0 auto; border: 1px solid rgba(125, 224, 195, .24); border-radius: 9px; background-color: rgba(4, 14, 18, .85); background-image: url("assets/characters/nie-feng-sheet.png"); background-repeat: no-repeat; background-size: 256px 384px; background-position: 0 0; image-rendering: pixelated; }
.hero-copy { min-width: 0; flex: 1; }
.hero-copy strong, .wave-panel strong { display: block; font-family: KaiTi, STKaiti, serif; font-size: 22px; letter-spacing: .08em; }
.eyebrow, .title-kicker { color: var(--jade); font-size: 10px; font-weight: 900; letter-spacing: .22em; text-transform: uppercase; }
.hero-copy small, .wave-panel small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.wave-panel { padding: 10px 15px; text-align: center; }
.wave-panel strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-panel { display: grid; grid-template-columns: repeat(3, 1fr); padding: 12px 8px; }
.run-panel span { display: flex; min-width: 0; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid var(--line); }
.run-panel span:last-child { border: 0; }
.run-panel b { font-variant-numeric: tabular-nums; color: #eafef7; font-size: 16px; }
.run-panel small { margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .14em; }

.bar { position: relative; height: 7px; margin-top: 5px; overflow: hidden; border-radius: 999px; background: rgba(0, 0, 0, .55); box-shadow: inset 0 1px 3px #000; }
.bar i { display: block; width: 100%; height: 100%; border-radius: inherit; transition: width .16s ease; }
.bar.hp i { background: linear-gradient(90deg, #45af78, #91e0a7); box-shadow: 0 0 10px #55c98a; }
.bar.progress i { background: linear-gradient(90deg, #4bacc7, #9be2ef); box-shadow: 0 0 10px #69c9dd; }
.bar.boss { height: 10px; }
.bar.boss i { background: linear-gradient(90deg, #b63b45, #ed7a62, #f0c66c); box-shadow: 0 0 14px #dc5d55; }

.boss-panel { position: absolute; top: 112px; left: 50%; width: min(540px, 58vw); padding: 9px 13px 11px; border-radius: 11px; transform: translateX(-50%); }
.boss-panel > div:first-child { display: flex; justify-content: space-between; color: #f0e5d2; font-size: 11px; font-weight: 800; letter-spacing: .08em; }
#boss-phase { color: var(--gold); }
#app[data-wave="11"] .boss-panel { border-color: rgba(224, 57, 68, .46); background: linear-gradient(145deg, rgba(53, 8, 17, .92), rgba(17, 3, 9, .82)); }
#app[data-wave="11"] .bar.boss i { background: linear-gradient(90deg, #8d0d20, #e02d3d, #ff776f); box-shadow: 0 0 16px rgba(244, 42, 60, .8); }
#app[data-wave="11"][data-boss-phase="2"] .boss-panel { border-color: rgba(255, 69, 79, .78); box-shadow: 0 0 32px rgba(208, 13, 38, .24), inset 0 1px rgba(255, 210, 202, .08); }
#app[data-wave="11"][data-boss-phase="2"] #boss-phase { color: #ff8e83; text-shadow: 0 0 12px rgba(255, 44, 62, .72); }
#app[data-wave="11"][data-boss-state="transforming"] .boss-panel { border-color: rgba(255, 98, 100, .92); background: linear-gradient(145deg, rgba(78, 4, 18, .96), rgba(12, 0, 5, .92)); animation: sword-awakening-hud .62s ease-in-out infinite alternate; }
#app[data-wave="11"][data-boss-state="transforming"] #boss-phase { color: #ffe0d3; text-shadow: 0 0 15px rgba(255, 38, 59, .9); }
#app[data-wave="11"][data-boss-state="transforming"] .skill { opacity: .58; filter: saturate(.55); }

.hud-bottom { position: absolute; right: 18px; bottom: max(16px, env(safe-area-inset-bottom)); left: 18px; display: flex; justify-content: space-between; align-items: end; gap: 14px; }
.controls-hint { display: flex; gap: 13px; padding: 9px 12px; border-radius: 10px; color: var(--muted); font-size: 10px; }
kbd { padding: 2px 5px; border: 1px solid rgba(255, 255, 255, .18); border-bottom-width: 2px; border-radius: 4px; background: rgba(255, 255, 255, .06); color: #dff8ef; font-size: 9px; }
.skills { display: flex; gap: 9px; }
.skill { position: relative; width: 154px; height: 58px; overflow: hidden; border-radius: 11px; padding: 9px 10px 8px 48px; }
.skill .key { position: absolute; left: 9px; top: 10px; display: grid; width: 31px; height: 31px; place-items: center; border: 1px solid rgba(255, 255, 255, .22); border-radius: 7px; color: var(--gold); font-size: 8px; font-weight: 900; }
.skill b, .skill small { position: relative; z-index: 2; display: block; }
.skill b { white-space: nowrap; font-family: KaiTi, STKaiti, serif; font-size: 14px; }
.skill small { margin-top: 4px; color: var(--muted); font-size: 9px; }
.skill > i { position: absolute; z-index: 1; right: 0; bottom: 0; left: 0; height: 0%; background: rgba(2, 6, 9, .68); transition: height .1s linear; }
.skill.ready { border-color: rgba(234, 203, 118, .45); box-shadow: 0 0 22px rgba(234, 203, 118, .12); }

.screen { position: absolute; inset: 0; z-index: 30; display: none; place-items: center; padding: 24px; background: rgba(1, 8, 12, .68); }
.screen.active { display: grid; }
.loading-screen { z-index: 70; }
#loading-screen { background: radial-gradient(circle, #12333c, #061217 58%); }
.loading-mark, .seal { display: grid; place-items: center; border: 2px solid currentColor; color: var(--jade); font-family: KaiTi, STKaiti, serif; transform: rotate(-5deg); }
.loading-mark { width: 78px; height: 78px; margin: auto; font-size: 52px; animation: breathe 1.5s ease-in-out infinite; }
#loading-screen p { color: var(--muted); font-size: 12px; letter-spacing: .18em; }

#start-screen { overflow: hidden; overscroll-behavior: none; background: radial-gradient(circle at 50% 44%, rgba(24, 74, 77, .45), rgba(3, 10, 14, .93) 62%); }
.start-backdrop { position: absolute; inset: -15%; contain: paint; pointer-events: none; opacity: .22; background: repeating-conic-gradient(from 20deg at 50% 50%, transparent 0 10deg, rgba(125, 224, 195, .12) 10deg 11deg); animation: slow-spin 60s linear infinite; }
.start-card, .choice-card, .end-card, .pause-card { position: relative; width: min(900px, 94vw); border-radius: 22px; text-align: center; }
.start-card { max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); margin: 0; padding: 30px 42px 26px; overflow-y: auto; overscroll-behavior: contain; overflow-anchor: none; scrollbar-gutter: stable; scroll-behavior: auto; }
.seal { width: 58px; height: 58px; margin: 0 auto 13px; border-color: rgba(125, 224, 195, .75); font-size: 37px; }
.start-card h1, .choice-card h2, .end-card h2, .pause-card h2 { margin: 4px 0; font-family: KaiTi, STKaiti, serif; font-weight: 900; letter-spacing: .12em; }
.start-card h1 { font-size: clamp(44px, 7vw, 82px); line-height: .95; text-shadow: 0 5px 32px rgba(74, 215, 193, .22); }
.subtitle { margin: 8px 0 18px; color: var(--gold); font-family: KaiTi, STKaiti, serif; font-size: 19px; letter-spacing: .7em; text-indent: .7em; }
.story { width: min(680px, 100%); margin: 0 auto 20px; color: #bad1cb; font-family: KaiTi, STKaiti, serif; font-size: 15px; line-height: 1.8; }
.journey { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 5px 8px; width: min(790px, 100%); margin: 0 auto 18px; color: #8cafaa; font-size: 10px; }
.journey i { color: rgba(234, 203, 118, .45); font-style: normal; }
.journey b { color: var(--gold); }
.test-mode-control { display: flex; width: min(610px, 100%); margin: 0 auto 15px; padding: 9px 12px; align-items: center; justify-content: center; gap: 18px; border: 1px solid var(--line); border-radius: 10px; background: rgba(4, 18, 23, .62); transition: border-color .18s, background .18s, box-shadow .18s; }
.test-mode-control.enabled { border-color: rgba(234, 203, 118, .4); background: rgba(13, 35, 38, .82); box-shadow: 0 0 24px rgba(125, 224, 195, .07); }
.test-mode-toggle { position: relative; display: flex; align-items: center; gap: 9px; cursor: pointer; text-align: left; }
.test-mode-toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.test-mode-switch { position: relative; width: 38px; height: 21px; flex: 0 0 auto; border: 1px solid rgba(139, 176, 172, .4); border-radius: 999px; background: rgba(139, 176, 172, .16); transition: border-color .18s, background .18s; }
.test-mode-switch i { position: absolute; top: 3px; left: 3px; width: 13px; height: 13px; border-radius: 50%; background: #839f9b; box-shadow: 0 2px 6px rgba(0, 0, 0, .4); transition: transform .18s, background .18s; }
#test-mode-checkbox:checked + .test-mode-switch { border-color: rgba(125, 224, 195, .72); background: rgba(47, 165, 142, .55); }
#test-mode-checkbox:checked + .test-mode-switch i { background: #e5fff6; transform: translateX(17px); }
#test-mode-checkbox:focus-visible + .test-mode-switch { outline: 2px solid var(--gold); outline-offset: 3px; }
.test-mode-copy b, .test-mode-copy small { display: block; }
.test-mode-copy b { color: var(--jade); font-size: 11px; letter-spacing: .12em; }
.test-mode-copy small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.test-wave-field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 9px; transition: opacity .18s; }
.test-wave-field select { max-width: 230px; padding: 7px 28px 7px 9px; border: 1px solid rgba(125, 224, 195, .36); border-radius: 7px; outline: 0; background: #071b21; color: var(--paper); cursor: pointer; font-size: 10px; }
.test-wave-field select:focus-visible { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(234, 203, 118, .13); }
.test-mode-control:not(.enabled) .test-wave-field { opacity: .38; }
.test-wave-field select:disabled { cursor: default; }
.primary-button { min-width: 180px; padding: 13px 28px; cursor: pointer; border: 1px solid rgba(161, 232, 210, .45); border-radius: 9px; background: linear-gradient(135deg, #217c70, #18525a); box-shadow: 0 12px 30px rgba(0, 0, 0, .35), inset 0 1px rgba(255, 255, 255, .12); color: white; font-weight: 900; letter-spacing: .16em; transition: transform .15s, filter .15s; }
.primary-button:hover { transform: translateY(-2px); filter: brightness(1.16); }
.primary-button:active { transform: translateY(1px); }
.secondary-button { min-width: 150px; padding: 11px 22px; cursor: pointer; border: 1px solid rgba(142, 220, 255, .32); border-radius: 9px; background: rgba(7, 28, 34, .82); color: #b9e7ed; font-weight: 800; letter-spacing: .1em; transition: transform .15s, border-color .15s, background .15s; }
.secondary-button:hover, .secondary-button:focus-visible { outline: 0; transform: translateY(-2px); border-color: rgba(234, 203, 118, .62); background: rgba(15, 48, 53, .9); }
.start-help { margin: 13px 0 0; color: #648581; font-size: 10px; }

.choice-card { padding: 30px 35px 27px; }
.choice-card h2, .end-card h2 { font-size: 42px; }
.choice-card > p:not(.title-kicker) { color: var(--muted); }
.upgrade-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; margin: 22px 0 17px; }
.upgrade-option { position: relative; min-height: 205px; padding: 22px 18px; cursor: pointer; border: 1px solid rgba(137, 207, 190, .22); border-radius: 14px; background: linear-gradient(155deg, rgba(22, 61, 63, .88), rgba(5, 19, 25, .95)); color: var(--paper); text-align: left; transition: transform .16s, border-color .16s, box-shadow .16s; }
.upgrade-option:hover, .upgrade-option:focus-visible { outline: 0; transform: translateY(-5px); border-color: rgba(234, 203, 118, .65); box-shadow: 0 18px 35px rgba(0, 0, 0, .32), 0 0 26px rgba(234, 203, 118, .1); }
.upgrade-option .number { position: absolute; top: 10px; right: 12px; color: rgba(234, 203, 118, .55); font-size: 11px; }
.upgrade-option .icon { display: block; margin-bottom: 14px; color: var(--gold); font-family: KaiTi, STKaiti, serif; font-size: 42px; }
.upgrade-option b { display: block; font-family: KaiTi, STKaiti, serif; font-size: 22px; }
.upgrade-option em { display: block; margin: 7px 0 12px; color: var(--jade); font-size: 10px; font-style: normal; letter-spacing: .16em; }
.upgrade-option p { margin: 0; color: #a8c3be; font-size: 12px; line-height: 1.65; }

.end-card { width: min(660px, 92vw); padding: 34px 38px 31px; }
.end-copy { color: #b8cfca; font-family: KaiTi, STKaiti, serif; font-size: 16px; line-height: 1.8; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 20px 0; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; }
.result-stats span { padding: 11px 6px; border-right: 1px solid var(--line); }
.result-stats span:last-child { border: 0; }
.result-stats b, .result-stats small { display: block; }
.result-stats b { color: var(--gold); font-size: 18px; }
.result-stats small { margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .12em; }
.victory-links { margin: 17px 0 22px; }
.victory-links p { color: var(--jade); font-size: 11px; letter-spacing: .16em; }
.victory-links a { display: inline-block; margin: 4px; padding: 8px 13px; border: 1px solid rgba(234, 203, 118, .35); border-radius: 7px; color: #f6dda0; text-decoration: none; }
.victory-links a:hover { background: rgba(234, 203, 118, .1); }
.end-actions { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px; }
.pause-screen { z-index: 45; background: rgba(1, 8, 12, .76); }
.pause-card { width: min(360px, 90vw); padding: 32px; }
.pause-card h2 { font-size: 34px; }
.pause-card p { color: var(--muted); }

.wave-banner { position: absolute; z-index: 25; top: 28%; left: 50%; display: flex; width: min(620px, 88vw); padding: 24px 25px; flex-direction: column; align-items: center; pointer-events: none; border-top: 1px solid rgba(234, 203, 118, .4); border-bottom: 1px solid rgba(234, 203, 118, .4); background: linear-gradient(90deg, transparent, rgba(4, 17, 22, .9) 17%, rgba(4, 17, 22, .9) 83%, transparent); opacity: 0; transform: translate(-50%, -12px); }
.wave-banner.show { animation: banner-in 2.7s ease both; }
.wave-banner span { color: var(--jade); font-size: 10px; font-weight: 900; letter-spacing: .32em; }
.wave-banner strong { margin: 3px 0; font-family: KaiTi, STKaiti, serif; font-size: clamp(30px, 5vw, 52px); letter-spacing: .12em; }
.wave-banner small { color: var(--gold); font-family: KaiTi, STKaiti, serif; }

.sound-button { position: absolute; z-index: 55; right: 17px; top: 104px; display: grid; width: 34px; height: 34px; place-items: center; cursor: pointer; border: 1px solid rgba(142, 220, 255, .28); border-radius: 50%; background: rgba(5, 21, 27, .82); color: var(--ice); }
.sound-button.muted { color: #60777a; }
.toast { position: absolute; z-index: 60; top: 165px; left: 50%; padding: 9px 15px; pointer-events: none; border: 1px solid rgba(234, 203, 118, .25); border-radius: 999px; background: rgba(3, 14, 18, .88); color: #f4e5bd; font-size: 11px; opacity: 0; transform: translate(-50%, -7px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.fan-note { position: absolute; z-index: 9; right: 20px; bottom: 4px; color: rgba(174, 206, 197, .28); font-size: 8px; pointer-events: none; }

@keyframes breathe { 50% { transform: rotate(-5deg) scale(1.07); filter: drop-shadow(0 0 20px rgba(125, 224, 195, .38)); } }
@keyframes slow-spin { to { transform: rotate(360deg); } }
@keyframes banner-in { 0% { opacity: 0; transform: translate(-50%, -24px) scale(.94); } 14%, 78% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, 18px) scale(1.02); } }
@keyframes sword-awakening-hud { from { box-shadow: 0 0 20px rgba(208, 13, 38, .24), inset 0 1px rgba(255, 210, 202, .08); } to { box-shadow: 0 0 42px rgba(255, 24, 53, .48), inset 0 1px rgba(255, 225, 216, .16); } }

@media (max-width: 820px) {
  .hud-top { grid-template-columns: 1fr 1fr; }
  .run-panel { display: none; }
  .controls-hint { display: none; }
  .hud-bottom { justify-content: flex-end; }
  .skill { width: 132px; }
  .boss-panel { top: 108px; width: min(520px, 82vw); }
  .start-card { padding: 28px 22px 24px; }
  .journey { max-height: 60px; overflow: hidden; }
}

@media (max-width: 560px) {
  .hud { padding: 9px; }
  .hud-top { grid-template-columns: 1fr; }
  .hero-panel { width: 195px; min-height: 65px; }
  .hero-portrait { width: 50px; height: 50px; background-size: 200px 300px; }
  .hero-copy strong { font-size: 17px; }
  .wave-panel { position: absolute; top: 0; right: 0; width: 160px; min-height: 65px; }
  .wave-panel strong { font-size: 15px; }
  .boss-panel { top: 82px; }
  .hud-bottom { right: 9px; bottom: 9px; left: 9px; }
  .skill { width: 117px; height: 52px; padding-left: 40px; }
  .skill .key { left: 6px; width: 28px; height: 28px; }
  .upgrade-options { grid-template-columns: 1fr; max-height: 60vh; overflow-y: auto; }
  .upgrade-option { min-height: 130px; }
  .upgrade-option .icon { float: left; margin: 0 14px 20px 0; }
  .choice-card { padding: 25px 18px; }
  .test-mode-control { align-items: stretch; flex-direction: column; gap: 8px; }
  .test-mode-toggle { justify-content: center; }
  .test-wave-field { justify-content: center; }
  .test-wave-field select { width: 100%; max-width: none; }
}

@media (max-height: 760px) {
  #start-screen { align-items: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  #app[data-wave="11"][data-boss-state="transforming"] .boss-panel { animation: none; box-shadow: 0 0 24px rgba(255, 24, 53, .34), inset 0 1px rgba(255, 225, 216, .12); }
}
