:root {
    --pixel-font-display: 'Press Start 2P', 'ZCOOL QingKe HuangYou', monospace;
    --pixel-font-ui: 'Pixelify Sans', 'ZCOOL QingKe HuangYou', ui-monospace, monospace;

    --game-bg: #06080c;
    --game-surface: #0b1118;
    --game-surface-raised: #111a24;
    --game-surface-active: #172330;
    --game-border: #2a3946;
    --game-border-strong: #607180;
    --game-text: #f5f9fc;
    --game-muted: #a7b4c2;
    --game-faint: #667583;
    --game-accent: #ffd84d;
    --game-system: #73e6f2;
    --game-green: #66e38f;
    --game-red: #ff6d77;
    --game-depth: #020405;

    --pixel-ink: var(--game-bg);
    --pixel-paper: var(--game-text);
    --pixel-muted: var(--game-muted);
    --pixel-line: var(--game-border);
    --pixel-yellow: var(--game-accent);
    --pixel-cyan: var(--game-system);
    --pixel-green: var(--game-green);
    --pixel-red: var(--game-red);

    --hud-shell: var(--game-surface);
    --hud-border: var(--game-border);
    --hud-text: var(--game-text);
    --hud-muted: var(--game-muted);
    --arcade-sky: var(--game-bg);
    --arcade-horizon: var(--game-surface);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;

    /* Motion tokens: stepped arcade motion. Skins may retune rhythm here. */
    --motion-step-fast: 90ms;
    --motion-step-base: 160ms;
    --motion-step-slow: 320ms;
}

/*
 * FLAPPY K / SINGLE-SURFACE MARKET OS
 * MARKET ARCADE pass, now expressed as PIXEL MARKET ARCADE.
 * Hard edges, hard depth, large score hierarchy and tactile controls.
 * Feature styles keep feature geometry; this file owns shared presentation.
 */

html,
body {
    background: var(--game-bg);
    color: var(--game-text);
}

body,
button,
select,
output,
summary,
input,
textarea {
    font-family: var(--pixel-font-ui);
    font-weight: 500;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

button,
select,
input,
textarea {
    border-radius: 0;
}

button {
    transition:
        background-color 70ms linear,
        border-color 70ms linear,
        color 70ms linear,
        transform 70ms linear,
        box-shadow 70ms linear;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible,
a:focus-visible {
    outline: 3px solid var(--game-accent);
    outline-offset: 3px;
}

#game-container {
    background: var(--game-bg);
}

#game-container::after {
    content: none;
}

.screen {
    color: var(--game-text);
}

/* ---------- Gameplay: one command surface ---------- */

#ui-layer {
    position: absolute;
    inset: 0;
    z-index: 42;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    min-height: 0 !important;
    padding: 0;
    pointer-events: none;
}

#ui-layer[data-hud-composition='rail'] {
    display: grid;
}

#ui-layer[hidden] {
    display: none !important;
}

#game-hud-rail {
    position: absolute;
    inset: 8px 8px auto 8px;
    display: grid;
    grid-template-columns: minmax(320px, 1.5fr) minmax(230px, 0.72fr);
    grid-template-areas:
        'performance controls'
        'progress progress';
    gap: 0;
    align-items: stretch;
    overflow: hidden;
    --pixel-outline: 2px 0 0 #000, -2px 0 0 #000, 0 2px 0 #000, 0 -2px 0 #000,
        1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000;
    pointer-events: none;
}

#game-hud-rail > * {
    pointer-events: auto;
}

#game-hud-rail .stats-box[data-composition='returns-only'] {
    grid-area: performance;
}

#game-top-controls {
    grid-area: controls;
}

#run-progress-panel {
    grid-area: progress;
}

.stats-box,
.run-progress-panel,
#game-top-controls,
.controls-hint {
    border: 0;
    border-radius: 0;
    background: transparent;
    backdrop-filter: none;
}

.stats-box {
    position: static !important;
    width: auto;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
    padding: 4px 12px 2px;
}

.hud-main {
    display: contents;
}

.hud-stat-row {
    min-width: 0;
}

.hud-metric-label {
    display: block;
    margin-bottom: 3px;
    color: #fff;
    font-family: var(--pixel-font-display);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-shadow: var(--pixel-outline);
}

.hud-total,
.hud-cash,
.hud-return {
    color: #fff;
}

.hud-total > span:last-child,
.hud-cash > span:last-child,
.hud-return > span:last-child {
    display: block;
    overflow: hidden;
    color: #fff;
    font-family: var(--pixel-font-display);
    font-size: clamp(18px, 1.45vw, 21px);
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    text-shadow: var(--pixel-outline);
}

.hud-return .positive,
#return-display.positive {
    color: var(--game-green);
}

.hud-return .negative,
#return-display.negative {
    color: var(--game-red);
}

.excess-meter {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--game-border);
}

.excess-meter-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: #fff;
    font-family: var(--pixel-font-display);
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-shadow: var(--pixel-outline);
}

.excess-meter-label strong {
    color: var(--game-red);
    font-family: var(--pixel-font-display);
    font-size: 11px;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}

.excess-meter-label strong::before {
    content: '×';
    margin-right: 2px;
}

.excess-meter[data-leading='true'] .excess-meter-label strong {
    color: var(--game-green);
}

.excess-meter-track {
    position: relative;
    height: 8px;
    margin-top: 4px;
    overflow: hidden;
    border: 2px solid #fff;
    background: #000;
}

.excess-meter-negative,
.excess-meter-positive {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 50%;
    opacity: 0.2;
}

.excess-meter-negative { left: 0; background: var(--game-red); }
.excess-meter-positive { right: 0; background: var(--game-green); }

.excess-meter-zero {
    position: absolute;
    inset: -2px auto -2px 50%;
    width: 2px;
    background: #fff;
}

.excess-meter-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 13px;
    border: 2px solid #000;
    background: var(--game-red);
    transform: translate(-50%, -50%);
    transition: left 120ms linear, background 70ms linear;
}

.excess-meter[data-leading='true'] .excess-meter-indicator {
    background: var(--game-green);
}

.run-progress-panel {
    position: static !important;
    display: grid;
    grid-template-columns: auto auto minmax(100px, 1fr) auto;
    gap: 10px;
    align-items: center;
    min-width: 0;
    padding: 2px 12px 4px;
}

.run-progress-panel .hud-header {
    display: contents;
}

.run-progress-panel .hud-game,
.run-progress-panel .hud-day {
    display: flex;
    align-items: baseline;
    gap: 6px;
    color: #fff;
    font-family: var(--pixel-font-display);
    font-size: 12px;
    font-weight: 400;
    white-space: nowrap;
    text-shadow: var(--pixel-outline);
}

.run-progress-panel .hud-metric-label {
    display: inline;
    margin: 0;
    font-size: 10px;
}

.day-progress {
    position: relative;
    grid-column: 3;
    grid-row: 1;
    height: 7px;
    overflow: hidden;
    border: 2px solid #fff;
    background: #000;
}

.day-progress-fill {
    display: block;
    width: 0;
    height: 100%;
    background: #fff;
    transition: width 120ms linear;
}

.hud-details,
.hud-legacy-goal {
    display: none !important;
}

/* ---------- Unified command buttons: NES tiles ---------- */

#game-top-controls {
    position: static !important;
    display: grid;
    grid-template-columns: minmax(132px, 1fr) 48px 48px 56px 48px;
    gap: 4px;
    align-items: stretch;
    padding: 4px 0 0 12px;
}

#game-top-controls[hidden] {
    display: none !important;
}

.game-speed-control,
.mobile-speed-control {
    display: grid;
    grid-template-columns: 40px minmax(52px, 1fr) 40px;
    gap: 4px;
    align-items: stretch;
}

.speed-step,
#game-back-btn,
#pause-btn,
#sound-toggle-btn,
#game-skin-toggle-btn,
#daily-run-btn,
.home-secondary-actions button,
.settlement-details-toggle,
.leaderboard-panel button,
.custom-challenge-panel button,
.onboarding-panel button,
.settlement-actions button,
.legend-actions button {
    min-width: 0;
    border: 2px solid #fff;
    border-radius: 0;
    background: #000;
    color: #fff;
}

.speed-step,
#game-back-btn,
#pause-btn,
#sound-toggle-btn,
#game-skin-toggle-btn {
    min-height: 36px;
    padding: 0;
    font-family: var(--pixel-font-display);
    font-size: 11px;
    text-shadow: none;
}

#game-skin-toggle-btn {
    overflow: hidden;
    color: #fff;
    font-size: 8px;
    letter-spacing: 0.02em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.speed-step:hover,
#game-back-btn:hover,
#pause-btn:hover,
#sound-toggle-btn:hover,
#game-skin-toggle-btn:hover,
#daily-run-btn:hover,
.home-secondary-actions button:hover,
.settlement-details-toggle:hover,
.leaderboard-panel button:hover,
.custom-challenge-panel button:hover,
.onboarding-panel button:hover,
.settlement-actions button:hover,
.legend-actions button:hover {
    background: #fff;
    color: #000;
}

.speed-readout {
    display: grid;
    place-items: center;
    border: 2px solid #fff;
    background: #000;
    color: #fff;
    font-family: var(--pixel-font-display);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.controls-hint {
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 44;
    display: grid;
    width: 240px;
    overflow: hidden;
    border: 2px solid #fff;
    background: #000;
    box-shadow: 4px 4px 0 var(--game-depth);
    transition: opacity var(--motion-step-base) steps(2, end);
}

.controls-hint.is-dismissed {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--motion-step-base) steps(2, end), visibility 0s var(--motion-step-base);
}

.trade-key-hints {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.trade-key-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 8px 9px;
    color: #fff;
    font-size: 12px;
    white-space: nowrap;
}

.trade-key-hint + .trade-key-hint {
    border-left: 1px solid #fff;
}

.trade-key-hint .key {
    min-width: 30px;
    padding: 3px 4px;
    border: 2px solid #fff;
    background: #000;
    color: #fff;
    box-shadow: 2px 2px 0 var(--game-depth);
    text-align: center;
}

.desktop-speed-control {
    border-top: 0;
}

#speed-btn[hidden] {
    display: none !important;
}

html[data-ui-state='home'] .controls-hint,
html[data-ui-state='settlement'] .controls-hint,
html[data-ui-state='run-complete'] .controls-hint,
html[data-virtual-controls='true'] .controls-hint {
    display: none !important;
}

html[data-virtual-controls='true'] #game-top-controls .desktop-speed-control {
    display: none !important;
}

/* Touch dock shows back / pause / skin; mute stays keyboard-owned. */
html[data-virtual-controls='true'] #game-top-controls #sound-toggle-btn {
    display: none !important;
}

html[data-virtual-controls='true'] #game-skin-toggle-btn {
    font-size: 7px;
}

/* Mobile geometry belongs to mobile-controls.css; this is skin only. */

#mobile-controls .mobile-btn,
#mobile-controls .speed-step,
#mobile-controls button {
    border-radius: 0;
}

#btn-buy,
#btn-sell {
    border: 2px solid var(--game-border-strong) !important;
    color: var(--game-text) !important;
    font-family: var(--pixel-font-display) !important;
    font-size: 17px !important;
    letter-spacing: 0.04em;
}

#btn-buy {
    border-top: 4px solid var(--game-green) !important;
    background: color-mix(in srgb, var(--game-green) 10%, var(--game-bg)) !important;
    box-shadow: 0 5px 0 #173423 !important;
}

#btn-sell {
    border-top: 4px solid var(--game-red) !important;
    background: color-mix(in srgb, var(--game-red) 9%, var(--game-bg)) !important;
    box-shadow: 0 5px 0 #3c1b22 !important;
}

#btn-buy:active,
#btn-sell:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 var(--game-depth) !important;
}

#btn-buy .trade-emoji,
#btn-sell .trade-emoji {
    display: none !important;
}

#btn-buy .pixel-trade-glyph,
#btn-sell .pixel-trade-glyph {
    margin-right: 6px;
    font-size: 14px;
}

#btn-buy > span:last-child,
#btn-sell > span:last-child {
    white-space: nowrap;
}

.mobile-speed-control .speed-readout {
    min-width: 0;
}

/* ---------- Home: one continuous terminal ---------- */

html[data-ui-state='home'] #game-container {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: 0;
    background: var(--game-bg);
}

#start-screen.arcade-home {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    align-content: stretch;
    align-items: stretch;
    justify-content: stretch;
    justify-items: stretch;
    min-height: 0;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    overflow: hidden;
    background: transparent;
}

.home-console-bezel {
    position: relative;
    z-index: 4;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 3px solid var(--game-border-strong);
    background: var(--game-bg);
    box-shadow: 7px 7px 0 var(--game-depth);
}

.home-console-bezel::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 5;
    width: 4px;
    background: var(--game-system);
    pointer-events: none;
}

.home-console-topline {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 12px;
    align-items: center;
    min-height: 46px;
    padding: 8px 12px;
    border-bottom: 2px solid var(--game-border);
    background: var(--game-surface);
}

.home-console-brand {
    color: var(--game-text);
    font-family: var(--pixel-font-display);
    font-size: 11px;
    white-space: nowrap;
}

.home-console-series {
    overflow: hidden;
    color: var(--game-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.home-console-lamps {
    display: none;
}

.home-console-lamps span {
    width: 8px;
    height: 8px;
    border: 2px solid var(--game-border-strong);
    background: var(--game-border);
}

.home-console-lamps span:first-child {
    background: var(--game-system);
}

.home-console-screen {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1.42fr) minmax(260px, 0.58fr);
    grid-template-areas:
        'kicker profile'
        'title side'
        'copy side'
        'worlds side'
        'play side';
    gap: 14px 34px;
    align-content: center;
    min-width: 0;
    min-height: 0;
    padding: clamp(24px, 4.6vw, 62px);
    overflow: hidden;
    background: var(--game-bg);
}

.home-console-screen::before {
    content: '';
    position: absolute;
    right: 32%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--game-border);
    pointer-events: none;
}

.home-console-screen::after {
    content: 'K';
    position: absolute;
    right: -0.06em;
    bottom: -0.22em;
    z-index: 0;
    color: #0d1b24;
    font-family: var(--pixel-font-display);
    font-size: clamp(260px, 34vw, 560px);
    line-height: 1;
    pointer-events: none;
}

.home-console-screen > * {
    position: relative;
    z-index: 1;
}

.home-console-kicker {
    grid-area: kicker;
    align-self: end;
    color: var(--game-system);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.15em;
}

#start-screen #game-title {
    grid-area: title;
    align-self: end;
    margin: 0;
    color: var(--game-text);
    font-family: var(--pixel-font-display);
    font-size: clamp(48px, 7.8vw, 98px);
    line-height: 0.98;
    letter-spacing: -0.045em;
    text-align: left;
    text-shadow: 5px 5px 0 var(--game-depth);
}

.home-console-intro-copy {
    grid-area: copy;
    max-width: 680px;
    margin: 0;
    color: var(--game-muted);
    font-size: clamp(17px, 1.6vw, 21px);
    font-weight: 500;
    line-height: 1.5;
    text-align: left;
}

.home-console-intro-copy + .home-console-intro-copy {
    display: none;
}

.home-world-strip {
    grid-area: worlds;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    max-width: 700px;
    margin-top: 6px;
    border: 2px solid var(--game-border-strong);
    background: var(--game-surface);
    box-shadow: 4px 4px 0 var(--game-depth);
}

.home-world {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 9px;
    align-items: center;
    min-width: 0;
    min-height: 50px;
    padding: 8px 10px;
    background: transparent;
}

.home-world + .home-world {
    border-left: 1px solid var(--game-border);
}

.home-world-index {
    color: var(--game-system);
    font-family: var(--pixel-font-display);
    font-size: 10px;
}

.home-world--ashare .home-world-index,
.home-world--us .home-world-index {
    color: var(--game-system);
    background: transparent;
}

.home-world-name {
    overflow: hidden;
    color: var(--game-text);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.home-primary-actions {
    grid-area: play;
    display: block;
    max-width: 700px;
    margin-top: 8px;
    padding-bottom: 7px;
}

.home-primary-actions #start-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 72px;
    padding: 14px 18px;
    border: 3px solid #ffe478;
    border-radius: 0;
    background: var(--game-accent);
    color: var(--game-bg);
    box-shadow: 7px 7px 0 #8e7520 !important;
    font-family: var(--pixel-font-display);
    font-size: clamp(20px, 2vw, 26px);
    letter-spacing: 0.03em;
    text-align: left;
}

.home-primary-actions #start-btn:hover {
    background: #ffe474;
    transform: translate(-1px, -1px);
    box-shadow: 8px 8px 0 #8e7520 !important;
}

.home-primary-actions #start-btn:active {
    transform: translate(4px, 4px);
    box-shadow: 3px 3px 0 #8e7520 !important;
}

.home-play-icon {
    order: 2;
    font-size: 18px;
    transition: transform 70ms linear;
}

.home-primary-actions #start-btn:hover .home-play-icon {
    transform: translateX(4px);
}

.home-mode-stack {
    grid-area: side;
    display: grid;
    gap: 0;
    align-content: start;
    min-width: 0;
    border: 2px solid var(--game-border-strong);
    background: var(--game-surface);
    box-shadow: 6px 6px 0 var(--game-depth);
}

.local-records-summary {
    grid-area: profile;
    align-self: end;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    align-items: baseline;
    min-height: 58px;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--game-border);
    background: var(--game-surface);
    color: var(--game-muted);
    font-size: 12px;
}

.local-records-summary strong {
    display: block;
    margin-top: 4px;
    color: var(--game-text);
    font-family: var(--pixel-font-display);
    font-size: 18px;
}

.daily-mode-card {
    display: grid;
    gap: 10px;
    padding: 14px;
    border: 0;
    border-bottom: 1px solid var(--game-border);
    background: transparent;
}

.daily-run-summary {
    color: var(--game-muted);
    font-size: 13px;
    line-height: 1.4;
}

#daily-run-btn {
    min-height: 48px;
    border: 2px solid var(--game-border-strong);
    background: var(--game-bg);
    color: var(--game-text);
    box-shadow: 3px 3px 0 var(--game-depth);
    font-size: 16px;
    font-weight: 700;
}

#daily-run-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--game-depth);
}

.home-secondary-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
}

.home-secondary-actions button {
    min-width: 0;
    min-height: 46px;
    padding: 8px;
    font-size: 14px;
    font-weight: 700;
}

.home-secondary-actions button + button {
    border-left: 1px solid var(--game-border);
}

.home-console-footer {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px;
    align-items: center;
    min-height: 34px;
    padding: 7px 12px;
    border-top: 2px solid var(--game-border);
    background: var(--game-surface);
}

.home-console-speaker {
    display: flex;
    gap: 4px;
}

.home-console-speaker span {
    width: 4px;
    height: 4px;
    background: var(--game-border-strong);
}

.home-console-legend {
    overflow: hidden;
    color: var(--game-muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.home-console-topline .home-utility-bar {
    position: static !important;
    justify-self: end;
    margin: 0 !important;
}

/* ---------- Settlement: same market surface ---------- */

#settlement-screen.active {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: center;
    justify-items: center;
    gap: 14px;
    padding: 22px;
    background: var(--game-bg);
}

.profit-card {
    width: min(760px, calc(100vw - 28px));
    max-height: calc(100dvh - 140px);
    overflow: auto;
    padding: 0;
    border: 3px solid var(--game-border-strong);
    border-radius: 0;
    background: var(--game-surface);
    color: var(--game-text);
    box-shadow: 8px 8px 0 var(--game-depth);
}

.profit-card #card-title {
    margin: 0;
    padding: 12px 16px;
    border-bottom: 2px solid var(--game-border);
    color: var(--game-muted);
    font-family: var(--pixel-font-display);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-align: left;
}

.settlement-summary {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
        'medal main'
        'compare compare';
    gap: 16px 20px;
    padding: 24px 20px 20px;
    border-bottom: 2px solid var(--game-border);
}

.settlement-medal-box {
    grid-area: medal;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 86px;
    padding: 6px;
    border: 3px solid var(--game-border-strong);
    background: var(--game-surface-raised);
    box-shadow: 4px 4px 0 var(--game-depth);
}

.settlement-medal-icon {
    font-size: 36px;
    line-height: 1;
    filter: drop-shadow(2px 2px 0 var(--game-depth));
}

.settlement-medal-title {
    margin-top: 4px;
    color: var(--game-accent);
    font-family: var(--pixel-font-display);
    font-size: 9px;
    letter-spacing: 0.08em;
}

.settlement-main-result {
    grid-area: main;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
}

#settlement-verdict {
    color: var(--game-muted);
    font-family: var(--pixel-font-display);
    font-size: 12px;
    line-height: 1.65;
}

.settlement-excess-summary {
    justify-self: end;
    color: var(--game-text);
    font-family: var(--pixel-font-display);
    font-size: clamp(40px, 6.4vw, 68px);
    line-height: 1;
    text-shadow: 5px 5px 0 var(--game-depth);
    font-variant-numeric: tabular-nums;
}

.profit-card[data-result='success'] .settlement-excess-summary {
    color: var(--game-green);
}

.profit-card[data-result='failure'] .settlement-excess-summary {
    color: var(--game-red);
}

.settlement-comparison {
    grid-area: compare;
    display: grid;
    gap: 10px;
}

.settlement-comparison-row {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr) 86px;
    gap: 10px;
    align-items: center;
    color: var(--game-muted);
    font-size: 12px;
    font-weight: 700;
}

.settlement-comparison-row strong {
    color: var(--game-text);
    font-size: 13px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.settlement-comparison-track {
    position: relative;
    height: 11px;
    border: 2px solid var(--game-border);
    background: #030507;
}

.settlement-comparison-track::after {
    content: '';
    position: absolute;
    inset: -1px auto -1px 50%;
    width: 2px;
    background: var(--game-text);
}

.settlement-comparison-track i {
    position: absolute;
    top: 1px;
    bottom: 1px;
    left: 50%;
    width: 2%;
    background: var(--game-system);
}

.settlement-market-identity {
    margin: 0;
    padding: 14px 24px;
    border-bottom: 1px solid var(--game-border);
}

.settlement-market-identity .settlement-verdict {
    color: var(--game-muted);
    font-size: 13px;
}

.settlement-market-identity .highlight {
    color: var(--game-text);
}

.card-details {
    display: none;
    padding: 14px 24px;
    color: var(--game-muted);
    font-size: 13px;
}

.profit-card[data-details-expanded='true'] .card-details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 18px;
    border-bottom: 1px solid var(--game-border);
}

.card-details p {
    margin: 0;
}

.settlement-details-toggle {
    width: 100%;
    min-height: 46px;
    margin: 0;
    border: 0;
    border-top: 1px solid var(--game-border);
    background: var(--game-surface-raised);
    color: var(--game-muted);
    font-size: 13px;
    font-weight: 700;
}

.big-return,
#card-status,
.card-return-caption {
    display: none !important;
}

.settlement-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    width: min(760px, calc(100vw - 28px));
    background: transparent;
}

.settlement-actions > button,
#custom-result-actions button {
    min-height: 50px;
    margin: 0;
    padding: 0 18px;
    border: 2px solid var(--game-border-strong) !important;
    background: var(--game-surface-raised) !important;
    color: var(--game-text) !important;
    box-shadow: 3px 3px 0 var(--game-depth) !important;
    font-size: 14px;
    font-weight: 700;
}

.settlement-actions > button:active,
#custom-result-actions button:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--game-depth) !important;
}

.settlement-actions > button:not([hidden]):first-child,
#champagne-btn:not([hidden]) {
    background: var(--game-accent) !important;
    color: var(--game-bg) !important;
    box-shadow: 4px 4px 0 #8e7520 !important;
}

#custom-result-actions[hidden] {
    display: none !important;
}

#custom-result-actions:not([hidden]) {
    display: flex !important;
    gap: 4px;
}

/* ---------- Dialogs: same system shell ---------- */

#leaderboard-screen.screen.active,
#custom-challenge-screen.screen.active {
    display: grid !important;
    place-items: center;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    background: rgba(2, 4, 6, 0.72);
}

.leaderboard-panel,
.custom-challenge-panel,
.onboarding-panel {
    width: min(680px, calc(100vw - 28px));
    padding: 0;
    overflow: hidden;
    border: 3px solid var(--game-border-strong) !important;
    border-radius: 0 !important;
    background: var(--game-bg) !important;
    color: var(--game-text);
    box-shadow: 8px 8px 0 var(--game-depth) !important;
}

.leaderboard-panel h2,
.custom-challenge-panel h2,
.onboarding-panel h2 {
    margin: 0;
    padding: 18px 20px;
    border-bottom: 2px solid var(--game-border);
    color: var(--game-text);
    font-family: var(--pixel-font-display);
    font-size: clamp(18px, 2.8vw, 28px);
}

.leaderboard-subtitle,
.custom-challenge-panel > p,
.custom-unlocked,
.onboarding-kicker,
.onboarding-panel > small {
    color: var(--game-muted) !important;
    font-size: 13px;
}

.leaderboard-subtitle,
.custom-challenge-panel > p,
.custom-unlocked,
.onboarding-kicker,
.onboarding-panel > small,
.custom-field,
.onboarding-rules,
.leaderboard-status,
.leaderboard-table {
    margin-left: 20px;
    margin-right: 20px;
}

.custom-field select {
    width: 100%;
    min-height: 44px;
    margin-top: 6px;
    border: 2px solid var(--game-border-strong);
    background: var(--game-surface);
    color: var(--game-text);
    font-size: 14px;
}

.custom-challenge-actions,
.onboarding-panel > button,
.leaderboard-panel > button {
    margin-top: 16px;
}

.custom-challenge-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    background: transparent;
}

.custom-challenge-actions button,
.onboarding-panel > button,
.leaderboard-panel > button {
    min-height: 50px;
    border: 2px solid var(--game-border-strong) !important;
    background: var(--game-surface-raised) !important;
    color: var(--game-text) !important;
    box-shadow: 3px 3px 0 var(--game-depth) !important;
    font-size: 14px;
    font-weight: 700;
}

#custom-start-btn,
#onboarding-start-btn {
    background: var(--game-accent) !important;
    color: var(--game-bg) !important;
    box-shadow: 4px 4px 0 #8e7520 !important;
}

.onboarding-rule {
    border-color: var(--game-border) !important;
    background: transparent !important;
}

.onboarding-rule strong {
    color: var(--game-system) !important;
}

/* ---------- Run complete: no separate celebration skin ---------- */

#champagne-screen {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    min-height: 100dvh;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    overflow-y: auto;
    background: var(--game-bg);
    color: var(--game-text);
}

#champagne-screen.active {
    display: flex;
}

.legend-terminal-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 16px;
    align-items: baseline;
    padding: clamp(24px, 4.5vw, 48px) 0 22px;
    border-bottom: 2px solid var(--game-border-strong);
}

.legend-terminal-kicker,
.legend-terminal-status {
    color: var(--game-system);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
}

.legend-terminal-head h1 {
    margin: 0;
    color: var(--game-text);
    font-family: var(--pixel-font-display);
    font-size: clamp(32px, 5.6vw, 66px);
    line-height: 1.05;
    text-align: left;
    text-shadow: 5px 5px 0 var(--game-depth);
}

#legend-ticker {
    margin: 0;
    border-bottom: 2px solid var(--game-border);
    background: var(--game-bg);
}

.legend-ticker-item {
    color: var(--game-muted) !important;
    font-size: 12px;
}

#daily-run-result,
#personal-best-result,
#friend-challenge-result,
.legend-export-wrapper,
.legend-actions,
#leaderboard-submit-status,
#champagne-screen .support-button {
    width: min(820px, 100%);
    margin-left: auto;
    margin-right: auto;
}

#daily-run-result,
#personal-best-result,
#friend-challenge-result {
    border-radius: 0 !important;
    border: 2px solid var(--game-border-strong) !important;
    background: var(--game-surface) !important;
    color: var(--game-text) !important;
    box-shadow: 6px 6px 0 var(--game-depth) !important;
}

.legend-export-wrapper {
    display: flex;
    justify-content: center;
    padding: 22px 0;
}

.legend-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    background: transparent;
}

.legend-actions button {
    min-height: 50px;
    padding: 10px 12px;
    border: 2px solid var(--game-border-strong);
    background: var(--game-surface-raised);
    color: var(--game-text);
    box-shadow: 3px 3px 0 var(--game-depth);
    font-size: 14px;
    font-weight: 700;
}

#champagne-restart-btn {
    background: var(--game-accent) !important;
    color: var(--game-bg) !important;
    box-shadow: 4px 4px 0 #8e7520 !important;
}

#champagne-screen .support-button {
    margin-top: 16px;
    border-radius: 0 !important;
    border-color: var(--game-border-strong) !important;
    background: transparent !important;
    color: var(--game-muted) !important;
    box-shadow: none !important;
}

/* ---------- Feedback and coachmarks ---------- */

.game-feedback-toast {
    position: absolute;
    left: 50%;
    bottom: 28px;
    z-index: 94;
    min-width: 220px;
    padding: 10px 18px;
    border: 3px solid var(--game-border-strong);
    background: var(--game-bg);
    color: var(--game-text);
    box-shadow: 4px 4px 0 var(--game-depth);
    font-family: var(--pixel-font-display);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-align: center;
    transform: translate(-50%, 8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 70ms linear, transform 70ms ease-out;
}

.game-feedback-toast.is-visible {
    transform: translate(-50%, 0);
    opacity: 1;
}

.game-feedback-toast[data-kind='error'] {
    border-color: var(--game-red);
    color: var(--game-red);
}

.game-feedback-toast[data-kind='success'] {
    border-color: var(--game-green);
    color: var(--game-green);
}

.game-coachmark {
    position: absolute;
    right: 14px;
    bottom: 14px;
    z-index: 96;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    width: min(460px, calc(100% - 28px));
    padding: 16px;
    border: 2px solid var(--game-border-strong);
    background: var(--game-surface-raised);
    color: var(--game-text);
    box-shadow: 6px 6px 0 var(--game-depth);
}

.game-coachmark-copy {
    display: grid;
    gap: 6px;
}

.game-coachmark-copy strong {
    color: var(--game-system);
    font-family: var(--pixel-font-display);
    font-size: 10px;
}

.game-coachmark-copy span {
    color: var(--game-muted);
    font-size: 13px;
    line-height: 1.5;
}

.game-coachmark button {
    min-width: 88px;
    min-height: 44px;
    border: 2px solid var(--game-border-strong);
    background: var(--game-surface);
    color: var(--game-text);
    box-shadow: 3px 3px 0 var(--game-depth);
    font-size: 13px;
}

.is-guide-target {
    outline: 3px solid var(--game-accent) !important;
    outline-offset: 3px;
}

#btn-buy.is-rejected,
#btn-sell.is-rejected {
    border-color: var(--game-red);
}

/* ---------- Bilingual typography ---------- */

html[data-flappyk-language='zh'] body,
html[data-flappyk-language='zh'] button,
html[data-flappyk-language='zh'] select,
html[data-flappyk-language='zh'] output,
html[data-flappyk-language='zh'] summary {
    font-family: 'ZCOOL QingKe HuangYou', var(--pixel-font-ui);
    font-weight: 400;
}

html[data-flappyk-language='zh'] #start-screen #game-title,
html[data-flappyk-language='zh'] .settlement-excess-summary,
html[data-flappyk-language='zh'] .legend-terminal-head h1,
html[data-flappyk-language='zh'] .local-records-summary strong {
    font-family: 'ZCOOL QingKe HuangYou', var(--pixel-font-display);
    letter-spacing: 0;
}

html[data-flappyk-language='zh'] .home-console-intro-copy {
    line-height: 1.7;
}

html[data-flappyk-language='zh'] .hud-metric-label,
html[data-flappyk-language='zh'] .run-progress-panel .hud-game,
html[data-flappyk-language='zh'] .run-progress-panel .hud-day {
    font-family: 'ZCOOL QingKe HuangYou', var(--pixel-font-ui);
}

html[data-flappyk-language='zh'] .hud-metric-label,
html[data-flappyk-language='zh'] .excess-meter-label,
html[data-flappyk-language='zh'] .run-progress-panel .hud-game,
html[data-flappyk-language='zh'] .run-progress-panel .hud-day {
    font-size: 12px;
}

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

@media (max-width: 820px) {
    #game-hud-rail {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            'performance controls'
            'progress progress';
    }

    .home-console-screen {
        grid-template-columns: minmax(0, 1fr) minmax(220px, 0.55fr);
        gap: 10px 22px;
        padding: clamp(18px, 3vw, 32px);
    }

    .home-mode-stack {
        align-self: center;
    }
}

@media (max-width: 719px) {
    #game-hud-rail {
        inset: 6px 6px auto 6px;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            'performance controls'
            'progress progress';
        box-shadow: 4px 4px 0 var(--game-depth);
    }

    .stats-box {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 5px 8px 4px;
    }

    .hud-metric-label {
        margin-bottom: 2px;
        font-size: 10px;
    }

    .hud-total > span:last-child,
    .hud-cash > span:last-child,
    .hud-return > span:last-child {
        font-size: clamp(16px, 4.2vw, 19px);
    }

    .excess-meter {
        margin-top: 4px;
        padding-top: 4px;
    }

    .excess-meter-label {
        font-size: 10px;
    }

    .excess-meter-label strong {
        font-size: 11px;
    }

    #game-top-controls {
        grid-template-columns: 44px 44px 44px 44px;
    }

    #game-skin-toggle-btn {
        font-size: 7px;
    }

    #game-top-controls .game-speed-control {
        display: none;
    }

    #start-screen.arcade-home {
        overflow: auto;
    }

    .home-console-bezel {
        min-height: 100%;
        height: auto;
        overflow: visible;
        box-shadow: 4px 4px 0 var(--game-depth);
    }

    .home-console-topline {
        grid-template-columns: auto minmax(0, 1fr) auto;
        min-height: 42px;
    }

    .home-console-brand {
        font-size: 10px;
    }

    .home-console-lamps {
        display: none;
    }

    .home-console-screen {
        grid-template-columns: 1fr;
        grid-template-areas:
            'kicker'
            'title'
            'copy'
            'worlds'
            'play'
            'profile'
            'side';
        align-content: start;
        gap: 14px;
        padding: 22px 16px 78px;
        overflow: visible;
    }

    .home-console-screen::before {
        display: none;
    }

    .home-console-screen::after {
        right: 0;
        bottom: 18%;
        font-size: clamp(220px, 76vw, 340px);
    }

    .home-console-kicker {
        font-size: 11px;
    }

    #start-screen #game-title {
        font-size: clamp(52px, 16vw, 72px);
        text-shadow: 4px 4px 0 var(--game-depth);
    }

    .home-console-intro-copy {
        font-size: 17px;
        line-height: 1.55;
    }

    .home-world-strip,
    .home-primary-actions {
        max-width: none;
    }

    .home-world {
        min-height: 48px;
    }

    .home-primary-actions #start-btn {
        min-height: 68px;
        font-size: 20px;
    }

    .home-mode-stack,
    .local-records-summary {
        width: 100%;
    }

    #settlement-screen.active {
        align-content: start;
        padding-top: max(14px, env(safe-area-inset-top));
        overflow-y: auto;
    }

    .profit-card {
        max-height: none;
        box-shadow: 5px 5px 0 var(--game-depth);
    }

    .settlement-summary {
        grid-template-columns: 1fr;
        grid-template-areas:
            'verdict'
            'excess'
            'compare';
        padding: 22px 18px;
    }

    .settlement-excess-summary {
        justify-self: start;
        font-size: clamp(46px, 16vw, 68px);
    }

    .settlement-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .legend-terminal-head {
        grid-template-columns: 1fr auto;
    }

    .legend-terminal-kicker {
        grid-column: 1 / -1;
    }
}

@media (max-width: 430px) {
    .home-console-topline {
        min-height: 40px;
        padding-inline: 9px;
    }

    .home-console-series {
        display: none;
    }

    .home-world-strip {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .home-world {
        grid-template-columns: 1fr;
        gap: 4px;
        min-height: 52px;
        padding: 6px 4px;
        text-align: center;
    }

    .home-world + .home-world {
        border-left: 1px solid var(--game-border);
        border-top: 0;
    }

    .home-world-index {
        justify-self: center;
    }

    .home-world-name {
        font-size: 10px;
        text-align: center;
    }

    .home-secondary-actions,
    .legend-actions,
    .settlement-actions {
        grid-template-columns: 1fr;
    }

    .settlement-comparison-row {
        grid-template-columns: 58px minmax(0, 1fr) 70px;
        font-size: 11px;
    }

    .profit-card[data-details-expanded='true'] .card-details {
        grid-template-columns: 1fr;
    }
}

@media (orientation: landscape) and (max-height: 540px) {
    #game-hud-rail {
        inset: 4px 4px auto 4px;
    }

    .home-console-screen {
        align-content: center;
        padding: 16px 20px;
    }

    #start-screen #game-title {
        font-size: clamp(38px, 10vh, 58px);
    }

    .home-console-intro-copy {
        font-size: 15px;
    }

    .home-primary-actions #start-btn {
        min-height: 54px;
        font-size: 16px;
    }
}

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