:root {
    color-scheme: dark;
    font-family: Inter, ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #101629;
    color: #f7f9ff;
}

* {
    box-sizing: border-box;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 20% 10%, rgba(49, 208, 170, 0.17), transparent 36rem),
        radial-gradient(circle at 90% 90%, rgba(103, 80, 255, 0.18), transparent 32rem),
        #101629;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    font: inherit;
}

.game-shell {
    width: min(100% - 32px, 620px);
    margin: 0 auto;
    padding: 24px 0 40px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    margin-bottom: 14px;
}

.back-link {
    color: #c9d1e8;
    font-weight: 700;
    text-decoration: none;
}

.back-link:hover {
    color: #ffffff;
}

.scores {
    display: flex;
    gap: 18px;
    color: #9ba7c5;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.scores strong {
    margin-left: 4px;
    color: #ffffff;
    font-variant-numeric: tabular-nums;
}

.game-card {
    padding: clamp(18px, 4vw, 28px);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 28px;
    background: rgba(24, 32, 57, 0.86);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(16px);
}

.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.eyebrow {
    margin: 0 0 4px;
    color: #58dfb7;
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

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

h1 {
    font-size: clamp(2rem, 8vw, 3.25rem);
    line-height: 0.95;
}

h2 {
    font-size: clamp(1.55rem, 6vw, 2.3rem);
}

.secondary-button,
.primary-button,
.direction {
    border: 0;
    color: #ffffff;
    cursor: pointer;
    font-weight: 800;
}

.secondary-button {
    padding: 10px 16px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
}

.secondary-button:disabled {
    cursor: default;
    opacity: 0.4;
}

.board-wrap {
    position: relative;
    overflow: hidden;
    width: 100%;
    border-radius: 20px;
    background: #0b1020;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
    aspect-ratio: 1;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(7, 12, 26, 0.74);
    text-align: center;
    backdrop-filter: blur(5px);
}

.overlay.hidden {
    display: none;
}

.overlay-panel {
    max-width: 330px;
}

.overlay-panel p:not(.eyebrow) {
    margin: 12px 0 22px;
    color: #b8c1d9;
    line-height: 1.5;
}

.primary-button {
    min-width: 150px;
    padding: 13px 22px;
    border-radius: 999px;
    background: #31d0aa;
    color: #071b18;
    box-shadow: 0 10px 28px rgba(49, 208, 170, 0.25);
}

.primary-button:hover,
.primary-button:focus-visible {
    background: #59e2c0;
}

.speed-control {
    margin: 20px auto 0;
    padding: 14px 16px 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.045);
}

.speed-control label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    color: #b8c1d9;
    font-size: 0.88rem;
    font-weight: 700;
}

.speed-control output {
    display: grid;
    width: 30px;
    height: 24px;
    place-items: center;
    border-radius: 999px;
    background: rgba(88, 223, 183, 0.15);
    color: #74f0ce;
    font-variant-numeric: tabular-nums;
}

.speed-control input {
    width: 100%;
    margin: 0;
    accent-color: #31d0aa;
    cursor: pointer;
}

.speed-scale {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    color: #687593;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.controls {
    display: grid;
    grid-template-columns: repeat(3, 58px);
    grid-template-areas:
        ". up ."
        "left down right";
    justify-content: center;
    gap: 8px;
    margin-top: 18px;
}

.direction {
    width: 58px;
    height: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    font-size: 1.3rem;
    touch-action: manipulation;
    user-select: none;
}

.direction:active {
    transform: scale(0.94);
    background: rgba(88, 223, 183, 0.25);
}

.up { grid-area: up; }
.left { grid-area: left; }
.down { grid-area: down; }
.right { grid-area: right; }

.hint {
    margin: 14px 0 0;
    color: #7f8baa;
    font-size: 0.82rem;
    text-align: center;
}

button:focus-visible,
a:focus-visible {
    outline: 3px solid #58dfb7;
    outline-offset: 3px;
}

@media (min-width: 720px) and (min-height: 800px) {
    .game-shell {
        padding-top: 40px;
    }
}

@media (max-height: 760px) and (min-width: 560px) {
    .game-shell {
        width: min(100% - 32px, 520px);
        padding-top: 12px;
    }

    .game-card {
        padding: 18px;
    }

    .title-row {
        margin-bottom: 14px;
    }

    .controls {
        margin-top: 12px;
    }

    .speed-control {
        margin-top: 12px;
        padding-block: 10px 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        scroll-behavior: auto !important;
    }
}
