/* Fire Biu — 2D 像素塔防皮肤。
 *
 * 几何来自 /assets/css/tokens.css 的 --pixel-* 令牌；Shell 的 pixel.css
 * 不进入 iframe。这里只定义游戏本地 --fb-* 颜色与像素组件：
 * 8px 网格、2/3px 硬边框、0 圆角、硬偏移阴影；无渐变、模糊、发光、
 * 玻璃半透明与柔和投影。Canvas 继续绘制游戏自己的 tilemap 与精灵。
 */

:root {
    color-scheme: light;

    --fb-border: var(--pixel-border-width);
    --fb-border-thin: var(--pixel-border-thin);
    --fb-shadow: var(--pixel-shadow-offset);
    --fb-shadow-lg: var(--pixel-shadow-offset-lg);
    --fb-font: "Fusion Pixel", ui-monospace, "Cascadia Mono", "Courier New", monospace;

    --fb-bg: #dff3ff;
    --fb-bg-2: #bfe4f6;
    --fb-surface: #fffdf2;
    --fb-surface-2: #ffeec9;
    --fb-ink: #24313f;
    --fb-muted: #5c7184;
    --fb-line: #24313f;
    --fb-brand: #1f5d86;
    --fb-brand-strong: #164766;
    --fb-brand-soft: #c9ecff;
    --fb-accent: #f5b921;
    --fb-accent-strong: #c98a00;
    --fb-accent-soft: #ffe9a8;
    --fb-on-accent: #4a3200;
    --fb-on-brand: #ffffff;
    --fb-on-success: #0f2208;
    --fb-danger: #e95a48;
    --fb-danger-strong: #b83a2a;
    --fb-danger-soft: #ffe3dd;
    --fb-leaf: #4a9433;
    --fb-leaf-strong: #3f8f26;
    --fb-leaf-soft: #d8f0c8;
    --fb-scrim: rgba(16, 32, 46, 0.62);
    --fb-shadow-color: #24313f;
}

[data-theme="dark"] {
    color-scheme: dark;

    --fb-bg: #0c1a24;
    --fb-bg-2: #122a38;
    --fb-surface: #16242e;
    --fb-surface-2: #1d3340;
    --fb-ink: #eaf6ff;
    --fb-muted: #93a9b8;
    --fb-line: #eaf6ff;
    --fb-brand: #1f5d86;
    --fb-brand-strong: #8fd6ff;
    --fb-brand-soft: #1d3f55;
    --fb-accent: #ffd54a;
    --fb-accent-strong: #c98a00;
    --fb-accent-soft: #4a3a14;
    --fb-on-accent: #2a1e00;
    --fb-on-brand: #ffffff;
    --fb-on-success: #06140a;
    --fb-danger: #ff7a66;
    --fb-danger-strong: #b83a2a;
    --fb-danger-soft: #4a201a;
    --fb-leaf: #74c954;
    --fb-leaf-strong: #4a9433;
    --fb-leaf-soft: #24401c;
    --fb-scrim: rgba(3, 10, 16, 0.78);
    --fb-shadow-color: #050d13;
}

@font-face {
    font-family: "Fusion Pixel";
    src: url("../assets/fonts/fusion-pixel-12px-monospaced-zh_hans.ttf") format("truetype");
    font-display: swap;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--fb-bg);
    -webkit-text-size-adjust: 100%;
}

body {
    color: var(--fb-ink);
    font-family: var(--fb-font);
    font-size: 16px;
    line-height: 1.35;
    -webkit-font-smoothing: none;
    text-rendering: optimizeSpeed;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overscroll-behavior: none;
}

button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
}

button:focus-visible,
input:focus-visible {
    outline: var(--fb-border) solid var(--color-focus);
    outline-offset: 2px;
}

#app {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: var(--fb-bg);
}

.hidden {
    display: none !important;
}

.file-input {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Background scene — generated light/dark pixel trail
   -------------------------------------------------------------------------- */

#scene {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background-color: var(--fb-bg);
    background-image: url("../assets/firebiu-scene-light.png");
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    image-rendering: pixelated;
    pointer-events: none;
}

[data-theme="dark"] #scene {
    background-image: url("../assets/firebiu-scene-dark.png");
}

/* --------------------------------------------------------------------------
   In-game layout: HUD / board / soldier tray
   -------------------------------------------------------------------------- */

#game-layout {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-top: env(safe-area-inset-top);
    overflow: hidden;
}

#hud {
    flex: 0 0 auto;
    padding: 4px 4px 0;
}

.hud-inner {
    width: 100%;
    max-width: none;
    margin: 0 auto;
    display: flex;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
    padding: 4px;
    border: var(--fb-border) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: var(--fb-shadow) var(--fb-shadow) 0 var(--fb-shadow-color);
}

.hud-left {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: none;
}

.hud-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 26px;
    padding: 2px 6px 2px 3px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.hud-pill.pop {
    animation: pill-pop 280ms steps(2, end);
}

.hud-pill .misc {
    width: 16px;
    height: 16px;
}

.hud-center {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.level-chip {
    max-width: 100%;
    padding: 2px 6px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface-2);
    color: var(--fb-ink);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wave-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    max-width: 100%;
}

.wave-chip {
    padding: 1px 5px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    color: var(--fb-ink);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
}

.wave-bar {
    display: flex;
    gap: 2px;
    width: min(8.5rem, 26vw);
    min-width: 36px;
}

.wave-bar__seg {
    flex: 1;
    height: 6px;
    border: 1px solid var(--fb-line);
    background: var(--fb-bg-2);
}

.wave-bar__seg--done {
    background: var(--fb-accent);
}

.wave-bar__seg--current {
    background: var(--fb-surface);
    animation: seg-pulse 1.1s steps(2, end) infinite;
}

.prep-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 1px;
    animation: fade-in 180ms steps(2, end);
}

.prep-text {
    padding: 1px 5px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    color: var(--fb-ink);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
}

.prep-btn {
    min-height: 24px;
    padding: 2px 8px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-accent);
    color: var(--fb-on-accent);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}

.prep-btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.hud-right {
    display: flex;
    gap: 4px;
    flex: none;
}

.round-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-brand);
    color: var(--fb-on-brand);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    transition:
        transform 80ms steps(2, end),
        box-shadow 80ms steps(2, end);
}

.round-btn .icon {
    width: 16px;
    height: 16px;
}

.round-btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.round-btn--speed {
    background: var(--fb-accent);
    color: var(--fb-on-accent);
}

/* --------------------------------------------------------------------------
   Board
   -------------------------------------------------------------------------- */

#board-area {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    overflow: hidden;
}

#board-frame {
    padding: 4px;
    border: var(--fb-border) solid var(--fb-line);
    background: var(--fb-surface-2);
    box-shadow: var(--fb-shadow) var(--fb-shadow) 0 var(--fb-shadow-color);
    line-height: 0;
}

#board {
    position: relative;
    overflow: hidden;
    background: var(--fb-leaf-strong);
    line-height: 0;
}

#game {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
    outline: none;
}

#game:focus-visible {
    outline: var(--fb-border) solid var(--color-focus);
    outline-offset: -3px;
}

/* --------------------------------------------------------------------------
   Bottom soldier tray
   -------------------------------------------------------------------------- */

#tray {
    flex: 0 0 auto;
    padding: 4px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
}

.tray-inner {
    width: 100%;
    max-width: none;
    margin: 0 auto;
    padding: 4px;
    border: var(--fb-border) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: var(--fb-shadow) var(--fb-shadow) 0 var(--fb-shadow-color);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tray-cards {
    display: flex;
    gap: 4px;
}

.tray-card {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 3px 5px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    text-align: left;
    transition:
        transform 80ms steps(2, end),
        box-shadow 80ms steps(2, end);
}

.tray-card:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.tray-card--selected {
    background: var(--fb-accent-soft);
    box-shadow:
        inset 0 0 0 2px var(--fb-accent-strong),
        2px 2px 0 var(--fb-shadow-color);
    transform: translateY(-2px);
}

.tray-card--disabled {
    opacity: 0.58;
    cursor: default;
}

.tray-card.shake {
    animation: card-shake 200ms steps(2, end);
}

.tray-avatar {
    flex: none;
    width: 34px;
    height: 34px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sprite-icon {
    display: block;
    width: 26px;
    height: 26px;
    background-repeat: no-repeat;
    image-rendering: pixelated;
}

.tray-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 2px;
}

.tray-name {
    font-size: 11px;
    font-weight: 700;
    line-height: 1.15;
    color: var(--fb-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tray-price {
    font-size: 11px;
    font-weight: 700;
    line-height: 1.15;
    color: var(--fb-accent-strong);
    white-space: nowrap;
}

[data-theme="dark"] .tray-price {
    color: var(--fb-accent);
}

.tray-card--disabled .tray-price {
    color: var(--fb-danger);
}

.tray-hotkey {
    position: absolute;
    top: -6px;
    left: -4px;
    width: 16px;
    height: 16px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-brand);
    color: var(--fb-on-brand);
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tray-hint {
    min-height: 14px;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--fb-muted);
}

.tray-hint--armed {
    color: var(--fb-accent-strong);
}

[data-theme="dark"] .tray-hint--armed {
    color: var(--fb-accent);
}

/* Soldier management sheet (replaces the tray, never pauses the game) */

.manage-sheet {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 38dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    animation: sheet-in 160ms steps(2, end);
}

.manage-head {
    display: flex;
    align-items: center;
    gap: 6px;
}

.manage-head .tray-avatar {
    width: 38px;
    height: 38px;
}

.manage-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.manage-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--fb-ink);
}

.manage-level {
    font-size: 10px;
    color: var(--fb-muted);
}

.manage-close {
    flex: none;
    width: 32px;
    height: 32px;
    padding: 0;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface-2);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}

.manage-close:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.manage-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 10px;
    font-size: 10px;
    color: var(--fb-muted);
}

.manage-stats b {
    color: var(--fb-ink);
    font-weight: 700;
}

.manage-priority {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.manage-label {
    font-size: 10px;
    color: var(--fb-muted);
}

.priority-chip {
    min-height: 24px;
    padding: 2px 6px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    color: var(--fb-muted);
    font-size: 9px;
    font-weight: 700;
    line-height: 1.2;
}

.priority-chip--active {
    border-color: var(--fb-brand-strong);
    background: var(--fb-brand);
    color: var(--fb-on-brand);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
}

.manage-actions {
    display: flex;
    gap: 5px;
}

.manage-actions .candy-btn {
    flex: 1;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.candy-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 6px 14px;
    border: var(--fb-border) solid var(--fb-line);
    background: var(--fb-accent);
    box-shadow: var(--fb-shadow) var(--fb-shadow) 0 var(--fb-shadow-color);
    color: var(--fb-on-accent);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    text-transform: uppercase;
    transition:
        transform 80ms steps(2, end),
        box-shadow 80ms steps(2, end);
    touch-action: manipulation;
    white-space: nowrap;
}

.candy-btn:active {
    transform: translate(3px, 3px);
    box-shadow: 1px 1px 0 var(--fb-shadow-color);
}

.candy-btn .icon {
    width: 16px;
    height: 16px;
}

.candy-btn--blue {
    background: var(--fb-brand);
    color: var(--fb-on-brand);
}

.candy-btn--success {
    background: var(--fb-leaf);
    color: var(--fb-on-success);
}

[data-theme="dark"] .candy-btn--success {
    color: var(--fb-on-success);
}

.candy-btn--danger {
    background: var(--fb-danger-strong);
    color: var(--fb-on-brand);
}

.candy-btn--ghost {
    background: var(--fb-surface);
    color: var(--fb-ink);
}

.candy-btn--lg {
    min-height: 52px;
    padding: 8px 20px;
    font-size: 16px;
}

.candy-btn--lg .icon {
    width: 18px;
    height: 18px;
}

.candy-btn--sm {
    min-height: 36px;
    padding: 4px 10px;
    border-width: var(--fb-border-thin);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    font-size: 11px;
}

.candy-btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: default;
}

.candy-btn[aria-disabled="true"]:active {
    transform: none;
    box-shadow: var(--fb-shadow) var(--fb-shadow) 0 var(--fb-shadow-color);
}

/* --------------------------------------------------------------------------
   Selector
   -------------------------------------------------------------------------- */

.candy-select {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.candy-select__btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-brand);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-on-brand);
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

.candy-select__btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.candy-select__value {
    min-width: 76px;
    padding: 4px 8px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    color: var(--fb-ink);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
    white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Icons / misc (sliced from the original atlases)
   -------------------------------------------------------------------------- */

.icon {
    flex: none;
    display: inline-block;
    width: 16px;
    height: 16px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    image-rendering: pixelated;
}

.icon-settings { background-image: url("../assets/images/ui/sliced/icon-settings.png"); }
.icon-globe    { background-image: url("../assets/images/ui/sliced/icon-globe.png"); }
.icon-sound    { background-image: url("../assets/images/ui/sliced/icon-sound.png"); }
.icon-music    { background-image: url("../assets/images/ui/sliced/icon-music.png"); }
.icon-home     { background-image: url("../assets/images/ui/sliced/icon-home.png"); }
.icon-play     { background-image: url("../assets/images/ui/sliced/icon-play.png"); }
.icon-next     { background-image: url("../assets/images/ui/sliced/icon-next.png"); }
.icon-pause    { background-image: url("../assets/images/ui/sliced/icon-pause.png"); }
.icon-exit     { background-image: url("../assets/images/ui/sliced/icon-exit.png"); }
.icon-upload   { background-image: url("../assets/images/ui/sliced/icon-upload.png"); }
.icon-restart  { background-image: url("../assets/images/ui/sliced/icon-restart.png"); }
.icon-delete   { background-image: url("../assets/images/ui/sliced/icon-delete.png"); }

.misc {
    flex: none;
    display: inline-block;
    width: 18px;
    height: 18px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    image-rendering: pixelated;
}

.misc-health { background-image: url("../assets/images/ui/sliced/misc-health.png"); }
.misc-money  { background-image: url("../assets/images/ui/sliced/misc-money.png"); }
.misc-star   { background-image: url("../assets/images/ui/sliced/misc-star.png"); }
.misc-star--gold { background-image: url("../assets/images/ui/sliced/misc-star-gold.png"); }
.misc-star--dim { opacity: 0.32; }

.star-row {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

/* --------------------------------------------------------------------------
   Home
   -------------------------------------------------------------------------- */

.home {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    pointer-events: auto;
}

.home-logo {
    max-width: 100%;
    font-size: clamp(32px, 9vmin, 64px);
    font-weight: 700;
    line-height: 0.95;
    letter-spacing: 0.02em;
    color: var(--fb-accent);
    text-shadow:
        4px 4px 0 var(--fb-brand-strong),
        8px 8px 0 var(--fb-shadow-color);
    text-transform: uppercase;
    text-align: center;
    white-space: nowrap;
    animation: logo-bob 3.4s steps(2, end) infinite;
}

.home-sub {
    padding: 3px 10px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.home-actions {
    width: min(280px, 82vw);
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 6px;
}

.home-stats {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

.home-stars {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface-2);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-on-accent);
    font-size: 12px;
    font-weight: 700;
}

.home-stars .misc {
    width: 16px;
    height: 16px;
}

.home-lineup {
    position: absolute;
    bottom: 8%;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
}

.home-lineup .sprite-icon {
    width: 34px;
    height: 34px;
    animation: soldier-bob 2.8s steps(2, end) infinite;
}

.home-lineup .sprite-icon:nth-child(2) { animation-delay: -0.7s; }
.home-lineup .sprite-icon:nth-child(3) { animation-delay: -1.4s; }
.home-lineup .sprite-icon:nth-child(4) { animation-delay: -2.1s; }

.home-version {
    position: absolute;
    right: 8px;
    bottom: 6px;
    padding: 1px 4px;
    border: 1px solid var(--fb-line);
    background: var(--fb-surface);
    color: var(--fb-muted);
    font-size: 9px;
}

/* --------------------------------------------------------------------------
   Adventure map
   -------------------------------------------------------------------------- */

.map-screen {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    padding: calc(8px + env(safe-area-inset-top)) 10px 10px;
    pointer-events: auto;
}

.map-top {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border: var(--fb-border) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: var(--fb-shadow) var(--fb-shadow) 0 var(--fb-shadow-color);
}

.map-title {
    flex: 1;
    min-width: 0;
    margin-left: 4px;
    overflow: hidden;
    color: var(--fb-ink);
    font-size: 20px;
    font-weight: 700;
    line-height: 1.1;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.map-top .spacer {
    flex: 1;
}

.map-stars {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface-2);
    color: var(--fb-on-accent);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.map-board {
    position: relative;
    flex: 1;
    min-height: 0;
    width: min(40rem, 96vw);
    margin: 8px auto 0;
}

.map-path {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.map-path svg {
    shape-rendering: crispEdges;
}

.map-path__shadow {
    fill: none;
    stroke: var(--fb-shadow-color);
    stroke-width: 3;
    stroke-dasharray: 5 3;
    opacity: 0.45;
}

.map-path__line {
    fill: none;
    stroke: var(--fb-accent);
    stroke-width: 1.6;
    stroke-dasharray: 5 3;
}

.map-node {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 64px;
    height: 64px;
    padding: 0;
    border: var(--fb-border) solid var(--fb-line);
    background: var(--fb-accent);
    box-shadow: var(--fb-shadow) var(--fb-shadow) 0 var(--fb-shadow-color);
    color: var(--fb-on-accent);
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 80ms steps(2, end);
}

.map-node:active {
    transform: translate(-50%, -50%) scale(0.96);
}

.map-node--current {
    animation: node-pulse 1.8s steps(2, end) infinite;
}

.map-node--locked {
    background: var(--fb-bg-2);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-muted);
    cursor: default;
}

.map-node--locked.shake {
    animation: card-shake 200ms steps(2, end);
}

.map-node__stars {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1px;
}

.map-node__stars .misc {
    width: 13px;
    height: 13px;
}

.map-node__badge {
    position: absolute;
    top: -9px;
    right: -7px;
    padding: 1px 4px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-danger-strong);
    box-shadow: 1px 1px 0 var(--fb-shadow-color);
    color: var(--fb-on-brand);
    font-size: 8px;
    font-weight: 700;
    line-height: 1.4;
    animation: badge-bob 1.4s steps(2, end) infinite;
}

.map-node__lock {
    position: relative;
    display: block;
    width: 18px;
    height: 14px;
    margin-top: 6px;
    border: 3px solid var(--fb-ink);
    background: var(--fb-surface-2);
}

.map-node__lock::before {
    content: "";
    position: absolute;
    left: 2px;
    top: -10px;
    width: 8px;
    height: 9px;
    border: 3px solid var(--fb-ink);
    border-bottom: 0;
}

.map-node--locked .map-node__lock::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 2px;
    width: 2px;
    height: 5px;
    background: var(--fb-ink);
}

.map-name {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    max-width: 140px;
    padding: 2px 6px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: 1px 1px 0 var(--fb-shadow-color);
    overflow: hidden;
    color: var(--fb-ink);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-bottom {
    display: flex;
    justify-content: center;
    padding-bottom: env(safe-area-inset-bottom);
}

.map-hint {
    padding: 2px 8px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}

/* --------------------------------------------------------------------------
   Overlays / cards
   -------------------------------------------------------------------------- */

#ui {
    position: absolute;
    inset: 0;
    z-index: 15;
    pointer-events: none;
}

#ui > * {
    pointer-events: auto;
}

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--fb-scrim);
}

.card {
    position: relative;
    width: min(320px, calc(100% - 8px));
    max-height: 80dvh;
    padding: 16px;
    border: var(--fb-border) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: var(--fb-shadow-lg) var(--fb-shadow-lg) 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    animation: card-in 160ms steps(2, end);
}

.card--wide {
    width: min(368px, calc(100% - 8px));
}

.card-title {
    padding-right: 24px;
    color: var(--fb-ink);
    font-size: 20px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    text-transform: uppercase;
}

.card-sub {
    color: var(--fb-muted);
    font-size: 11px;
    line-height: 1.4;
    text-align: center;
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setting-label {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--fb-muted);
    font-size: 12px;
    font-weight: 700;
}

.setting-label .icon {
    width: 14px;
    height: 14px;
}

.card-actions {
    display: flex;
    gap: 6px;
    margin-top: 2px;
}

.card-actions .candy-btn {
    flex: 1;
}

.close-x {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 32px;
    height: 32px;
    padding: 0;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface-2);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}

.close-x:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

/* Victory / defeat */

.result-card {
    align-items: center;
    padding-top: 40px;
}

.result-stars {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: flex-end;
    gap: 3px;
}

.result-stars .misc {
    width: 40px;
    height: 40px;
    opacity: 0;
    transform: scale(0.3);
    animation: star-pop 500ms steps(4, end) forwards;
}

.result-stars .misc:nth-child(2) {
    animation-delay: 160ms;
    width: 46px;
    height: 46px;
}

.result-stars .misc:nth-child(3) {
    animation-delay: 320ms;
}

.result-title {
    color: var(--fb-ink);
    font-size: 22px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    text-transform: uppercase;
}

.result-level {
    max-width: 100%;
    overflow: hidden;
    color: var(--fb-muted);
    font-size: 12px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.confetti {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.confetti i {
    position: absolute;
    top: -16px;
    width: 6px;
    height: 10px;
    opacity: 0.9;
    animation: confetti-fall linear forwards;
}

.confetti i:nth-child(1) { left: 8%; background: var(--fb-accent); animation-duration: 2.2s; animation-delay: 0.1s; }
.confetti i:nth-child(2) { left: 18%; background: var(--fb-danger); animation-duration: 2.6s; animation-delay: 0.4s; }
.confetti i:nth-child(3) { left: 28%; background: var(--fb-brand); animation-duration: 2.1s; animation-delay: 0.2s; }
.confetti i:nth-child(4) { left: 38%; background: var(--fb-leaf); animation-duration: 2.8s; animation-delay: 0.6s; }
.confetti i:nth-child(5) { left: 48%; background: var(--fb-accent); animation-duration: 2.3s; animation-delay: 0.3s; }
.confetti i:nth-child(6) { left: 58%; background: var(--fb-danger); animation-duration: 2.5s; animation-delay: 0.7s; }
.confetti i:nth-child(7) { left: 68%; background: var(--fb-brand); animation-duration: 2.2s; animation-delay: 0.5s; }
.confetti i:nth-child(8) { left: 78%; background: var(--fb-leaf); animation-duration: 2.7s; animation-delay: 0.1s; }
.confetti i:nth-child(9) { left: 88%; background: var(--fb-accent); animation-duration: 2.4s; animation-delay: 0.8s; }
.confetti i:nth-child(10) { left: 94%; background: var(--fb-danger); animation-duration: 2.6s; animation-delay: 0.35s; }
.confetti i:nth-child(11) { left: 12%; background: var(--fb-brand); animation-duration: 2.9s; animation-delay: 0.9s; }
.confetti i:nth-child(12) { left: 72%; background: var(--fb-accent); animation-duration: 2.4s; animation-delay: 1s; }

/* --------------------------------------------------------------------------
   Toasts / banner
   -------------------------------------------------------------------------- */

#toasts {
    position: absolute;
    top: calc(84px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    max-width: calc(100% - 16px);
    pointer-events: none;
}

.toast {
    max-width: 100%;
    padding: 3px 8px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    animation:
        toast-in 160ms steps(2, end),
        toast-out 240ms steps(2, end) 1.7s forwards;
}

.toast--error {
    border-color: var(--fb-danger-strong);
    background: var(--fb-danger-soft);
    color: var(--fb-danger-strong);
}

[data-theme="dark"] .toast--error {
    color: var(--fb-danger);
}

.toast--reward {
    background: var(--fb-accent-soft);
    color: var(--fb-on-accent);
}

#fx {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wave-banner {
    position: absolute;
    top: 33%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    max-width: 90vw;
    text-align: center;
    animation: banner-in 2s steps(4, end) forwards;
}

.wave-banner__main {
    max-width: 90vw;
    color: var(--fb-on-brand);
    font-size: 24px;
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
    text-shadow:
        3px 3px 0 var(--fb-shadow-color),
        6px 6px 0 var(--fb-brand-strong);
    text-transform: uppercase;
}

.wave-banner__sub {
    padding: 2px 8px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Boot
   -------------------------------------------------------------------------- */

#boot {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background-color: var(--fb-bg);
    background-image: url("../assets/firebiu-scene-light.png");
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    image-rendering: pixelated;
    transition: opacity 200ms steps(2, end);
}

[data-theme="dark"] #boot {
    background-image: url("../assets/firebiu-scene-dark.png");
}

#boot::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    background: var(--fb-bg);
    opacity: 0.84;
}

#boot > * {
    position: relative;
    z-index: 1;
}

#boot.hidden {
    opacity: 0;
    pointer-events: none;
}

.boot-logo {
    color: var(--fb-accent);
    font-size: 44px;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    text-shadow:
        4px 4px 0 var(--fb-brand-strong),
        8px 8px 0 var(--fb-shadow-color);
    text-transform: uppercase;
    animation: logo-bob 3s steps(2, end) infinite;
}

#boot-status {
    padding: 3px 10px;
    border: var(--fb-border-thin) solid var(--fb-line);
    background: var(--fb-surface);
    box-shadow: 2px 2px 0 var(--fb-shadow-color);
    color: var(--fb-ink);
    font-size: 12px;
    font-weight: 700;
}

#boot.error #boot-status {
    max-width: 82vw;
    border-color: var(--fb-danger-strong);
    background: var(--fb-danger-soft);
    color: var(--fb-danger-strong);
    text-align: center;
    line-height: 1.5;
}

[data-theme="dark"] #boot.error #boot-status {
    color: var(--fb-danger);
}

/* --------------------------------------------------------------------------
   Animations — discrete pixel steps, no blur or glow
   -------------------------------------------------------------------------- */

@keyframes logo-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@keyframes soldier-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

@keyframes seg-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

@keyframes pill-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

@keyframes card-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@keyframes node-pulse {
    0%, 100% { box-shadow: 4px 4px 0 var(--fb-shadow-color); }
    50% { box-shadow: 2px 2px 0 var(--fb-shadow-color); }
}

@keyframes badge-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}

@keyframes star-pop {
    0% { opacity: 0; transform: scale(0.3); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateY(-4px); }
}

@keyframes banner-in {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    12% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    78% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

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

@keyframes sheet-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes confetti-fall {
    0% { transform: translateY(0); opacity: 1; }
    100% { transform: translateY(105vh); opacity: 0.9; }
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

/* Wide screens: board on the left, HUD + soldier tray in the right rail. */
@media (orientation: landscape) and (min-width: 640px) {
    #game-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) clamp(172px, 22vw, 224px);
        grid-template-rows: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "board hud"
            "board ."
            "board tray";
        gap: 6px;
        padding:
            max(4px, env(safe-area-inset-top))
            max(6px, min(env(safe-area-inset-right, 0px), 10px))
            max(4px, env(safe-area-inset-bottom))
            max(4px, min(env(safe-area-inset-left, 0px), 6px));
    }

    #board-area {
        grid-area: board;
        padding: 0;
    }

    #hud {
        grid-area: hud;
        min-width: 0;
        padding: 0;
    }

    #tray {
        grid-area: tray;
        min-width: 0;
        padding: 0;
    }

    .hud-inner,
    .tray-inner {
        max-width: none;
    }

    .hud-inner {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "left right"
            "center center";
        align-items: start;
        gap: 4px;
        padding: 4px;
    }

    .hud-left {
        grid-area: left;
        flex-direction: row;
        gap: 4px;
    }

    .hud-pill {
        flex: 1;
        justify-content: center;
        min-width: 0;
        padding-inline: 3px;
    }

    .hud-center {
        grid-area: center;
        align-items: stretch;
        gap: 4px;
    }

    .hud-right {
        grid-area: right;
        justify-content: flex-end;
    }

    .level-chip {
        display: block;
        text-align: center;
    }

    .wave-row {
        justify-content: space-between;
        gap: 3px;
    }

    .wave-bar {
        flex: 1;
        width: auto;
        min-width: 24px;
    }

    .prep-row {
        flex-wrap: wrap;
    }

    .round-btn {
        width: 44px;
        height: 44px;
    }

    .tray-inner {
        gap: 0;
        padding: 4px;
    }

    .tray-cards {
        flex-direction: column;
        gap: 4px;
    }

    .tray-card {
        flex: none;
        justify-content: flex-start;
        min-height: 40px;
        gap: 6px;
    }

    .tray-hotkey {
        display: none;
    }

    .tray-hint {
        display: none;
    }
}

@media (orientation: landscape) and (max-height: 430px) {
    .level-chip {
        display: none;
    }

    .prep-row {
        display: none;
    }

    .hud-left {
        flex-direction: column;
        gap: 3px;
    }

    .hud-pill {
        padding-inline: 4px;
    }

    .round-btn {
        width: 44px;
        height: 44px;
    }

    .tray-card {
        min-height: 44px;
        padding-block: 2px;
    }

    .tray-avatar {
        width: 28px;
        height: 28px;
    }

    .sprite-icon {
        width: 22px;
        height: 22px;
    }

    .tray-name,
    .tray-price {
        font-size: 10px;
    }

    .candy-select__btn,
    .close-x,
    .manage-close {
        width: 44px;
        height: 44px;
    }

    .candy-btn--sm,
    .priority-chip {
        min-height: 44px;
    }

    .card-title {
        padding-right: 48px;
    }
}

@media (max-width: 600px) {
    #hud {
        padding: 3px 3px 0;
    }

    .hud-inner {
        gap: 3px;
        padding: 3px;
    }

    .hud-left {
        gap: 2px;
    }

    .hud-pill {
        min-height: 30px;
        padding: 2px 6px 2px 3px;
        font-size: 13px;
    }

    .hud-pill .misc {
        width: 18px;
        height: 18px;
    }

    .level-chip {
        display: none;
    }

    .wave-chip,
    .prep-text,
    .prep-btn {
        font-size: 11px;
    }

    .round-btn {
        width: 44px;
        height: 44px;
    }

    .round-btn .icon {
        width: 18px;
        height: 18px;
    }

    .tray-inner {
        padding: 3px;
    }

    .tray-card {
        min-height: 48px;
        gap: 4px;
        padding: 3px 4px;
    }

    .tray-avatar {
        width: 30px;
        height: 30px;
    }

    .sprite-icon {
        width: 22px;
        height: 22px;
    }

    .tray-name,
    .tray-price {
        font-size: 10px;
    }

    .tray-name {
        white-space: normal;
        line-height: 1.05;
    }

    .tray-hotkey {
        display: none;
    }

    .tray-hint {
        font-size: 11px;
    }

    .home-logo {
        font-size: clamp(30px, 10vmin, 48px);
    }

    .home-sub {
        font-size: 13px;
    }

    .map-title {
        font-size: 17px;
    }

    .map-stars {
        font-size: 10px;
    }

    .map-node {
        width: 56px;
        height: 56px;
        font-size: 18px;
        min-width: 44px;
        min-height: 44px;
    }

    .map-name {
        max-width: 110px;
        font-size: 10px;
    }

    .card {
        width: calc(100% - 8px);
        padding: 12px;
    }

    .card--wide {
        width: calc(100% - 8px);
    }

    .card-title {
        font-size: 18px;
        padding-right: 48px;
    }

    .card-actions {
        flex-wrap: wrap;
    }

    .card-actions .candy-btn {
        flex: 1 1 auto;
        padding-inline: 8px;
        font-size: 12px;
    }

    .candy-btn {
        font-size: 14px;
    }

    .candy-btn--sm {
        min-height: 44px;
        font-size: 12px;
    }

    .prep-btn {
        min-height: 44px;
    }

    .candy-select__btn {
        width: 44px;
        height: 44px;
    }

    .candy-select__value {
        font-size: 13px;
    }

    .priority-chip {
        min-height: 44px;
        font-size: 10px;
    }

    .close-x,
    .manage-close {
        width: 44px;
        height: 44px;
    }
}

@media (max-height: 520px) {
    .home-logo {
        font-size: 38px;
    }

    .home-actions {
        gap: 6px;
    }

    .home-lineup {
        display: none;
    }

    .tray-hint {
        display: none;
    }

    .card {
        padding: 12px;
        gap: 6px;
    }

    .result-card {
        padding-top: 32px;
    }

    .result-actions {
        gap: 4px;
    }
}

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

    .wave-banner {
        animation: none !important;
        opacity: 1;
    }
}
