/* ============================================================
   VOID ARCADE — midnight arcade design system
   Palette: hall-dark blue-black, backlit marquee amber (action),
   CRT phosphor cyan (system/info). Type: Press Start 2P (wordmark
   + eyebrows only), Chakra Petch (headings/UI), system stack (body).
   ============================================================ */

:root {
    --ink: #0a0d18;
    --panel: #121729;
    --panel-2: #1a2138;
    --edge: #252e4e;
    --edge-soft: #1d2440;
    --marquee: #ffc53d;
    --marquee-hot: #ffd766;
    --phosphor: #63e0ff;
    --text: #e9ecf6;
    --muted: #8b94b0;
    --danger: #ff5d5d;
    --ok: #59d99d;
    --accent: var(--phosphor);
    --font-display: 'Press Start 2P', monospace;
    --font-ui: 'Chakra Petch', 'Segoe UI', sans-serif;
    --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --radius: 12px;
    --touch-opacity: 0.5;
}

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

html, body { height: 100%; }

body {
    font-family: var(--font-body);
    background:
        radial-gradient(1100px 500px at 75% -10%, rgba(99, 224, 255, 0.07), transparent 60%),
        radial-gradient(900px 420px at 15% -10%, rgba(255, 197, 61, 0.06), transparent 55%),
        var(--ink);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

.hidden { display: none !important; }

::selection { background: rgba(255, 197, 61, 0.35); }

button { font-family: var(--font-ui); }

:focus-visible {
    outline: 2px solid var(--phosphor);
    outline-offset: 2px;
}

/* ---- Header: backlit marquee bar ---------------------------------------- */

#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    background: linear-gradient(180deg, #141a30 0%, #101527 100%);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text);
}

.brand-coin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--marquee);
    box-shadow: 0 0 10px 2px rgba(255, 197, 61, 0.65), 0 0 26px 6px rgba(255, 197, 61, 0.25);
    flex: 0 0 auto;
}

.brand h1 {
    font-family: var(--font-display);
    font-size: 14px;
    letter-spacing: 2px;
    color: var(--text);
    text-shadow: 0 0 18px rgba(255, 197, 61, 0.35);
}

.brand h1 em {
    font-style: normal;
    color: var(--marquee);
    margin-left: 8px;
}

.header-right { display: flex; gap: 8px; align-items: center; }

.header-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 13px;
    background: transparent;
    border: 1px solid var(--edge);
    border-radius: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}

.header-btn:hover { color: var(--text); border-color: var(--phosphor); }

.header-btn.active {
    color: #1a1405;
    background: var(--marquee);
    border-color: var(--marquee);
}

/* Signature: the marquee light tube under the header */
.marquee-line {
    height: 3px;
    background: linear-gradient(90deg,
        transparent 0%, var(--marquee) 18%, var(--marquee-hot) 38%,
        var(--phosphor) 62%, var(--marquee) 85%, transparent 100%);
    background-size: 200% 100%;
    box-shadow: 0 1px 14px rgba(255, 197, 61, 0.35);
    animation: tube-drift 14s linear infinite;
}

@keyframes tube-drift {
    from { background-position: 0% 0; }
    to   { background-position: 200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .marquee-line { animation: none; }
    * { transition: none !important; }
}

/* ---- Library ------------------------------------------------------------- */

#main { flex: 1; display: flex; flex-direction: column; }

#library-view { padding: 34px 24px 60px; max-width: 1280px; margin: 0 auto; width: 100%; }

.library-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 26px;
}

.eyebrow {
    font-family: var(--font-display);
    font-size: 9px;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--marquee);
    display: block;
}

.library-title h2 {
    font-family: var(--font-ui);
    font-size: 30px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-top: 8px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--panel);
    border: 1px solid var(--edge);
    border-radius: 8px;
    padding: 9px 13px;
    min-width: 250px;
    color: var(--muted);
}

.search-box input {
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    width: 100%;
}

.search-box input::placeholder { color: var(--muted); }
.search-box:focus-within { border-color: var(--phosphor); }

.category-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.category-chips:empty { margin-bottom: 0; }

.chip {
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px solid var(--edge);
    background: transparent;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}

.chip:hover { color: var(--text); border-color: var(--phosphor); }

.chip.active {
    background: var(--marquee);
    border-color: var(--marquee);
    color: #1a1405;
}

.rom-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

/* Card = a small cabinet marquee */
.rom-card {
    background: var(--panel);
    border: 1px solid var(--edge-soft);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.rom-card:hover {
    transform: translateY(-3px);
    border-color: var(--edge);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 197, 61, 0.18);
}

.rom-card-header {
    position: relative;
    min-height: 132px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    /* backlit-marquee shading along the bottom edge */
    box-shadow: inset 0 -26px 34px -22px rgba(0, 0, 0, 0.65);
}

.system-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    font-family: var(--font-display);
    font-size: 7px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #fff;
    background: rgba(6, 8, 16, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    padding: 4px 8px;
    backdrop-filter: blur(2px);
}

.rom-card-icon { width: 92px; }
.rom-card-icon svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 4px 14px rgba(0,0,0,.4)); }

.rom-marquee-title {
    font-family: var(--font-display);
    font-size: 13px;
    line-height: 1.8;
    text-align: center;
    color: #fff;
    text-shadow: 0 0 14px rgba(255, 255, 255, 0.45), 0 2px 4px rgba(0, 0, 0, 0.6);
    word-break: break-word;
}

.rom-card-body { padding: 15px 16px 4px; flex: 1; }

.rom-card-body h3 {
    font-family: var(--font-ui);
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 7px;
}

.rom-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    color: var(--muted);
    font-size: 12.5px;
}

.rom-meta span + span::before { content: '·'; margin-right: 12px; color: var(--edge); }

.rom-description {
    margin-top: 8px;
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rom-features { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }

.feature-tag {
    font-size: 11px;
    font-weight: 600;
    color: var(--phosphor);
    background: rgba(99, 224, 255, 0.08);
    border: 1px solid rgba(99, 224, 255, 0.22);
    padding: 2px 8px;
    border-radius: 999px;
}

.rom-card-footer { padding: 14px 16px 16px; display: flex; gap: 8px; }

.rom-play-btn {
    flex: 1;
    padding: 11px 14px;
    border: none;
    border-radius: 8px;
    background: var(--marquee);
    color: #1a1405;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: background .15s, box-shadow .15s;
}

.rom-play-btn:hover {
    background: var(--marquee-hot);
    box-shadow: 0 0 18px rgba(255, 197, 61, 0.45);
}

.rom-cheat-btn {
    padding: 11px 14px;
    border: 1px solid var(--edge);
    border-radius: 8px;
    background: transparent;
    color: var(--phosphor);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.rom-cheat-btn:hover { border-color: var(--phosphor); }

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 90px 20px;
    color: var(--muted);
}

.empty-cab { color: var(--edge); margin-bottom: 18px; }

.empty-state h3 {
    font-family: var(--font-ui);
    font-size: 20px;
    color: var(--text);
    margin-bottom: 8px;
}

/* ---- Emulator view -------------------------------------------------------- */

#emulator-view { flex: 1; display: flex; padding: 18px 24px 24px; }

.emulator-container {
    flex: 1;
    display: flex;
    gap: 18px;
    max-width: 1500px;
    margin: 0 auto;
    width: 100%;
}

#emulator-screen {
    flex: 1;
    position: relative;
    background: #000;
    border: 1px solid var(--edge-soft);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 420px;
}

#canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    max-width: 100%;
    max-height: 100%;
}

#canvas.render-smooth { image-rendering: auto; }

/* HD upscale overlay (js/upscaler.js) — sits exactly on top of #canvas */
#upscale-canvas {
    position: absolute;
    pointer-events: none;
    background: #000;
}
#upscale-canvas.hidden { display: none; }
body.console-playing #upscale-canvas { display: none !important; }

#scanlines {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(0deg, rgba(0,0,0,.22) 0 1px, transparent 1px 3px);
}

#emulator-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(6, 8, 16, 0.9);
    z-index: 5;
}

.overlay-content { text-align: center; width: min(340px, 82%); }

.overlay-content p {
    font-family: var(--font-ui);
    font-size: 17px;
    font-weight: 600;
    margin: 12px 0 18px;
}

.progress-bar {
    height: 8px;
    background: var(--panel-2);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--marquee), var(--phosphor));
    border-radius: 999px;
    transition: width .25s ease;
}

/* Sidebar control panel */
.emulator-info {
    width: 300px;
    flex: 0 0 300px;
    background: var(--panel);
    border: 1px solid var(--edge-soft);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-self: flex-start;
}

.emulator-info-top { display: flex; flex-direction: column; gap: 10px; }

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
    padding: 7px 12px;
    background: transparent;
    border: 1px solid var(--edge);
    border-radius: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.btn-back:hover { color: var(--text); border-color: var(--phosphor); }

.rom-name {
    font-family: var(--font-ui);
    font-size: 17px;
    font-weight: 700;
    line-height: 1.3;
}

.ctrl-select {
    width: 100%;
    padding: 8px 10px;
    background: var(--panel-2);
    border: 1px solid var(--edge);
    border-radius: 8px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13px;
}

.emulator-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.ctrl-btn {
    padding: 9px 10px;
    background: var(--panel-2);
    border: 1px solid var(--edge);
    border-radius: 8px;
    color: var(--text);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.ctrl-btn:hover { border-color: var(--phosphor); color: var(--phosphor); }

.btn-cheat {
    grid-column: 1 / -1;
    padding: 9px 10px;
    background: rgba(255, 197, 61, 0.1);
    border: 1px solid rgba(255, 197, 61, 0.4);
    border-radius: 8px;
    color: var(--marquee);
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
}

.btn-cheat:hover { background: rgba(255, 197, 61, 0.18); }

.share-section { border-top: 1px solid var(--edge-soft); padding-top: 14px; }

.btn-share { width: 100%; }

#share-info { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }

.share-link-row { display: flex; gap: 6px; }

#share-link {
    flex: 1;
    min-width: 0;
    padding: 7px 9px;
    background: var(--panel-2);
    border: 1px solid var(--edge);
    border-radius: 8px;
    color: var(--phosphor);
    font-size: 12px;
}

#share-status { color: var(--muted); font-size: 12.5px; }

.viewer-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-top: 4px; }
.viewer-role { width: auto; }

.share-note {
    font-size: 11.5px;
    color: var(--marquee);
    background: rgba(255, 197, 61, 0.07);
    border: 1px solid rgba(255, 197, 61, 0.2);
    border-radius: 8px;
    padding: 8px 10px;
    line-height: 1.45;
}

.controls-help {
    border-top: 1px solid var(--edge-soft);
    padding-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    color: var(--muted);
    font-size: 12px;
}

kbd {
    font-family: var(--font-ui);
    background: var(--panel-2);
    border: 1px solid var(--edge);
    border-bottom-width: 2px;
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 11px;
    color: var(--text);
}

/* ---- Modals --------------------------------------------------------------- */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(4, 6, 12, 0.72);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-content {
    background: var(--panel);
    border: 1px solid var(--edge);
    border-radius: 14px;
    width: min(560px, 100%);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.modal-small { width: min(420px, 100%); }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--edge-soft);
}

.modal-header h2 { font-family: var(--font-ui); font-size: 19px; font-weight: 700; }

.btn-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

.btn-close:hover { color: var(--danger); }

.modal-body { padding: 20px; overflow-y: auto; }

.setting-group { margin-bottom: 26px; }
.setting-group:last-child { margin-bottom: 0; }

.setting-group h3 {
    font-family: var(--font-display);
    font-size: 9px;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: var(--marquee);
    margin-bottom: 13px;
}

.setting-group label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 11px;
    font-size: 14px;
}

.setting-group select, .setting-group input[type="range"] {
    background: var(--panel-2);
    border: 1px solid var(--edge);
    border-radius: 8px;
    color: var(--text);
    padding: 7px 9px;
    font-size: 13px;
    min-width: 170px;
}

.setting-group input[type="range"] { padding: 0; accent-color: var(--marquee); }
.setting-group input[type="checkbox"] { accent-color: var(--marquee); width: 17px; height: 17px; }

.setting-hint { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; line-height: 1.5; }

.controls-config { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13.5px;
    color: var(--muted);
}

.control-row kbd { cursor: pointer; min-width: 84px; text-align: center; padding: 4px 8px; }
.control-row kbd:hover { border-color: var(--phosphor); color: var(--phosphor); }

.btn-primary, .btn-secondary, .btn-danger {
    padding: 9px 16px;
    border-radius: 8px;
    border: none;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.btn-primary { background: var(--marquee); color: #1a1405; }
.btn-primary:hover { background: var(--marquee-hot); }

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--edge);
}
.btn-secondary:hover { border-color: var(--phosphor); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid rgba(255, 93, 93, 0.4);
}
.btn-danger:hover { background: rgba(255, 93, 93, 0.1); }

.btn-small { padding: 5px 10px; font-size: 12px; }

/* Save state slots */
.state-slots { display: flex; flex-direction: column; gap: 8px; }

.state-slot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--panel-2);
    border: 1px solid var(--edge);
    border-radius: 10px;
    cursor: pointer;
}

.state-slot:hover { border-color: var(--marquee); }
.state-slot.empty { opacity: 0.6; }
.state-slot-name { font-weight: 700; font-size: 14px; font-family: var(--font-ui); }
.state-slot-date { color: var(--muted); font-size: 12px; margin-top: 2px; }
.state-slot-actions { display: flex; gap: 6px; }

/* Cheats */
.cheat-note { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

.cheat-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

.cheat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 13px;
    background: var(--panel-2);
    border: 1px solid var(--edge);
    border-radius: 10px;
}

.cheat-name { font-weight: 600; font-size: 14px; }
.cheat-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }

.cheat-toggle { position: relative; display: inline-block; width: 40px; height: 22px; flex: 0 0 auto; }
.cheat-toggle input { opacity: 0; width: 0; height: 0; }

.cheat-toggle .slider {
    position: absolute;
    inset: 0;
    background: var(--edge);
    border-radius: 999px;
    transition: background .15s;
}

.cheat-toggle .slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: var(--text);
    border-radius: 50%;
    transition: transform .15s;
}

.cheat-toggle input:checked + .slider { background: var(--marquee); }
.cheat-toggle input:checked + .slider::before { transform: translateX(18px); background: #1a1405; }

.cheat-actions { display: flex; gap: 8px; }

#cheat-toast {
    position: fixed;
    bottom: 26px;
    left: 50%;
    transform: translate(-50%, 16px);
    background: var(--panel);
    border: 1px solid var(--marquee);
    color: var(--text);
    padding: 11px 18px;
    border-radius: 10px;
    font-size: 13.5px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    z-index: 300;
    box-shadow: 0 10px 30px rgba(0,0,0,.5);
}

#cheat-toast.show { opacity: 1; transform: translate(-50%, 0); }

.coin-btn {
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 197, 61, 0.4);
    background: rgba(255, 197, 61, 0.1);
    color: var(--marquee);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.coin-btn.flash { background: var(--marquee); color: #1a1405; }

/* ---- Viewer mode (?watch=CODE) -------------------------------------------- */

#viewer-wrap {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px;
    background: var(--ink);
}

#viewer-status { color: var(--phosphor); font-family: var(--font-ui); font-size: 14px; flex: 0 0 auto; }

/* The stream keeps its aspect ratio and letterboxes inside whatever space is
   left — never cropped */
#viewer-screen-box {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: min(96vw, 1100px);
    background: #000;
    border: 1px solid var(--edge);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#viewer-screen, #viewer-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    image-rendering: pixelated;
}

/* Mobile guest with touch controls: stream fills the whole screen (still
   aspect-correct), hint hidden, status shrinks into a corner badge */
body.viewer-touch #viewer-wrap { padding: 0; gap: 0; }

body.viewer-touch #viewer-screen-box {
    width: 100vw;
    max-width: none;
    border: none;
    border-radius: 0;
}

body.viewer-touch #viewer-hint { display: none; }

body.viewer-touch #viewer-status {
    position: fixed;
    top: calc(14px + env(safe-area-inset-top));
    left: calc(14px + env(safe-area-inset-left));
    z-index: 60;
    font-size: 11px;
    opacity: 0.75;
    pointer-events: none;
}

#viewer-sound {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 13, 24, 0.85);
    border: 1px solid var(--marquee);
    color: var(--marquee);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
}

#viewer-hint { color: var(--muted); font-size: 13px; text-align: center; line-height: 1.6; }

/* ---- Touch controls overlay (mobile play) ---------------------------------- */

.touch-controls {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
    font-family: var(--font-ui);
    -webkit-user-select: none;
    user-select: none;
}

.tc-btn {
    pointer-events: auto;
    opacity: var(--touch-opacity);
    background: rgba(18, 23, 41, 0.55);
    border: 2px solid rgba(233, 236, 246, 0.75);
    color: #fff;
    font-weight: 700;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tc-btn.tc-pressed {
    opacity: 1;
    background: rgba(255, 197, 61, 0.85);
    border-color: var(--marquee);
    color: #1a1405;
}

/* Radial quick menu: a small 🎮 button in the top corner; tapping it fans the
   COIN/START/… buttons out in a quarter circle, tapping again collapses them */
.tc-menu {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    z-index: 5;
    width: 48px;
    height: 48px;
}

.tc-fab {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 20px;
    transition: transform .25s ease;
}

.tc-menu.open .tc-fab {
    opacity: 1;
    transform: rotate(-20deg) scale(1.06);
    border-color: var(--marquee);
}

.tc-menu-items {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.tc-mi {
    position: absolute;
    top: 0;
    right: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 9.5px;
    letter-spacing: 0.5px;
    opacity: 0;
    pointer-events: none;
    transform: translate(0, 0) scale(0.3);
    transition: transform .28s cubic-bezier(0.25, 1, 0.4, 1.15), opacity .2s ease;
}

.tc-menu.open .tc-mi {
    opacity: var(--touch-opacity);
    pointer-events: auto;
    transform: translate(var(--tx), var(--ty)) scale(1);
}

.tc-menu.open .tc-mi.tc-pressed { opacity: 1; }

.tc-mi.tc-ic { font-size: 17px; }
.tc-mi.tc-exit { color: var(--danger); border-color: rgba(255, 93, 93, 0.6); font-size: 15px; }
.tc-share { color: var(--marquee); border-color: rgba(255, 197, 61, 0.7); }

/* Mirrored layout: directions on the right, Z/X on the left */
.tc-flipped .tc-dirs {
    left: auto;
    right: calc(20px + env(safe-area-inset-right));
}

.tc-flipped .tc-acts {
    right: auto;
    left: calc(20px + env(safe-area-inset-left));
    flex-direction: row-reverse;
}

/* Directions LEFT (d-pad or round joystick) */
.tc-dirs {
    position: absolute;
    left: calc(20px + env(safe-area-inset-left));
    bottom: calc(30px + env(safe-area-inset-bottom));
}

/* Z / X actions RIGHT */
.tc-acts {
    position: absolute;
    right: calc(20px + env(safe-area-inset-right));
    bottom: calc(30px + env(safe-area-inset-bottom));
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.tc-action {
    width: 74px;
    height: 74px;
    border-radius: 50%;
    font-size: 24px;
}

.tc-acts .tc-action:first-child { margin-bottom: 34px; }

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

.tc-dir { font-size: 18px; border-radius: 10px; }
.tc-dpad .tc-du { grid-column: 2; grid-row: 1; }
.tc-dpad .tc-dl { grid-column: 1; grid-row: 2; }
.tc-dpad .tc-dr { grid-column: 3; grid-row: 2; }
.tc-dpad .tc-dd { grid-column: 2; grid-row: 3; }

/* Round joystick */
.tc-stick {
    pointer-events: auto;
    position: relative;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    opacity: var(--touch-opacity);
    border: 2px solid rgba(233, 236, 246, 0.6);
    background: radial-gradient(circle at 50% 42%, rgba(37, 46, 78, 0.75), rgba(10, 13, 24, 0.65) 72%);
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

.tc-stick.tc-pressed { opacity: 1; }

.tc-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.95), rgba(180, 188, 212, 0.9) 70%);
    border: 2px solid #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.tc-stick.tc-pressed .tc-knob {
    background: radial-gradient(circle at 35% 30%, var(--marquee-hot), var(--marquee) 75%);
    border-color: var(--marquee-hot);
}

#tc-toast {
    position: fixed;
    top: calc(58px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel);
    border: 1px solid var(--marquee);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13.5px;
    font-family: var(--font-ui);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
    z-index: 310;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    max-width: 88vw;
    text-align: center;
}

#tc-toast.show { opacity: 1; }

/* Body state while playing on a touch device: emulator fills the viewport */
body.mobile-playing #header,
body.mobile-playing .marquee-line,
body.mobile-playing .emulator-info {
    display: none;
}

body.mobile-playing #emulator-view { padding: 0; }
body.mobile-playing .emulator-container { gap: 0; max-width: none; }

body.mobile-playing #emulator-screen {
    border: none;
    border-radius: 0;
    min-height: 100dvh;
    height: 100dvh;
}

/* ---- Console games (EmulatorJS engine) ------------------------------------- */

#ejs-mount { position: absolute; inset: 0; }

/* MAME-specific controls make no sense for console games — but Share /
   Multiplayer stays (guest input is routed into EmulatorJS) */
body.console-playing #canvas,
body.console-playing #scanlines,
body.console-playing .emulator-actions,
body.console-playing .controls-help,
body.console-playing #quick-resolution,
body.console-playing #upscale-canvas {
    display: none !important;
}

body.console-playing .share-section { border-top: none; padding-top: 0; }

#console-exit {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(18, 23, 41, 0.7);
    border: 2px solid rgba(233, 236, 246, 0.75);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

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

@media (max-width: 900px) {
    .emulator-container { flex-direction: column; }
    .emulator-info { width: 100%; flex: none; align-self: stretch; }
    #emulator-screen { min-height: 300px; }
}

@media (max-width: 640px) {
    #header { padding: 12px 14px; }
    .brand h1 { font-size: 11px; }
    .header-btn span { display: none; }
    #library-view { padding: 22px 14px 44px; }
    .library-title h2 { font-size: 24px; }
    .search-box { min-width: 0; width: 100%; }
    .library-actions { width: 100%; }
    .rom-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
    .rom-card-header { min-height: 100px; }
    .rom-card-body h3 { font-size: 15px; }
    #emulator-view { padding: 10px; }
}

/* Single-game site (dino.void.bd): one big centred card, no search/filters */
body.single-game .library-actions,
body.single-game #category-chips,
body.single-game #btn-library { display: none !important; }
body.single-game .library-header { justify-content: center; text-align: center; }
body.single-game .rom-grid { grid-template-columns: minmax(0, 520px); justify-content: center; }
