:root {
    --ink: #102010;
    --leaf: #2f8a40;
    --sun: #f6d03a;
    --scarf: #e31b23;
    --cream: #fff6ea;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

html,
body.kong-lab {
    overflow-x: clip;
}

body.kong-lab {
    position: relative;
    min-height: 100dvh;
    padding: max(1.1rem, var(--safe-top))
        max(1rem, var(--safe-right))
        max(1.1rem, var(--safe-bottom))
        max(1rem, var(--safe-left));
    background:
        radial-gradient(circle at 12% 10%, rgba(246, 208, 58, 0.12), transparent 28rem),
        radial-gradient(circle at 90% 80%, rgba(227, 27, 35, 0.1), transparent 26rem),
        linear-gradient(160deg, #102010 0%, #1c3a1c 48%, #0e1c12 100%);
    color: var(--cream);
}

.ambient {
    position: fixed;
    z-index: -1;
    width: 24rem;
    height: 24rem;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
    opacity: 0.16;
}

.ambient-a {
    top: 8%;
    left: -8rem;
    background: #3d9a3a;
}

.ambient-b {
    right: -8rem;
    bottom: 10%;
    background: var(--scarf);
}

.kong-lab header {
    max-width: 1080px;
    margin-bottom: 1rem;
}

.kong-lab .app-logo {
    color: var(--cream);
    font-family: "Titan One", system-ui, sans-serif;
    letter-spacing: 0.04em;
}

.kong-lab .logo-mark {
    color: var(--scarf);
}

.kong-lab .back-link,
.kong-lab .theme-toggle {
    color: rgba(255, 246, 234, 0.82);
    border-color: rgba(255, 246, 234, 0.14);
    background: rgba(16, 32, 16, 0.55);
    box-shadow: none;
    backdrop-filter: blur(12px);
}

.kong-lab .theme-toggle-thumb {
    background: var(--leaf);
}

.stage-wrap {
    width: min(100%, 1080px);
    margin: 0 auto;
}

.cabinet {
    overflow: hidden;
    border: 1px solid rgba(246, 208, 58, 0.22);
    border-radius: 1.25rem;
    background: #142414;
    box-shadow: 0 28px 80px rgba(0, 8, 0, 0.45), inset 0 1px rgba(255, 255, 255, 0.06);
}

.rail {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem;
    color: rgba(255, 246, 234, 0.42);
    font: 700 0.58rem/1 "Nunito", system-ui, sans-serif;
    letter-spacing: 0.18em;
}

.rail-top {
    height: 32px;
}

.rail-top span {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(246, 208, 58, 0.28));
}

.rail-top span:last-child {
    background: linear-gradient(90deg, rgba(246, 208, 58, 0.28), transparent);
}

.rail-bottom {
    min-height: 36px;
    justify-content: space-between;
    padding-top: 0.35rem;
    padding-bottom: 0.45rem;
    letter-spacing: 0.04em;
    text-transform: none;
    font-weight: 700;
}

.rail-bottom p {
    margin: 0;
    max-width: min(70ch, 100%);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.rail-bottom strong {
    color: var(--sun);
    margin-right: 0.4rem;
}

.sig {
    flex-shrink: 0;
    letter-spacing: 0.16em;
}

.stage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #102010;
    isolation: isolate;
}

#game {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    touch-action: none;
}

.vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 90px rgba(0, 8, 0, 0.35);
}

.hud-dock {
    position: absolute;
    top: max(0.45rem, var(--safe-top));
    right: max(0.45rem, var(--safe-right));
    z-index: 8;
    display: flex;
    gap: 0.4rem;
    pointer-events: none;
}

.icon-btn {
    pointer-events: auto;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255, 246, 234, 0.18);
    border-radius: 12px;
    background: rgba(12, 24, 12, 0.55);
    color: var(--cream);
    font-size: 1rem;
    cursor: pointer;
    backdrop-filter: blur(8px);
}

.icon-btn.is-dim {
    opacity: 0.55;
}

.touch-pad {
    display: none;
    position: absolute;
    z-index: 9;
    left: 0;
    right: 0;
    bottom: 0;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.45rem max(0.55rem, var(--safe-right)) max(0.55rem, var(--safe-bottom)) max(0.55rem, var(--safe-left));
    pointer-events: none;
}

.touch-pad.is-hidden {
    opacity: 0;
    pointer-events: none;
}

.dpad,
.actions,
.dpad-mid {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.dpad-mid {
    flex-direction: column;
}

.pad-btn {
    pointer-events: auto;
    min-width: 52px;
    min-height: 52px;
    border: 1px solid rgba(255, 246, 234, 0.16);
    border-radius: 16px;
    background: rgba(16, 32, 16, 0.62);
    color: var(--cream);
    font: 800 0.78rem/1 "Nunito", system-ui, sans-serif;
    backdrop-filter: blur(8px);
    touch-action: manipulation;
    user-select: none;
}

.pad-jump {
    min-width: 64px;
    min-height: 64px;
    border-radius: 50%;
    background: rgba(227, 27, 35, 0.78);
}

.pad-roll {
    min-width: 56px;
    min-height: 56px;
    border-radius: 50%;
    background: rgba(246, 208, 58, 0.82);
    color: #3a2410;
}

.pad-sm {
    min-width: 44px;
    min-height: 44px;
}

.help {
    margin: 0.75rem 0 0;
    color: rgba(255, 246, 234, 0.55);
    font: 700 0.78rem/1.4 "Nunito", system-ui, sans-serif;
    text-align: center;
}

.help kbd {
    display: inline-block;
    margin: 0 0.12rem;
    padding: 0.12rem 0.4rem;
    border: 1px solid rgba(255, 246, 234, 0.18);
    border-radius: 0.4rem;
    background: rgba(0, 0, 0, 0.25);
    font-size: 0.72rem;
}

.kong-lab footer {
    margin-top: 1.1rem;
}

@media (hover: none) and (pointer: coarse) {
    .touch-pad {
        display: flex;
    }

    .help {
        display: none;
    }
}

@media (max-width: 768px) {
    body.kong-lab {
        padding: max(0.55rem, var(--safe-top))
            max(0.55rem, var(--safe-right))
            max(0.55rem, var(--safe-bottom))
            max(0.55rem, var(--safe-left));
    }

    .kong-lab header {
        margin-bottom: 0.55rem;
    }

    .kong-lab header .app-logo {
        font-size: 0.95rem;
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .cabinet {
        border-radius: 1rem;
    }

    .rail-top {
        height: 24px;
    }

    .stage {
        aspect-ratio: auto;
        min-height: min(58dvh, 520px);
    }

    .touch-pad {
        display: flex;
    }

    .help {
        display: none;
    }

    .rail-bottom p {
        white-space: normal;
        font-size: 0.62rem;
        letter-spacing: 0;
    }

    .sig {
        display: none;
    }

    .kong-lab footer {
        margin-top: 0.6rem;
    }
}

@media (max-height: 520px) and (orientation: landscape) {
    body.kong-lab {
        padding: 0;
    }

    .kong-lab header,
    .kong-lab footer,
    .rail,
    .help {
        display: none;
    }

    .stage-wrap,
    .cabinet,
    .stage {
        width: 100%;
        max-width: none;
        height: 100dvh;
        border: 0;
        border-radius: 0;
        aspect-ratio: auto;
        min-height: 0;
    }

    .touch-pad {
        display: flex;
    }

    .pad-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .pad-jump,
    .pad-roll {
        min-width: 52px;
        min-height: 52px;
    }

    .hud-dock {
        top: max(0.3rem, var(--safe-top));
        right: max(0.35rem, var(--safe-right));
    }
}

@media (prefers-reduced-motion: reduce) {
    .ambient {
        display: none;
    }
}
