:root {
    color-scheme: dark;
    font-family: system-ui, "Microsoft YaHei", "PingFang SC", sans-serif;
    color: #f5e8c7;
    background: #111912;
    --ink: #182012;
    --gold: #ffd68c;
    --muted: #c4b99a;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    --safe-top: max(0.375rem, env(safe-area-inset-top));
    --safe-bottom: max(0.375rem, env(safe-area-inset-bottom));
    --usable-height: calc(100vh - var(--safe-top) - var(--safe-bottom));
    min-height: 100vh;
    margin: 0;
    display: grid;
    place-items: center;
    padding: var(--safe-top) env(safe-area-inset-right) var(--safe-bottom) env(safe-area-inset-left);
    background: radial-gradient(ellipse at 50% 15%, #2c3c26 0, #172018 51%, #101710 100%);
    overscroll-behavior: none;
}

@supports (height: 100dvh) {
    body {
        --usable-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
        min-height: 100dvh;
    }
}

.game-shell { width: min(100%, calc(var(--usable-height) * 0.5625), 31rem); }

.game-stage {
    position: relative;
    isolation: isolate;
    container-type: inline-size;
    aspect-ratio: 9 / 16;
    overflow: hidden;
    border-radius: clamp(0.45rem, 2vw, 1rem);
    background: #154422 url("./assets/field.png") center / 70%;
    box-shadow: 0 0 0 1px #a9aa6b3d, 0 1.25rem 4rem #080d08b8;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    user-select: none;
    -webkit-touch-callout: none;
}

canvas[inert] { pointer-events: none; }

.battle-impact {
    position: absolute;
    inset: 0;
    opacity: 0;
    background: radial-gradient(ellipse at center, transparent 53%, #971e305c 83%, #cd314fbf);
    pointer-events: none;
}

.touch-joystick {
    position: absolute;
    width: 76px;
    height: 76px;
    transform: translate(-50%, -50%);
    border: 1px solid #ffe4ac9c;
    border-radius: 50%;
    background: #17272180;
    box-shadow: 0 0 0 4px #17272166, inset 0 0 0 4px #f1cd793b;
    pointer-events: none;
}

.touch-joystick span {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    transform: translate(calc(-50% + var(--stick-x, 0px)), calc(-50% + var(--stick-y, 0px)));
    border: 1px solid #ffe9bdd9;
    border-radius: 50%;
    background: #ebcc899e;
    box-shadow: 0 2px 4px #101c1580;
}

:focus-visible { outline: 2px solid #f6d48d; outline-offset: 3px; }
canvas:focus-visible { outline-offset: -3px; }

.hud {
    position: absolute;
    inset: 0 0 auto;
    padding: clamp(0.45rem, 3.2cqw, 0.9rem);
    background: linear-gradient(#112016ec, #112016be 74%, transparent);
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}

.hud-heading {
    display: grid;
    align-items: start;
    grid-template-columns: 0.9fr minmax(0, 1.7fr) 0.9fr;
    gap: 0.375rem;
    text-shadow: 0 1px 2px #090f0a;
}

.hud-heading span, .meter-label {
    color: #e5d4ad;
    font-size: clamp(0.62rem, 3cqw, 0.8rem);
    line-height: 1.35;
}

.hud-heading strong { display: block; }

.hud-time strong, .hud-kills strong {
    color: #fff2cf;
    font-size: clamp(1.05rem, 6cqw, 1.75rem);
    line-height: 1.05;
    letter-spacing: -0.045em;
}

#round-timer[data-urgent="true"] { color: #ffb29b; }
.hud-kills { text-align: right; }
.hud-wave { align-self: center; text-align: center; }

.hud-wave strong {
    color: var(--gold);
    font-size: clamp(0.72rem, 3.8cqw, 1rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.meters { margin-top: 0.55rem; display: grid; gap: 0.375rem; }
.meter { --meter-fill: #91bb64; }
.meter--health { --meter-fill: #db7866; }
.meter--experience { --meter-fill: #e9be63; }

.meter-label {
    margin-bottom: 0.15rem;
    display: flex;
    justify-content: space-between;
    gap: 0.25rem;
}

.meter-label strong { color: #f9e9c4; }

progress {
    display: block;
    appearance: none;
    width: 100%;
    height: 0.34rem;
    overflow: hidden;
    border: 0;
    border-radius: 100vw;
    background: #171d15;
    color: var(--meter-fill);
    box-shadow: 0 0 0 1px #b6a7774d;
}

progress::-webkit-progress-bar { background: #171d15; }
progress::-webkit-progress-value { background: var(--meter-fill); border-radius: 100vw; }
progress::-moz-progress-bar { background: var(--meter-fill); border-radius: 100vw; }

.boss-hud {
    --meter-fill: #d87a5a;
    display: grid;
    grid-template: "name health" auto "meter meter" auto / minmax(0, 1fr) auto;
    gap: 0.3rem 0.55rem;
    margin-top: 0.55rem;
    padding: 0.42rem 0.48rem;
    border: 1px solid #d17e6369;
    border-radius: 0.4rem;
    background: #261715e6;
    color: #ffe3b8;
    font-size: clamp(0.67rem, 3.6cqw, 0.89rem);
    line-height: 1.22;
}

.boss-hud[data-charging="true"] {
    --meter-fill: #f3b172;
    border-color: #f3b172cf;
    box-shadow: inset 0 0 0.8rem #ef9a4d35;
}

#boss-name { grid-area: name; font-weight: 750; overflow-wrap: anywhere; }
#boss-health { grid-area: health; font-variant-numeric: tabular-nums; }
#boss-meter { grid-area: meter; height: 0.38rem; }

.boss-hud[data-charging="true"] #boss-name::after {
    display: inline-block;
    margin-inline-start: 0.4rem;
    color: #ffb984;
    content: "蓄力";
    font-size: 0.84em;
}

.battle-notice {
    width: fit-content;
    max-width: 95%;
    margin: 0.55rem auto 0;
    padding: 0.29rem 0.7rem;
    border: 1px solid #cba862a6;
    border-radius: 0.4rem;
    background: #202519ee;
    color: #ffdfa1;
    text-align: center;
    font-size: clamp(0.67rem, 3.7cqw, 0.95rem);
    font-weight: 720;
    overflow-wrap: anywhere;
}

.battle-notice[data-kind="boss"] {
    border-color: #f79578a6;
    background: #482322ee;
    color: #ffe2bb;
}

.game-stage[data-phase="choosing"] .battle-notice[data-kind="level"] { display: none; }

.skill-build {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin: 0.5rem 0 0;
    padding: 0;
    list-style: none;
}

.skill-build li {
    padding: 0.15rem 0.4rem;
    border: 1px solid #b6a7774d;
    border-radius: 0.3rem;
    color: #f9e9c4;
    background: #142117e3;
    font-size: clamp(0.6rem, 2.75cqw, 0.75rem);
}

.play-hint {
    position: absolute;
    inset: auto 0 clamp(0.55rem, 4cqw, 1rem);
    width: fit-content;
    max-width: 94%;
    margin: 0 auto;
    padding: 0.32rem 0.6rem;
    border-radius: 0.3rem;
    color: #fff1cd;
    background: #142117de;
    text-align: center;
    font-size: clamp(0.61rem, 3.15cqw, 0.85rem);
    pointer-events: none;
}

.keyboard-hint { display: none; }
@media (hover: hover) and (pointer: fine) {
    .touch-hint { display: none; }
    .keyboard-hint { display: inline; }
}

.overlay, .no-script {
    z-index: 2;
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: clamp(0.45rem, 5cqw, 1.35rem);
    background: linear-gradient(#111b11a6, #101b13ed);
    touch-action: manipulation;
}

.game-stage[data-phase="ready"] .overlay {
    background: radial-gradient(ellipse at 50% 35%, #253d2438, #0e1812af 65%, #0d1510);
}

.game-stage[data-phase="ready"] canvas { opacity: 0; }

.no-script { margin: 0; }

.panel {
    width: 100%;
    max-height: 100%;
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    text-align: center;
}

.panel--loading, .panel--start { padding: 0.375rem; }
.panel--loading { color: #f6e6c0; }
.panel--loading p { margin: 0.35rem 0; }
.panel--loading .action { margin-top: 0.7rem; }

.pause-button {
    position: absolute;
    right: 0.7rem;
    top: calc(100% + 0.25rem);
    pointer-events: auto;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid rgba(247, 210, 134, 0.38);
    border-radius: 0.55rem;
    background: rgba(19, 31, 23, 0.88);
    color: #f6e6c0;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.93rem;
    touch-action: manipulation;
}

.panel--pause {
    padding: 1.2rem;
    background: #202d21;
    border: 1px solid rgba(247, 210, 134, 0.42);
    border-radius: 1rem;
    text-align: center;
}

.panel--pause h2 { margin: 0 0 1rem; }
.error-detail { color: #f6bfac; font-size: 0.85rem; overflow-wrap: anywhere; }

.hero-sigil {
    display: grid;
    place-items: center;
    position: relative;
    margin: 0 auto clamp(0.45rem, 3.2cqw, 0.95rem);
    width: clamp(3.4rem, 36cqw, 9.5rem);
    aspect-ratio: 1;
    border: 1px solid #f7bf6d83;
    border-radius: 50%;
    background: radial-gradient(circle, #eac87844, #6a64342e 55%, #161d1600 70%);
    box-shadow: inset 0 0 0 0.35rem #9c8b482b, 0 0 2rem #eab76c22;
}

.hero-sigil::before {
    position: absolute;
    inset: 12%;
    border: 1px dashed #ffdb8c6b;
    border-radius: 50%;
    content: "";
}

.hero-sigil img {
    width: 82%;
    filter: drop-shadow(0 6px 0 #1319119e);
    image-rendering: pixelated;
}

h1, h2 { margin: 0; font-weight: 800; }

h1 {
    color: #ffe1a2;
    font-family: "STKaiti", "KaiTi", "Songti SC", "Microsoft YaHei", serif;
    font-size: clamp(1.7rem, 13.2cqw, 4.25rem);
    letter-spacing: 0.09em;
    line-height: 1.17;
    text-shadow: 0 2px #70522a, 0 5px 19px #19100ce8;
}

.run-goal {
    margin: 0.55rem 0 0;
    color: #f8d080;
    font-size: clamp(0.67rem, 4cqw, 1rem);
    font-weight: 700;
}

.start-guide {
    margin: 0.6rem 0 clamp(0.75rem, 6cqw, 1.6rem);
    color: #e3d5b1;
    font-size: clamp(0.62rem, 3.5cqw, 1rem);
    line-height: 1.65;
}

#campaign-menu:empty { display: none; }

.panel--start:has(#campaign-menu:not(:empty)) .hero-sigil {
    width: clamp(3.25rem, 21cqw, 6.5rem);
    margin-bottom: 0.35rem;
}

.panel--start:has(#campaign-menu:not(:empty)) h1 {
    font-size: clamp(1.55rem, 10cqw, 3.45rem);
}

.panel--start:has(#campaign-menu:not(:empty)) .start-guide {
    margin-block: 0.38rem 0.72rem;
}

@media (min-height: 660px) {
    .panel--start #campaign-menu .campaign-list:is([data-tab="heroes"], [data-tab="stages"]) {
        max-height: clamp(8rem, 53cqw, 13rem);
    }
}

@media (max-height: 620px) {
    .panel--start:has(#campaign-menu:not(:empty)) .hero-sigil {
        width: clamp(2.7rem, 16cqw, 4.5rem);
    }

    .panel--start:has(#campaign-menu:not(:empty)) .start-guide {
        margin-block: 0.27rem 0.5rem;
    }
}

button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.action {
    width: min(82%, 17.5rem);
    min-height: 2.75rem;
    padding: 0.6rem 0.8rem;
    border: 1px solid #ffd58b;
    border-radius: 0.55rem;
    background: linear-gradient(#ffda91, #e7a858);
    color: #252213;
    box-shadow: inset 0 1px #ffecbb, 0 0.28rem 0 #946137, 0 0.6rem 1rem #0a100a8c;
    font-size: clamp(0.78rem, 4.45cqw, 1.2rem);
    font-weight: 820;
}

.action:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: inset 0 1px #ffecbb, 0 0.12rem 0 #946137;
}

button:disabled { cursor: progress; opacity: 0.75; }

.sound-controls { margin: 0.65rem 0 0; }

.sound-toggle {
    min-height: 2.75rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid #b2ac756d;
    border-radius: 0.5rem;
    background: #152219d9;
    color: #efe2be;
    font-size: clamp(0.7rem, 3.8cqw, 0.92rem);
}

.sound-toggle[aria-pressed="true"] {
    border-color: #d8b570;
    color: #ffe1a5;
}

.panel--choices, .panel--result {
    padding: clamp(0.55rem, 4.8cqw, 1.22rem);
    border: 1px solid #c59d625e;
    border-radius: clamp(0.55rem, 3.5cqw, 0.92rem);
    background: linear-gradient(145deg, #263a27 0%, #17271b 76%);
    box-shadow: inset 0 0 0 1px #ffffc812, 0 0.75rem 2.25rem #080d0ac7;
}

.panel--result { padding-block: clamp(0.85rem, 7cqw, 1.9rem); }
.panel-label {
    margin: 0 0 0.22rem;
    color: #e0bf81;
    font-size: clamp(0.62rem, 3.45cqw, 0.86rem);
    font-weight: 700;
}

h2 {
    color: #ffebba;
    font-size: clamp(1rem, 7.4cqw, 2rem);
    line-height: 1.2;
}

.panel-description {
    margin: 0.35rem 0 clamp(0.4rem, 3.8cqw, 0.95rem);
    color: var(--muted);
    font-size: clamp(0.64rem, 3.4cqw, 0.88rem);
}

.skill-options { display: grid; gap: clamp(0.35rem, 2.25cqw, 0.65rem); }

.skill-card {
    display: grid;
    align-items: center;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: clamp(0.25rem, 2.6cqw, 0.65rem);
    min-height: 3rem;
    padding: clamp(0.32rem, 2.6cqw, 0.65rem);
    border: 1px solid #ae9b6869;
    border-radius: 0.55rem;
    background: linear-gradient(105deg, #55653a69, #34452d74);
    text-align: left;
}

.skill-card:not(:disabled):is(:hover, :active) {
    border-color: #e1b577;
    background: linear-gradient(105deg, #677745a8, #475b37a8);
}

.skill-icon {
    display: grid;
    place-items: center;
    width: clamp(1.55rem, 11cqw, 2.75rem);
    aspect-ratio: 1;
    border: 1px solid #c1a16661;
    border-radius: 0.45rem;
    background: #233224;
    color: #ffd999;
    font-size: clamp(0.82rem, 6.4cqw, 1.55rem);
    font-weight: 800;
    line-height: 1;
}

.skill-icon[data-kind="movement"] { color: #c7dda3; }
.skill-icon[data-kind="heal"] { color: #ffad96; }

.skill-name, .skill-description { display: block; }

.skill-name {
    color: #fbebbd;
    font-size: clamp(0.7rem, 4.2cqw, 1rem);
    font-weight: 750;
    overflow-wrap: anywhere;
}

.skill-description {
    margin-top: 0.17rem;
    color: #e5dcc1;
    font-size: clamp(0.58rem, 3.45cqw, 0.86rem);
    line-height: 1.42;
    overflow-wrap: anywhere;
}

.skill-rank {
    color: #f5ce87;
    font-size: clamp(0.53rem, 3cqw, 0.76rem);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
    margin: clamp(0.75rem, 5.8cqw, 1.4rem) 0;
}

.result-stats > div {
    padding: 0.48rem 0.2rem;
    border: 1px solid #b9a5744a;
    border-radius: 0.45rem;
    background: #12201687;
}

.result-stats dt {
    color: #d3c49e;
    font-size: clamp(0.56rem, 3.35cqw, 0.82rem);
}

.result-stats dd {
    margin: 0.18rem 0 0;
    color: #ffdea0;
    font-size: clamp(0.84rem, 5.1cqw, 1.5rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

@container (max-width: 285px) {
    .skill-card { grid-template-columns: auto minmax(0, 1fr); }
    .skill-rank { grid-column: 2; }
}
