:root {
    --violet: #b266ff;
    --glow: var(--violet);
    --ink: #3b2a4d;
    --cream: #fff8e7;
    --pixel-font: 'Press Start 2P', 'Courier New', monospace;
    --fun-font: 'Chewy', 'Comic Sans MS', cursive;
    --cols: 4;
    --rows: 3;
    /* Tile size follows the screen, so every tile count fits without scrolling on a laptop */
    --tile: clamp(40px, min(104px, calc((100vh - 330px) / var(--rows) - 8px), calc((100vw - 96px) / var(--cols) - 8px)), 104px);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 10px 12px 40px;
    font-family: var(--pixel-font);
    color: #fff;
    background:
        radial-gradient(circle at 50% 0%, #5a2a9a 0%, transparent 62%),
        radial-gradient(circle, rgba(255, 255, 255, 0.07) 0 2px, transparent 3px) 0 0 / 34px 34px,
        #1a0b33;
    background-attachment: fixed;
}

.home {
    display: inline-block;
    margin-bottom: 8px;
    font-size: 10px;
    color: var(--violet);
    text-decoration: none;
    text-shadow: 0 0 8px var(--violet);
}

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

/* ---------- Cabinet: a toy-box purple with polka dots ---------- */
.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 #0f0620;
    border-radius: 18px 18px 4px 4px;
    box-shadow: 0 0 0 3px var(--glow), 0 0 26px rgba(178, 102, 255, 0.45), 0 10px 30px rgba(0, 0, 0, 0.6);
    background:
        radial-gradient(circle at 12px 12px, #ff70a6 0 5px, transparent 6px) 0 0 / 48px 48px,
        radial-gradient(circle at 36px 36px, #ffd93b 0 5px, transparent 6px) 0 0 / 48px 48px,
        radial-gradient(circle at 36px 12px, #4cc9f0 0 4px, transparent 5px) 0 0 / 48px 48px,
        linear-gradient(#3a1a6e, #2a1250);
}

.marquee {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 5px 12px;
    background: #12072a;
    border-radius: 8px;
    border: 3px solid var(--glow);
    box-shadow: 0 0 16px var(--glow), inset 0 0 12px rgba(178, 102, 255, 0.3);
}

.mq-title {
    margin: 0 6px;
    font-size: clamp(11px, 3.4vw, 18px);
    letter-spacing: 2px;
    text-shadow: 0 0 6px var(--violet), 0 0 18px var(--violet);
}

.mq-icon {
    display: block;
    width: 30px;
    height: 30px;
    padding: 2px;
    background: var(--cream);
    border-radius: 6px;
}

.mq-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

@media (max-width: 520px) {
    .mq-icon:nth-of-type(2),
    .mq-icon:nth-of-type(3) {
        display: none;
    }
}

/* ---------- Screen ---------- */
.bezel {
    margin-top: 10px;
    padding: 8px 10px 10px;
    background: #0d0620;
    border-radius: 10px;
    border: 3px solid #4a2a80;
    box-shadow: inset 0 0 14px #000;
}

.hud {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 6px;
    margin-bottom: 8px;
}

.hud-cell {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 6px 6px;
    background: #1c0f38;
    border: 2px solid #3d2470;
    border-radius: 6px;
}

.hud-cell .label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 8px;
    color: #b9a6d8;
}

.hud-cell .value {
    font-size: 15px;
    color: #fff;
    text-shadow: 0 0 6px var(--violet);
}

.hud-cell.active {
    border-color: var(--violet);
    box-shadow: 0 0 12px var(--violet);
    background: #2d1760;
}

.hud-cell.active .label {
    color: #fff;
}

.hud-cell.low .value {
    color: #ff6b6b;
    text-shadow: 0 0 8px #ff3b3b;
}

.stage {
    position: relative;
    min-height: 440px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    border-radius: 8px;
    overflow: hidden;
    background:
        radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.06) 0 2px, transparent 3px) 0 0 / 30px 30px,
        linear-gradient(#2b1660, #1d0e44);
    box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.55);
}

.status {
    min-height: 22px;
    margin-top: 10px;
    font-size: clamp(7px, 1.8vw, 10px);
    line-height: 1.6;
    text-align: center;
    color: #ffe14d;
    text-shadow: 0 0 6px #ffe14d;
    overflow-wrap: anywhere;
}

/* ---------- Board + tiles ---------- */
.board {
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--tile));
    grid-template-rows: repeat(var(--rows), var(--tile));
    gap: 8px;
}

.tile {
    position: relative;
    width: var(--tile);
    height: var(--tile);
    padding: 0;
    background: none;
    border: 0;
    perspective: 700px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.45s ease, opacity 0.45s ease;
}

.tile:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
    border-radius: 14px;
}

.inner {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.38s ease;
}

.tile.up .inner {
    transform: rotateY(180deg);
}

.face {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.face.back {
    background:
        radial-gradient(circle at 25% 25%, rgba(255, 255, 255, 0.25) 0 6px, transparent 7px),
        linear-gradient(135deg, #c77dff, #7b2cbf);
    border: 3px solid #e0b3ff;
    color: #fff;
    font-family: var(--fun-font);
    font-size: calc(var(--tile) * 0.55);
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.face.front {
    transform: rotateY(180deg);
    padding: 8%;
    background: var(--cream);
    border: 3px solid #ffd93b;
}

.face.front svg {
    display: block;
    width: 100%;
    height: 100%;
}

.tile.good .face.front {
    border-color: #52e07a;
    box-shadow: 0 0 16px #52e07a;
}

.tile.bad .face.front {
    border-color: #ff6b6b;
    box-shadow: 0 0 14px #ff6b6b;
}

.tile.gone {
    opacity: 0;
    transform: scale(0.3) rotate(12deg);
    pointer-events: none;
    visibility: hidden;
    transition: transform 0.45s ease, opacity 0.45s ease, visibility 0s 0.45s;
}

/* ---------- Overlays ---------- */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 14px;
    text-align: center;
    background: rgba(18, 7, 42, 0.94);
    overflow-y: auto;
}

/* Springy spacers centre the content when there is room, and let a tall panel scroll from its top when there isn't */
.overlay::before,
.overlay::after {
    content: '';
    flex: 1 0 0;
}

.overlay[hidden] {
    display: none;
}

.overlay h2 {
    margin: 0;
    font-size: clamp(14px, 3.6vw, 22px);
    font-weight: 400;
    color: #fff;
    text-shadow: 0 0 8px var(--violet), 0 0 20px var(--violet);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    align-items: center;
}

.field-label {
    font-size: 8px;
    color: #b9a6d8;
}

.options {
    display: flex;
    gap: 8px;
}

.opt {
    padding: 9px 12px;
    font-family: var(--pixel-font);
    font-size: 10px;
    color: #d9c8f5;
    background: #1c0f38;
    border: 2px solid #5a3a9a;
    border-radius: 6px;
    cursor: pointer;
    touch-action: manipulation;
}

.opt[aria-checked="true"] {
    color: #1a0b33;
    background: var(--violet);
    border-color: var(--violet);
    box-shadow: 0 0 12px var(--violet);
}

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

.names {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: min(380px, 100%);
}

.names[hidden] {
    display: none;
}

.names label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 8px;
    color: #b9a6d8;
    text-align: left;
}

.names input,
.online-name input,
.join-row input {
    width: 100%;
    padding: 9px 8px;
    font-family: var(--fun-font);
    font-size: 16px;
    color: #fff;
    background: #0d0620;
    border: 2px solid #5a3a9a;
    border-radius: 6px;
}

.names input:focus,
.online-name input:focus,
.join-row input:focus {
    outline: none;
    border-color: var(--violet);
    box-shadow: 0 0 10px var(--violet);
}

/* ---------- Online ---------- */
.options {
    flex-wrap: wrap;
    justify-content: center;
}

.online {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: min(380px, 100%);
}

.online[hidden] {
    display: none;
}

.online-name {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: min(260px, 100%);
    font-size: 8px;
    color: #b9a6d8;
    text-align: left;
}

.or {
    font-size: 8px;
    color: #b9a6d8;
}

.join-row {
    display: flex;
    gap: 8px;
    width: min(340px, 100%);
}

.join-row input {
    flex: 1;
    min-width: 0;
}

.online-error {
    max-width: 340px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
    color: #ff8a8a;
}

.online-error[hidden] {
    display: none;
}

.start-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.lobby-code {
    padding: 12px 16px;
    max-width: 100%;
    font-size: clamp(14px, 5vw, 24px);
    line-height: 1.4;
    text-transform: uppercase;
    color: #ffe14d;
    text-shadow: 0 0 8px #ffb703;
    background: #0d0620;
    border: 3px dashed #5a3a9a;
    border-radius: 10px;
    overflow-wrap: anywhere;
}

.waiting {
    font-size: 9px;
    color: #b9a6d8;
    animation: waiting 1.6s ease-in-out infinite;
}

@keyframes waiting {
    50% {
        opacity: 0.35;
    }
}

@media (prefers-reduced-motion: reduce) {
    .waiting {
        animation: none;
    }
}

.link-btn {
    padding: 10px;
    font-family: var(--pixel-font);
    font-size: 9px;
    color: #b9a6d8;
    background: none;
    border: 0;
    text-decoration: underline;
    cursor: pointer;
    touch-action: manipulation;
}

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

.net {
    margin-top: 8px;
    font-size: 8px;
    line-height: 1.6;
    text-align: center;
    color: #ff9e9e;
    overflow-wrap: anywhere;
}

.net[hidden] {
    display: none;
}

.rules {
    margin: 0;
    max-width: 380px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.5;
    color: #e6dcf7;
}

.start-btn {
    padding: 12px 20px;
    font-family: var(--pixel-font);
    font-size: 11px;
    color: #1a0b33;
    background: linear-gradient(#ffe66d, #ffb703);
    border: 3px solid #7a4a00;
    border-radius: 8px;
    box-shadow: 0 5px 0 #7a4a00, 0 0 14px rgba(255, 183, 3, 0.55);
    cursor: pointer;
    touch-action: manipulation;
}

.start-btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #7a4a00;
}

.start-btn:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}

.result-lines {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 100%;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    color: #e6dcf7;
}

.result-lines .big {
    font-family: var(--pixel-font);
    font-size: 12px;
    color: #ffe14d;
    text-shadow: 0 0 8px #ffb703;
    overflow-wrap: anywhere;
}

.result-lines div {
    overflow-wrap: anywhere;
}

/* ---------- Control area ---------- */
.panel {
    margin: 10px -16px 0;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: linear-gradient(#2a1250, #1c0c3a);
    border-top: 4px solid #6a3fb0;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.4);
}

.menu-btn {
    padding: 9px 14px;
    font-family: var(--pixel-font);
    font-size: 9px;
    color: #fff;
    background: linear-gradient(#d68cff, #8a3fd6);
    border: 3px solid #3b1a70;
    border-radius: 8px;
    box-shadow: 0 4px 0 #3b1a70;
    cursor: pointer;
    touch-action: manipulation;
}

.menu-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #3b1a70;
}

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

.hint {
    font-size: 7px;
    line-height: 1.9;
    text-align: right;
    color: #b9a6d8;
}

.base {
    height: 16px;
    margin: 10px -16px 0;
    border-radius: 0 0 4px 4px;
    background: repeating-linear-gradient(90deg, #12072a 0 20px, var(--violet) 20px 24px);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.6);
}

/* ---------- Winner banner (2 players), above the fireworks ---------- */
.banner {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
}

.banner[hidden] {
    display: none;
}

/* "WINNER!" stays put. The name starts big, shrinks and grows 4 times, then stays big until the fireworks end. */
.banner-label {
    font-size: clamp(14px, 3vw, 26px);
    color: #ffe14d;
    text-shadow: 0 0 10px #ffb703, 0 3px 0 #000;
}

.banner-name {
    max-width: 100%;
    font-family: var(--fun-font);
    font-weight: 900;
    font-size: clamp(44px, 13vw, 150px);
    line-height: 1.05;
    color: #fff;
    overflow-wrap: anywhere;
    text-shadow: 0 0 14px var(--violet), 0 0 36px var(--violet), 0 6px 0 #3b1a70, 0 10px 30px #000;
    -webkit-text-stroke: 3px #3b1a70;
    paint-order: stroke fill;
    transform-origin: center;
    animation: grow-shrink 1.6s ease-in-out 4;
}

.banner-hint {
    font-size: 8px;
    color: #d9c8f5;
    text-shadow: 0 2px 0 #000;
}

@keyframes grow-shrink {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.4); }
}

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