:root {
    --bg: #090b12;
    --panel: #111827;
    --text: #e5f0ff;
    --accent: #63f5a6;
    --muted: #8191a8;
    --danger: #ff5f75;
    --border: #2b3850;
    --shadow: #03050a;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 50% -20%, rgba(91, 115, 160, .16), transparent 42rem),
        var(--bg);
    font-family: "Courier New", "Lucida Console", monospace;
    letter-spacing: .035em;
}
button, input, textarea, select { font: inherit; }
a { color: inherit; }

.scanlines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 99;
    opacity: .12;
    background: repeating-linear-gradient(to bottom, transparent 0, transparent 3px, #000 4px);
}

.pixel-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: bold;
    text-transform: uppercase;
}
.pixel-link:hover, .pixel-link:focus-visible { text-decoration: underline; }

.pixel-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: .8rem 1rem;
    border: 3px solid currentColor;
    border-radius: 0;
    color: var(--text);
    background: transparent;
    box-shadow: 4px 4px 0 var(--shadow);
    text-decoration: none;
    text-transform: uppercase;
    font-weight: bold;
    cursor: pointer;
    transition: transform .08s ease, box-shadow .08s ease, background .08s ease;
}
.pixel-button:hover, .pixel-button:focus-visible {
    transform: translate(-1px, -1px);
    box-shadow: 6px 6px 0 var(--shadow);
}
.pixel-button:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--shadow); }
.pixel-button.primary { color: var(--bg); border-color: var(--accent); background: var(--accent); }

/* Game selector */
.selector-body { padding: 1rem; }
.selector-shell { width: min(1100px, 100%); margin: 0 auto; position: relative; z-index: 1; }
.selector-header { padding: 3rem 0 2rem; }
.selector-header .eyebrow { color: var(--accent); font-weight: bold; margin: 0 0 1rem; }
.selector-header h1 {
    margin: 0;
    max-width: 12ch;
    font-size: clamp(2.5rem, 13vw, 6rem);
    line-height: .84;
    letter-spacing: -.08em;
    text-shadow: 4px 4px 0 #25304a;
}
.selector-header > p:last-child { color: var(--muted); margin-top: 1.5rem; }
.game-grid { display: grid; gap: 1.25rem; }
.game-card {
    --card-accent: var(--accent);
    --card-panel: var(--panel);
    border: 4px solid var(--border);
    background: var(--card-panel);
    box-shadow: 8px 8px 0 #03050a;
    overflow: hidden;
}
.cartridge-stripes {
    height: 18px;
    background: repeating-linear-gradient(90deg, var(--card-accent) 0 12px, transparent 12px 20px);
    border-bottom: 4px solid var(--border);
}
.game-card-body { padding: 1.25rem; }
.game-card .game-id { color: var(--card-accent); font-size: .78rem; text-transform: uppercase; }
.game-card h2 { margin: .45rem 0 .8rem; font-size: 1.45rem; text-transform: uppercase; }
.game-card p { min-height: 3.2em; color: var(--muted); line-height: 1.6; }
.game-card .pixel-button { --accent: var(--card-accent); margin-top: .5rem; }
.selector-footer { padding: 2.5rem 0; text-align: right; }

/* Player */
.player-body { display: grid; place-items: center; padding: .5rem; }
.game-shell {
    position: relative;
    z-index: 1;
    width: min(920px, 100%);
    border: 4px solid var(--border);
    background: #05070d;
    box-shadow: 10px 10px 0 #020308;
}
.game-topbar, .game-footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 48px;
    padding: .6rem .75rem;
    border-bottom: 4px solid var(--border);
    color: var(--muted);
    font-size: .72rem;
    text-transform: uppercase;
}
.game-topbar > span { color: var(--text); text-align: center; font-weight: bold; }
.sound-toggle {
    justify-self: end;
    padding: .35rem;
    border: 2px solid var(--border);
    color: var(--accent);
    background: transparent;
    cursor: pointer;
}
.game-screen {
    min-height: min(75vh, 690px);
    padding: clamp(.65rem, 3vw, 1.5rem);
    display: grid;
    align-items: center;
    background:
        linear-gradient(rgba(255,255,255,.015), rgba(255,255,255,.015)),
        var(--panel);
}
.game-footer { display: block; min-height: 0; border: 0; border-top: 4px solid var(--border); text-align: center; }
.story-card { width: 100%; display: grid; gap: 1rem; }
.story-card h1 {
    margin: 0;
    color: var(--accent);
    font-size: clamp(1.2rem, 4vw, 2rem);
    line-height: 1.15;
    text-transform: uppercase;
}
.story-text {
    padding: 1rem;
    border: 3px solid var(--border);
    background: rgba(0,0,0,.22);
    font-size: clamp(.95rem, 2.6vw, 1.12rem);
    line-height: 1.7;
    white-space: normal;
}
.pixel-scene {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: contain;
    border: 4px solid var(--border);
    background: #000;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}
.choice-list { display: grid; gap: .75rem; }
.choice-button { justify-content: flex-start; text-align: left; }
.choice-button:hover .choice-cursor { animation: blink .45s steps(1) infinite; }
.answer-form { display: grid; gap: .75rem; }
.pixel-input {
    width: 100%;
    min-height: 52px;
    padding: .8rem;
    border: 3px solid var(--border);
    border-radius: 0;
    outline: 0;
    color: var(--text);
    background: #05070d;
    box-shadow: inset 3px 3px 0 #000;
    text-transform: uppercase;
}
.pixel-input:focus { border-color: var(--accent); }
.input-error { padding: .75rem; border: 3px solid var(--danger); color: var(--danger); animation: blink .7s steps(1) 2; }
.template-redirect { text-align: center; }
.loading-bar { height: 20px; border: 3px solid var(--border); padding: 3px; }
.loading-bar span { display: block; height: 100%; width: 0; background: var(--accent); animation: loadbar 1.2s steps(10, end) forwards; }
.fallback-link { justify-self: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes loadbar { to { width: 100%; } }

@media (min-width: 650px) {
    .selector-body { padding: 2rem; }
    .game-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .answer-form { grid-template-columns: 1fr auto; }
    .template-image-text { grid-template-columns: minmax(0, 1.25fr) minmax(260px, .75fr); align-items: start; }
    .template-image-text h1 { grid-column: 1 / -1; }
    .template-image-text .pixel-scene { grid-row: 2 / span 2; }
    .template-image-text .pixel-button { align-self: end; }
}

@media (min-width: 980px) {
    .game-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

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

/* Optional page music and frame animations */
.audio-controls {
    justify-self: end;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .4rem;
}
.music-toggle,
.sound-toggle {
    min-height: 32px;
    padding: .3rem .45rem;
    border: 2px solid var(--border);
    color: var(--accent);
    background: transparent;
    font: inherit;
    font-size: .68rem;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
}
.music-toggle[aria-pressed="true"] { color: var(--danger); border-color: var(--danger); }
.music-toggle:hover,
.music-toggle:focus-visible,
.sound-toggle:hover,
.sound-toggle:focus-visible { border-color: currentColor; }

.template-animation { align-items: start; }
.retro-animation { display: grid; gap: .55rem; }
.animation-stage { position: relative; background: #000; }
.animation-frame { margin: 0; }
.animation-counter {
    position: absolute;
    right: .45rem;
    bottom: .45rem;
    padding: .25rem .4rem;
    border: 2px solid var(--border);
    color: var(--text);
    background: rgba(0, 0, 0, .82);
    font-size: .68rem;
}
.animation-caption {
    min-height: 1.4em;
    color: var(--muted);
    font-size: .75rem;
    text-align: center;
    text-transform: uppercase;
}
.animation-progress { height: 12px; padding: 2px; border: 2px solid var(--border); }
.animation-progress span { display: block; width: 0; height: 100%; background: var(--accent); }
.animation-controls { display: flex; flex-wrap: wrap; gap: .55rem; }
.animation-controls .pixel-button { min-height: 38px; padding: .45rem .7rem; }
.animation-next { justify-self: start; }

@media (max-width: 520px) {
    .game-topbar { grid-template-columns: auto 1fr auto; gap: .4rem; }
    .game-topbar > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .music-toggle { font-size: 0; }
    .music-toggle::before { content: "♪"; font-size: .9rem; }
}
