* {
    box-sizing: border-box;
}

html,
body {
    overscroll-behavior: none;
    user-select: none;
}

.board,
.pieces,
.piece,
.piece-source,
.piece-ghost {
    touch-action: none;
    user-select: none;
}

:root {
    --bg: #060818;
    --panel: rgba(15, 23, 42, 0.92);
    --panel2: rgba(30, 41, 59, 0.92);
    --accent: #38bdf8;
    --accent2: #f97316;
    --text: #f8fafc;
    --muted: #94a3b8;
    --danger: #ef4444;
    --success: #22c55e;
    --cell: #172554;
    --line: rgba(255, 255, 255, 0.1);
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(56, 189, 248, 0.22), transparent 32%),
        radial-gradient(circle at bottom right, rgba(249, 115, 22, 0.18), transparent 35%),
        var(--bg);
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

button, input {
    font: inherit;
}

.page {
    min-height: 100vh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 22px;
}

.card {
    width: min(520px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 28px;
    padding: 28px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(14px);
}

.brand {
    text-align: center;
    margin-bottom: 22px;
}

.brand h1 {
    margin: 0;
    font-size: clamp(42px, 9vw, 72px);
    line-height: 0.9;
    letter-spacing: -3px;
    text-transform: uppercase;
    background: linear-gradient(135deg, #38bdf8, #ffffff, #f97316);
    -webkit-background-clip: text;
    color: transparent;
}

.brand p {
    color: var(--muted);
    margin: 12px 0 0;
}

.btn-group {
    display: grid;
    gap: 14px;
}

.btn {
    width: 100%;
    border: 0;
    border-radius: 18px;
    padding: 16px 18px;
    cursor: pointer;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-align: center;
    background: linear-gradient(135deg, var(--accent), #2563eb);
    color: white;
    box-shadow: 0 14px 35px rgba(37, 99, 235, 0.35);
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:hover, .btn:active {
    transform: translateY(-2px);
}

.btn.secondary {
    background: var(--panel2);
    box-shadow: none;
    border: 1px solid var(--line);
}

.btn.orange {
    background: linear-gradient(135deg, var(--accent2), #ef4444);
}

.form-field {
    margin: 18px 0;
}

.form-field label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-weight: 700;
}

.form-field input {
    width: 100%;
    border: 1px solid var(--line);
    background: rgba(2, 6, 23, 0.72);
    color: var(--text);
    border-radius: 16px;
    padding: 16px;
    outline: none;
}

.form-field input:focus {
    border-color: var(--accent);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 18px;
}

.modal-backdrop.show {
    display: flex;
}

.modal {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 24px;
}

.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 14px 0;
}

.switch {
    width: 58px;
    height: 32px;
    position: relative;
}

.switch input {
    display: none;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    border-radius: 999px;
    background: #475569;
}

.slider::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    left: 4px;
    top: 4px;
    border-radius: 50%;
    background: white;
    transition: 0.2s;
}

.switch input:checked + .slider {
    background: var(--accent);
}

.switch input:checked + .slider::before {
    transform: translateX(26px);
}

.game-shell {
    min-height: 100vh;
    width: 100%;
    padding: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-topbar {
    width: min(820px, 100%);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 12px;
    margin-bottom: 14px;
}

.stat {
    font-weight: 800;
    color: white;
}

.stat small {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.stat.center {
    text-align: center;
}

.stat.right {
    text-align: right;
}

.board {
    width: min(92vw, 520px);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 8px;
    touch-action: none;
}

.cell {
    border-radius: 9px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.cell.filled {
    background: linear-gradient(135deg, #38bdf8, #2563eb);
    box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.22);
}

.pieces {
    width: min(820px, 100%);
    margin-top: 14px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.piece-tray {
    min-height: 120px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.piece {
    display: grid;
    gap: 5px;
    cursor: grab;
    touch-action: none;
}

.piece.used {
    opacity: 0.25;
    pointer-events: none;
}

.mini-cell {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    background: linear-gradient(135deg, #f97316, #ef4444);
    box-shadow: inset 0 0 9px rgba(255, 255, 255, 0.3);
}

.mini-cell.empty {
    opacity: 0;
}

.countdown {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.84);
    z-index: 99;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(80px, 25vw, 180px);
    font-weight: 900;
}

.leaderboard-table,
.admin-table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    border-radius: 16px;
}

.leaderboard-table th,
.leaderboard-table td,
.admin-table th,
.admin-table td {
    padding: 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.leaderboard-table th,
.admin-table th {
    color: var(--muted);
    font-size: 13px;
}

.table-card {
    width: min(960px, 100%);
}

.admin-wrapper {
    min-height: 100vh;
    padding: 24px;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.notice {
    color: var(--muted);
    text-align: center;
    line-height: 1.5;
}

@media (max-width: 620px) {
    .card {
        padding: 22px;
    }

    .pieces {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 8px;
    }

    .piece-tray {
        min-height: 96px;
    }

    .mini-cell {
        width: 18px;
        height: 18px;
        border-radius: 5px;
    }

    .game-topbar {
        font-size: 13px;
    }

    .leaderboard-table th,
    .leaderboard-table td,
    .admin-table th,
    .admin-table td {
        padding: 9px;
        font-size: 13px;
    }
}

/* BoomBlast drag-and-drop gameplay updates */
.cell.preview-valid {
    background: rgba(34, 197, 94, 0.55);
    border-color: rgba(34, 197, 94, 0.95);
    box-shadow: inset 0 0 0 2px rgba(34, 197, 94, 0.9);
}

.cell.preview-invalid {
    background: rgba(239, 68, 68, 0.45);
    border-color: rgba(239, 68, 68, 0.95);
    box-shadow: inset 0 0 0 2px rgba(239, 68, 68, 0.9);
}

.cell.clearing {
    animation: boomClear 0.45s ease forwards;
}

@keyframes boomClear {
    0% {
        transform: scale(1);
        opacity: 1;
        filter: brightness(1);
    }

    45% {
        transform: scale(1.25) rotate(8deg);
        opacity: 1;
        filter: brightness(1.8);
    }

    100% {
        transform: scale(0);
        opacity: 0;
        filter: brightness(2.4);
    }
}

@keyframes blastAway {
    0% {
        opacity: 1;
        transform: scale(1);
        filter: brightness(1);
    }
    45% {
        opacity: 1;
        transform: scale(1.18) rotate(6deg);
        filter: brightness(1.8);
    }
    100% {
        opacity: 0;
        transform: scale(0.12) rotate(18deg);
        filter: brightness(2.3);
    }
}

.piece-source {
    touch-action: none;
    cursor: grab;
}

.piece-source:active {
    cursor: grabbing;
}

.dragging-source {
    opacity: 0.35;
    transform: scale(0.92);
}

.piece-ghost {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 9999;
    pointer-events: none;
    display: grid;
    gap: 4px;
    filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.35));
    transition: none;
}

.empty-tray::after {
    content: 'Placed';
    color: rgba(148, 163, 184, 0.45);
    font-weight: 800;
    font-size: 13px;
}

.game-over-modal {
    text-align: center;
    animation: modalPop 0.24s ease-out;
}

.game-over-modal h2 {
    margin: 0 0 10px;
    font-size: 34px;
}

.modal-kicker {
    margin: 0 0 8px;
    color: var(--accent2);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.final-score {
    margin: 16px auto;
    width: fit-content;
    min-width: 170px;
    padding: 16px 24px;
    border-radius: 22px;
    font-size: 42px;
    font-weight: 900;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(249, 115, 22, 0.2));
    border: 1px solid var(--line);
}

@keyframes modalPop {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
