:root {
    color-scheme: dark;
    font-family: "SFMono-Regular", "Cascadia Mono", "PingFang SC", "Microsoft YaHei", monospace;
    background: #211032;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #211032;
}

button {
    font: inherit;
    letter-spacing: 0;
}

.game-shell {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 420px;
    overflow: hidden;
    background: #211032;
    isolation: isolate;
}

#game-container,
#game-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#game-container canvas {
    object-fit: contain;
    background: #211032;
}

.game-shell::before {
    position: absolute;
    inset: 0;
    z-index: 12;
    pointer-events: none;
    opacity: 0.1;
    background: repeating-linear-gradient(to bottom, transparent 0, transparent 3px, rgba(168, 255, 236, 0.15) 4px);
    content: "";
}

.screen-layer {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 52px;
    background: rgba(33, 16, 50, 0.76);
}

.screen-layer.is-visible {
    display: flex;
}

#start-screen {
    justify-content: flex-start;
    background: linear-gradient(90deg, rgba(33, 16, 50, 0.94) 0%, rgba(33, 16, 50, 0.72) 40%, rgba(33, 16, 50, 0.08) 72%);
}

.start-copy {
    width: 490px;
    color: #dceae7;
}

.eyebrow {
    margin: 0 0 10px;
    color: #ad79f0;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    color: #e6f1ef;
    font-family: "SFMono-Regular", "Cascadia Mono", "PingFang SC", monospace;
    font-size: 68px;
    font-weight: 700;
    line-height: 0.98;
    letter-spacing: 0;
    text-shadow: 0 0 28px rgba(221, 182, 255, 0.18);
}

h1 span {
    color: #ddb6ff;
    font-size: 0.82em;
    text-shadow: 0 0 22px rgba(221, 182, 255, 0.28);
}

.mission {
    max-width: 470px;
    margin: 34px 0 18px;
    color: #8fa3a1;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.8;
}

.mode-selector {
    display: inline-grid;
    grid-template-columns: repeat(2, minmax(116px, 1fr));
    margin-bottom: 18px;
    border: 1px solid rgba(221, 182, 255, 0.38);
    background: rgba(33, 16, 50, 0.72);
}

.mode-option {
    min-height: 44px;
    border: 0;
    color: #829592;
    background: transparent;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.mode-option + .mode-option {
    border-left: 1px solid rgba(221, 182, 255, 0.38);
}

.mode-option span,
.mode-button span,
.agent-title span {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 8px;
    border-radius: 50%;
    background: #526361;
    vertical-align: 1px;
}

.mode-option.is-active {
    color: #211032;
    background: #ddb6ff;
}

.mode-option.is-active span,
.mode-button.is-active span,
.agent-title span {
    background: #ddb6ff;
    box-shadow: 0 0 10px #ddb6ff;
}

.primary-button {
    display: block;
    min-width: 196px;
    min-height: 52px;
    border: 1px solid #ddb6ff;
    border-radius: 2px;
    color: #211032;
    background: #ddb6ff;
    box-shadow: 4px 4px 0 rgba(157, 102, 205, 0.75);
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.primary-button:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 rgba(157, 102, 205, 0.75);
}

.primary-button:active {
    transform: translate(3px, 3px);
    box-shadow: 2px 2px 0 rgba(157, 102, 205, 0.75);
}

.result-panel {
    width: min(520px, 92vw);
    padding: 32px;
    border: 1px solid #ddb6ff;
    border-radius: 2px;
    color: #dceae7;
    background: rgba(33, 16, 50, 0.96);
    box-shadow: 8px 8px 0 rgba(157, 102, 205, 0.28);
    text-align: center;
}

.result-panel h2 {
    margin: 4px 0 22px;
    color: #e6f1ef;
    font-family: inherit;
    font-size: 42px;
    line-height: 1;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2px;
    margin: 0 0 26px;
    border: 1px solid rgba(221, 182, 255, 0.4);
    background: rgba(221, 182, 255, 0.28);
}

.result-stats span {
    padding: 15px 10px;
    color: #a9b9b7;
    background: #081116;
    font-size: 14px;
    font-weight: 800;
}

.result-stats b {
    display: block;
    color: #ddb6ff;
    font-size: 28px;
}

.utility-buttons {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    z-index: 20;
    display: flex;
    gap: 8px;
}

.icon-button,
.mode-button,
.touch-button {
    display: grid;
    place-items: center;
    border: 1px solid rgba(221, 182, 255, 0.38);
    color: #b8c8c5;
    background: rgba(33, 16, 50, 0.84);
    box-shadow: none;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.icon-button {
    width: 42px;
    height: 42px;
    border-radius: 2px;
    font-size: 19px;
    font-weight: 900;
}

.mode-button {
    grid-auto-flow: column;
    width: 68px;
    height: 42px;
    border-radius: 2px;
    font-size: 13px;
    font-weight: 950;
}

.mode-button.is-active {
    border-color: #ddb6ff;
    color: #ddb6ff;
}

.agent-panel {
    position: absolute;
    top: max(68px, calc(env(safe-area-inset-top) + 56px));
    right: max(14px, env(safe-area-inset-right));
    z-index: 18;
    width: 246px;
    border: 1px solid rgba(221, 182, 255, 0.44);
    color: #dceae7;
    background: rgba(33, 16, 50, 0.9);
    box-shadow: 5px 5px 0 rgba(157, 102, 205, 0.18);
    transition: opacity 160ms ease;
}

.agent-panel.is-inactive {
    opacity: 0.42;
}

.agent-title {
    padding: 9px 12px;
    border-bottom: 1px solid rgba(221, 182, 255, 0.44);
    color: #ddb6ff;
    font-size: 12px;
    font-weight: 950;
}

.agent-panel dl {
    margin: 0;
}

.agent-panel dl div {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 8px;
    padding: 7px 11px;
    border-bottom: 1px solid rgba(221, 182, 255, 0.14);
    font-size: 11px;
}

.agent-panel dl div:last-child {
    border-bottom: 0;
}

.agent-panel dt {
    color: #ad79f0;
}

.agent-panel dd {
    margin: 0;
    overflow: hidden;
    color: #c4d2cf;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.touch-controls {
    position: absolute;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    left: max(18px, env(safe-area-inset-left));
    z-index: 14;
    display: none;
    justify-content: space-between;
    pointer-events: none;
}

.touch-group {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.touch-button {
    width: 64px;
    height: 64px;
    border-radius: 2px;
    font-size: 30px;
    font-weight: 950;
    pointer-events: auto;
}

.touch-button.action {
    width: 72px;
    height: 72px;
}

.touch-button.jump {
    color: #211032;
    background: rgba(239, 183, 248, 0.9);
}

.touch-button.dash {
    color: #211032;
    background: rgba(221, 182, 255, 0.9);
}

.touch-button.is-pressed,
.icon-button:active,
.mode-button:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 rgba(16, 21, 44, 0.46);
}

@media (pointer: coarse), (max-width: 900px) {
    .touch-controls {
        display: flex;
    }

    .utility-buttons {
        top: max(8px, env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
    }

    .agent-panel {
        top: max(58px, calc(env(safe-area-inset-top) + 50px));
        right: max(8px, env(safe-area-inset-right));
        width: 194px;
    }

    #start-screen {
        align-items: flex-start;
        padding: max(34px, env(safe-area-inset-top)) 24px 120px;
    }

    .start-copy {
        width: min(390px, 82vw);
    }

    h1 {
        font-size: 54px;
    }

    h1 span {
        font-size: 34px;
    }

    .mission {
        margin-top: 22px;
        font-size: 15px;
    }
}

@media (max-width: 620px) {
    .agent-panel {
        width: 174px;
    }

    .agent-panel dl div {
        grid-template-columns: 40px 1fr;
        font-size: 10px;
    }

    .mode-button {
        width: 58px;
    }

    .touch-button {
        width: 54px;
        height: 54px;
    }

    .touch-button.action {
        width: 60px;
        height: 60px;
    }
}

@media (max-height: 560px) {
    .game-shell {
        min-height: 320px;
    }

    .start-copy {
        transform: scale(0.76);
        transform-origin: left top;
    }

    .agent-panel {
        transform: scale(0.78);
        transform-origin: right top;
    }
}
