:root {
    --ui-dark: #1a1c2c;
    --ui-panel: #29366f;
    --ui-border: #f4f4f4;
    --ui-accent: #ffcd75;
    --ui-green: #38b764;
    --ui-red: #ef7d57;
    --title-shadow: #b13e53;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-height: 100vh;
    padding: 12px;
    background: var(--ui-dark);
    font-family: "Press Start 2P", monospace;
    color: var(--ui-border);
    overflow-x: hidden;
}

header {
    text-align: center;
    line-height: 1.7;
}

header h1 {
    font-size: clamp(0.8rem, 3vw, 1.3rem);
    color: var(--ui-accent);
    text-shadow: 3px 3px 0 var(--title-shadow);
}

header p {
    font-size: clamp(0.45rem, 1.6vw, 0.6rem);
    color: #94b0c2;
}

.game-frame {
    position: relative;
    width: min(96vw, 840px);
    border: 4px solid var(--ui-border);
    border-radius: 6px;
    box-shadow: 0 0 0 4px var(--ui-dark), 0 0 0 8px #566c86, 0 18px 40px rgba(0, 0, 0, 0.6);
    background: #000;
    overflow: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* CRT scanlines */
.game-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(0deg,
            rgba(0, 0, 0, 0.16) 0px,
            rgba(0, 0, 0, 0.16) 1px,
            transparent 1px,
            transparent 3px);
    mix-blend-mode: multiply;
}

.hud {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    width: min(96vw, 840px);
    padding: 8px 12px;
    border: 3px solid var(--ui-border);
    border-radius: 4px;
    background: var(--ui-panel);
    font-size: clamp(0.5rem, 1.8vw, 0.65rem);
    text-align: center;
    line-height: 1.8;
}

.hud .key {
    color: var(--ui-accent);
}

/* Dialog */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.65);
}

.dialog-backdrop.open {
    display: flex;
}

.dialog {
    width: min(92vw, 480px);
    border: 4px solid var(--ui-border);
    border-radius: 4px;
    background: var(--ui-panel);
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.5);
    animation: pop 0.15s steps(3) both;
}

@keyframes pop {
    from {
        transform: scale(0.7);
    }

    to {
        transform: scale(1);
    }
}

.dialog-title {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 4px solid var(--ui-border);
    background: var(--ui-dark);
    font-size: clamp(0.6rem, 2.2vw, 0.8rem);
    color: var(--ui-accent);
}

.dialog-title .emoji {
    font-size: 1.4em;
}

.dialog-body {
    padding: 14px;
    font-size: clamp(0.5rem, 1.9vw, 0.62rem);
    line-height: 1.9;
    color: #c0d1e0;
}

.dialog-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 14px 14px;
}

.dialog-links a,
.dialog-links button {
    display: block;
    width: 100%;
    padding: 12px 10px;
    border: 3px solid var(--ui-border);
    border-radius: 3px;
    background: var(--ui-green);
    color: #fff;
    font-family: inherit;
    font-size: clamp(0.5rem, 1.9vw, 0.62rem);
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.dialog-links a.selected,
.dialog-links button.selected,
.dialog-links a:hover,
.dialog-links button:hover {
    background: var(--ui-accent);
    color: var(--ui-dark);
}

.dialog-links a.selected::before,
.dialog-links button.selected::before {
    content: "▶ ";
}

.dialog-links button.close-btn {
    background: var(--ui-red);
}

/* Touch controls */
.touch-controls {
    display: none;
    width: min(96vw, 840px);
    justify-content: space-between;
    align-items: center;
    padding: 4px;
    user-select: none;
    -webkit-user-select: none;
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    gap: 2px;
}

.dpad button,
.action-btn {
    border: 3px solid var(--ui-border);
    border-radius: 6px;
    background: var(--ui-panel);
    color: var(--ui-border);
    font-family: inherit;
    font-size: 0.9rem;
    touch-action: none;
}

.dpad button:active,
.action-btn:active {
    background: var(--ui-accent);
    color: var(--ui-dark);
}

.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }

.action-btn {
    width: 78px;
    height: 78px;
    border-radius: 50%;
    background: var(--ui-green);
    font-size: 0.6rem;
}

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

footer {
    font-size: clamp(0.42rem, 1.4vw, 0.5rem);
    color: #566c86;
    text-align: center;
    line-height: 1.8;
    padding-bottom: 8px;
}

footer a {
    color: #94b0c2;
}
