:root {
    --accent: #ffb37c;
    --glow: var(--accent);
    --p0: #5cc8ff;
    --p1: #ff6fae;
    --gold: #ffd23f;
    --ink: #f6eefc;
    --dim: #b79fc9;
    --line: #6a4a78;
    --pixel-font: 'Press Start 2P', 'Courier New', monospace;
    --n: 4;
    --dot: 14px;
    --body-pad: 16px;
    --bezel-pad: 10px;
    /* page padding + everything around the board, left and right (board border 3px + padding 8px) */
    --chrome-x: calc(24px + 2 * (25px + var(--body-pad) + var(--bezel-pad)));
    /* Box size follows the screen so the whole cabinet fits without scrolling */
    --cell: clamp(30px, min(64px, calc((100vw - var(--chrome-x) - (var(--n) + 1) * var(--dot)) / var(--n)), calc((100vh - 400px - (var(--n) + 1) * var(--dot)) / var(--n))), 64px);
}

* {
    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%, #432452 0%, transparent 62%),
        repeating-linear-gradient(0deg, transparent 0 38px, rgba(255, 179, 124, 0.04) 38px 40px),
        #120a1c;
    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: #ffc9a3;
    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 var(--body-pad) 0;
    border: 4px solid #000;
    border-radius: 18px 18px 4px 4px;
    box-shadow: 0 0 0 3px var(--glow), 0 0 28px rgba(255, 179, 124, 0.45), 0 10px 30px rgba(0, 0, 0, 0.7);
    background:
        repeating-linear-gradient(90deg, transparent 0 46px, rgba(255, 179, 124, 0.07) 46px 47px),
        linear-gradient(#37213f, #1d1226);
}

.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(255, 179, 124, 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: var(--bezel-pad);
    background: #0d0714;
    border: 3px solid var(--line);
    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: #1b1024;
    border: 2px solid var(--line);
    border-radius: 4px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.hud-item.mid {
    flex: 0 0 22%;
}

.hud-item.p0 { --c: var(--p0); }
.hud-item.p1 { --c: var(--p1); }

/* whose turn it is */
.hud-item.turn {
    border-color: var(--c);
    box-shadow: 0 0 12px color-mix(in srgb, var(--c) 70%, transparent);
}

.hud .label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 8px;
    text-transform: uppercase;
    color: var(--dim);
}

.hud .turn .label {
    color: var(--c);
}

.hud .value {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--gold);
    text-shadow: 0 0 8px rgba(255, 210, 63, 0.6);
    font-variant-numeric: tabular-nums;
}

.hud .value b {
    font-weight: 400;
}

.swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: var(--c);
    box-shadow: 0 0 6px var(--c);
}

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

/* ---------- The dots, lines and boxes ----------
   A (2n+1) x (2n+1) grid: dots where both numbers are even, lines where one is odd, boxes where both are. */
.board {
    --cur: var(--p0);
    display: grid;
    grid-template-columns: repeat(var(--n), var(--dot) var(--cell)) var(--dot);
    grid-template-rows: repeat(var(--n), var(--dot) var(--cell)) var(--dot);
    padding: 8px;
    background: #07040c;
    border: 3px solid var(--glow);
    border-radius: 8px;
    box-shadow: 0 0 14px rgba(255, 179, 124, 0.5), inset 0 0 14px #000;
    touch-action: none;
}

.board.turn1 { --cur: var(--p1); }

.dot {
    width: var(--dot);
    height: var(--dot);
    border-radius: 50%;
    background: #f4e6ff;
    box-shadow: 0 0 6px rgba(244, 230, 255, 0.6);
    z-index: 2;
    pointer-events: none;
}

.edge {
    position: relative;
    display: block;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.edge.h { width: var(--cell); height: var(--dot); }
.edge.v { width: var(--dot); height: var(--cell); }

.edge i {
    position: absolute;
    border-radius: 3px;
    background: rgba(244, 230, 255, 0.1);
    pointer-events: none;
    transition: background 0.1s;
}

.edge.h i { left: 0; right: 0; top: 50%; height: 6px; margin-top: -3px; }
.edge.v i { top: 0; bottom: 0; left: 50%; width: 6px; margin-left: -3px; }

/* the line that would be drawn */
.edge.cand i {
    background: color-mix(in srgb, var(--cur) 60%, transparent);
    box-shadow: 0 0 8px var(--cur);
}

.edge.done {
    cursor: default;
}

.edge.done i {
    background: var(--c);
    box-shadow: 0 0 8px var(--c);
}

.edge.l0 { --c: var(--p0); }
.edge.l1 { --c: var(--p1); }

.edge.last i {
    animation: flash 0.7s ease-out;
}

@keyframes flash {
    from { background: #fff; box-shadow: 0 0 16px #fff; }
}

.edge:focus-visible {
    outline: none;
}

.edge:focus-visible i {
    background: #fff;
    box-shadow: 0 0 10px #fff;
}

.box {
    --c: var(--p0);
    display: grid;
    place-items: center;
    width: var(--cell);
    height: var(--cell);
    font-size: calc(var(--cell) * 0.36);
    color: var(--c);
    pointer-events: none;
}

.box.own0 { --c: var(--p0); }
.box.own1 { --c: var(--p1); }

.box.own0,
.box.own1 {
    background: color-mix(in srgb, var(--c) 24%, transparent);
    border-radius: 4px;
    text-shadow: 0 0 8px var(--c);
    animation: claim 0.35s ease-out;
}

.box::after {
    content: attr(data-mark);
}

@keyframes claim {
    0% { transform: scale(0.4); opacity: 0; }
    70% { transform: scale(1.12); opacity: 1; }
    100% { transform: scale(1); }
}

.board.done .edge {
    cursor: default;
}

.board.done {
    box-shadow: 0 0 24px rgba(255, 210, 63, 0.7), inset 0 0 14px #000;
}

.status {
    min-height: 34px;
    margin-top: 10px;
    padding: 8px 6px;
    font-size: 8px;
    line-height: 1.8;
    text-align: center;
    text-transform: uppercase;
    color: var(--dim);
    background: #1b1024;
    border: 2px solid var(--line);
    border-radius: 4px;
}

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

/* ---------- Control area ---------- */
.panel {
    margin: 10px calc(-1 * var(--body-pad)) 0;
    padding: 12px var(--body-pad);
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(#5c3b6c, #35213f);
    border-top: 4px solid #8d62a0;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.4);
}

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

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

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

.act {
    flex: 1;
    padding: 14px 6px;
    font-family: var(--pixel-font);
    font-size: 8px;
    color: #2a1608;
    background: linear-gradient(#ffe0c4, #ffb37c);
    border: 3px solid #86501f;
    border-radius: 8px;
    box-shadow: 0 4px 0 #86501f;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.act.alt {
    background: linear-gradient(#f1e8f6, #b9a2c8);
    border-color: #5d466e;
    box-shadow: 0 4px 0 #5d466e;
}

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

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

.base {
    height: 14px;
    margin: 0 calc(-1 * var(--body-pad));
    border-radius: 0 0 4px 4px;
    background: repeating-linear-gradient(90deg, #0d0614 0 24px, var(--accent) 24px 28px);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.6);
}

/* ---------- Opponent 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(13, 7, 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: #f0e2f8;
}

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

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

@media (max-width: 480px) {
    :root {
        --body-pad: 10px;
        --bezel-pad: 8px;
        --dot: 12px;
    }
    .mq-icon { width: 24px; height: 24px; }
}

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