:root {
    color-scheme: dark;
    font-family: 'Trebuchet MS', Arial, sans-serif;
    background: #11121a;
    color: #f6f4f1;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    --muted: #a4a2ae;
}

* {
    box-sizing: border-box;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    padding: 38px 20px 24px;
    background:
        radial-gradient(ellipse at 50% 24%, rgba(114, 91, 156, .26), transparent 40%),
        radial-gradient(ellipse at 50% 100%, rgba(64, 69, 98, .16), transparent 42%),
        #11121a;
}

header {
    margin: 0 auto 30px;
    text-align: center;
}

header h1 {
    margin: 0;
    color: #f8f6f2;
    font-size: clamp(1.35rem, 4vw, 1.8rem);
    font-weight: 700;
    letter-spacing: .18em;
}

header p,
footer {
    color: var(--muted);
    font-size: .82rem;
    letter-spacing: .04em;
}

header p {
    margin: 8px 0 0;
}

#container {
    width: min(100%, 520px);
    margin: 0 auto;
}

.handheld {
    position: relative;
    overflow: hidden;
    padding: 25px 30px 22px;
    border: 1px solid rgba(255, 255, 255, .36);
    border-radius: 24px 24px 64px 24px;
    background: linear-gradient(145deg, #e0dfe2 0%, #c7c6ce 48%, #aaaab5 100%);
    box-shadow:
        0 34px 80px rgba(0, 0, 0, .48),
        inset 2px 2px 2px rgba(255, 255, 255, .65),
        inset -3px -4px 8px rgba(62, 59, 76, .25);
}

.display-panel {
    padding: 14px 18px 12px;
    border: 1px solid #43414b;
    border-radius: 12px 12px 36px 12px;
    background: linear-gradient(145deg, #25232b, #17171e);
    box-shadow: inset 0 3px 8px rgba(0, 0, 0, .65), 0 2px 2px rgba(255, 255, 255, .3);
}

.display-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0 0 9px;
    color: #a9a7b2;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: .55rem;
    letter-spacing: .06em;
}

.power-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #e4a5aa;
}

.power-indicator i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #ff5366;
    box-shadow: 0 0 8px rgba(255, 83, 102, .8);
}

.canvas-container {
    display: flex;
    min-height: 150px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 10px;
    border: 5px solid #0e1010;
    border-radius: 4px;
    background: #82916a;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1);
}

canvas {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    border: 0;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    outline-color: #f7c56a;
}

.display-caption {
    margin: 9px 0 0;
    color: #bebcc5;
    font-size: .57rem;
    font-style: italic;
    font-weight: 600;
    letter-spacing: .15em;
    text-align: right;
}

.console-brand {
    margin: 14px 0 4px;
    color: #57515f;
    font-size: 1.24rem;
    font-style: italic;
    font-weight: 700;
    letter-spacing: -.08em;
}

.console-brand span {
    font-size: .45em;
    vertical-align: top;
}

#gbControls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 132px 54px;
    align-items: center;
    gap: 5px 12px;
    padding: 4px 0;
}

#gbControls button {
    border: 0;
    color: #eeedf0;
    cursor: pointer;
    font: inherit;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
    transition: filter 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

#gbControls button:hover {
    filter: brightness(1.12);
}

#gbControls button:focus-visible,
.commands button:focus-visible,
.config-toggle:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 3px solid #f7c56a;
    outline-offset: 3px;
}

#gbControls button:active,
#gbControls button.is-pressed {
    transform: translateY(3px);
    filter: brightness(.84);
}

.dpad {
    display: grid;
    grid-column: 1;
    grid-row: 1;
    grid-template: repeat(3, 42px) / repeat(3, 42px);
    justify-self: start;
    filter: drop-shadow(0 5px 2px rgba(25, 24, 31, .3));
}

.dpad button {
    z-index: 1;
    background: linear-gradient(145deg, #484650, #292831);
    box-shadow: inset 1px 1px 1px rgba(255, 255, 255, .22), inset -1px -2px 2px rgba(0, 0, 0, .3);
    font-size: 1rem !important;
}

.dpad button:nth-child(1) {
    grid-area: 1 / 2;
    border-radius: 7px 7px 2px 2px;
}

.dpad button:nth-child(2) {
    grid-area: 3 / 2;
    border-radius: 2px 2px 7px 7px;
}

.dpad button:nth-child(3) {
    grid-area: 2 / 1;
    border-radius: 7px 2px 2px 7px;
}

.dpad button:nth-child(4) {
    grid-area: 2 / 3;
    border-radius: 2px 7px 7px 2px;
}

.dpad::after {
    z-index: 2;
    grid-area: 2 / 2;
    border-radius: 2px;
    background: linear-gradient(145deg, #484650, #292831);
    box-shadow: inset 1px 1px 1px rgba(255, 255, 255, .18), inset -1px -2px 2px rgba(0, 0, 0, .3);
    content: '';
    pointer-events: none;
}

.ab-buttons {
    display: flex;
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    gap: 11px;
    transform: rotate(-24deg);
}

.ab-buttons button {
    width: 51px;
    height: 51px;
    border-radius: 50%;
    background: linear-gradient(145deg, #aa3d69, #782747);
    box-shadow: 0 5px 0 #522036, inset 1px 2px 2px rgba(255, 255, 255, .28);
    font-size: 1rem !important;
    font-weight: 700 !important;
}

.ab-buttons button:first-child {
    margin-top: 20px;
}

.ab-buttons button:active,
.ab-buttons button.is-pressed {
    box-shadow: 0 2px 0 #522036, inset 1px 2px 2px rgba(255, 255, 255, .2);
}

.start-select-buttons {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: center;
    gap: 10px;
}

.start-select-buttons button {
    min-width: 66px;
    padding: 6px 12px;
    border-radius: 20px;
    background: linear-gradient(180deg, #777580, #585762);
    box-shadow: 0 3px 0 #41404a, inset 0 1px 1px rgba(255, 255, 255, .35);
    font-family: 'Consolas', 'Courier New', monospace !important;
    font-size: .56rem !important;
    font-weight: 500 !important;
    letter-spacing: .07em;
}

.device-note {
    margin: 9px 0 0;
    color: #797682;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: .55rem;
    letter-spacing: .18em;
    text-align: right;
}

.emulator-tools {
    margin: 18px 0 0;
    padding: 17px;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 16px;
    background: rgba(31, 32, 43, .86);
    box-shadow: 0 14px 34px rgba(0, 0, 0, .2);
}

.commands {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0;
}

.commands button,
.config-toggle {
    padding: 8px 15px;
    border: 1px solid rgba(255, 255, 255, .13);
    border-radius: 8px;
    background: #373847;
    color: #f6f4f1;
    cursor: pointer;
    font: inherit;
    font-size: .82rem;
    transition: background-color 150ms ease, border-color 150ms ease;
}

.commands button:hover,
.config-toggle:hover {
    border-color: rgba(255, 255, 255, .35);
    background: #454657;
}

.sound-toggle,
.zoom-control {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #d3d1db;
    font-size: .8rem;
}

input[type='checkbox'] {
    accent-color: #f27b91;
}

select {
    padding: 7px 9px;
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: 7px;
    background: #262733;
    color: #f6f4f1;
    font: inherit;
}

.game-status {
    min-height: 22px;
    margin: 14px 0 8px;
    color: #b7b5c1;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: .76rem;
}

#game-name {
    color: #f0c77b;
}

#error {
    margin: 8px 0;
    color: #ff8792;
}

.config-toggle {
    width: 100%;
    text-align: left;
}

.config-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 16px 0 0;
}

.rom-section {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

#rom-file {
    width: 100%;
}

#rom-file label {
    display: grid;
    gap: 10px;
    color: #d3d1db;
    font-size: .84rem;
}

input[type='file'] {
    width: 100%;
    color: var(--muted);
    font: inherit;
    font-size: .75rem;
}

#dropzone {
    display: grid;
    min-height: 95px;
    place-items: center;
    margin-top: 12px;
    padding: 16px;
    border: 1px dashed #696879;
    border-radius: 10px;
    color: #c3c0cc;
    text-align: center;
    transition: border-color 180ms ease, background-color 180ms ease, color 180ms ease;
}

#dropzone p {
    margin: 0;
}

#dropzone.drag-active {
    border-color: #f27b91;
    background: rgba(242, 123, 145, .12);
    color: #fff;
}

#keyboard-info {
    color: #d3d1db;
    font-size: .82rem;
}

#keyboard-info p {
    margin: 0 0 8px;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
    color: #c7c5cf;
    font-size: .78rem;
    text-align: left;
}

th,
td {
    padding: 7px 9px;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}

th {
    color: #aaa8b5;
    font-weight: 500;
}

.hide {
    display: none;
}

footer {
    margin: 22px auto 0;
    text-align: center;
}

@media (max-width: 480px) {
    body {
        padding: 26px 13px 20px;
    }

    header {
        margin-bottom: 22px;
    }

    .handheld {
        padding: 18px 18px 16px;
        border-radius: 19px 19px 48px 19px;
    }

    .display-panel {
        padding: 11px 11px 10px;
    }

    .display-heading {
        font-size: .48rem;
    }

    #gbControls {
        grid-template-rows: 116px 48px;
        gap: 4px 8px;
    }

    .dpad {
        grid-template: repeat(3, 36px) / repeat(3, 36px);
    }

    .ab-buttons button {
        width: 45px;
        height: 45px;
    }

    .emulator-tools {
        padding: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
    }
}
