:root {
    --green: #28d17c;
    --green-dark: #144a32;
    --slate: #6f839c;
    --bg: #050a08;
    --panel: rgba(8, 20, 15, .78);
    --line: rgba(83, 255, 162, .15);
    --text: #eaf7ef;
    --muted: #91a59a;
    --danger: #ff5e6c;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    background:
        radial-gradient(circle at 50% -15%, rgba(20, 74, 50, .55), transparent 42rem),
        linear-gradient(180deg, #07110d 0%, #030604 100%);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overscroll-behavior: none;
}

body {
    min-height: 100dvh;
    overflow: hidden;
    padding:
        max(12px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(12px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
}

button {
    font: inherit;
}

.shell {
    width: min(1180px, 100%);
    height: calc(100dvh - max(24px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    margin: 0 auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: clamp(8px, 1.5vw, 16px);
}

.topbar,
footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: var(--muted);
    font-size: clamp(.63rem, 1.5vw, .78rem);
    letter-spacing: .12em;
}

.topbar {
    min-height: 48px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
}

.brand strong {
    display: block;
    color: #f1fff6;
    font-size: clamp(.82rem, 2vw, 1rem);
    letter-spacing: .13em;
}

.brand small {
    display: block;
    margin-top: 2px;
    font-size: clamp(.48rem, 1.4vw, .6rem);
    color: #71837a;
    letter-spacing: .1em;
}

.brand-mark {
    width: 14px;
    height: 28px;
    border-radius: 4px;
    background: linear-gradient(180deg, #38ee91, #144a32);
    box-shadow: 0 0 22px rgba(40, 209, 124, .45);
}

.node-state {
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}

.pulse {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 12px var(--green);
    animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
    50% {
        opacity: .35;
        transform: scale(.72);
    }
}

.game-frame {
    min-height: 0;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(101, 255, 169, .16);
    border-radius: clamp(16px, 3vw, 26px);
    background:
        linear-gradient(rgba(26, 78, 52, .05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(26, 78, 52, .05) 1px, transparent 1px),
        #050c08;
    background-size: 32px 32px;
    box-shadow:
        0 30px 90px rgba(0, 0, 0, .46),
        inset 0 0 60px rgba(20, 74, 50, .08);
    touch-action: none;
    user-select: none;
}

.game-frame::after {
    content: "";
    pointer-events: none;
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(0, 0, 0, .18), transparent 18%, transparent 82%, rgba(0, 0, 0, .2)),
        repeating-linear-gradient(0deg, rgba(255,255,255,.012) 0 1px, transparent 1px 4px);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.hud {
    pointer-events: none;
    position: absolute;
    z-index: 4;
    top: clamp(10px, 2vw, 18px);
    left: clamp(10px, 2vw, 18px);
    right: clamp(10px, 2vw, 18px);
    display: grid;
    grid-template-columns: 1fr 1.3fr 1fr;
    padding: 9px 13px;
    border: 1px solid rgba(91, 255, 161, .12);
    border-radius: 13px;
    background: rgba(3, 12, 8, .58);
    backdrop-filter: blur(10px);
}

.hud-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.hud-cell.center {
    align-items: center;
    text-align: center;
}

.hud-cell.right {
    align-items: flex-end;
}

.hud span,
.result-grid span {
    color: #6f887a;
    font-size: clamp(.45rem, 1.4vw, .59rem);
    letter-spacing: .13em;
}

.hud strong {
    color: #dffff0;
    font-size: clamp(.72rem, 2vw, 1rem);
    letter-spacing: .08em;
}

.overlay {
    position: absolute;
    z-index: 10;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(1, 6, 4, .58);
    backdrop-filter: blur(6px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .22s ease, visibility .22s ease;
}

.overlay.visible {
    opacity: 1;
    visibility: visible;
}

.panel {
    width: min(560px, 94%);
    padding: clamp(24px, 5vw, 48px);
    border: 1px solid rgba(81, 255, 157, .18);
    border-radius: 24px;
    text-align: center;
    background:
        radial-gradient(circle at 50% 0%, rgba(40, 209, 124, .09), transparent 55%),
        rgba(4, 14, 9, .91);
    box-shadow: 0 25px 80px rgba(0, 0, 0, .55);
}

.panel.compact {
    width: min(480px, 94%);
}

.eyebrow {
    margin-bottom: 12px;
    color: var(--green);
    font-size: clamp(.58rem, 1.7vw, .72rem);
    letter-spacing: .22em;
}

.eyebrow.warning {
    color: #ff808c;
}

h1,
h2 {
    margin: 0;
    letter-spacing: -.04em;
}

h1 {
    font-size: clamp(2.1rem, 9vw, 4.8rem);
}

h1 span {
    color: var(--green);
}

h2 {
    font-size: clamp(1.8rem, 7vw, 3.4rem);
}

.panel p {
    max-width: 450px;
    margin: 16px auto 24px;
    color: #93a89b;
    line-height: 1.6;
    font-size: clamp(.82rem, 2.2vw, .98rem);
}

button {
    min-width: 190px;
    min-height: 50px;
    border: 1px solid rgba(61, 242, 139, .42);
    border-radius: 12px;
    padding: 13px 22px;
    cursor: pointer;
    color: #eafff2;
    background: linear-gradient(180deg, #1c6948, #123d2b);
    box-shadow: 0 8px 30px rgba(19, 126, 78, .2);
    font-weight: 800;
    letter-spacing: .09em;
}

button:hover,
button:focus-visible {
    outline: none;
    background: linear-gradient(180deg, #227b55, #154a33);
    border-color: #42ed91;
}

.controls {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    color: #62766a;
    font-size: .62rem;
    letter-spacing: .09em;
}

.controls span {
    padding: 5px 7px;
    border: 1px solid rgba(255,255,255,.09);
    border-radius: 6px;
}

.controls b {
    align-self: center;
    margin-left: 3px;
    color: #7d9387;
}

.result-grid {
    width: min(300px, 100%);
    margin: 0 auto 22px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.result-grid div {
    padding: 12px;
    border: 1px solid rgba(255,255,255,.07);
    border-radius: 11px;
    background: rgba(255,255,255,.025);
}

.result-grid strong {
    display: block;
    margin-top: 3px;
    color: #e8fff1;
    font-size: 1.2rem;
}

.shield-state {
    position: absolute;
    z-index: 6;
    bottom: 16px;
    left: 50%;
    transform: translate(-50%, 10px);
    opacity: 0;
    padding: 8px 12px;
    border: 1px solid rgba(66, 226, 247, .35);
    border-radius: 999px;
    color: #9ff6ff;
    background: rgba(4, 24, 28, .78);
    font-size: .6rem;
    letter-spacing: .12em;
    transition: .2s ease;
}

.shield-state.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

footer {
    min-height: 26px;
    padding-inline: 4px;
}

@media (max-width: 640px) {
    body {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-right: max(8px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        padding-left: max(8px, env(safe-area-inset-left));
    }

    .shell {
        height: calc(100dvh - max(16px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    }

    .topbar {
        min-height: 40px;
    }

    .brand small,
    .desktop-copy {
        display: none;
    }

    .hud {
        grid-template-columns: .8fr 1.5fr .8fr;
    }

    .panel {
        padding: 25px 20px;
        border-radius: 18px;
    }

    footer {
        justify-content: center;
    }
}

@media (orientation: portrait) and (max-width: 820px) {
    .game-frame {
        border-radius: 18px;
    }
}

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