/* ============================================================
   BingoBango — playful + game-themed
   ============================================================ */

:root {
    /* Palette */
    --bg-1: #fff5ee;
    --bg-2: #ffe6f0;
    --fg: #1f1235;
    --fg-soft: #4a3a66;
    --muted: #7a6a8a;
    --surface: #ffffff;
    --surface-2: #faf6ff;
    --border: #e6d9f0;
    --border-strong: #c9b5e0;

    --primary: #8b5cf6;            /* purple */
    --primary-dark: #7c3aed;
    --primary-fg: #ffffff;
    --accent: #ec4899;              /* pink */
    --gold: #f59e0b;
    --gold-soft: #fde68a;
    --stamp: #dc2626;               /* dauber red */
    --stamp-dark: #991b1b;

    --success-bg: #dcfce7;
    --success-fg: #166534;
    --error-bg: #fee2e2;
    --error-fg: #991b1b;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(31, 18, 53, 0.06), 0 1px 1px rgba(31, 18, 53, 0.04);
    --shadow-md: 0 6px 16px -6px rgba(31, 18, 53, 0.18), 0 2px 4px rgba(31, 18, 53, 0.06);
    --shadow-lg: 0 18px 40px -12px rgba(124, 58, 237, 0.28), 0 8px 16px -6px rgba(31, 18, 53, 0.12);

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;

    --font-display: "Fredoka", "Segoe UI", system-ui, sans-serif;
    --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, "Cascadia Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
    color: var(--fg);
    line-height: 1.5;
    min-height: 100%;
    background:
        radial-gradient(1100px 600px at 110% -10%, rgba(236, 72, 153, 0.18), transparent 60%),
        radial-gradient(900px 600px at -10% 110%, rgba(139, 92, 246, 0.16), transparent 55%),
        linear-gradient(135deg, var(--bg-1) 0%, var(--bg-2) 100%);
    background-attachment: fixed;
    -webkit-tap-highlight-color: rgba(139, 92, 246, 0.15);
    -webkit-text-size-adjust: 100%;
}

/* ---------- Typography ---------- */
h1, h2, h3 {
    font-family: var(--font-display);
    color: var(--fg);
    letter-spacing: -0.01em;
    line-height: 1.15;
}
h1 { font-size: 2rem; margin: 0.2rem 0 0.6rem; font-weight: 700; }
h2 { font-size: 1.25rem; margin-top: 1.5rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

/* ---------- Header ---------- */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.85rem 1.5rem;
    padding-left: max(1.5rem, env(safe-area-inset-left));
    padding-right: max(1.5rem, env(safe-area-inset-right));
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: saturate(140%) blur(10px);
    -webkit-backdrop-filter: saturate(140%) blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    text-decoration: none;
    color: var(--fg);
}
.brand-text {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.25rem;
    background: linear-gradient(120deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* Mini bingo-card logo */
.brand-mark {
    display: inline-grid;
    grid-template-columns: repeat(3, 9px);
    grid-template-rows: repeat(3, 9px);
    gap: 2px;
    padding: 4px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
}
.brand-mark > span {
    background: rgba(255, 255, 255, 0.92);
    border-radius: 2px;
}
.brand-mark .b {
    background: var(--gold);
    color: var(--fg);
    font-family: var(--font-display);
    font-size: 8px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.site-header nav { display: flex; gap: 0.4rem; }
.site-header nav a {
    color: var(--fg-soft);
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    font-weight: 500;
    font-size: 0.92rem;
    transition: background-color 0.15s, color 0.15s;
}
.site-header nav a:hover { background: var(--surface-2); color: var(--primary-dark); }

/* ---------- Layout ---------- */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.75rem 1.25rem 3.5rem;
    /* Honor iOS safe areas (notch / home indicator) without breaking desktop spacing */
    padding-left: max(1.25rem, env(safe-area-inset-left));
    padding-right: max(1.25rem, env(safe-area-inset-right));
    padding-bottom: max(3.5rem, calc(2rem + env(safe-area-inset-bottom)));
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.1rem;
    background: var(--surface);
    color: var(--fg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transition: transform 0.08s ease, box-shadow 0.15s, background-color 0.15s, color 0.15s, border-color 0.15s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--primary-fg);
    border-color: transparent;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger {
    background: #fff;
    color: var(--stamp-dark);
    border-color: #fecaca;
}
.btn.danger:hover { background: #fee2e2; }

/* ---------- Alerts ---------- */
.error {
    background: var(--error-bg);
    color: var(--error-fg);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin: 0.75rem 0;
    border-left: 4px solid var(--error-fg);
}
.success {
    background: var(--success-bg);
    color: var(--success-fg);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin: 0.75rem 0;
    border-left: 4px solid var(--success-fg);
}

/* ---------- Forms ---------- */
.card-form, .join-form {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    max-width: 560px;
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}
.card-form label, .join-form label {
    display: flex;
    flex-direction: column;
    font-weight: 600;
    color: var(--fg-soft);
    font-size: 0.92rem;
}
.card-form small, .join-form small {
    font-weight: 400;
    color: var(--muted);
}
.card-form input[type="text"],
.card-form input[type="number"],
.card-form textarea,
.join-form input[type="text"] {
    margin-top: 0.35rem;
    padding: 0.65rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.card-form input:focus,
.card-form textarea:focus,
.join-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}
/* 16px floor on touch devices keeps iOS Safari from zooming the page on focus. */
.card-form textarea { font-family: var(--font-mono); font-size: max(0.9rem, 16px); }
.card-form .checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}
.card-form .checkbox input { margin-top: 0; width: 18px; height: 18px; accent-color: var(--primary); }

/* Marker color picker */
.color-picker {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem 0.95rem;
    margin: 0;
    background: var(--surface);
}
.color-picker legend {
    padding: 0 0.4rem;
    font-weight: 600;
    color: var(--fg-soft);
    font-size: 0.92rem;
}
.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-top: 0.25rem;
}
.swatch {
    position: relative;
    cursor: pointer;
    line-height: 0;
}
.swatch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}
.swatch-dot {
    display: inline-block;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--c);
    border: 3px solid white;
    box-shadow: 0 0 0 1px var(--border), var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.swatch:hover .swatch-dot { transform: scale(1.08); }
.swatch input:checked + .swatch-dot {
    box-shadow: 0 0 0 3px var(--c), var(--shadow-md);
    transform: scale(1.05);
}
.swatch input:focus-visible + .swatch-dot {
    box-shadow: 0 0 0 3px var(--c), 0 0 0 5px rgba(139, 92, 246, 0.35);
}
.swatch-label {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* "Already taken" indicator: diagonal stripes + slight desaturation */
.swatch.taken .swatch-dot {
    background:
        repeating-linear-gradient(
            45deg,
            rgba(255, 255, 255, 0.55) 0,
            rgba(255, 255, 255, 0.55) 3px,
            transparent 3px,
            transparent 7px
        ),
        var(--c);
    opacity: 0.6;
}
.swatch.taken:hover .swatch-dot { opacity: 0.85; }
.swatch.taken input:checked + .swatch-dot { opacity: 0.95; }

.picker-hint {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 0.7rem 0 0;
}

/* ============================================================
   Mode picker (create + edit forms) + mode indicator (landing + play)
   ============================================================ */
.mode-picker {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem 0.95rem;
    margin: 0;
    background: var(--surface);
}
.mode-picker legend {
    padding: 0 0.4rem;
    font-weight: 600;
    color: var(--fg-soft);
    font-size: 0.92rem;
}
.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.65rem;
    margin-top: 0.4rem;
}
.mode-option { position: relative; cursor: pointer; }
.mode-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}
.mode-card {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.7rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    transition: border-color 0.15s, background-color 0.15s, transform 0.08s, box-shadow 0.15s;
}
.mode-option:hover .mode-card {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.mode-option input:checked + .mode-card {
    border-color: var(--primary);
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--primary) 8%, white),
        color-mix(in srgb, var(--accent) 8%, white));
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2), var(--shadow-sm);
}
.mode-option input:focus-visible + .mode-card {
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.35);
}
.mode-text { flex: 1; min-width: 0; }
.mode-name { font-weight: 700; font-size: 0.95rem; color: var(--fg); }
.mode-desc { font-size: 0.82rem; color: var(--muted); line-height: 1.3; }

/* Mini preview grid (used in picker AND indicators) */
.mode-preview {
    display: grid;
    grid-template-columns: repeat(var(--size, 5), 1fr);
    gap: 2px;
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    background: var(--border);
    padding: 2px;
    border-radius: 5px;
}
.mp-cell {
    background: var(--surface);
    border-radius: 1px;
}
.mp-cell.active {
    background: linear-gradient(135deg, var(--primary), var(--accent));
}

/* Mode indicator banner (landing + play) */
.mode-indicator {
    display: flex;
    align-items: center;
    gap: 0.95rem;
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.mode-indicator .mode-preview {
    width: 64px;
    height: 64px;
}
.mode-indicator-text { flex: 1; min-width: 0; }
.mode-indicator-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.mode-indicator-label strong {
    font-family: var(--font-display);
    font-size: 1.15rem;
    color: var(--fg);
    text-transform: none;
    letter-spacing: 0;
    margin-left: 0.35em;
    background: linear-gradient(120deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.mode-indicator-desc {
    color: var(--fg-soft);
    font-size: 0.95rem;
    margin-top: 0.1rem;
}
.landing-indicator { margin-bottom: 1.5rem; }

/* Inline color dot used in sidebars + headers */
.player-dot {
    display: inline-block;
    width: 0.7em;
    height: 0.7em;
    border-radius: 50%;
    background: var(--muted);
    margin-right: 0.45em;
    vertical-align: baseline;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6), 0 0 0 2px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

/* ---------- Home hero ---------- */
.hero {
    padding: 2rem 0 1rem;
    position: relative;
}
.hero h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
    background: linear-gradient(120deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.hero p { font-size: 1.05rem; max-width: 640px; color: var(--fg-soft); }
.how {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
}
.how ol { padding-left: 1.3rem; margin: 0.5rem 0; }
.how li { margin: 0.4rem 0; color: var(--fg-soft); }

/* Floating decorative cells on home page */
.hero::before, .hero::after {
    content: "";
    position: absolute;
    width: 64px;
    height: 64px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    opacity: 0.18;
    transform: rotate(-12deg);
    box-shadow: var(--shadow-md);
    z-index: -1;
}
.hero::before { top: 1rem; right: 0; }
.hero::after {
    width: 40px; height: 40px;
    top: 7rem; right: 5rem;
    background: var(--gold);
    opacity: 0.6;
    transform: rotate(18deg);
}

/* ---------- Created-page link blocks ---------- */
.link-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin: 1rem 0;
    box-shadow: var(--shadow-sm);
}
.link-block.warn { border-color: var(--gold); border-width: 1px; box-shadow: 0 6px 16px -6px rgba(245, 158, 11, 0.4); }
.link {
    display: block;
    background: var(--surface-2);
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    word-break: break-all;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--fg-soft);
    border: 1px dashed var(--border-strong);
}

/* ---------- Landing leaderboard ---------- */
.leaderboard { margin-top: 1.5rem; }
.leaderboard ul {
    list-style: none;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.leaderboard li {
    display: flex;
    justify-content: space-between;
    padding: 0.55rem 0.85rem;
    border-bottom: 1px solid var(--border);
}
.leaderboard li:last-child { border-bottom: none; }
.player-meta { color: var(--muted); font-size: 0.9rem; }

/* ============================================================
   Play page
   ============================================================ */
.play-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.75rem 1.25rem;
    margin-bottom: 0.5rem;
}
.play-header h1 { margin: 0; }
.leave-form { margin-left: auto; }
.bingo-banner {
    background: linear-gradient(120deg, var(--gold), #fb923c);
    color: #422006;
    padding: 0.55rem 1.1rem;
    border-radius: 999px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.08em;
    margin: 0;
    box-shadow: 0 8px 22px -6px rgba(245, 158, 11, 0.6);
    animation: bingoPulse 1.4s ease-in-out infinite;
}
@keyframes bingoPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 8px 22px -6px rgba(245, 158, 11, 0.6); }
    50%      { transform: scale(1.04); box-shadow: 0 10px 28px -6px rgba(245, 158, 11, 0.85); }
}
.conn-status {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.conn-status::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--muted);
    transition: background-color 0.15s;
}
.conn-status.ok { color: var(--success-fg); }
.conn-status.ok::before { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }

.play-layout {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 1.5rem;
    margin-top: 1.25rem;
    align-items: start;
}
@media (max-width: 760px) {
    .play-layout { grid-template-columns: 1fr; }
}

.board-wrap {
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.board {
    display: grid;
    grid-template-columns: repeat(var(--size), minmax(0, 1fr));
    gap: 8px;
    aspect-ratio: 1 / 1;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

/* Desktop: scale the board to fit the viewport height so no page scroll is needed.
   --play-chrome estimates the height of site-header + play-header + mode-indicator + container padding.
   Sidebar also caps at viewport height and scrolls internally if its content overflows. */
@media (min-width: 760px) {
    .play-layout { --play-chrome: 340px; }
    .board {
        width: min(100%, calc(100vh - var(--play-chrome)));
        width: min(100%, calc(100dvh - var(--play-chrome)));
    }
    .sidebar {
        max-height: calc(100vh - var(--play-chrome));
        max-height: calc(100dvh - var(--play-chrome));
        overflow-y: auto;
    }
}

.cell {
    position: relative;
    background: linear-gradient(180deg, #ffffff 0%, var(--surface-2) 100%);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.15;
    color: var(--fg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform 0.12s ease, box-shadow 0.15s, border-color 0.15s, background-color 0.15s;
}
.cell:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}
.cell:active { transform: translateY(0); }

/* Target overlay: cells that matter for the current win pattern.
   Subtle inner ring + corner dot using theme gradient (not marker color, to avoid
   confusion with the dauber stamp). */
.cell.target {
    border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
    box-shadow:
        var(--shadow-sm),
        inset 0 0 0 1.5px color-mix(in srgb, var(--primary) 25%, transparent);
}
.cell.target::before {
    content: "";
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    box-shadow: 0 0 0 2px var(--surface);
    z-index: 3;
    pointer-events: none;
}
/* Hover should still feel responsive */
.cell.target:hover {
    border-color: var(--primary);
    box-shadow:
        var(--shadow-md),
        inset 0 0 0 1.5px color-mix(in srgb, var(--primary) 35%, transparent);
}

.cell-text {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    position: relative;
    z-index: 1;
    transition: opacity 0.2s;
}

/* The dauber stamp — appears OVER the text when a cell is marked.
   Color is driven by --marker-color set on the board container per-player. */
.cell.marked .cell-text { opacity: 0.55; }
.cell.marked::after {
    content: "";
    position: absolute;
    inset: 12%;
    border-radius: 50%;
    background: radial-gradient(closest-side,
        color-mix(in srgb, var(--marker-color, #dc2626) 78%, transparent) 0%,
        color-mix(in srgb, var(--marker-color, #dc2626) 60%, transparent) 55%,
        color-mix(in srgb, var(--marker-color, #dc2626) 25%, transparent) 95%);
    border: 3px solid color-mix(in srgb, var(--marker-color, #dc2626) 75%, black);
    box-shadow: inset 0 -3px 8px rgba(0, 0, 0, 0.15);
    transform: rotate(-7deg);
    pointer-events: none;
    animation: stamp 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2;
}
@keyframes stamp {
    0%   { transform: rotate(-7deg) scale(2.4); opacity: 0; }
    60%  { transform: rotate(-7deg) scale(0.9); opacity: 1; }
    100% { transform: rotate(-7deg) scale(1);   opacity: 1; }
}
.cell.marked {
    border-color: color-mix(in srgb, var(--marker-color, #dc2626) 40%, transparent);
    background: linear-gradient(180deg,
        color-mix(in srgb, var(--marker-color, #dc2626) 6%, white) 0%,
        color-mix(in srgb, var(--marker-color, #dc2626) 14%, white) 100%);
}

/* Free center cell */
.cell.free {
    background: linear-gradient(135deg, var(--gold-soft), #fbbf24);
    color: #422006;
    border-color: var(--gold);
    font-family: var(--font-display);
    font-weight: 700;
    cursor: default;
}
.cell.free:hover { transform: none; box-shadow: var(--shadow-sm); border-color: var(--gold); }
.cell.free .cell-text { opacity: 1; }
/* Stamp on free is the same dauber but smaller — visible but doesn't overwhelm */
.cell.free.marked::after { inset: 22%; opacity: 0.65; }

/* ---------- Sidebar ---------- */
.sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-md);
}
.sidebar h2 {
    margin-top: 1rem;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    font-family: var(--font-body);
    font-weight: 700;
}
.sidebar h2:first-of-type { margin-top: 0; }

.player-list, .winners {
    list-style: none;
    padding: 0;
    margin: 0;
}
.player-list li, .winners li {
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.93rem;
    color: var(--fg-soft);
}
.player-list li:last-child, .winners li:last-child { border-bottom: none; }
.player-list li.self {
    font-weight: 600;
    color: var(--primary-dark);
}
.player-list li.offline { color: var(--muted); font-style: italic; }
.winners li.empty { color: var(--muted); font-style: italic; }
.winners li {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
}
.winners .medal {
    font-size: 1.15rem;
    min-width: 1.6em;
    text-align: center;
}
.winners .winner-name { flex: 1; }
.winners li.place-1 {
    background: linear-gradient(90deg, rgba(250, 204, 21, 0.18), transparent 70%);
    font-weight: 600;
    color: #78350f;
    border-radius: 6px;
    padding-left: 0.4rem;
}
.winners li.place-2 {
    background: linear-gradient(90deg, rgba(148, 163, 184, 0.2), transparent 70%);
    font-weight: 600;
    color: #334155;
    border-radius: 6px;
    padding-left: 0.4rem;
}
.winners li.place-3 {
    background: linear-gradient(90deg, rgba(217, 119, 6, 0.18), transparent 70%);
    font-weight: 600;
    color: #7c2d12;
    border-radius: 6px;
    padding-left: 0.4rem;
}
.winners li.place-n .medal { color: var(--muted); font-size: 0.95rem; }
.winners li.self .winner-name::after {
    content: " (you)";
    color: var(--muted);
    font-weight: 400;
}

/* ---------- Confetti container ---------- */
.confetti {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 100;
}
.confetti span {
    position: absolute;
    top: -10vh;
    width: 10px;
    height: 14px;
    opacity: 0;
    animation: fall 1.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}
@keyframes fall {
    0%   { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
    100% { transform: translate3d(var(--dx, 0), 110vh, 0) rotate(720deg); opacity: 0.9; }
}

/* ============================================================
   Admin console
   ============================================================ */
.admin-cards { display: flex; flex-direction: column; gap: 1.1rem; margin-top: 1rem; }
.admin-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.12s, box-shadow 0.15s;
}
.admin-card:hover { box-shadow: var(--shadow-md); }
.admin-card.live {
    border-left: 4px solid transparent;
    background:
        linear-gradient(var(--surface), var(--surface)) padding-box,
        linear-gradient(180deg, var(--primary), var(--accent)) border-box;
    border-left-color: transparent;
}
.admin-card.live::before {
    content: "LIVE";
    display: inline-block;
    background: linear-gradient(120deg, var(--primary), var(--accent));
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow-sm);
}
.admin-card h2 { margin: 0; font-size: 1.15rem; }
.admin-card .card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0 0.65rem;
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 0.3rem;
}
.admin-card .card-meta span + span::before { content: "·"; margin-right: 0.6rem; }

.link-row {
    display: grid;
    grid-template-columns: 110px 1fr auto;
    gap: 0.55rem;
    align-items: center;
    margin: 0.45rem 0;
}
.link-row label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.link-row label small { font-weight: 400; }
.link-row input[type="text"] {
    padding: 0.45rem 0.65rem;
    font-family: var(--font-mono);
    font-size: 0.84rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 100%;
    color: var(--fg-soft);
}
.copy-btn { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
.copy-btn.ok {
    background: var(--success-bg);
    color: var(--success-fg);
    border-color: var(--success-fg);
}

.room-state {
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px dashed var(--border);
}
.room-state h3 {
    margin: 0 0 0.4rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    font-family: var(--font-body);
    font-weight: 700;
}
.player-list.compact li { padding: 0.22rem 0; font-size: 0.9rem; border-bottom: none; }

.admin-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.95rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
}
.inline-form { display: inline; margin: 0; }

.admin-flash {
    margin: 0.75rem 0 1rem;
    padding: 0.7rem 0.9rem;
    background: var(--success-bg);
    color: var(--success-fg);
    border: 1px solid var(--success-fg);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
}

.admin-toolbar {
    margin: 1rem 0 1.5rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.admin-toolbar h2 {
    margin: 0 0 0.25rem;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-family: var(--font-body);
    font-weight: 700;
}
.admin-toolbar .small { font-size: 0.85rem; margin: 0.25rem 0 0.75rem; }
.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}
.import-form {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.import-form input[type="file"] {
    font-size: 0.85rem;
    color: var(--fg-soft);
}

@media (max-width: 600px) {
    .link-row { grid-template-columns: 1fr; }
    .link-row label { margin-bottom: -0.25rem; }
}

/* ============================================================
   Gate page (access required)
   ============================================================ */
.gate { max-width: 560px; margin: 0 auto; }
.gate h1 {
    background: linear-gradient(120deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.gate-flash { margin: 0.75rem 0 1rem; }
.gate-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.1rem 1.25rem;
    margin: 1rem 0;
}
.gate-panel h2 { margin-top: 0; font-size: 1.05rem; }
.gate-request-form { padding: 0; background: transparent; border: none; box-shadow: none; }
.gate-request-form textarea {
    font-family: var(--font-body);
    font-size: max(0.95rem, 16px);
}

/* ============================================================
   Admin — tabs + access requests
   ============================================================ */
.admin-tabs {
    display: flex;
    gap: 0.25rem;
    margin: -0.25rem 0 1rem;
    border-bottom: 1px solid var(--border);
}
.admin-tabs a {
    padding: 0.55rem 0.95rem;
    color: var(--fg-soft);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border: 1px solid transparent;
    border-bottom: none;
    margin-bottom: -1px;
}
.admin-tabs a:hover { color: var(--primary-dark); background: var(--surface-2); }
.admin-tabs a.active {
    color: var(--primary-dark);
    background: var(--surface);
    border-color: var(--border);
}

.gate-disabled-banner { margin: 0.5rem 0 1rem; }

.access-requests { display: flex; flex-direction: column; gap: 0.85rem; margin-top: 1rem; }
.access-request {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.15rem;
    box-shadow: var(--shadow-sm);
}
.access-request header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.55rem;
}
.ar-status { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.status-pill {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.status-pill.status-pending { background: #fef3c7; color: #92400e; }
.status-pill.status-approved { background: var(--success-bg); color: var(--success-fg); }
.status-pill.status-revoked { background: #f1f5f9; color: #475569; }
.access-request.status-revoked { opacity: 0.7; }

.ar-note {
    margin: 0.4rem 0;
    padding: 0.55rem 0.85rem;
    background: var(--surface-2);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    color: var(--fg-soft);
    white-space: pre-wrap;
    word-break: break-word;
}

.ar-code {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
    margin: 0.6rem 0;
    padding: 0.55rem 0.85rem;
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--primary) 5%, white),
        color-mix(in srgb, var(--accent) 5%, white));
    border-radius: var(--radius);
    border: 1px dashed color-mix(in srgb, var(--primary) 25%, transparent);
}
.ar-code label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.ar-code label small { font-weight: 400; }

.ar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.85rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

/* ============================================================
   Mobile / narrow-viewport adjustments
   Stacked from broadest to tightest so later rules override.
   ============================================================ */

/* Touch-capable pointers get a 44px tap-target floor on the things you actually
   tap. We scope this to coarse-pointer devices so desktop keeps compact buttons. */
@media (pointer: coarse) {
    .btn { min-height: 44px; }
    .code-pill { min-height: 28px; padding-top: 0.3em; padding-bottom: 0.3em; }
    .code-pill.small { min-height: 24px; }
    /* Cells already large enough on small grids; tighten only the larger ones in width media below. */
    .swatch-dot { width: 40px; height: 40px; }  /* easier thumb targeting */
}

@media (max-width: 760px) {
    h1 { font-size: 1.7rem; }
    h2 { font-size: 1.15rem; }
    .container { padding: 1.25rem 1rem 3rem; }
    .site-header { padding: 0.7rem 1rem; }
    .site-header nav { gap: 0.2rem; }
    .site-header nav a { padding: 0.35rem 0.6rem; font-size: 0.88rem; }
    .brand-text { font-size: 1.1rem; }

    /* Hero decorations get in the way of the wrapped header on narrow phones. */
    .hero { padding-top: 1.25rem; }
    .hero::before, .hero::after { display: none; }
    .hero p { font-size: 1rem; }

    .card-form, .join-form { padding: 1.1rem; gap: 0.9rem; }
    .home-panel { padding: 1rem; }

    /* Card lobby + game meta lines often have 4+ middots — let them breathe. */
    .lobby-header .muted, .play-header .muted { line-height: 1.6; }

    /* Tighter board: smaller gap + padding + smaller wrapper give more pixels back to cell content. */
    .board { gap: 6px; }
    .board-wrap { padding: 0.6rem; }
    .cell { padding: 4px; font-size: 0.78rem; }

    /* Bingo banner scales down so it stays on one line on a 360px phone. */
    .bingo-banner { font-size: 0.95rem; padding: 0.4rem 0.85rem; }

    /* Created-page big code pill: cap so it doesn't blow past the surface on narrow screens. */
    .big-code .code-pill { font-size: 1.5rem; padding: 0.35rem 0.85rem; }

    /* Admin: card meta wraps on long titles; tighten the toolbar file input. */
    .admin-card { padding: 0.9rem; }
    .admin-toolbar { padding: 0.9rem; }
    .import-form input[type="file"] { max-width: 100%; }

    .admin-card-actions { gap: 0.4rem; }
    .admin-card-actions .btn { flex: 1 1 auto; min-width: 0; }
}

@media (max-width: 480px) {
    h1 { font-size: 1.5rem; }
    .container { padding: 1rem 0.85rem 2.5rem; }
    .site-header { padding: 0.55rem 0.85rem; }

    /* Stack code-form input + button so the button doesn't get squeezed below tap size */
    .code-form { flex-direction: column; align-items: stretch; gap: 0.45rem; }
    .code-form button { width: 100%; }

    /* Play header: keep h1 on its own line, push status + leave to a tidy row. */
    .play-header h1 { width: 100%; }
    .play-header .muted { width: 100%; margin: 0.1rem 0 0; }
    .conn-status { margin-left: 0; }
    .leave-form { margin-left: auto; }

    /* Mode indicator: stack preview above text on the tightest screens. */
    .mode-indicator { flex-direction: column; align-items: flex-start; gap: 0.55rem; }
    .mode-indicator .mode-preview { width: 56px; height: 56px; }

    /* Mode picker grid: single column when 180px minmax can't fit two */
    .mode-grid { grid-template-columns: 1fr; }

    /* Active-game cards stack the arrow indicator below content */
    .active-game-link { flex-wrap: wrap; }
    .join-arrow { width: 100%; text-align: right; }

    /* Tighter board for sub-iPhone-SE widths — especially helps 8x8+ */
    .board { gap: 4px; }
    .cell { padding: 3px; font-size: 0.72rem; line-height: 1.1; }

    /* Created-page link blocks: smaller padding, ensure long URLs wrap nicely */
    .link-block { padding: 0.85rem 1rem; }
    .big-code .code-pill { font-size: 1.3rem; padding: 0.3rem 0.75rem; letter-spacing: 0.08em; }

    /* Admin toolbar: stack the import controls vertically so the file picker has room. */
    .toolbar-actions { flex-direction: column; align-items: stretch; }
    .import-form { width: 100%; }
    .admin-game-header { font-size: 0.85rem; }
    .admin-game-header .inline-form { margin-left: 0; width: 100%; }
}

/* ============================================================
   Visually-hidden utility (a11y)
   ============================================================ */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ============================================================
   Code pill — used to display card codes / game codes prominently
   ============================================================ */
.code-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.18em 0.55em;
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--primary) 12%, white),
        color-mix(in srgb, var(--accent) 12%, white));
    color: var(--fg);
    border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-weight: 700;
    letter-spacing: 0.06em;
    font-size: 0.95em;
    user-select: all;
    cursor: pointer;
    transition: transform 0.08s, background-color 0.15s;
    text-decoration: none;
}
.code-pill.small {
    padding: 0.1em 0.5em;
    font-size: 0.78em;
}
.code-pill:hover { transform: translateY(-1px); }
.code-pill.copied {
    background: var(--success-bg);
    color: var(--success-fg);
    border-color: var(--success-fg);
}

.big-code {
    text-align: center;
    margin: 0.75rem 0 0.5rem;
}
.big-code .code-pill {
    font-size: 2rem;
    padding: 0.4rem 1.2rem;
    letter-spacing: 0.12em;
    box-shadow: var(--shadow-md);
}

/* ============================================================
   Home page — three panels
   ============================================================ */
.home-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0 2rem;
}
.home-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.25rem 1.1rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}
.home-panel.primary {
    background:
        linear-gradient(var(--surface), var(--surface)) padding-box,
        linear-gradient(135deg, var(--primary), var(--accent)) border-box;
    border: 2px solid transparent;
    box-shadow: var(--shadow-md);
}
.home-panel h2 { margin: 0 0 0.4rem; font-size: 1.1rem; }
.home-panel p { color: var(--fg-soft); margin: 0.2rem 0 0.7rem; font-size: 0.95rem; }

.code-form {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.4rem;
}
.code-form input[type="text"] {
    flex: 1;
    padding: 0.6rem 0.8rem;
    font-family: var(--font-mono);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--surface-2);
    text-align: center;
    min-width: 0;
}
.code-form input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}
.code-form button { flex-shrink: 0; }

.public-cards-heading {
    margin: 1rem 0 0.4rem;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 700;
    font-family: var(--font-body);
}
.public-cards {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 280px;
    overflow-y: auto;
}
.public-cards li a {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.5rem 0.65rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--fg);
    transition: border-color 0.15s, transform 0.08s;
}
.public-cards li a:hover {
    border-color: var(--primary);
    transform: translateX(2px);
}
.public-card-title { font-weight: 600; font-size: 0.95rem; }
.public-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--muted);
}
.active-tag { color: var(--success-fg); font-weight: 600; }
.private-tag {
    background: #fef3c7;
    color: #92400e;
    padding: 0.1em 0.5em;
    border-radius: 999px;
    font-size: 0.78em;
    font-weight: 600;
}

/* ============================================================
   Card lobby — active games + start game form
   ============================================================ */
.lobby-header { margin-bottom: 1rem; }
.lobby-header h1 { margin-bottom: 0.25rem; }

.active-games { margin: 1rem 0 1.5rem; }
.active-games ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.active-game-link {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.7rem 0.9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--fg);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s, transform 0.08s, box-shadow 0.15s;
}
.active-game-link:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.active-game-link .mode-preview { width: 48px; height: 48px; }
.active-game-text { flex: 1; min-width: 0; }
.active-game-mode {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
}
.active-game-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    color: var(--muted);
    font-size: 0.88rem;
    margin-top: 0.15rem;
}
.join-arrow {
    color: var(--primary);
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.start-game { margin-top: 1rem; }
.start-game h2 { font-size: 1.1rem; }
.start-game-form { margin-top: 0.6rem; }
.start-game-form .mode-picker { margin-bottom: 0.85rem; }

/* ============================================================
   Admin — nested per-game blocks
   ============================================================ */
.admin-games {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.admin-game {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.55rem 0.8rem;
}
.admin-game-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.7rem;
    margin-bottom: 0.3rem;
    font-size: 0.9rem;
}
.admin-game-header .inline-form { margin-left: auto; }
.btn.small { padding: 0.3rem 0.65rem; font-size: 0.82rem; }
