:root {
    --accent: #13b8a6;
    --glow: var(--accent);
    --gold: #ffd23f;
    --ink: #e8fffb;
    --pixel-font: 'Press Start 2P', 'Courier New', monospace;
    --discs: 4;
    /* Disc thickness follows the screen so the whole cabinet fits without scrolling */
    --dh: clamp(14px, min(28px, calc((100vh - 480px) / (var(--discs) + 2))), 28px);
}

* {
    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%, #0d5a54 0%, transparent 62%),
        repeating-linear-gradient(0deg, transparent 0 38px, rgba(19, 184, 166, 0.06) 38px 40px),
        #03100f;
    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: #3de0cc;
    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(19, 184, 166, 0.45), 0 10px 30px rgba(0, 0, 0, 0.7);
    background:
        repeating-linear-gradient(90deg, transparent 0 46px, rgba(19, 184, 166, 0.07) 46px 47px),
        linear-gradient(#0c3a36, #072220);
}

.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(19, 184, 166, 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: #020a09;
    border: 3px solid #1c5d57;
    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: #06201e;
    border: 2px solid #1c5d57;
    border-radius: 4px;
}

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

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

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

/* ---------- The three pegs ---------- */
.tower {
    --base: 14px;
    position: relative;
    width: min(calc(100vw - 100px), 420px);
    height: calc(var(--base) + (var(--discs) + 2) * var(--dh));
    background: linear-gradient(#031614, #02100f);
    border: 3px solid var(--glow);
    border-radius: 8px;
    box-shadow: 0 0 14px rgba(19, 184, 166, 0.5), inset 0 0 14px #000;
    overflow: hidden;
}

.tower::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--base);
    background: linear-gradient(#caa26a, #8a6232);
    box-shadow: 0 -2px 0 #e6c48e;
}

.peg {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 33.3333%;
    left: calc(var(--p) * 33.3333%);
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.peg[data-peg='0'] { --p: 0; }
.peg[data-peg='1'] { --p: 1; }
.peg[data-peg='2'] { --p: 2; }

/* the post */
.peg::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: var(--base);
    width: 8px;
    height: calc((var(--discs) + 1.4) * var(--dh));
    margin-left: -4px;
    border-radius: 4px 4px 0 0;
    background: linear-gradient(90deg, #7a9a96, #d6ece8 45%, #6f8e8a);
}

/* little flag on the goal peg */
.peg.goal::after {
    content: '';
    position: absolute;
    left: calc(50% + 4px);
    bottom: calc(var(--base) + (var(--discs) + 1.4) * var(--dh) - 10px);
    border-left: 16px solid var(--gold);
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

.peg.target {
    background: radial-gradient(ellipse at 50% 70%, rgba(61, 224, 204, 0.28), transparent 70%);
}

.peg.no {
    opacity: 0.55;
}

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

.peg.shake {
    animation: shake 0.3s ease;
}

@keyframes shake {
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* ---------- Discs ---------- */
.disc {
    --w: calc((36% + var(--k) * 56%) / 3);
    position: absolute;
    left: calc((var(--p) + 0.5) * 33.3333% - var(--w) / 2);
    bottom: calc(var(--base) + var(--i) * var(--dh));
    width: var(--w);
    height: calc(var(--dh) - 3px);
    border-radius: 999px;
    background: var(--c);
    box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.4), inset 0 -3px 0 rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 2;
    transition: left 0.22s ease, bottom 0.2s ease;
}

.disc.lifted {
    filter: brightness(1.2) drop-shadow(0 0 8px rgba(255, 255, 255, 0.7));
}

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

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

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

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

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

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

.act {
    flex: 1;
    padding: 14px 6px;
    font-family: var(--pixel-font);
    font-size: 8px;
    color: #06201e;
    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(#e4fbf7, #9cc9c3);
    border-color: #3d6f69;
    box-shadow: 0 4px 0 #3d6f69;
}

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

.act:disabled {
    opacity: 0.4;
    cursor: default;
}

.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, #020a09 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(2, 12, 11, 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: #d3f6f1;
}

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

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

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

.lvl {
    --c: #7dffb0;
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 12px;
    font-family: var(--pixel-font);
    color: #fff;
    background: #06201e;
    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(--gold); }
.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: #8fcfc7;
}

.lvl:hover,
.lvl:focus-visible {
    background: color-mix(in srgb, var(--c) 18%, #06201e);
    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;
    }
}
