:root {
    --azure: #19b5ff;
    --glow: var(--azure);
    --amber: #ffb020;
    --danger: #ff4d4d;
    --ink: #e6f4ff;
    --panel: #07182b;
    --pixel-font: 'Press Start 2P', 'Courier New', monospace;
    --cols: 8;
    --rows: 8;
    /* Cell size follows the screen so the whole cabinet fits without scrolling */
    --cell: clamp(26px, min(44px, calc((100vw - 96px) / var(--cols)), calc((100vh - 415px) / var(--rows))), 44px);
}

* {
    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%, #0d3a63 0%, transparent 62%),
        repeating-linear-gradient(0deg, transparent 0 38px, rgba(25, 181, 255, 0.05) 38px 40px),
        #030b16;
    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: var(--azure);
    text-decoration: none;
    text-shadow: 0 0 8px var(--azure);
}

.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(25, 181, 255, 0.45), 0 10px 30px rgba(0, 0, 0, 0.7);
    background:
        repeating-linear-gradient(90deg, transparent 0 46px, rgba(25, 181, 255, 0.07) 46px 47px),
        linear-gradient(#0c2740, #07182b);
}

.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(25, 181, 255, 0.25);
}

.mq-title {
    font-size: clamp(10px, 3.2vw, 15px);
    letter-spacing: 1px;
    color: #fff;
    text-shadow: 0 0 6px var(--azure), 0 0 18px var(--azure), 0 0 34px var(--azure);
}

.mq-icon {
    flex: none;
    width: 28px;
    height: 28px;
    filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.35));
}

/* ---------- Play area ---------- */
.bezel {
    margin-top: 10px;
    padding: 10px;
    background: #030b16;
    border: 3px solid #1d3b57;
    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: #061425;
    border: 2px solid #1d3b57;
    border-radius: 4px;
}

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

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

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

.board {
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--cell));
    grid-template-rows: repeat(var(--rows), var(--cell));
    gap: 2px;
    padding: 4px;
    background: #01060d;
    border: 3px solid var(--glow);
    border-radius: 6px;
    box-shadow: 0 0 14px rgba(25, 181, 255, 0.5), inset 0 0 14px #000;
}

/* ---------- Squares ---------- */
.cell {
    position: relative;
    display: grid;
    place-items: center;
    width: var(--cell);
    height: var(--cell);
    margin: 0;
    padding: 0;
    font-family: var(--pixel-font);
    font-size: calc(var(--cell) * 0.5);
    line-height: 1;
    color: var(--ink);
    border: 0;
    border-radius: 3px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* untouched water */
.cell.h,
.cell.f {
    background: linear-gradient(145deg, #2f78a8, #1b4a70);
    box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.28), inset -2px -2px 0 rgba(0, 0, 0, 0.4);
}

.cell.h:hover {
    background: linear-gradient(145deg, #3a89bd, #215781);
}

.cell.pressing {
    transform: scale(0.9);
    filter: brightness(1.25);
}

/* dug out */
.cell.r,
.cell.m,
.cell.boom,
.cell.x {
    background: #071a2e;
    box-shadow: inset 0 0 0 1px #0f2e4a;
    cursor: default;
}

.cell.r.pop {
    animation: pop 0.18s ease-out;
}

.cell.r[data-n] {
    cursor: pointer;
}

.cell.boom {
    background: radial-gradient(circle, #ff7a3d 0%, #c01f1f 70%);
    box-shadow: 0 0 12px rgba(255, 77, 77, 0.9);
}

.cell.x::after {
    content: '';
    position: absolute;
    inset: 18%;
    background:
        linear-gradient(45deg, transparent 44%, var(--danger) 44% 56%, transparent 56%),
        linear-gradient(-45deg, transparent 44%, var(--danger) 44% 56%, transparent 56%);
}

.cell .ico {
    width: 74%;
    height: 74%;
    pointer-events: none;
}

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

/* numbers: each count has its own colour */
.cell[data-n='1'] { color: #4dd2ff; }
.cell[data-n='2'] { color: #5cf2a0; }
.cell[data-n='3'] { color: #ffd23f; }
.cell[data-n='4'] { color: #ff9a3d; }
.cell[data-n='5'] { color: #ff6fb1; }
.cell[data-n='6'] { color: #b98cff; }
.cell[data-n='7'] { color: #ffffff; }
.cell[data-n='8'] { color: #ff5a5a; }
.cell[data-n] { text-shadow: 0 0 6px currentColor; }

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

.status.good { color: #5cf2a0; text-shadow: 0 0 8px rgba(92, 242, 160, 0.6); }
.status.bad { color: var(--danger); text-shadow: 0 0 8px rgba(255, 77, 77, 0.6); }
.status.warn { color: var(--amber); }

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

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

.idle {
    font-size: 9px;
    color: #6f93b3;
}

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

.mode {
    display: flex;
    border: 3px solid #0a3a5c;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 0 #04202f;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 13px 14px;
    font-family: var(--pixel-font);
    font-size: 10px;
    color: #8fb6d6;
    background: #0d2a44;
    border: 0;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mode-btn svg {
    width: 18px;
    height: 18px;
}

.mode-btn.on {
    color: #031018;
    background: linear-gradient(#6fd4ff, #19b5ff);
}

.mode-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -4px;
}

.act {
    padding: 14px 14px;
    font-family: var(--pixel-font);
    font-size: 9px;
    color: #031018;
    background: linear-gradient(#ffd37a, #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(#e4eef6, #9db6c9);
    border-color: #3f5a70;
    box-shadow: 0 4px 0 #3f5a70;
}

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

.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, #02070d 0 24px, var(--azure) 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(2, 9, 18, 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(--azure), 0 0 22px var(--azure);
}

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

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

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

.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: #061425;
    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(--amber); }
.lvl.crazy { --c: var(--danger); }

.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: #8fb6d6;
}

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

@keyframes pop {
    from { transform: scale(0.6); opacity: 0.4; }
    to { transform: scale(1); opacity: 1; }
}

@media (max-width: 480px) {
    .body { padding: 10px 10px 0; }
    .panel { margin: 10px -10px 0; }
    .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;
    }
}
