/*

$N64X GBA Player — 8-bit design system.

Everything here derives from one idea: a GBA cartridge on a shelf. Cards are
cartridge labels (notched corner, hue band, hard shadow), texture is a 4px
checkerboard dither rather than blur or glow, and no transition uses easing —
motion advances in steps() so it snaps frame-by-frame like a sprite.

*/


/*
|-----------------------------------------
| Tokens
|-----------------------------------------
*/

:root {
    /* NES/PICO-8-limited palette, anchored on the brand magenta. */
    --void: #0b0910;
    --void-2: #14111d;
    --void-3: #1e1a2b;
    --ink: #f2f0ff;
    --ink-dim: #9b93b8;
    --ink-faint: #6a6383;

    --magenta: #d600ff;
    --cyan: #29adff;
    --acid: #00e436;
    --amber: #ffa300;
    --red: #ff3b5c;

    --line: #2e2842;

    /* Pixel grid. Every spacing value is a multiple of 4px so nothing
       ever lands on a half-pixel and blurs. */
    --u: 4px;
    --u2: 8px;
    --u3: 12px;
    --u4: 16px;
    --u6: 24px;
    --u8: 32px;
    --u12: 48px;
    --u16: 64px;

    /* karma future for display, karma suture for UI. ARCADECLASSIC.TTF was
       tried first and rejected: its L and T glyphs carry a broken right side
       bearing that injects a phantom space ("SEL ECT", "GOL DEN SUN"). Both
       karma faces ship with the repo, so neither costs a network request. */
    --display: "karma-future", "Courier New", monospace;
    --display-2: "karma-suture", "Courier New", monospace;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    /* Stepped timing. steps() is the whole personality — never add easing. */
    --snap: 120ms steps(2, end);
    --snap-slow: 240ms steps(4, end);

    --shadow-hard: 4px 4px 0 var(--void);
    --maxw: 1240px;
}

@font-face {
    font-family: "karma-future";
    src: url("../karma future.ttf") format("truetype");
    font-display: swap;
}

@font-face {
    font-family: "karma-suture";
    src: url("../karma suture.ttf") format("truetype");
    font-display: swap;
}


/*
|-----------------------------------------
| Reset
|-----------------------------------------
*/

*,
*::before,
*::after { box-sizing: border-box; }

html {
    /* The old rule set html{overflow:hidden} and gave body a hardcoded
       17px right pad to fake a scrollbar. That broke layout anywhere the
       scrollbar was not 17px. Let the page scroll normally instead. */
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100%;
    background-color: var(--void);
    color: var(--ink);
    font-family: var(--body);
    font-size: 16px;
    line-height: 1.6;
    text-align: left;
    overflow-x: hidden;
}

img { max-width: 100%; height: auto; }

a { color: var(--cyan); text-decoration: none; }

:focus-visible {
    outline: 3px solid var(--amber);
    outline-offset: 3px;
}


/*
|-----------------------------------------
| Atmosphere
|-----------------------------------------
|
| Two fixed layers: a static scanline field and a checkerboard dither.
| Both are non-interactive and deliberately static — animated scanlines
| read as cheap and make text hard to hold.
*/

.crt::before,
.crt::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
}

.crt::before {
    background: repeating-linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.22) 0 1px,
        transparent 1px 3px
    );
    opacity: 0.55;
}

.crt::after {
    /* Vignette: the corners of a CRT never reach full brightness. */
    background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}

.dither {
    background-image: repeating-conic-gradient(
        var(--dither-color, var(--line)) 0% 25%,
        transparent 0% 50%
    );
    background-size: var(--u) var(--u);
}


/*
|-----------------------------------------
| Typography
|-----------------------------------------
*/

.display {
    font-family: var(--display);
    font-weight: 400;
    letter-spacing: 0.02em;
    line-height: 1.1;
    text-transform: uppercase;
}

.eyebrow {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

h1, h2, h3 { margin: 0; }


/*
|-----------------------------------------
| Shell
|-----------------------------------------
*/

.wrap {
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 0 var(--u6);
}

.rule {
    height: var(--u);
    border: 0;
    margin: var(--u6) 0;
    --dither-color: var(--line);
}


/*
|-----------------------------------------
| Hero
|-----------------------------------------
*/

.hero {
    position: relative;
    text-align: center;
    padding: var(--u8) 0 var(--u6);
}

.hero__mark {
    width: min(190px, 34vw);
    height: auto;
    image-rendering: pixelated;
    margin-bottom: var(--u4);
}

.hero__title {
    font-family: var(--display);
    font-size: clamp(1.6rem, 5vw, 3rem);
    line-height: 1.05;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--magenta);
    margin: 0 0 var(--u4);
    /* Hard 4-way outline instead of a blur — a sprite has no soft edges. */
    text-shadow:
        -2px 0 0 var(--ink), 2px 0 0 var(--ink),
        0 -2px 0 var(--ink), 0 2px 0 var(--ink),
        6px 6px 0 rgba(0, 0, 0, 0.9);
}

.hero__tagline {
    font-family: var(--mono);
    font-size: clamp(0.7rem, 1.8vw, 0.85rem);
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--ink-dim);
    margin: 0 0 var(--u6);
}

/* Chunky pixel button. The 4px hard shadow is the "unpressed" state; on
   press the button translates into its own shadow. */
.btn {
    display: inline-block;
    font-family: var(--display);
    font-size: 1.5rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink);
    background: var(--magenta);
    border: 3px solid var(--ink);
    padding: var(--u3) var(--u8);
    box-shadow: var(--shadow-hard);
    cursor: pointer;
    transition: transform var(--snap), box-shadow var(--snap), background var(--snap);
}

.btn small {
    display: block;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.18em;
    opacity: 0.8;
}

.btn:hover { background: var(--cyan); color: var(--void); }

.btn:active {
    transform: translate(4px, 4px);
    box-shadow: 0 0 0 var(--void);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    cursor: not-allowed;
    background: var(--void-3);
    color: var(--ink-dim);
    border-color: var(--line);
}

.btn:disabled:hover,
.btn[aria-disabled="true"]:hover { background: var(--void-3); color: var(--ink-dim); }
.btn:disabled:active { transform: none; box-shadow: var(--shadow-hard); }


/*
|-----------------------------------------
| Library toolbar
|-----------------------------------------
*/

.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--u4);
    margin-bottom: var(--u6);
}

.section-head__title {
    font-family: var(--display);
    font-size: clamp(1.6rem, 4vw, 2.6rem);
    color: var(--ink);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.section-head__count {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--acid);
    margin-left: auto;
}

.search {
    position: relative;
    flex: 1 1 260px;
    min-width: 0;
}

.search__input {
    width: 100%;
    font-family: var(--mono);
    font-size: 14px;
    color: var(--ink);
    background: var(--void-2);
    border: 3px solid var(--line);
    padding: var(--u3) var(--u3) var(--u3) var(--u8);
    transition: border-color var(--snap), background var(--snap);
}

.search__input::placeholder { color: var(--ink-faint); }

.search__input:focus {
    border-color: var(--magenta);
    background: var(--void-3);
    outline: none;
}

.search__icon {
    position: absolute;
    left: var(--u3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--ink-faint);
    font-family: var(--mono);
    pointer-events: none;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--u2);
    margin-bottom: var(--u8);
}

.chip {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-dim);
    background: transparent;
    border: 2px solid var(--line);
    padding: 6px var(--u3);
    cursor: pointer;
    transition: color var(--snap), border-color var(--snap), background var(--snap);
}

.chip:hover { color: var(--ink); border-color: var(--ink-faint); }

.chip[aria-pressed="true"] {
    color: var(--void);
    background: var(--magenta);
    border-color: var(--magenta);
}


/*
|-----------------------------------------
| Cartridge grid
|-----------------------------------------
|
| Each card is a GBA cartridge label: notched top-right corner, a hue band
| keyed to the series, and a hard offset shadow. No box art exists in the
| repo, so the hue is derived from the game key — deterministic, zero assets.
*/

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: var(--u4);
    padding: 0;
    margin: 0;
    list-style: none;
}

.cart {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 132px;
    background: var(--void-2);
    border: 3px solid var(--line);
    /* The notch is the cartridge's own asymmetric shape, not decoration. */
    clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%);
    text-decoration: none;
    color: inherit;
    overflow: hidden;
    transition: transform var(--snap), border-color var(--snap), background var(--snap);
}

.cart::before {
    /* Series hue band across the top of the label. */
    content: "";
    display: block;
    height: var(--u3);
    background: hsl(var(--hue) 90% 58%);
}

.cart__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: var(--u3);
    gap: var(--u2);
}

.cart__title {
    font-family: var(--display-2);
    font-size: 1.05rem;
    line-height: 1.15;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--ink);
    word-break: break-word;
}

.cart__meta {
    margin-top: auto;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--u2);
}

.cart__series { color: hsl(var(--hue) 70% 62%); }

.cart__go {
    opacity: 0;
    color: var(--acid);
    transition: opacity var(--snap);
}

.cart:hover,
.cart:focus-visible {
    transform: translate(-3px, -3px);
    border-color: hsl(var(--hue) 90% 58%);
    background: var(--void-3);
}

.cart:hover .cart__go,
.cart:focus-visible .cart__go { opacity: 1; }

.cart:active { transform: translate(0, 0); }

/* Debug ROMs read as tooling, not games. */
.cart--debug { border-style: dashed; }
.cart--debug .cart__title { color: var(--ink-dim); font-size: 0.95rem; }

.empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: var(--u16) var(--u4);
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.empty b { color: var(--amber); }


/*
|-----------------------------------------
| Collapsible (test ROMs)
|-----------------------------------------
*/

.disclose { margin: var(--u8) 0 0; }

.disclose__toggle {
    width: 100%;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-dim);
    background: var(--void-2);
    border: 2px solid var(--line);
    padding: var(--u3) var(--u4);
    cursor: pointer;
    text-align: left;
    display: flex;
    justify-content: space-between;
    transition: color var(--snap), border-color var(--snap);
}

.disclose__toggle:hover { color: var(--ink); border-color: var(--ink-faint); }
.disclose__toggle[aria-expanded="true"] { color: var(--magenta); border-color: var(--magenta); }
.disclose__panel { padding-top: var(--u4); }
.disclose__panel[hidden] { display: none; }


/*
|-----------------------------------------
| Footer
|-----------------------------------------
*/

.footer {
    padding: var(--u12) 0 var(--u16);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-faint);
    text-align: center;
}

.footer a { color: var(--ink-dim); }
.footer a:hover { color: var(--magenta); }


/*
|-----------------------------------------
| Motion
|-----------------------------------------
*/

@keyframes flicker-in {
    0% { opacity: 0; }
    40% { opacity: 0.4; }
    70% { opacity: 0.15; }
    100% { opacity: 1; }
}

@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.flicker { animation: flicker-in 260ms steps(3, end) both; }

/* Hard on/off, no fade — this is how NES text blinks. */
.blink { animation: blink 1s steps(1, end) infinite; }

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
        scroll-behavior: auto !important;
    }
    .cart:hover,
    .cart:focus-visible { transform: none; }
    .crt::before { display: none; }
    /* Never let a stopped animation park an element at opacity 0. */
    .blink { animation: none !important; opacity: 1 !important; }
    .flicker { animation: none !important; opacity: 1 !important; }
}


/*
|-----------------------------------------
| Responsive
|-----------------------------------------
*/

@media (max-width: 900px) {
    .wrap { padding: 0 var(--u4); }
    .hero { padding: var(--u6) 0 var(--u4); }
}

@media (max-width: 700px) {
    .filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        padding-bottom: var(--u2);
        margin-right: calc(var(--u4) * -1);
        scroll-snap-type: x proximity;
    }
    .filters::-webkit-scrollbar { display: none; }
    .chip { flex: 0 0 auto; scroll-snap-align: start; }
}

@media (max-width: 560px) {
    .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--u3); }
    .cart { min-height: 128px; }
    .cart__title { font-size: 0.92rem; }
    .section-head__count { margin-left: 0; width: 100%; }
    .btn { font-size: 1.15rem; padding: var(--u3) var(--u4); }
    .rule { margin: var(--u8) 0; }
}

@media (max-width: 380px) {
    .grid { grid-template-columns: 1fr 1fr; }
}


/*
|-----------------------------------------
| Arcade cabinet modal
|-----------------------------------------
|
| Games open here instead of navigating away. The emulator still runs from
| player.html, embedded in an iframe, so all of its wiring is untouched — the
| cabinet supplies the chrome and drives the emulator through the frame.
*/

.modal {
    position: fixed;
    inset: 0;
    z-index: 8000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--u4);
    background: rgba(6, 5, 10, 0.88);
}

.modal[hidden] { display: none !important; }

.cab {
    width: min(1000px, 100%);
    max-height: calc(100vh - var(--u8));
    display: flex;
    flex-direction: column;
    background: var(--void-2);
    border: 3px solid var(--line);
    box-shadow: 0 0 0 3px var(--void), 12px 12px 0 rgba(0, 0, 0, 0.6);
    animation: cab-in 200ms steps(4, end) both;
}

@keyframes cab-in {
    from { transform: translateY(12px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* Title bar */

.cab__bar {
    display: flex;
    align-items: center;
    gap: var(--u3);
    padding: var(--u2) var(--u3);
    background: var(--void-3);
    border-bottom: 3px solid var(--line);
}

.cab__dot {
    width: 10px;
    height: 10px;
    background: var(--acid);
    flex: 0 0 auto;
    animation: blink 1.6s steps(1, end) infinite;
}

.cab__name {
    font-family: var(--display-2);
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cab__series {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
    white-space: nowrap;
}

.cab__close {
    margin-left: auto;
    flex: 0 0 auto;
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1;
    color: var(--ink-dim);
    background: transparent;
    border: 2px solid var(--line);
    padding: 6px 10px;
    cursor: pointer;
    transition: color var(--snap), border-color var(--snap), background var(--snap);
}

.cab__close:hover { color: var(--void); background: var(--red); border-color: var(--red); }

/* Screen */

.cab__screen {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    background: #000;
    /* GBA is 240x160. Holding 3:2 stops the frame from being letterboxed
       inconsistently as the viewport changes. */
    aspect-ratio: 3 / 2;
    max-height: calc(100vh - 220px);
}

.cab__screen iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* Control strip */

.cab__controls {
    display: flex;
    align-items: center;
    gap: var(--u2);
    flex-wrap: wrap;
    padding: var(--u2) var(--u3);
    background: var(--void-3);
    border-top: 3px solid var(--line);
}

.ctrl {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-dim);
    background: var(--void-2);
    border: 2px solid var(--line);
    padding: 8px 12px;
    min-height: 36px;
    cursor: pointer;
    transition: color var(--snap), border-color var(--snap), background var(--snap);
}

.ctrl:hover { color: var(--ink); border-color: var(--ink-faint); }

.ctrl[aria-pressed="true"] {
    color: var(--void);
    background: var(--acid);
    border-color: var(--acid);
}

.ctrl--wide { flex: 0 0 auto; }

.cab__vol {
    display: flex;
    align-items: center;
    gap: var(--u2);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.cab__vol input[type="range"] {
    width: 90px;
    accent-color: var(--magenta);
}

.cab__hint {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

@media (max-width: 720px) {
    .modal { padding: 0; align-items: stretch; }
    .cab { width: 100%; max-height: 100vh; border-width: 0; box-shadow: none; }
    .cab__screen { max-height: none; }
    .cab__hint { display: none; }
    .cab__controls { justify-content: center; }
}
