* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--ink); }
body { margin: 0; min-width: 320px; color: var(--paper); background: var(--ink); font-family: var(--font-body); }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--paper); outline-offset: 3px; }
[hidden] { display: none !important; }
.site-header { position: sticky; top: 0; z-index: var(--z-header); display: flex; align-items: center; justify-content: space-between; min-height: 76px; padding: calc(var(--space-2) + env(safe-area-inset-top)) clamp(1rem, 4vw, 4rem) var(--space-2); border-bottom: 1px solid var(--line-soft); background: rgba(25, 22, 19, .96); }
.brand { display: inline-flex; gap: .8rem; align-items: center; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 43px; aspect-ratio: 1; color: var(--paper); border: 2px solid var(--paper); font: 800 1rem var(--font-mono); }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .1em; }
.brand small, .header-note { margin: .15rem 0 0; color: var(--paper-muted); font: .7rem var(--font-mono); letter-spacing: .08em; }
main { width: min(1480px, 100%); margin: 0 auto; padding: clamp(1.25rem, 4vw, 4rem); }
.library-intro { display: grid; grid-template-columns: minmax(0, 1fr); padding: clamp(2rem, 7vw, 6rem) 0 clamp(2rem, 5vw, 4rem); border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 .75rem; color: var(--paper-muted); font: .72rem var(--font-mono); letter-spacing: .16em; }
.library-intro .eyebrow { grid-column: 1 / -1; }
h1 { margin: 0; max-width: 14ch; font: 400 clamp(3.1rem, 8vw, 7.8rem)/.98 var(--font-display); letter-spacing: -.025em; text-transform: uppercase; }
.catalog-toolbar { display: grid; grid-template-columns: minmax(15rem, 1fr) auto auto; gap: var(--space-3); align-items: end; padding: var(--space-4) 0; }
.search-field { display: grid; gap: .45rem; color: var(--paper-muted); font: .72rem var(--font-mono); letter-spacing: .12em; text-transform: uppercase; }
.search-field input { width: 100%; padding: .85rem 0; color: var(--paper); border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; font-size: 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: .4rem; }
.filter, .text-action, .console-controls button { padding: .7rem .85rem; border: 1px solid var(--line); background: transparent; cursor: pointer; }
.filter:hover, .filter.is-active, .text-action:hover, .console-controls button:hover { border-color: var(--paper); background: var(--paper); color: var(--ink); }
.catalog-count { margin: 0; color: var(--paper-muted); font: .75rem var(--font-mono); white-space: nowrap; }
.catalog-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); gap: clamp(1.5rem, 4vw, 4rem); align-items: start; }
.recent-strip { display: grid; grid-template-columns: auto 1fr; gap: 1rem; align-items: center; padding: 0 0 1.25rem; }
.recent-strip h2 { margin: 0; color: var(--paper-muted); font: .72rem var(--font-mono); letter-spacing: .12em; text-transform: uppercase; }
.recent-games { display: flex; gap: .5rem; overflow-x: auto; }
.recent-games button { flex: 0 0 auto; padding: .5rem .7rem; color: var(--paper); border: 1px solid var(--line); background: transparent; cursor: pointer; }
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.game-card { position: relative; min-width: 0; padding: .7rem; overflow: hidden; color: var(--paper); text-align: left; border: 1px solid var(--line); border-radius: var(--radius-sm) var(--radius-sm) 1rem 1rem; background: var(--ink-soft); cursor: pointer; }
.game-card::before { content: ""; position: absolute; inset: 7px 7px auto; height: 7px; border: 1px solid var(--line); }
.game-card:hover, .game-card[aria-pressed="true"] { border-color: var(--paper); background: #2b2520; }
.cover-surface { display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); background: #15120f; }
.game-card-cover { width: 100%; aspect-ratio: 5 / 7; margin-top: .8rem; }
.game-cover-image { display: block; width: 100%; height: 100%; object-fit: contain; background: #15120f; }
.cover-fallback-cartridge { position: relative; display: grid; place-items: center; width: 76%; aspect-ratio: 1 / 1.18; color: var(--red); border: 2px solid #81786d; border-radius: .3rem .3rem .9rem .9rem; background: var(--metal); box-shadow: inset 0 -1.4rem 0 #aaa092; }
.cover-fallback-cartridge::before { content: ""; position: absolute; inset: .65rem .65rem auto; height: 1.35rem; border: 1px solid #918779; background: #b1a798; }
.cover-fallback-cartridge::after { content: ""; position: absolute; right: .75rem; bottom: .65rem; width: 22%; height: 14%; border: 1px solid #81786d; }
.cover-fallback-label { font: 900 clamp(1.4rem, 4vw, 2.5rem) var(--font-display); }
.game-card-index { display: block; margin-top: .7rem; color: var(--paper-muted); font: .65rem var(--font-mono); }
.game-card-name { display: block; min-height: 2.5em; margin-top: .4rem; overflow-wrap: anywhere; font-weight: 800; line-height: 1.25; }
.game-card-state, .game-card-cheat { display: block; margin-top: .45rem; color: var(--paper-muted); font: .62rem var(--font-mono); }
.game-card-cheat { font-size: .58rem; }
.catalog-empty { grid-column: 1 / -1; padding: 3rem; color: var(--paper-muted); border: 1px dashed var(--line); text-align: center; }
.state-dot { display: inline-block; width: .45rem; height: .45rem; margin-right: .35rem; border-radius: 50%; background: var(--warning); }
.state-dot.is-error { background: var(--danger); }
.state-dot.is-ready { background: var(--success); }
.game-detail { position: sticky; top: 100px; padding: 1.4rem; border: 1px solid var(--line); background: #201c18; }
.detail-index, .detail-status, .detail-hint { color: var(--paper-muted); font: .7rem var(--font-mono); }
.detail-cover { width: min(100%, 250px); aspect-ratio: 5 / 7; margin: 1.2rem auto; }
.detail-status { color: var(--warning); }
.game-detail h2 { min-height: 2.5em; margin: .65rem 0 1.2rem; font: 400 2rem/1.05 var(--font-display); }
.detail-meta { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 0 1.25rem; border-block: 1px solid var(--line); }
.detail-meta div { padding: .8rem .25rem; }
.detail-meta dt { color: var(--paper-muted); font: .62rem var(--font-mono); }
.detail-meta dd { margin: .35rem 0 0; font-size: .82rem; }
.primary-action { width: 100%; padding: 1rem; color: var(--paper); border: 1px solid var(--red); background: var(--red); font-weight: 800; cursor: pointer; }
.primary-action:hover:not(:disabled) { background: var(--red-dark); }
.primary-action:disabled { opacity: .45; cursor: not-allowed; }
.detail-hint { line-height: 1.6; }
.player { min-height: 100vh; min-height: 100dvh; }
.player-bar { display: flex; align-items: end; justify-content: space-between; padding-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.player-bar h2 { margin: 0; font: 400 clamp(2rem, 5vw, 4rem)/1 var(--font-display); }
.player-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--space-4); padding-top: var(--space-4); }
.console-shell { padding: clamp(.7rem, 2vw, 1.5rem); border: 1px solid #a79d8e; border-radius: var(--radius-md); background: var(--metal); color: var(--ink); }
.console-label { display: flex; justify-content: space-between; margin-bottom: .75rem; font: .7rem var(--font-mono); }
.screen { width: 100%; aspect-ratio: 4 / 3; overflow: hidden; border: clamp(10px, 2vw, 22px) solid #292622; border-radius: .5rem; background: #050505; }
.screen iframe { display: block; width: 100%; height: 100%; }
.console-controls { display: flex; flex-wrap: wrap; gap: .5rem; padding-top: .8rem; }
.console-controls button { color: var(--ink); border-color: #82796d; }
.console-controls button:disabled { opacity: .45; }
.player-side { display: grid; gap: 1rem; }
.cheat-card, .controls-card { padding: 1.25rem; border: 1px solid var(--line); background: var(--ink-soft); }
.cheat-card h3, .controls-card h3 { margin: 0 0 1rem; }
.empty-note, .controls-card p { color: var(--paper-muted); font-size: .85rem; line-height: 1.6; }
#verified-cheats { max-height: 26rem; overflow-y: auto; padding-right: .25rem; }
.cheat-toggle { display: flex; gap: .75rem; align-items: center; justify-content: space-between; width: 100%; margin-top: .6rem; padding: .75rem; border: 1px solid var(--line); background: transparent; cursor: pointer; text-align: left; }
.cheat-toggle span:last-child { flex: 0 0 auto; color: var(--paper-muted); font: .62rem var(--font-mono); white-space: nowrap; }
.cheat-feedback { min-height: 1.3em; margin: .75rem 0 0; color: var(--danger); font-size: .78rem; }
kbd { padding: .15rem .35rem; color: var(--paper); border: 1px solid var(--line); border-radius: .2rem; background: var(--ink); font: .7rem var(--font-mono); }
.touch-controls { display: none; flex-wrap: wrap; gap: 1rem; justify-content: space-between; padding: 1rem 0 env(safe-area-inset-bottom); }
.touch-dpad { display: grid; grid-template-columns: repeat(3, 3rem); grid-template-rows: repeat(3, 3rem); gap: .2rem; }
.touch-dpad button:nth-child(1) { grid-column: 2; grid-row: 1; }
.touch-dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.touch-dpad button:nth-child(3) { grid-column: 3; grid-row: 2; }
.touch-dpad button:nth-child(4) { grid-column: 2; grid-row: 3; }
.touch-actions { display: grid; grid-template-columns: repeat(2, 3rem); gap: .5rem; align-content: center; }
.touch-meta { display: flex; width: 100%; gap: .35rem; align-items: end; justify-content: center; }
.touch-meta button { min-width: 4.3rem; padding-inline: .45rem; border-radius: 1rem; font: .65rem var(--font-mono); }
.retry-action { display: block; margin: 1rem 0 0 auto; padding: .75rem 1rem; color: var(--paper); border: 1px solid var(--red); background: var(--red); cursor: pointer; }
.touch-controls button { min-height: 3rem; border: 1px solid var(--line); border-radius: 50%; background: var(--ink-soft); touch-action: none; }
footer { display: flex; justify-content: space-between; gap: 1rem; padding: 2rem clamp(1rem, 4vw, 4rem); color: var(--paper-muted); border-top: 1px solid var(--line-soft); font: .65rem var(--font-mono); }
@media (max-width: 900px) {
  .library-intro, .catalog-layout, .player-layout { grid-template-columns: 1fr; }
  .catalog-toolbar { grid-template-columns: 1fr; align-items: start; }
  .game-detail { position: static; }
  .player-side { grid-template-columns: 1fr 1fr; }
  .touch-controls { display: flex; }
}
@media (max-width: 560px) {
  .header-note { display: none; }
  main { padding: 1rem; }
  h1 { font-size: clamp(2.8rem, 17vw, 4.5rem); }
  .game-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .game-grid { gap: .7rem; }
  .game-card { padding: .55rem; }
  .game-card-name { font-size: .9rem; }
  .player-side { grid-template-columns: 1fr; }
  .player-bar { align-items: start; gap: 1rem; }
  footer { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
