:root {
    --accent: #6f6bff;
    --glow: var(--accent);
    --sun: #ffd23f;
    --ink: #eeeeff;
    --pixel-font: 'Press Start 2P', 'Courier New', monospace;
    --n: 3;
    --gap: 4px;
    /* Tile size follows the screen so the whole cabinet fits without scrolling */
    --cell: clamp(44px, min(104px, calc((100vw - 110px) / var(--n)), calc((100vh - 440px) / var(--n))), 104px);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 10px 12px 28px;
    font-family: var(--pixel-font);
    color: var(--ink);
    background:
        radial-gradient(circle at 50% 0%, #2a2470 0%, transparent 62%),
        repeating-linear-gradient(0deg, transparent 0 38px, rgba(111, 107, 255, 0.06) 38px 40px),
        #070618;
    background-attachment: fixed;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.home {
    display: inline-block;
    margin-bottom: 8px;
    padding: 6px 4px;
    font-size: 10px;
    color: #a9a6ff;
    text-decoration: none;
    text-shadow: 0 0 8px var(--accent);
}

.home:hover,
.home:focus-visible {
    color: #fff;
    outline: none;
}

/* ---------- Cabinet ---------- */
.cabinet {
    position: relative;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
}

.cabinet::after {
    content: '';
    position: absolute;
    left: 6%;
    right: 6%;
    bottom: -16px;
    height: 24px;
    background: radial-gradient(ellipse at center, var(--glow) 0%, transparent 70%);
    opacity: 0.5;
    filter: blur(8px);
}

.body {
    position: relative;
    z-index: 1;
    padding: 10px 16px 0;
    border: 4px solid #000;
    border-radius: 18px 18px 4px 4px;
    box-shadow: 0 0 0 3px var(--glow), 0 0 28px rgba(111, 107, 255, 0.5), 0 10px 30px rgba(0, 0, 0, 0.7);
    background:
        repeating-linear-gradient(90deg, transparent 0 46px, rgba(111, 107, 255, 0.08) 46px 47px),
        linear-gradient(#1c1850, #100d32);
}

.marquee {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 12px;
    background: #000;
    border: 3px solid var(--glow);
    border-radius: 6px;
    box-shadow: 0 0 16px var(--glow), inset 0 0 12px rgba(111, 107, 255, 0.3);
}

.mq-title {
    font-size: clamp(11px, 3.6vw, 16px);
    letter-spacing: 1px;
    color: #fff;
    text-shadow: 0 0 6px var(--accent), 0 0 18px var(--accent), 0 0 34px var(--accent);
}

.mq-icon {
    flex: none;
    width: 28px;
    height: 28px;
}

/* ---------- Play area ---------- */
.bezel {
    margin-top: 10px;
    padding: 10px;
    background: #05040f;
    border: 3px solid #2e2a78;
    border-radius: 10px;
    box-shadow: inset 0 0 14px #000;
}

.hud {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.hud-item {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 7px 4px;
    background: #0b0924;
    border: 2px solid #2e2a78;
    border-radius: 4px;
}

.hud .label {
    font-size: 8px;
    color: #8a87d0;
}

.hud .value {
    font-size: 14px;
    color: var(--sun);
    text-shadow: 0 0 8px rgba(255, 210, 63, 0.6);
    font-variant-numeric: tabular-nums;
}

.field {
    display: flex;
    justify-content: center;
}

.board {
    position: relative;
    width: calc(var(--n) * var(--cell) + (var(--n) - 1) * var(--gap) + 16px);
    height: calc(var(--n) * var(--cell) + (var(--n) - 1) * var(--gap) + 16px);
    padding: 8px;
    background: #02010a;
    border: 3px solid var(--glow);
    border-radius: 8px;
    box-shadow: 0 0 14px rgba(111, 107, 255, 0.6), inset 0 0 14px #000;
    transition: box-shadow 0.4s ease, border-color 0.4s ease;
}

.board:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

/* ---------- Tiles ---------- */
.tile {
    position: absolute;
    left: 8px;
    top: 8px;
    width: var(--cell);
    height: var(--cell);
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    background-color: #2a2670;
    image-rendering: pixelated;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28), inset 0 -3px 0 rgba(0, 0, 0, 0.3);
    transform: translate(calc(var(--x) * (var(--cell) + var(--gap))), calc(var(--y) * (var(--cell) + var(--gap))));
    transition: transform 0.13s ease-out;
}

.tile.blank {
    opacity: 0;
    pointer-events: none;
}

.board.solved .tile.blank {
    opacity: 1;
    transition: opacity 0.4s ease 0.15s, transform 0.13s ease-out;
}

.board.solved .tile {
    pointer-events: none;
}

.board.solved {
    box-shadow: 0 0 24px rgba(125, 255, 176, 0.7), inset 0 0 14px #000;
    border-color: #7dffb0;
}

.tile:active {
    filter: brightness(1.25);
}

.tile .num {
    position: absolute;
    left: 4px;
    top: 4px;
    min-width: 20px;
    padding: 3px 4px;
    font-family: var(--pixel-font);
    font-size: clamp(8px, calc(var(--cell) * 0.2), 14px);
    line-height: 1;
    color: #fff;
    text-align: center;
    background: rgba(5, 4, 20, 0.72);
    border-radius: 4px;
    pointer-events: none;
}

.board.no-numbers .tile .num,
.board.solved .tile .num {
    display: none;
}

.tile:focus-visible {
    outline: 3px solid #fff;
    outline-offset: -3px;
    z-index: 2;
}

/* hold PEEK: the finished picture covers the board */
.peek-img {
    position: absolute;
    inset: 8px;
    z-index: 3;
    border-radius: 6px;
    background-size: 100% 100%;
    image-rendering: pixelated;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease;
}

.board.peek .peek-img {
    opacity: 1;
}

.status {
    min-height: 34px;
    margin-top: 10px;
    padding: 8px 6px;
    font-size: 8px;
    line-height: 1.8;
    text-align: center;
    color: #8a87d0;
    background: #0b0924;
    border: 2px solid #2e2a78;
    border-radius: 4px;
}

.status.good { color: #7dffb0; text-shadow: 0 0 8px rgba(125, 255, 176, 0.6); }

/* ---------- Control area ---------- */
.panel {
    margin: 10px -16px 0;
    padding: 12px 16px;
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(#2c2682, #1a1654);
    border-top: 4px solid #4a44b0;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.4);
}

.panel [hidden] {
    display: none !important;
}

.idle {
    font-size: 9px;
    color: #8a87d0;
}

.controls {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.act {
    flex: 1;
    padding: 14px 4px;
    font-family: var(--pixel-font);
    font-size: 8px;
    color: #0a0824;
    background: linear-gradient(#ffe27a, #ffb020);
    border: 3px solid #7a4d00;
    border-radius: 8px;
    box-shadow: 0 4px 0 #7a4d00;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.act.alt {
    background: linear-gradient(#e8e8ff, #a9a8d8);
    border-color: #4f4d86;
    box-shadow: 0 4px 0 #4f4d86;
}

.act[aria-pressed='false'] {
    background: linear-gradient(#8f8eb8, #5f5e8a);
    color: #d8d8f2;
}

.act:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #4f4d86;
}

.act:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

.base {
    height: 14px;
    margin: 0 -16px;
    border-radius: 0 0 4px 4px;
    background: repeating-linear-gradient(90deg, #05040f 0 24px, var(--accent) 24px 28px);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.6);
}

/* ---------- Level picker ---------- */
.menu {
    position: fixed;
    inset: 44px 0 0 0; /* leaves the Arcade link tappable */
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px 16px 28px;
    text-align: center;
    background: rgba(6, 5, 20, 0.96);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.menu[hidden] {
    display: none;
}

.menu > :first-child { margin-top: auto; }
.menu > :last-child { margin-bottom: auto; }

.menu h2 {
    margin: 0;
    font-size: clamp(16px, 5vw, 22px);
    font-weight: 400;
    color: #fff;
    text-shadow: 0 0 8px var(--accent), 0 0 22px var(--accent);
}

.menu-text,
.menu-tip {
    margin: 0;
    max-width: 380px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    color: #dcdcff;
}

.menu-tip {
    font-size: 12px;
    color: #a7a5de;
}

.menu-tip b {
    color: var(--sun);
}

.levels {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(360px, 100%);
}

.lvl {
    --c: #5cf2a0;
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 12px;
    font-family: var(--pixel-font);
    color: #fff;
    background: #0b0924;
    border: 2px solid var(--c);
    border-radius: 6px;
    box-shadow: 0 0 10px color-mix(in srgb, var(--c) 40%, transparent);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.lvl.hard { --c: var(--sun); }
.lvl.crazy { --c: #ff5d73; }

.lvl-name {
    font-size: 13px;
    color: var(--c);
    text-shadow: 0 0 6px var(--c);
}

.lvl-info {
    font-size: 8px;
    line-height: 1.6;
    color: #fff;
}

.lvl-best {
    font-size: 7px;
    color: #a7a5de;
}

.lvl:hover,
.lvl:focus-visible {
    background: color-mix(in srgb, var(--c) 18%, #0b0924);
    outline: none;
    transform: scale(1.02);
}

@media (max-width: 480px) {
    .body { padding: 10px 10px 0; }
    .panel { margin: 10px -10px 0; padding: 12px 10px; }
    .base { margin: 0 -10px; }
    .bezel { padding: 8px; }
    .mq-icon { width: 24px; height: 24px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}
