:root {
    color-scheme: dark;
    --bg: #11131b;
    --surface: #191c27;
    --surface-2: #222634;
    --surface-3: #2b3040;
    --text: #f3f4f7;
    --muted: #a8adba;
    --line: rgba(255,255,255,.11);
    --accent: #e34c4c;
    --accent-2: #f2c14e;
    --good: #5bc28b;
    --bad: #ff7979;
    --warning: #f2c14e;
    --shadow: 0 24px 70px rgba(0,0,0,.36);
    --radius: 18px;
    --header-height: 76px;
}

html[data-theme="light"] {
    color-scheme: light;
    --bg: #eceef2;
    --surface: #ffffff;
    --surface-2: #f5f6f8;
    --surface-3: #e6e8ed;
    --text: #1b1d24;
    --muted: #666d7a;
    --line: rgba(20,24,35,.13);
    --shadow: 0 24px 60px rgba(34,40,55,.14);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 8% 8%, rgba(227,76,76,.12), transparent 28rem),
        radial-gradient(circle at 90% 20%, rgba(242,193,78,.07), transparent 24rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; }
a { color: inherit; }

.site-header {
    min-height: var(--header-height);
    padding: 14px clamp(18px, 4vw, 58px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--line);
}
.brand { display:flex; align-items:center; gap:13px; text-decoration:none; min-width:0; }
.brand strong { display:block; font-size:clamp(.98rem, 2vw, 1.14rem); letter-spacing:.01em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.brand small { display:block; color:var(--muted); font-size:.76rem; }
.cartridge-logo { width:38px; height:46px; border-radius:4px 4px 7px 7px; background:#d8d9dc; padding:7px; box-shadow:inset 0 -5px 0 rgba(0,0,0,.14); flex:0 0 auto; }
.cartridge-logo i { display:block; width:100%; height:22px; background:var(--accent); border:5px solid #303443; }
.header-actions { display:flex; align-items:center; gap:10px; }

main { width:min(1500px, calc(100% - 32px)); margin:0 auto; padding:34px 0 70px; }
.hero-panel {
    min-height: 260px;
    display:grid;
    grid-template-columns:minmax(0, 1.2fr) minmax(260px, .8fr);
    align-items:center;
    gap:36px;
    padding:clamp(28px, 5vw, 68px);
    background:linear-gradient(145deg, color-mix(in srgb, var(--surface) 93%, var(--accent) 7%), var(--surface));
    border:1px solid var(--line);
    border-radius:28px;
    box-shadow:var(--shadow);
    overflow:hidden;
    position:relative;
}
.hero-panel::after { content:""; position:absolute; inset:auto -8% -55% auto; width:420px; aspect-ratio:1; border:80px solid rgba(255,255,255,.025); border-radius:50%; }
.eyebrow { margin:0 0 8px; color:var(--accent-2); font-size:.74rem; font-weight:800; letter-spacing:.18em; }
h1,h2,h3,p { margin-top:0; }
.hero-panel h1 { margin-bottom:12px; font-size:clamp(2rem, 5vw, 4.5rem); line-height:.98; max-width:780px; letter-spacing:-.045em; }

.system-symbols { position:absolute; width:0; height:0; overflow:hidden; }
.system-picker-hero { display:block; padding:clamp(24px,4vw,44px); min-height:0; }
.system-picker-hero::after { display:none; }
.system-picker-hero h1 { margin-bottom:26px; font-size:clamp(1.8rem,4vw,3.4rem); }
.system-icon-grid { display:grid; grid-template-columns:repeat(7,minmax(118px,1fr)); gap:12px; position:relative; z-index:1; }
.system-icon-card {
    --system-color:var(--accent);
    min-width:0;
    padding:20px 12px 16px;
    display:grid;
    justify-items:center;
    gap:6px;
    color:var(--system-color);
    text-align:center;
    text-decoration:none;
    background:color-mix(in srgb,var(--surface-2) 92%,var(--system-color) 8%);
    border:1px solid color-mix(in srgb,var(--line) 65%,var(--system-color) 35%);
    border-radius:17px;
    transition:transform .18s ease,border-color .18s ease,box-shadow .18s ease;
}
.system-icon-card:hover,.system-icon-card:focus-visible { transform:translateY(-5px); border-color:var(--system-color); box-shadow:0 16px 30px rgba(0,0,0,.22); outline:none; }
.system-icon-card svg { width:min(105px,82%); aspect-ratio:120/84; fill:currentColor; filter:drop-shadow(0 8px 12px rgba(0,0,0,.25)); }
.system-icon-card .system-icon-cut,.selected-system-icon .system-icon-cut { fill:var(--surface-2); }
.system-icon-card strong { color:var(--text); font-size:.92rem; line-height:1.15; }
.system-icon-card small { color:var(--muted); font-size:.7rem; line-height:1.25; }
.system-snes { --system-color:#9b7cff; }
.system-genesis { --system-color:#4da0ff; }
.system-n64 { --system-color:#63c977; }
.system-playstation { --system-color:#8ec9e8; }
.system-atari-7800 { --system-color:#f09a4a; }
.system-arcade { --system-color:#f15bb5; }

.system-vault-heading { display:flex; align-items:center; gap:24px; margin-bottom:18px; padding:20px 24px; background:var(--surface); border:1px solid var(--line); border-radius:22px; box-shadow:0 12px 34px rgba(0,0,0,.12); }
.all-systems-link { color:var(--muted); text-decoration:none; font-weight:750; white-space:nowrap; }
.all-systems-link:hover { color:var(--text); }
.selected-system-title { display:flex; align-items:center; gap:14px; min-width:0; flex:1; }
.selected-system-title h1 { margin:0; font-size:clamp(1.8rem,4vw,3.2rem); line-height:1; }
.selected-system-title .eyebrow { margin-bottom:5px; }
.selected-system-icon { --system-color:var(--accent); width:90px; height:66px; padding:8px; display:grid; place-items:center; flex:0 0 auto; color:var(--system-color); background:var(--surface-2); border:1px solid var(--line); border-radius:15px; }
.selected-system-icon svg { width:100%; height:100%; fill:currentColor; }
.system-vault-actions { display:flex; align-items:center; justify-content:flex-end; gap:12px; flex-wrap:wrap; }
.owned-toggle { display:inline-flex; padding:4px; border:1px solid var(--line); border-radius:12px; background:var(--surface-2); }
.owned-toggle button { min-width:76px; padding:8px 13px; border:0; border-radius:8px; color:var(--muted); background:transparent; font-weight:800; cursor:pointer; }
.owned-toggle button.active { color:#fff; background:var(--accent); box-shadow:0 5px 13px rgba(227,76,76,.28); }

.stats-grid { display:grid; grid-template-columns:repeat(4, minmax(0,1fr)); gap:14px; margin:18px 0 26px; }
.stats-grid article { background:var(--surface); border:1px solid var(--line); border-radius:16px; padding:20px 22px; }
.stats-grid span { display:block; font-size:clamp(1.45rem, 3vw, 2.1rem); font-weight:850; letter-spacing:-.035em; }
.stats-grid small { color:var(--muted); }

.catalog-toolbar { display:flex; align-items:center; gap:12px; margin:0 0 22px; flex-wrap:wrap; }
.search-box { flex:1 1 330px; min-width:230px; position:relative; }
.search-box span { position:absolute; left:15px; top:50%; transform:translateY(-50%); color:var(--muted); font-size:1.3rem; }
.search-box input { padding-left:43px; }
.result-count { margin-left:auto; color:var(--muted); font-size:.9rem; white-space:nowrap; }

input, select, textarea {
    width:100%;
    color:var(--text);
    background:var(--surface-2);
    border:1px solid var(--line);
    border-radius:11px;
    padding:12px 13px;
    outline:none;
    transition:border-color .16s, box-shadow .16s, background .16s;
}
input:focus, select:focus, textarea:focus { border-color:color-mix(in srgb, var(--accent) 72%, white); box-shadow:0 0 0 3px rgba(227,76,76,.14); }
textarea { min-height:130px; resize:vertical; }
label { display:grid; gap:7px; color:var(--muted); font-size:.88rem; font-weight:650; }
label input, label select, label textarea { color:var(--text); font-weight:400; }

.game-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(215px, 1fr)); gap:18px; }
.game-card {
    background:var(--surface);
    border:1px solid var(--line);
    border-radius:18px;
    overflow:hidden;
    position:relative;
    cursor:pointer;
    min-width:0;
    box-shadow:0 8px 26px rgba(0,0,0,.08);
    transition:transform .18s ease, border-color .18s, box-shadow .18s;
}
.game-card:hover { transform:translateY(-5px); border-color:rgba(227,76,76,.5); box-shadow:0 20px 40px rgba(0,0,0,.18); }
.game-cover { aspect-ratio:4 / 5.65; background:linear-gradient(145deg, #252a38, #151823); overflow:hidden; display:grid; place-items:center; position:relative; }
.game-cover img { width:100%; height:100%; object-fit:cover; display:block; }
.cover-placeholder { width:76%; height:82%; border-radius:5px 5px 10px 10px; background:#d3d5d9; padding:18px 12px; box-shadow:inset 0 -12px 0 rgba(0,0,0,.12), 0 14px 30px rgba(0,0,0,.3); color:#20232c; text-align:center; display:flex; flex-direction:column; justify-content:space-between; }
.cover-placeholder span { display:block; padding:20px 4px; background:#2d313d; color:#ef5151; font-size:1.25rem; font-weight:950; letter-spacing:.08em; }
.cover-placeholder b { font-size:.88rem; line-height:1.15; }
.quantity-badge { position:absolute; top:10px; right:10px; z-index:2; min-width:34px; height:34px; padding:0 9px; display:grid; place-items:center; border-radius:999px; background:var(--accent); color:#fff; font-size:.82rem; font-weight:850; box-shadow:0 6px 16px rgba(0,0,0,.28); }
.availability-badge { position:absolute; top:10px; left:10px; z-index:2; padding:6px 9px; border-radius:999px; background:rgba(9,12,18,.86); border:1px solid rgba(255,255,255,.2); color:#fff; font-size:.68rem; font-weight:850; letter-spacing:.04em; }
.game-card-body { padding:15px 16px 17px; }
.game-card-body .eyebrow { margin:0 0 5px; font-size:.62rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.game-card h2 { font-size:1rem; line-height:1.25; margin-bottom:9px; min-height:2.5em; }
.game-meta-row { display:flex; align-items:center; justify-content:space-between; gap:8px; color:var(--muted); font-size:.78rem; }
.game-value { color:var(--good); font-weight:800; font-size:.92rem; }
.media-icons { display:flex; gap:7px; }
.media-icons span { opacity:.35; }
.media-icons span.active { opacity:1; }

.empty-state { text-align:center; padding:80px 20px; color:var(--muted); }
.pixel-ghost { font-size:5rem; color:var(--surface-3); }
footer { padding:26px 20px 42px; text-align:center; color:var(--muted); font-size:.8rem; }
footer p { max-width:900px; margin:auto; }

.button, .icon-button {
    border:0;
    border-radius:11px;
    padding:11px 16px;
    background:var(--surface-3);
    color:var(--text);
    font-weight:750;
    cursor:pointer;
    transition:transform .15s, opacity .15s, background .15s;
}
.button:hover, .icon-button:hover { transform:translateY(-1px); }
.button:disabled, .icon-button:disabled { opacity:.5; cursor:not-allowed; transform:none; }
.button.primary { background:var(--accent); color:#fff; }
.button.ghost { background:transparent; border:1px solid var(--line); }
.button.small { padding:7px 10px; border-radius:8px; font-size:.78rem; }
.button.wide { width:100%; }
.icon-button { width:42px; height:42px; padding:0; display:grid; place-items:center; }
.danger-text { color:var(--bad); }
.button-row { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }

.modal { width:min(92vw, 720px); max-height:90vh; padding:0; border:1px solid var(--line); border-radius:20px; color:var(--text); background:var(--surface); box-shadow:var(--shadow); }
.modal::backdrop { background:rgba(3,5,10,.75); backdrop-filter:blur(6px); }
.modal[open] { animation:modal-in .18s ease-out; }
@keyframes modal-in { from { opacity:0; transform:translateY(12px) scale(.985); } }
.modal-shell { padding:clamp(22px, 4vw, 34px); position:relative; }
.compact-modal { width:min(92vw, 430px); }
.wide-modal { width:min(94vw, 950px); }
.game-modal { width:min(94vw, 1080px); }
.modal-close { position:absolute; top:14px; right:14px; width:38px; height:38px; border:0; border-radius:50%; color:var(--text); background:var(--surface-3); cursor:pointer; font-size:1.5rem; line-height:1; z-index:5; }
.modal-heading { display:flex; justify-content:space-between; align-items:flex-start; gap:50px; }
.muted { color:var(--muted); }

.stack-form { display:grid; gap:16px; }
.form-grid { display:grid; gap:14px; }
.form-grid.two { grid-template-columns:repeat(2, minmax(0,1fr)); }
.form-grid.three { grid-template-columns:repeat(3, minmax(0,1fr)); }
.check-row { display:flex; align-items:center; grid-template-columns:auto 1fr; gap:10px; }
.check-row input { width:auto; }
.provider-fields { margin-top:18px; }
details { border:1px solid var(--line); border-radius:12px; padding:13px 15px; }
summary { cursor:pointer; font-weight:750; }

.tabs { display:flex; gap:8px; margin:20px 0; border-bottom:1px solid var(--line); overflow:auto; }
.tab { border:0; border-bottom:3px solid transparent; background:transparent; color:var(--muted); padding:11px 13px; cursor:pointer; white-space:nowrap; }
.tab.active { color:var(--text); border-color:var(--accent); }
.tab-panel { display:none; }
.tab-panel.active { display:block; }
.split-panel { display:grid; grid-template-columns:1fr 1fr; gap:20px; }
.file-drop { padding:26px; border:2px dashed var(--line); border-radius:14px; text-align:center; cursor:pointer; background:var(--surface-2); }
.file-drop input { margin-top:12px; }
.example-card { background:var(--surface-2); padding:20px; border-radius:14px; border:1px solid var(--line); min-width:0; }
pre { overflow:auto; white-space:pre; color:var(--muted); font-size:.78rem; }

.notice { padding:14px 16px; border-radius:12px; margin:12px 0; border:1px solid var(--line); }
.notice.success { background:rgba(91,194,139,.1); border-color:rgba(91,194,139,.35); }
.notice.error { background:rgba(255,121,121,.1); border-color:rgba(255,121,121,.35); }
.notice.info { background:rgba(105,154,255,.09); border-color:rgba(105,154,255,.28); }
.notice ul { margin:0; padding-left:20px; }
.provider-status { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:14px; }
.provider-chip { display:inline-flex; align-items:center; gap:7px; padding:7px 10px; border-radius:999px; background:var(--surface-2); border:1px solid var(--line); font-size:.78rem; }
.provider-chip::before { content:""; width:8px; height:8px; border-radius:50%; background:var(--bad); }
.provider-chip.on::before { background:var(--good); }
.progress-block { margin-top:18px; }
progress { width:100%; height:14px; accent-color:var(--accent); }

.game-detail-grid { display:grid; grid-template-columns:minmax(240px, 330px) minmax(0, 1fr); gap:28px; align-items:start; }
.detail-cover-column { position:static; align-self:start; }
.detail-cover { border-radius:13px; overflow:hidden; background:var(--surface-2); border:1px solid var(--line); aspect-ratio:4/5.65; display:grid; place-items:center; }
.detail-cover img { width:100%; height:100%; object-fit:cover; }
.detail-cover .cover-placeholder { height:84%; }
.detail-media-column { min-width:0; }
.detail-title { padding-right:44px; }
.detail-title h2 { font-size:clamp(1.65rem, 4vw, 2.8rem); line-height:1.03; letter-spacing:-.035em; margin-bottom:8px; }
.detail-info-section { grid-column:1/-1; border-top:1px solid var(--line); padding-top:22px; }
.detail-tags { display:flex; flex-wrap:wrap; gap:7px; margin:0 0 18px; }
.tag { padding:5px 8px; border-radius:7px; background:var(--surface-2); color:var(--muted); font-size:.75rem; }
.value-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:9px; margin:18px 0 10px; }
.value-grid article { background:var(--surface-2); border:1px solid var(--line); border-radius:11px; padding:11px; }
.value-grid strong { display:block; color:var(--good); }
.value-grid small { color:var(--muted); }
.value-source { margin:0 0 18px; color:var(--muted); font-size:.78rem; }
.value-source a { color:inherit; text-underline-offset:3px; }
.detail-actions { display:flex; flex-wrap:wrap; gap:9px; margin:16px 0; }
.video-frame { position:relative; aspect-ratio:16/9; margin-top:18px; border-radius:14px; overflow:hidden; background:#000; }
.video-frame iframe, .video-frame video { position:absolute; inset:0; width:100%; height:100%; border:0; }
.video-frame video { object-fit:contain; background:#000; }
.video-placeholder { display:grid; place-items:center; border:1px solid var(--line); background:linear-gradient(145deg, #050505, #171717); color:#aaa; }
.video-placeholder span { padding:20px; text-align:center; }
.copies-section { grid-column:1/-1; border-top:1px solid var(--line); padding-top:22px; }
.static-value-note { margin:12px 0 0; }
.copy-list { display:grid; gap:9px; }
.copy-row { display:grid; grid-template-columns:1fr auto auto auto; gap:10px; align-items:center; background:var(--surface-2); border:1px solid var(--line); border-radius:11px; padding:11px 12px; }
.copy-row small { color:var(--muted); }

.enrich-list { display:grid; gap:10px; margin:18px 0; }
.enrich-field { display:grid; grid-template-columns:auto minmax(120px, 180px) 1fr; gap:10px; align-items:start; padding:12px; border:1px solid var(--line); border-radius:11px; background:var(--surface-2); }
.enrich-field input { width:auto; margin-top:4px; }
.enrich-field strong { font-size:.85rem; }
.enrich-field .preview-value { color:var(--muted); font-size:.86rem; white-space:pre-wrap; overflow-wrap:anywhere; max-height:150px; overflow:auto; }
.provider-errors { font-size:.83rem; }

.toast-region { position:fixed; right:18px; bottom:18px; z-index:1000; display:grid; gap:10px; width:min(390px, calc(100vw - 36px)); }
.toast { padding:13px 15px; border-radius:12px; background:var(--surface-3); border:1px solid var(--line); box-shadow:var(--shadow); animation:toast-in .2s ease-out; }
.toast.error { border-color:rgba(255,121,121,.45); }
.toast.success { border-color:rgba(91,194,139,.45); }
@keyframes toast-in { from { opacity:0; transform:translateY(10px); } }

.install-page { display:grid; place-items:center; padding:30px; }
.install-card { width:min(760px,100%); background:var(--surface); border:1px solid var(--line); border-radius:22px; box-shadow:var(--shadow); padding:clamp(24px,5vw,48px); }
.brand-mark { display:inline-grid; place-items:center; width:64px; height:64px; border-radius:14px; background:var(--accent); color:#fff; font-weight:950; margin-bottom:18px; box-shadow:inset 0 -7px 0 rgba(0,0,0,.17); }
code { background:var(--surface-3); border-radius:5px; padding:.12em .35em; }

@media (max-width: 900px) {
    .hero-panel { grid-template-columns:1fr; }
    .stats-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
    .game-detail-grid { grid-template-columns:1fr; }
    .detail-cover-column { position:static; }
    .detail-cover { max-width:330px; width:100%; margin:auto; }
    .detail-info-section, .copies-section { grid-column:auto; }
    .split-panel { grid-template-columns:1fr; }
    .system-icon-grid { grid-template-columns:repeat(4,minmax(110px,1fr)); }
    .system-vault-heading { align-items:flex-start; flex-wrap:wrap; }
    .system-vault-actions { width:100%; justify-content:space-between; }
}

@media (max-width: 620px) {
    .site-header { padding:12px 14px; }
    .brand small { display:none; }
    main { width:min(100% - 20px, 1500px); padding-top:18px; }
    .hero-panel { padding:26px 20px; border-radius:20px; }
    .system-picker-hero { padding:22px 14px; }
    .system-icon-grid { grid-template-columns:repeat(2,minmax(0,1fr)); gap:9px; }
    .system-icon-card { padding:16px 8px 13px; }
    .system-vault-heading { padding:16px; gap:12px; }
    .all-systems-link { width:100%; }
    .selected-system-icon { width:72px; height:55px; }
    .system-vault-actions { align-items:stretch; }
    .system-vault-actions .button { display:grid; place-items:center; }
    .stats-grid { gap:9px; }
    .stats-grid article { padding:15px; }
    .catalog-toolbar > select { flex:1 1 calc(50% - 8px); }
    .result-count { width:100%; margin:0; }
    .game-grid { grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
    .game-card-body { padding:11px; }
    .game-card h2 { font-size:.87rem; }
    .media-icons { display:none; }
    .modal { width:calc(100vw - 16px); max-height:calc(100vh - 16px); }
    .modal-shell { padding:22px 17px; }
    .form-grid.two, .form-grid.three { grid-template-columns:1fr; }
    .value-grid { grid-template-columns:1fr 1fr; }
    .copy-row { grid-template-columns:1fr auto; }
    .copy-row > :nth-child(3) { display:none; }
    .enrich-field { grid-template-columns:auto 1fr; }
    .enrich-field .preview-value { grid-column:2; }
}

/* =========================================================
   PLAYABLE ROM COVER
   ========================================================= */
.detail-cover-play {
    position: relative;
    width: 100%;
    padding: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}
.detail-cover-play::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 0 2px transparent;
    transition: box-shadow .18s ease;
}
.detail-cover-play:hover::after,
.detail-cover-play:focus-visible::after {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 80%, white);
}
.cover-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 20px;
    color: #fff;
    text-align: center;
    background: linear-gradient(180deg, rgba(0,0,0,.02), rgba(0,0,0,.66));
    opacity: 0;
    transition: opacity .18s ease;
    pointer-events: none;
}
.detail-cover-play:hover .cover-play-overlay,
.detail-cover-play:focus-visible .cover-play-overlay {
    opacity: 1;
}
.cover-play-icon {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    padding-left: 4px;
    border-radius: 50%;
    background: rgba(227,76,76,.94);
    box-shadow: 0 12px 30px rgba(0,0,0,.38);
    font-size: 1.7rem;
}
.cover-play-overlay strong {
    font-size: 1.08rem;
}
.cover-play-overlay small {
    opacity: .84;
}
