:root {
    --bg: #e7e1c8;
    --bg-deep: #b4b494;
    --panel: #20252c;
    --ink: #161a1d;
    --muted: #59605a;
    --accent: #c43e2f;
    --lcd: #9ead78;
    --lcd-dark: #2f3c2f;
    --button: #343a3f;
    --button-face: #4b5258;
    --shadow: rgba(18, 22, 25, 0.28);
    color-scheme: light;
}

body.dark {
    --bg: #111418;
    --bg-deep: #222a30;
    --panel: #080b0d;
    --ink: #edf2dc;
    --muted: #a6ad9d;
    --accent: #ff695b;
    --lcd: #81976c;
    --lcd-dark: #172717;
    --button: #181d21;
    --button-face: #2d353b;
    --shadow: rgba(0, 0, 0, 0.48);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    font-family: "Share Tech Mono", monospace;
    color: var(--ink);
    background:
        linear-gradient(90deg, rgba(22, 26, 29, 0.06) 1px, transparent 1px),
        linear-gradient(0deg, rgba(22, 26, 29, 0.05) 1px, transparent 1px),
        radial-gradient(circle at top left, rgba(196, 62, 47, 0.24), transparent 28rem),
        linear-gradient(145deg, var(--bg), var(--bg-deep));
    background-size: 28px 28px, 28px 28px, auto, auto;
    transition: background-color 220ms ease, color 220ms ease;
}

button,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.arcade-stage {
    width: min(100%, 1440px);
    min-height: 100vh;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(250px, 0.72fr) minmax(320px, 470px) minmax(250px, 0.72fr);
    gap: clamp(0.8rem, 1.7vw, 1.6rem);
    align-items: center;
    padding: clamp(1rem, 3vw, 2.5rem);
}

.hero-panel,
.command-deck {
    min-width: 0;
}

.eyebrow {
    margin: 0 0 0.8rem;
    color: var(--accent);
    font-size: 0.78rem;
    letter-spacing: 0;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    max-width: 8ch;
    font-size: clamp(2.8rem, 6vw, 5.6rem);
    line-height: 0.86;
}

h2 {
    font-size: clamp(1.6rem, 2vw, 2.35rem);
}

.hero-copy {
    max-width: 32rem;
    margin: 1rem 0 1.15rem;
    color: var(--muted);
    font-size: clamp(1rem, 1.4vw, 1.2rem);
    line-height: 1.45;
}

.score-rack {
    display: grid;
    gap: 0.65rem;
    max-width: 25rem;
}

.score-card,
.mini-stats > div {
    border: 2px solid rgba(22, 26, 29, 0.18);
    background: rgba(255, 255, 255, 0.36);
    box-shadow: 0 14px 30px var(--shadow);
    padding: 0.82rem;
}

body.dark .score-card,
body.dark .mini-stats > div {
    border-color: rgba(237, 242, 220, 0.14);
    background: rgba(255, 255, 255, 0.05);
}

.score-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.score-card span,
.mini-stats span,
.field span {
    color: var(--muted);
    font-size: 0.8rem;
}

.score-card strong {
    color: var(--lcd-dark);
    font-size: clamp(1.7rem, 3vw, 2.6rem);
    line-height: 1;
}

body.dark .score-card strong {
    color: #c9e783;
}

.score-card.is-live {
    border-color: var(--accent);
}

.brick-phone {
    width: min(100%, 470px);
    justify-self: center;
    padding: clamp(0.85rem, 2.4vw, 1.35rem);
    border-radius: 32px 32px 46px 46px;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.18), transparent 26%),
        linear-gradient(160deg, #383f45, var(--panel) 62%, #111519);
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.22),
        inset 0 -10px 24px rgba(0, 0, 0, 0.35),
        0 30px 70px var(--shadow);
    border: 3px solid rgba(0, 0, 0, 0.24);
}

.phone-top,
.screen-header,
.screen-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.phone-top {
    color: #e7e1c8;
    padding: 0.25rem 0.4rem 1rem;
    font-size: 0.9rem;
}

.mobile-score,
.mobile-mode {
    display: none;
}

.screen-bezel {
    padding: clamp(0.8rem, 2.5vw, 1.1rem);
    border-radius: 18px;
    background: #161a1d;
    border: 2px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.75);
}

.screen-header,
.screen-footer {
    color: #1f2a20;
    background: var(--lcd);
    padding: 0.45rem 0.65rem;
    font-size: clamp(0.74rem, 2.5vw, 0.9rem);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    background: var(--lcd);
    border: 0;
    image-rendering: pixelated;
}

.console-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: center;
    padding-top: clamp(0.8rem, 2.4vw, 1.2rem);
}

.dpad {
    width: min(100%, 158px);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 0.35rem;
}

.control-btn,
.round-btn {
    border: 0;
    color: #f5f2e7;
    background: linear-gradient(145deg, var(--button-face), var(--button));
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        inset 0 -5px 10px rgba(0, 0, 0, 0.28),
        0 9px 0 #111519,
        0 13px 24px rgba(0, 0, 0, 0.36);
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.control-btn:active,
.round-btn:active {
    transform: translateY(6px);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.12),
        inset 0 -3px 7px rgba(0, 0, 0, 0.32),
        0 3px 0 #111519,
        0 8px 16px rgba(0, 0, 0, 0.28);
}

.control-btn {
    min-width: 0;
    min-height: 0;
    border-radius: 8px;
    font-size: clamp(1rem, 4vw, 1.4rem);
}

.control-btn.up {
    grid-column: 2;
    grid-row: 1;
}

.control-btn.left {
    grid-column: 1;
    grid-row: 2;
}

.control-btn.down {
    grid-column: 2;
    grid-row: 3;
}

.control-btn.right {
    grid-column: 3;
    grid-row: 2;
}

.action-pad {
    display: flex;
    justify-content: center;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.round-btn {
    width: clamp(4.7rem, 18vw, 6.3rem);
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    font-size: clamp(0.72rem, 2.5vw, 0.95rem);
}

.round-btn.start {
    background: linear-gradient(145deg, #d85a4d, #9f2e25);
}

.round-btn.sound {
    background: linear-gradient(145deg, #5f7c53, #2f4a2f);
}

.round-btn.sound.is-muted {
    background: linear-gradient(145deg, #6f7477, #343a3f);
    color: #cac6b9;
}

.round-btn.theme {
    background: linear-gradient(145deg, #e7bd5c, #8c6b29);
    color: #1b1c18;
}

.command-deck {
    padding: 1.35rem;
    border: 2px solid rgba(22, 26, 29, 0.18);
    background: rgba(255, 255, 255, 0.28);
    box-shadow: 0 22px 55px var(--shadow);
}

body.dark .command-deck {
    border-color: rgba(237, 242, 220, 0.13);
    background: rgba(255, 255, 255, 0.05);
}

.deck-header {
    margin-bottom: 1.2rem;
}

.field {
    display: grid;
    gap: 0.45rem;
    margin-bottom: 1rem;
}

select {
    width: 100%;
    color: #161a1d;
    background: #f3ecd2;
    border: 2px solid rgba(22, 26, 29, 0.18);
    border-radius: 6px;
    padding: 0.8rem 0.85rem;
}

body.dark select {
    color: #edf2dc;
    background: #172026;
    border-color: rgba(237, 242, 220, 0.18);
}

select option {
    color: #161a1d;
    background: #f3ecd2;
}

body.dark select option {
    color: #edf2dc;
    background: #172026;
}

.mini-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
    margin: 1.2rem 0;
}

.mini-stats > div {
    display: grid;
    gap: 0.35rem;
}

.mini-stats strong {
    color: var(--accent);
    font-size: 1.55rem;
}

.key-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
}

.key-panel span {
    display: grid;
    min-height: 2.4rem;
    place-items: center;
    color: var(--lcd-dark);
    background: var(--lcd);
    border: 2px solid rgba(22, 26, 29, 0.18);
}

@media (max-width: 980px) {
    .arcade-stage {
        grid-template-columns: 1fr;
        align-items: start;
        padding: 0.85rem;
    }

    .hero-panel {
        order: 2;
    }

    .brick-phone {
        order: 1;
    }

    .command-deck {
        order: 3;
    }

    h1 {
        max-width: none;
        font-size: clamp(2.4rem, 12vw, 4rem);
    }

    .hero-copy {
        margin-bottom: 1rem;
    }

    .score-rack {
        max-width: none;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .arcade-stage {
        min-height: 100svh;
        display: grid;
        place-items: center;
        gap: 0;
        padding: 0.65rem;
    }

    .hero-panel,
    .command-deck {
        display: none;
    }

    .brick-phone {
        width: min(100%, 430px);
        max-height: calc(100svh - 1.3rem);
    }

    #gameCanvas {
        width: min(100%, 48svh, 330px);
        margin: 0 auto;
    }
}

@media (max-height: 820px) and (min-width: 981px) {
    .arcade-stage {
        grid-template-columns: minmax(230px, 0.7fr) minmax(310px, 430px) minmax(230px, 0.7fr);
        padding: 0.75rem 1rem;
    }

    .brick-phone {
        width: min(100%, 430px);
        padding: 0.9rem;
    }

    .phone-top {
        padding-bottom: 0.6rem;
    }

    .screen-bezel {
        padding: 0.75rem;
    }

    .dpad {
        width: min(100%, 138px);
    }

    .round-btn {
        width: 4.35rem;
    }

    h1 {
        font-size: clamp(2.6rem, 5vw, 4.8rem);
    }

    .hero-copy {
        font-size: 0.95rem;
    }

    .score-card strong {
        font-size: 1.8rem;
    }
}

@media (max-width: 560px) {
    body {
        background-size: 18px 18px, 18px 18px, auto, auto;
    }

    .arcade-stage {
        padding: 0.5rem;
    }

    .brick-phone {
        width: min(100%, 380px);
        max-height: calc(100svh - 1rem);
        border-radius: 24px 24px 38px 38px;
        padding: 0.68rem;
    }

    .phone-top {
        font-size: 0.68rem;
        padding: 0.1rem 0.25rem 0.45rem;
    }

    .screen-bezel {
        padding: 0.55rem;
        border-radius: 14px;
    }

    .screen-header,
    .screen-footer {
        padding: 0.34rem 0.42rem;
        font-size: 0.68rem;
        gap: 0.45rem;
    }

    .screen-title,
    #screenScore {
        display: none;
    }

    .mobile-score {
        display: inline-flex;
        align-items: center;
        gap: 0.25rem;
        margin-right: auto;
    }

    .mobile-mode {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        margin-left: auto;
    }

    .mobile-mode select {
        width: auto;
        min-width: 4.4rem;
        padding: 0.18rem 0.25rem;
        border-radius: 3px;
        color: var(--lcd-dark);
        background: rgba(255, 255, 255, 0.18);
        border-color: rgba(47, 60, 47, 0.36);
        font-size: 0.68rem;
    }

    #gameCanvas {
        width: min(100%, 48svh, 300px);
    }

    .console-controls {
        grid-template-columns: minmax(126px, 1fr) minmax(105px, 0.8fr);
        gap: 0.65rem;
        padding-top: 0.65rem;
    }

    .dpad {
        width: 100%;
        max-width: 136px;
        gap: 0.26rem;
    }

    .control-btn {
        border-radius: 7px;
        font-size: 1rem;
    }

    .action-pad {
        gap: 0.55rem;
    }

    .round-btn {
        width: clamp(3.25rem, 18vw, 4rem);
        font-size: 0.62rem;
    }
}
