:root {
    --bg: #f4f6fb;
    --card-bg: #ffffff;
    --ink: #1f2733;
    --muted: #6b7686;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --danger: #dc2626;
    --border: #e2e6ee;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

a { color: var(--primary); }

.app-header {
    background: linear-gradient(135deg, #1e3a5f, #334155);
    color: #fff;
    padding: 1.6rem 1.5rem;
    text-align: center;
    border-bottom: 3px solid rgba(255, 255, 255, .12);
}
.app-header h1 { margin: 0; font-size: 1.6rem; }
.app-header .tagline { margin: .4rem 0 0; opacity: .9; }
.app-header a { color: #fff; }

.container {
    max-width: 820px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 3px rgba(20, 30, 60, .04);
}
.card h2 { margin-top: 0; font-size: 1.15rem; }

/* Forms */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .35rem; }
.field-row { display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: flex-end; }
.field-row .field { flex: 1 1 180px; }
.hint { color: var(--muted); font-weight: 400; font-size: .88rem; }
.count-note { font-weight: 600; }
.count-note.count-short { color: #b45309; }
.count-note.count-ok { color: #15803d; }

input[type="text"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
}
textarea { resize: vertical; }

.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.checkbox input { width: auto; }

.inline-form {
    display: flex;
    gap: .6rem;
    align-items: center;
    flex-wrap: wrap;
}
.inline-form input[type="text"] { flex: 1 1 auto; }

.actions { display: flex; gap: .7rem; flex-wrap: wrap; margin-top: .5rem; }

/* Buttons */
.btn {
    display: inline-block;
    padding: .5rem .9rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f2f8; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: #f3c4c4; color: var(--danger); }
.btn-danger:hover { background: #fde8e8; }

/* Alerts */
.alert {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
    padding: .75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }

/* Project list */
.project-list { list-style: none; margin: 0; padding: 0; }
.project-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: .85rem 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.project-item:last-child { border-bottom: none; }
.project-title { font-weight: 600; display: block; }
.project-meta { color: var(--muted); font-size: .85rem; }
.warn-badge {
    display: inline-block;
    margin-left: .35rem;
    padding: .05rem .4rem;
    border-radius: 999px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
    font-size: .75rem;
    font-weight: 600;
    cursor: help;
    white-space: nowrap;
}
.status-badge {
    display: inline-block;
    margin-right: .4rem;
    padding: .05rem .45rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
    white-space: nowrap;
}
.status-live { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.status-draft { background: #f1f5f9; border: 1px solid #cbd5e1; color: #475569; }
.pin-form { max-width: 360px; }
/* Honeypot: visually and physically hidden, but bots still fill it. */
.hp-field {
    position: absolute !important;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ---------------- Professional login page ---------------- */
.auth-body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        radial-gradient(1200px 600px at 50% -10%, rgba(79, 70, 229, .18), transparent 60%),
        linear-gradient(160deg, #0f172a 0%, #1e293b 55%, #334155 100%);
}
.auth-shell {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.auth-card {
    width: 100%;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2.25rem 2rem 1.75rem;
    box-shadow: 0 24px 60px -20px rgba(2, 6, 23, .55), 0 6px 18px rgba(2, 6, 23, .25);
    border: 1px solid rgba(255, 255, 255, .06);
    text-align: center;
}
.auth-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    border-radius: 16px;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    box-shadow: 0 8px 20px -6px rgba(79, 70, 229, .6);
}
.auth-card-admin .auth-logo {
    background: linear-gradient(135deg, #0f766e, #0d9488);
    box-shadow: 0 8px 20px -6px rgba(13, 148, 136, .55);
}
.auth-title {
    margin: 0;
    font-size: 1.5rem;
    letter-spacing: -.01em;
    color: var(--ink);
}
.auth-sub {
    margin: .4rem 0 1.5rem;
    color: var(--muted);
    font-size: .95rem;
}
.auth-form { text-align: left; }
.auth-field { display: block; margin-bottom: 1rem; }
.auth-label {
    display: block;
    font-weight: 600;
    font-size: .85rem;
    margin-bottom: .4rem;
    color: var(--ink);
}
.auth-field input {
    width: 100%;
    padding: .7rem .85rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
}
.auth-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .18);
}
.auth-btn {
    width: 100%;
    margin-top: .25rem;
    padding: .8rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform .08s, box-shadow .15s, opacity .15s;
    box-shadow: 0 10px 24px -10px rgba(79, 70, 229, .7);
}
.auth-card-admin .auth-btn {
    background: linear-gradient(135deg, #0d9488, #0f766e);
    box-shadow: 0 10px 24px -10px rgba(13, 148, 136, .7);
}
.auth-btn:hover { transform: translateY(-1px); }
.auth-btn:active { transform: translateY(0); }
.auth-btn:disabled {
    opacity: .55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.auth-alert {
    margin-bottom: 1.1rem;
    padding: .7rem .85rem;
    border-radius: 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: .9rem;
    text-align: left;
}
.auth-switch {
    margin: 1.25rem 0 0;
    font-size: .9rem;
    color: var(--muted);
}
.auth-switch a { font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.auth-foot {
    margin: 1.25rem 0 0;
    font-size: .85rem;
    color: rgba(226, 232, 240, .75);
    text-align: center;
}
.seed-form { max-width: 420px; }
.publish-field {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .85rem 1rem;
}
.project-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.delete-form { display: inline; margin: 0; }
.empty { color: var(--muted); }

.app-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem; }
.app-footer .footer-quip { font-style: italic; font-weight: 600; color: var(--ink); margin: 0 0 .25rem; }
.app-footer .footer-fine { margin: 0; opacity: .8; }
.app-footer code { background: #e9edf5; padding: .1rem .35rem; border-radius: 4px; }

/* ---------- Splash page ---------- */
.splash-choices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}
.splash-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem 1.5rem;
    text-align: center;
    text-decoration: none;
    color: var(--ink);
    box-shadow: 0 1px 3px rgba(20, 30, 60, .04);
    transition: transform .15s, box-shadow .15s, border-color .15s;
}
.splash-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(20, 30, 60, .12);
    border-color: var(--primary);
}
.splash-card h2 { margin: .25rem 0 .5rem; }
.splash-card p { color: var(--muted); margin: 0 0 1.1rem; }
.splash-icon { font-size: 2.6rem; line-height: 1; }

/* ---------- Play page ---------- */
.play-area { max-width: 640px; }

/* Themed, calm full-page background while playing. */
.play-body {
    --page-bg: linear-gradient(180deg, #eef2f8, #d6e0ee);
    background: var(--page-bg);
    background-attachment: fixed;
    min-height: 100vh;
}
.play-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.play-buttons { display: flex; gap: .6rem; flex-wrap: wrap; }
.play-status { color: var(--muted); font-weight: 600; }

.play-card {
    /* Fallback theme variables (overridden by .theme-* classes). */
    --card-bg: #fff;
    --card-border: var(--ink);
    --card-grid-line: #333;
    --card-text: #1f2733;
    --card-free-bg: #eef2ff;
    --card-free-text: #1f2733;
    --card-pattern: none;
    --card-pattern-size: 40px 40px;
    --card-pattern-opacity: 0;
    --card-glow: rgba(0, 0, 0, .12);

    position: relative;
    overflow: hidden;
    margin: 0 auto;
    max-width: 560px;
    border-radius: 12px;
    padding: 1rem;
    background: var(--card-bg);
    color: var(--card-text);
    border: 2px solid var(--card-border);
    box-shadow: 0 10px 30px -14px var(--card-glow);
}
.play-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--card-pattern);
    background-size: var(--card-pattern-size);
    opacity: var(--card-pattern-opacity);
    pointer-events: none;
    z-index: 0;
}
.play-grid {
    position: relative;
    z-index: 1;
}
.play-grid td {
    cursor: pointer;
    user-select: none;
    transition: background .12s, box-shadow .12s;
    color: var(--card-text);
}
.play-grid td:hover { box-shadow: inset 0 0 0 2px var(--card-border); }
.play-grid td span { font-size: clamp(.55rem, 2.4vw, 1rem); }
.play-grid td.marked {
    background: var(--card-free-bg);
    color: var(--card-free-text);
}
.play-grid td.marked span::after {
    content: "";
    position: absolute;
    inset: 10%;
    border: 2px solid currentColor;
    border-radius: 50%;
    opacity: .5;
    pointer-events: none;
}

.win-banner {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
    background: linear-gradient(135deg, #1e3a5f, #334155);
    border: 1px solid rgba(255, 255, 255, .25);
    border-radius: 10px;
    padding: .85rem;
    margin-bottom: 1rem;
    letter-spacing: .06em;
    box-shadow: 0 10px 26px -10px rgba(0, 0, 0, .35);
}

/* ---------- Bingo cards ---------- */
.print-area {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    max-width: 1000px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

.bingo-card {
    /* Theme variables (overridden by .theme-* classes below) */
    --card-bg: #fff;
    --card-border: var(--ink);
    --card-grid-line: #333;
    --card-text: #1f2733;
    --card-title: #1f2733;
    --card-free-bg: #eef2ff;
    --card-free-text: #1f2733;
    --card-pattern: none;
    --card-pattern-size: 40px 40px;
    --card-pattern-opacity: .18;
    --card-glow: rgba(0, 0, 0, .15);

    position: relative;
    overflow: hidden;
    background: var(--card-bg);
    color: var(--card-text);
    border: 2px solid var(--card-border);
    border-radius: 8px;
    padding: .75rem;
    page-break-inside: avoid;
    break-inside: avoid;
}
/* Decorative pattern overlay drawn behind the grid. */
.bingo-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--card-pattern);
    background-size: var(--card-pattern-size);
    opacity: var(--card-pattern-opacity);
    pointer-events: none;
    z-index: 0;
}
.bingo-card .bingo-title,
.bingo-card .bingo-grid,
.bingo-card .bingo-card-no {
    position: relative;
    z-index: 1;
}
.bingo-title {
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: .5rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--card-title);
}
.bingo-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.bingo-grid td {
    border: 1px solid var(--card-grid-line);
    text-align: center;
    vertical-align: middle;
    width: calc(100% / var(--size));
    height: 0;
    padding: 0;
    position: relative;
}
.bingo-grid td::before {
    content: "";
    display: block;
    padding-top: 100%;
}
.bingo-grid td span {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
    font-size: clamp(.45rem, 1.6vw, .8rem);
    line-height: 1.1;
    overflow: hidden;
    word-break: break-word;
}
.bingo-grid td.free {
    background: var(--card-free-bg);
    color: var(--card-free-text);
    font-weight: 700;
}
.bingo-card-no {
    text-align: right;
    color: var(--muted);
    font-size: .7rem;
    margin-top: .35rem;
}

/* ---------- Card themes (refined / professional) ---------- */

/* Classic — clean monochrome with a hairline keyline. */
.theme-classic {
    --card-bg: #ffffff;
    --card-border: #111827;
    --card-grid-line: #9ca3af;
    --card-text: #111827;
    --card-title: #111827;
    --card-free-bg: #111827;
    --card-free-text: #ffffff;
    --card-pattern: none;
    --card-pattern-opacity: 0;
    --card-glow: rgba(17, 24, 39, .12);
    --page-bg: #f3f4f6;
}

/* Slate — modern neutral with a subtle cool gradient. */
.theme-slate {
    --card-bg: linear-gradient(170deg, #ffffff 0%, #f1f5f9 100%);
    --card-border: #334155;
    --card-grid-line: #cbd5e1;
    --card-text: #1e293b;
    --card-title: #0f172a;
    --card-free-bg: #475569;
    --card-free-text: #ffffff;
    --card-pattern: none;
    --card-pattern-opacity: 0;
    --card-glow: rgba(51, 65, 85, .14);
    --page-bg: linear-gradient(180deg, #f8fafc, #e2e8f0);
}

/* Navy — corporate deep blue with a restrained accent. */
.theme-navy {
    --card-bg: linear-gradient(170deg, #ffffff 0%, #eef2f8 100%);
    --card-border: #1e3a5f;
    --card-grid-line: #b8c4d6;
    --card-text: #1e293b;
    --card-title: #1e3a5f;
    --card-free-bg: #1e3a5f;
    --card-free-text: #ffffff;
    --card-pattern: none;
    --card-pattern-opacity: 0;
    --card-glow: rgba(30, 58, 95, .16);
    --page-bg: linear-gradient(180deg, #eef2f8, #d6e0ee);
}

/* Theme preview in the editor */
.theme-preview {
    margin-top: .75rem;
    max-width: 240px;
}
.theme-preview .bingo-card { margin: 0; }

/* ---------- Print: two cards per US Letter page ---------- */
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }

    /* Ensure themed background colours are printed. */
    .bingo-card,
    .bingo-grid td,
    .bingo-grid td.free {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    @page {
        size: letter portrait;
        margin: 0.5in;
    }

    /* Printable area on Letter with 0.5in margins is 7.5in x 10in.
       Two cards stacked vertically, each ~half the height. */
    .print-area {
        display: block;
        margin: 0;
        padding: 0;
        max-width: none;
    }

    .bingo-card {
        border-color: var(--card-border);
        width: 100%;
        height: 4.8in;            /* two of these fit within the 10in tall area */
        margin: 0 0 0.4in;
        padding: 0.2in;
        display: flex;
        flex-direction: column;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Force a page break after every second card. */
    .bingo-card:nth-of-type(2n) {
        margin-bottom: 0;
        page-break-after: always;
        break-after: page;
    }

    /* Let the grid grow to fill the available card height. */
    .bingo-card .bingo-grid {
        flex: 1 1 auto;
        height: 100%;
    }

    /* Square cells rely on padding hacks on screen; in print let the
       fixed card height drive cell sizing so the grid fills the card. */
    .bingo-grid td::before { content: none; }
    .bingo-grid td {
        height: auto;
    }
    .bingo-grid td span {
        position: static;
        inset: auto;
        height: 100%;
        font-size: calc(55pt / var(--size));
    }

    .bingo-title { font-size: 14pt; }
}
