:root {
    --cabinet-bg: #1a1a2e;
    --screen-bg: #050510;
    --neon-pink: #ff007f;
    --neon-cyan: #00f0ff;
    --neon-green: #39ff14;
    --neon-yellow: #fffb00;
    --arcade-gold: #ffd700;
    --neon-purple: #a855f7;
    --neon-orange: #ffaa00;

}

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

body {
    background-color: #0b0b16;
    color: #ffffff;
    font-family: 'Press Start 2P', monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow-x: hidden;

    padding: 10px;
}

.screen-header {
    font-size: 50%;
    margin-bottom: 0.75rem;
}

.screen-footer {
    font-size: 50%;
    margin-top: 0.75rem;
}

/* Retro Arcade Cabinet Wrapper */
.arcade-cabinet {
    background: linear-gradient(145deg, #151525, #0a0a14);
    border: 12px solid #2d2d44;
    border-radius: 20px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8),
                inset 0 0 20px rgba(0, 240, 255, 0.2),
                0 0 50px rgba(255, 0, 127, 0.15);
    width: 100%;
    max-width: 900px;
    padding: 20px;
    position: relative;
}

/* Cabinet Marquee Header */
.arcade-marquee {

    background-color: #000;
    border: 4px solid var(--neon-pink);
    text-align: center;
    padding: 12px 10px;
    margin-bottom: 15px;
    box-shadow: 0 0 15px var(--neon-pink);
    text-transform: uppercase;
}

.marquee-text {
    font-size: 20px;
    color: #fff;
    text-shadow: 0 0 5px #fff, 0 0 10px var(--neon-pink), 0 0 20px var(--neon-pink);
    animation: pulse 1.5s infinite alternate;
}

/* CRT Screen Simulation */
.arcade-screen {
    background-color: var(--screen-bg);

    border: 6px solid #444;
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 1), 0 0 20px rgba(0, 240, 255, 0.3);
    aspect-ratio: 4 / 3;
    width: 100%;
}

/* Scanlines and Flicker effect */
.arcade-screen::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.04), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.04));
    z-index: 10;
    background-size: 100% 4px, 6px 100%;
    pointer-events: none;

}

/* Dynamic App Views */
.view {
    display: none;
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    padding: 15px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.view.active {
    display: flex;
}

/* Main Menu Styles */

.menu-title {
    font-size: 15px;
    color: var(--neon-cyan);
    margin-bottom: 20px;
    text-align: center;
    text-shadow: 0 0 8px var(--neon-cyan);
}

.game-selector-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    width: 95%;
    max-width: 680px;
}

.arcade-btn {
    background-color: rgba(255, 255, 255, 0.05);
    border: 3px solid var(--neon-cyan);

    color: #fff;
    font-family: 'Press Start 2P', monospace;
    padding: 12px 10px;
    font-size: 10px;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.2s ease;
    text-align: center;
    text-transform: uppercase;
}

.arcade-btn:hover {
    background-color: var(--neon-cyan);
    color: #000;
    box-shadow: 0 0 12px var(--neon-cyan);
    transform: scale(1.02);
}

.arcade-btn.btn-pink { border-color: var(--neon-pink); }

.arcade-btn.btn-pink:hover { background-color: var(--neon-pink); color: #fff; box-shadow: 0 0 12px var(--neon-pink); }

.arcade-btn.btn-green { border-color: var(--neon-green); }
.arcade-btn.btn-green:hover { background-color: var(--neon-green); color: #000; box-shadow: 0 0 12px var(--neon-green); }

.arcade-btn.btn-yellow { border-color: var(--neon-yellow); }
.arcade-btn.btn-yellow:hover { background-color: var(--neon-yellow); color: #000; box-shadow: 0 0 12px var(--neon-yellow); }

.arcade-btn.btn-purple { border-color: var(--neon-purple); }
.arcade-btn.btn-purple:hover { background-color: var(--neon-purple); color: #fff; box-shadow: 0 0 12px var(--neon-purple); }

.arcade-btn.btn-orange { border-color: var(--neon-orange); }
.arcade-btn.btn-orange:hover { background-color: var(--neon-orange); color: #000; box-shadow: 0 0 12px var(--neon-orange); }


.menu-footer-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    width: 95%;
    max-width: 680px;
    margin-top: 16px;
}

.menu-footer-buttons .arcade-btn {
    width: 100%;
}

.leaderboard-launch-button {
    border-color: var(--arcade-gold);
    color: var(--arcade-gold);
}

.settings-launch-button {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
}

/* Canvas Game Core Container */
#gameCanvas {
    background-color: #020208;
    width: 100%;
    height: 100%;

    display: block;
}

/* Arcade Scoreboard Entry View */
.entry-title {
    color: var(--neon-yellow);
    font-size: 16px;
    margin-bottom: 10px;
    text-shadow: 0 0 10px var(--neon-yellow);
    text-align: center;
}

.entry-subtitle {
    font-size: 9px;
    margin-bottom: 20px;
    color: #aaa;
    text-align: center;
}


.score-display {
    font-size: 24px;
    color: var(--neon-green);
    margin-bottom: 25px;
    text-shadow: 0 0 10px var(--neon-green);
}

.initials-input-container {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
}

.initial-slot {
    font-size: 36px;
    border-bottom: 5px solid #fff;
    width: 50px;
    text-align: center;

    padding-bottom: 4px;
    color: #fff;
}

.initial-slot.active {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
    animation: blink 0.6s infinite alternate;
}

/* Arcade Keyboard UI for Initials */
.arcade-keyboard {
    display: grid;
    grid-template-columns: repeat(7, 13%);
    gap: 6px;
    justify-content: center;
    width: 100%;
    max-width: 480px;
    margin-bottom: 15px;

}

.key-btn {
    background: #222;
    border: 2px solid #555;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    padding: 8px 0;
    text-align: center;
    cursor: pointer;
    border-radius: 4px;
}

.key-btn:hover,
.key-btn.keyboard-selected {
    background: var(--neon-cyan);
    color: #000;
    border-color: #fff;
    outline: 2px solid #fff;
    outline-offset: 1px;
}


.key-btn.action-key {
    grid-column: span 2;
    background: #331122;
    border-color: var(--neon-pink);
    color: var(--neon-pink);
}
.key-btn.action-key:hover,
.key-btn.action-key.keyboard-selected {
    background: var(--neon-pink);
    color: #fff;
}

/* Leaderboard Panel Layout */
.leaderboard-title {
    color: var(--arcade-gold);
    text-shadow: 0 0 10px var(--arcade-gold);
    margin-bottom: 5px;
}

.leaderboard-scope-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
    max-width: 420px;
    margin-bottom: 5px;
}

.leaderboard-scope-btn {
    padding: 6px 8px;
    font-size: 9px;
    background: #111;
    border: 2px solid #444;
    color: #888;
    font-family: 'Press Start 2P', monospace;
    cursor: pointer;
    text-align: center;
}

/* Navigation focus and the selected scope are deliberately different.
   Focus uses a white outline only; it cannot make GLOBAL look selected. */
.leaderboard-scope-btn.keyboard-selected,
.leaderboard-scope-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.tab-btn.keyboard-selected,
.leaderboard-action-button.keyboard-selected {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
    box-shadow: 0 0 7px var(--neon-cyan);
}

/* Avoid sticky :hover highlighting on touch browsers. */
@media (hover: hover) and (pointer: fine) {
    .leaderboard-scope-btn:hover:not([aria-pressed="true"]) {
        border-color: #777;
        color: #bbb;
        box-shadow: none;
    }
}

.leaderboard-scope-controls[data-selected-scope="global"] #leaderboard-scope-global,
.leaderboard-scope-controls[data-selected-scope="local"] #leaderboard-scope-local {
    background: #222;
    border-color: var(--neon-green);
    color: var(--neon-green);
    box-shadow: 0 0 5px var(--neon-green);
}

.leaderboard-scope-controls[data-selected-scope="global"] #leaderboard-scope-local,
.leaderboard-scope-controls[data-selected-scope="local"] #leaderboard-scope-global {
    background: #111;
    border-color: #444;
    color: #888;
    box-shadow: none;
}

.leaderboard-status {
    width: 100%;
    min-height: 14px;
    margin-bottom: 7px;
    color: #777;
    font-size: 7px;
    line-height: 1.4;
    text-align: center;
}

.leaderboard-status.error {
    color: var(--neon-pink);
}

.leaderboard-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    width: 100%;
    margin-bottom: 10px;
}


.tab-btn {
    padding: 6px 2px;
    font-size: 9px;
    background: #111;
    border: 2px solid #444;
    color: #888;
    font-family: 'Press Start 2P', monospace;
    cursor: pointer;
    text-align: center;
    text-transform: uppercase;
}

.tab-btn.active {
    background: #222;
    border-color: var(--arcade-gold);
    color: var(--arcade-gold);
    box-shadow: 0 0 5px var(--arcade-gold);
}


.leaderboard-box {
    width: 100%;
    flex: 1;
    background: rgba(0, 0, 0, 0.6);
    border: 3px solid #333;
    border-radius: 5px;
    overflow-y: auto;
    padding: 8px;
    margin-bottom: 10px;
}


#leaderboard-scroll-spacer {
    height: 0;
    pointer-events: none;
}

.row-new-score {
    outline: 1px solid var(--neon-green);
    outline-offset: -1px;
    background: rgba(57, 255, 20, 0.08);
}

.score-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9px;
    text-align: left;
}

.score-table th {

    color: var(--neon-cyan);
    border-bottom: 2px solid #444;
    padding: 6px 4px;
    font-size: 7px;
}

.score-table td {
    padding: 6px 4px;
    border-bottom: 1px solid #222;
    vertical-align: middle;
}

.row-rank-1 { color: var(--arcade-gold); }
.row-rank-2 { color: #c0c0c0; }
.row-rank-3 { color: #cd7f32; }

.score-meta-info {
    font-size: 8px;
    color: #666;

    margin-top: 5px;
    text-align: center;
    width: 100%;
}

.leaderboard-footer-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.leaderboard-footer-row .score-meta-info {
    width: auto;
    margin: 0;
    text-align: left;
}

.leaderboard-footer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.leaderboard-action-button {
    padding: 5px 10px;
    font-size: 8px;
    white-space: nowrap;
}

#leaderboard-play-again-button {
    border-color: var(--neon-green);
    color: var(--neon-green);
}

/* Arcade Cabinet Controller Base Panel Simulation */
.cabinet-controls {
    background: #252538;
    border-top: 6px solid #151525;
    margin-top: 15px;
    padding: 12px;
    border-radius: 0 0 10px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: inset 0 10px 15px rgba(0,0,0,0.5);
}

.joystick-group {

    display: flex;
    gap: 10px;
    align-items: center;
}

.control-label {
    font-size: 7px;
    color: #888;
    line-height: 1.5;
}

.arcade-brand {
    font-size: 9px;
    color: #444;
    text-shadow: 1px 1px 0 #000;
}

/* Animations */
@keyframes pulse {

    from { text-shadow: 0 0 5px #fff, 0 0 10px var(--neon-pink); }
    to { text-shadow: 0 0 10px #fff, 0 0 20px var(--neon-pink); }
}

@keyframes blink {
    from { opacity: 1; }
    to { opacity: 0.2; }
}

@media(max-width: 650px) {
    .game-selector-container { grid-template-columns: 1fr; }
    .leaderboard-tabs { grid-template-columns: repeat(2, 1fr); }
    .marquee-text { font-size: 14px; }
    .entry-title,
    .pause-title { font-size: 12px; }
    .score-display { font-size: 18px; }
    .initial-slot { font-size: 24px; width: 35px; }
    .key-btn { font-size: 8px; padding: 4px 0; }
}

/* Keyboard cabinet navigation */
.arcade-btn.keyboard-selected,
.tab-btn.keyboard-selected {
    outline: 3px solid #fff;
    outline-offset: 2px;
    filter: brightness(1.35);
    transform: scale(1.02);
}

.tab-btn.keyboard-selected:not(.active) {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
    box-shadow: 0 0 8px var(--neon-cyan);
}

/* Gameplay pause prompt */
.game-view {
    padding: 0;
}

.pause-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 12;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(2, 2, 8, 0.82);
}

.pause-overlay.active {
    display: flex;
}

.pause-message {
    color: var(--neon-yellow);
    font-size: 14px;
    line-height: 1.8;
    text-align: center;
    text-shadow: 0 0 10px var(--neon-yellow);
}

/* Console and per-game option panels */
.options-view {
    justify-content: flex-start;
    padding: 12px;
    overflow-y: auto;
}

.options-title {
    margin-bottom: 4px;
}

.options-help,
.pause-subtitle,
.options-note {
    color: #888;
    font-size: 7px;
    line-height: 1.5;
    text-align: center;
}

.options-panel,
.pause-options-panel {
    width: 100%;
    max-width: 720px;
    display: grid;
    gap: 6px;
    margin: 10px 0;
}

.option-row {
    display: grid;
    grid-template-columns: minmax(120px, 0.8fr) minmax(0, 2.2fr);
    gap: 8px;
    align-items: center;
    padding: 6px;
    border: 1px solid #292947;
    background: rgba(255, 255, 255, 0.025);
}

.option-row.compact {
    padding: 4px;
    gap: 6px;
}

.option-label {
    color: var(--neon-cyan);
    font-size: 9px;
    line-height: 1.45;
}

.option-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.option-btn {
    min-height: 27px;
    padding: 5px 7px;
    border: 2px solid #444;
    border-radius: 3px;
    background: #111;
    color: #888;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    cursor: pointer;
}

.option-btn:hover,
.option-btn.keyboard-selected {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
    box-shadow: 0 0 7px var(--neon-cyan);
}

.option-btn.selected {
    border-color: var(--neon-green);
    color: var(--neon-green);
    background: rgba(57, 255, 20, 0.08);
    box-shadow: 0 0 7px rgba(57, 255, 20, 0.55);
}

.option-btn.inherited-selected {
    border-color: var(--arcade-gold);
    color: var(--arcade-gold);
    box-shadow: 0 0 7px rgba(255, 215, 0, 0.55);
}

.options-menu-button {
    width: 100%;
    max-width: 360px;
    margin-top: 5px;
}

.speed-value {
    color: var(--neon-yellow);
}

.pause-overlay {
    align-items: stretch;
    justify-content: stretch;
    overflow-y: auto;
    padding: 10px;
}

.pause-panel {
    width: 100%;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.pause-title {
    color: var(--neon-yellow);
    font-size: 16px;
    line-height: 1.5;
    text-align: center;
    text-shadow: 0 0 10px var(--neon-yellow);
}

.pause-options-panel {
    gap: 4px;
    margin: 6px 0;
}

.pause-options-panel .option-btn {
    min-height: 23px;
    padding: 4px 5px;
}

.pause-actions {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 560px;
    margin-top: auto;
}

.pause-action-btn {
    flex: 1;
    padding: 7px;
    font-size: 8px;
}

html[data-device-mode="small"] .game-selector-container,
html[data-device-mode="small"] .leaderboard-tabs,
html[data-device-mode="small"] .leaderboard-scope-controls {
    grid-template-columns: 1fr;
}

html[data-device-mode="small"] .marquee-text {
    font-size: 14px;
}

html[data-device-mode="large"] .game-selector-container {
    grid-template-columns: repeat(2, 1fr);
}

html[data-device-mode="large"] .leaderboard-tabs {
    grid-template-columns: repeat(4, 1fr);
}

@media(max-width: 650px) {
    .option-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .option-buttons {
        justify-content: center;
    }

    .options-view {
        padding: 8px;
    }

    .pause-overlay {
        padding: 6px;
    }

    .leaderboard-footer-row {
        align-items: stretch;
        flex-direction: column;
    }

    .leaderboard-footer-row .score-meta-info {
        text-align: center;
    }

    .leaderboard-footer-actions {
        width: 100%;
    }

    .leaderboard-action-button {
        flex: 1;
    }
}

.menu-hint {
    margin-top: 8px;
    color: #666;
    font-size: 7px;
}

/* Responsive touch controller */
.touch-controller,
.touch-show-button {
    display: none;
}

.touch-controller.active {
    display: block;
    margin-top: 10px;
    padding: 10px;
    border: 3px solid #353552;
    border-radius: 10px;
    background: linear-gradient(180deg, #222238, #151524);
    box-shadow: inset 0 8px 15px rgba(0, 0, 0, 0.55), 0 0 12px rgba(0, 240, 255, 0.15);
    touch-action: none;
}

.touch-controller-toolbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 10px;
}

.touch-toolbar-btn,
.touch-show-button {
    min-height: 42px;
    padding: 7px 5px;
    border: 2px solid var(--neon-cyan);
    border-radius: 5px;
    background: #0b0b16;
    color: var(--neon-cyan);
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    line-height: 1.4;
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
}

.touch-pause-button {
    border-color: var(--neon-yellow);
    color: var(--neon-yellow);
}

.touch-show-button:not([hidden]) {
    display: block;
    width: 100%;
    margin-top: 8px;
    border-color: var(--neon-green);
    color: var(--neon-green);
}

.touch-control-layout {
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: clamp(18px, 8vw, 80px);
    width: 100%;
    max-width: 100%;
    min-height: 174px;
}

.touch-control-layout.dpad-left .touch-dpad { order: 1; }
.touch-control-layout.dpad-left .touch-action-button { order: 2; }
.touch-control-layout.dpad-right .touch-action-button { order: 1; }
.touch-control-layout.dpad-right .touch-dpad { order: 2; }

.touch-control-layout.single-control.dpad-left {
    justify-content: flex-start;
    padding-left: clamp(4px, 4vw, 32px);
}

.touch-control-layout.single-control.dpad-center {
    justify-content: center;
}

.touch-control-layout.single-control.dpad-right {
    justify-content: flex-end;
    padding-right: clamp(4px, 4vw, 32px);
}

.touch-dpad {
    --dpad-shape: polygon(
        21% 0, 79% 0, 79% 21%, 100% 21%,
        100% 79%, 79% 79%, 79% 100%, 21% 100%,
        21% 79%, 0 79%, 0 21%, 21% 21%
    );
    position: relative;
    width: clamp(138px, 29vw, 174px);
    max-width: 100%;
    aspect-ratio: 1;
    flex: 0 0 auto;
    contain: layout paint;
}

/* Draw one continuous outline behind the direction hit areas. v1.1.0 put a
   clipped border on every overlapping trapezoid; browser clipping produced
   broken cyan strokes at the overlaps. */
.touch-dpad::before,
.touch-dpad::after {
    content: "";
    position: absolute;
    inset: 0;
    clip-path: var(--dpad-shape);
    pointer-events: none;
}

.touch-dpad::before {
    z-index: 0;
    background: var(--neon-cyan);
    filter: drop-shadow(0 0 5px rgba(0, 240, 255, 0.38));
}

.touch-dpad::after {
    z-index: 1;
    inset: 3px;
    background: linear-gradient(145deg, #19192a, #080810);
}

.touch-dpad.three-way {
    --dpad-shape: polygon(
        21% 0, 79% 0, 79% 21%, 100% 21%,
        100% 79%, 58% 79%, 50% 72%, 42% 79%,
        0 79%, 0 21%, 21% 21%
    );
}

.touch-direction,
.touch-action-button {
    border: 3px solid var(--neon-cyan);
    background: linear-gradient(145deg, #19192a, #080810);
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    cursor: pointer;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.5), 0 0 8px rgba(0, 240, 255, 0.25);
}

.touch-direction {
    position: absolute;
    z-index: 3;
    width: 58%;
    height: 58%;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: #fff;
    font-family: system-ui, sans-serif;
    font-size: 25px;
    line-height: 1;
    filter: none;
}

/* Each directional hit polygon stops at the center hub. The four polygons
   share boundary lines but never overlap, so a slow slide across the hub has
   one deterministic current direction instead of competing active buttons. */
.touch-up {
    top: 0;
    left: 21%;
    width: 58%;
    height: 43%;
    clip-path: polygon(0 0, 100% 0, 100% 49%, 62% 100%, 38% 100%, 0 49%);
}
.touch-left {
    top: 21%;
    left: 0;
    width: 43%;
    height: 58%;
    clip-path: polygon(0 0, 49% 0, 100% 38%, 100% 62%, 49% 100%, 0 100%);
}
.touch-right {
    top: 21%;
    right: 0;
    width: 43%;
    height: 58%;
    clip-path: polygon(51% 0, 100% 0, 100% 100%, 51% 100%, 0 62%, 0 38%);
}
.touch-down {
    bottom: 0;
    left: 21%;
    width: 58%;
    height: 43%;
    clip-path: polygon(38% 0, 62% 0, 100% 51%, 100% 100%, 0 100%, 0 51%);
}

.touch-dpad-center {
    position: absolute;
    z-index: 5;
    top: 43%;
    left: 43%;
    width: 14%;
    aspect-ratio: 1;
    border: 2px solid #303048;
    border-radius: 50%;
    background: #11111d;
    box-shadow: inset 0 0 8px #000;
    pointer-events: none;
}

.touch-dpad.horizontal-only {
    --dpad-shape: inset(0 round 8px);
    width: clamp(150px, 34vw, 204px);
    height: clamp(58px, 12vw, 70px);
    aspect-ratio: auto;
}
.touch-dpad.horizontal-only .touch-up,
.touch-dpad.horizontal-only .touch-down {
    display: none !important;
}
.touch-dpad.horizontal-only .touch-left,
.touch-dpad.horizontal-only .touch-right {
    top: 0;
    width: 46%;
    height: 100%;
}
.touch-dpad.horizontal-only .touch-left {
    left: 0;
    clip-path: polygon(0 0, 82% 0, 100% 50%, 82% 100%, 0 100%);
}
.touch-dpad.horizontal-only .touch-right {
    right: 0;
    clip-path: polygon(18% 0, 100% 0, 100% 100%, 18% 100%, 0 50%);
}
.touch-dpad.horizontal-only .touch-dpad-center {
    top: 39%;
    left: 46%;
    width: 8%;
}

.touch-dpad.vertical-only {
    --dpad-shape: inset(0 round 8px);
    width: clamp(58px, 12vw, 70px);
    height: clamp(150px, 34vw, 204px);
    aspect-ratio: auto;
}
.touch-dpad.vertical-only .touch-left,
.touch-dpad.vertical-only .touch-right {
    display: none !important;
}
.touch-dpad.vertical-only .touch-up,
.touch-dpad.vertical-only .touch-down {
    left: 0;
    width: 100%;
    height: 46%;
}
.touch-dpad.vertical-only .touch-up {
    top: 0;
    clip-path: polygon(0 0, 100% 0, 100% 82%, 50% 100%, 0 82%);
}
.touch-dpad.vertical-only .touch-down {
    bottom: 0;
    clip-path: polygon(0 18%, 50% 0, 100% 18%, 100% 100%, 0 100%);
}
.touch-dpad.vertical-only .touch-dpad-center {
    top: 46%;
    left: 39%;
    width: 22%;
}

.touch-action-button {
    width: clamp(88px, 24vw, 126px);
    aspect-ratio: 1;
    border-radius: 50%;
    border-color: var(--neon-pink);
    color: var(--neon-pink);
    font-size: clamp(8px, 2.2vw, 12px);
    box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.5), 0 0 12px rgba(255, 0, 127, 0.35);
}

.touch-direction.pressed,
.touch-action-button.pressed {
    transform: translateY(3px) scale(0.97);
    filter: brightness(1.55) drop-shadow(0 0 7px currentColor);
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.6), 0 0 16px currentColor;
}

.touch-direction.pressed {
    background: rgba(0, 240, 255, 0.22);
}

.touch-controller.paused .touch-direction,
.touch-controller.paused .touch-action-button {
    opacity: 0.35;
}

.touch-dpad[hidden],
.touch-direction[hidden],
.touch-action-button[hidden],
.touch-toolbar-btn[hidden],
.touch-show-button[hidden] {
    display: none !important;
}

html[data-touch-controls="on"] .cabinet-controls {
    display: none;
}

/* Compact layout selected by DEVICE AUTO/SMALL. */

    html[data-device-layout="small"] body {
        min-height: 100dvh;
        justify-content: flex-start;
        padding: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
        overflow-y: auto;
    }

    html[data-device-layout="small"] .screen-header,
html[data-device-layout="small"] .screen-footer {
        font-size: 5px;
        line-height: 1.4;
        text-align: center;
    }

    html[data-device-layout="small"] .screen-header { margin-bottom: 4px; }
    html[data-device-layout="small"] .screen-footer { margin-top: 5px; }

    html[data-device-layout="small"] .arcade-cabinet {
        max-width: 650px;
        padding: 6px;
        border-width: 5px;
        border-radius: 11px;
        box-shadow: 0 0 12px rgba(0, 0, 0, 0.8), inset 0 0 10px rgba(0, 240, 255, 0.16);
    }

    html[data-device-layout="small"] .arcade-marquee {
        padding: 6px 4px;
        margin-bottom: 7px;
        border-width: 2px;
        box-shadow: 0 0 8px var(--neon-pink);
    }

    html[data-device-layout="small"] .marquee-text,
html[data-device-layout="small"][data-device-mode="small"] .marquee-text {
        font-size: clamp(7px, 2.5vw, 10px);
        line-height: 1.45;
    }

    html[data-device-layout="small"] .arcade-screen {
        border-width: 3px;
        border-radius: 6px;
    }

    html[data-device-layout="small"] .view {
        padding: 6px;
    }

    html[data-device-layout="small"] .menu-title {
        margin-bottom: 7px;
        font-size: clamp(7px, 2.2vw, 9px);
        line-height: 1.5;
    }

    html[data-device-layout="small"] .game-selector-container,
html[data-device-layout="small"][data-device-mode="small"] .game-selector-container,
html[data-device-layout="small"][data-device-mode="large"] .game-selector-container {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        width: 100%;
    }

    html[data-device-layout="small"] .arcade-btn {
        min-height: 25px;
        padding: 5px 3px;
        border-width: 2px;
        font-size: clamp(5.5px, 1.7vw, 7px);
        line-height: 1.35;
    }

    html[data-device-layout="small"] .menu-footer-buttons {
        width: 100%;
        max-width: none;
        gap: 8px;
        margin-top: 10px;
    }

    html[data-device-layout="small"] .menu-hint {
        margin-top: 7px;
        font-size: 5px;
    }

    html[data-device-layout="small"] .leaderboard-tabs,
html[data-device-layout="small"][data-device-mode="small"] .leaderboard-tabs,
html[data-device-layout="small"][data-device-mode="large"] .leaderboard-tabs {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 3px;
    }

    html[data-device-layout="small"] .tab-btn,
html[data-device-layout="small"] .leaderboard-scope-btn {
        min-height: 23px;
        padding: 4px 2px;
        font-size: 5.5px;
    }

    html[data-device-layout="small"] .leaderboard-title {
        margin-bottom: 4px;
    }

    html[data-device-layout="small"] .leaderboard-status,
html[data-device-layout="small"] .score-meta-info {
        font-size: 5.5px;
        line-height: 1.4;
    }

    html[data-device-layout="small"] .score-table th,
html[data-device-layout="small"] .score-table td {
        padding: 4px 2px;
        font-size: 6px;
    }

    html[data-device-layout="small"] .arcade-keyboard {
        gap: 3px;
        margin-bottom: 6px;
    }

    html[data-device-layout="small"] .initials-input-container {
        margin-bottom: 8px;
    }

    html[data-device-layout="small"] .entry-subtitle {
        margin-bottom: 8px;
        font-size: 6px;
        line-height: 1.5;
    }

    html[data-device-layout="small"] .score-display {
        margin-bottom: 9px;
    }

    html[data-device-layout="small"] .cabinet-controls {
        display: none;
    }

    html[data-device-layout="small"] .touch-controller.active {
        margin-top: 7px;
        padding: 7px;
        border-width: 2px;
    }

    html[data-device-layout="small"] .touch-controller-toolbar {
        gap: 5px;
        margin-bottom: 7px;
    }

    html[data-device-layout="small"] .touch-toolbar-btn,
html[data-device-layout="small"] .touch-show-button {
        min-height: 40px;
        padding: 5px 3px;
        font-size: 6px;
    }

    html[data-device-layout="small"] .touch-control-layout {
        min-height: 150px;
        gap: 12px;
    }

    /* Compact controls size from the controller, not the browser viewport.
       This keeps mobile browser chrome, zoom, and device-pixel ratio from
       making the D-pad scale against the full page or cabinet. */
    html[data-device-layout="small"] .touch-dpad {
        width: clamp(124px, 44%, 166px);
    }

    html[data-device-layout="small"] .touch-dpad.horizontal-only {
        width: clamp(136px, 52%, 194px);
        height: clamp(52px, 18vw, 66px);
    }

    html[data-device-layout="small"] .touch-dpad.vertical-only {
        width: clamp(52px, 18%, 66px);
        height: clamp(136px, 52vw, 194px);
    }

    html[data-device-layout="small"] .touch-direction {
        font-size: 22px;
    }

    html[data-device-layout="small"] .touch-action-button {
        width: clamp(76px, 25%, 104px);
        font-size: clamp(7px, 2vw, 9px);
    }


@media (max-width: 380px) {

    html[data-device-layout="small"] .touch-control-layout {
        gap: 7px;
    }

    html[data-device-layout="small"] .touch-dpad {
        width: clamp(120px, 44%, 148px);
    }

    html[data-device-layout="small"] .touch-dpad.horizontal-only {
        width: clamp(132px, 52%, 170px);
        height: clamp(48px, 17vw, 60px);
    }

    html[data-device-layout="small"] .touch-action-button {
        width: 76px;
    }

}
