/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:   #4f46e5;
    --primary-h: #3730a3;
    --secondary: #64748b;
    --success:   #16a34a;
    --danger:    #dc2626;
    --bg:        #f1f5f9;
    --card-bg:   #ffffff;
    --text:      #1e293b;
    --muted:     #64748b;
    --border:    #e2e8f0;
    --radius:    12px;
    --shadow:    0 4px 24px rgba(0,0,0,.08);
    --marked-bg: #4f46e5;
    --marked-fg: #ffffff;
    --free-bg:   #fbbf24;
    --free-fg:   #1e293b;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ───────────────────────────────────────────────────── */
header {
    background: var(--primary);
    color: #fff;
    padding: 1.25rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ── Auth nav (header) ────────────────────────────────────────── */
.auth-nav { font-size: 0.9rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.auth-nav-email { color: #fff; font-weight: 600; }
.auth-nav-sep { color: rgba(255,255,255,0.5); }
.auth-nav-link {
    color: #fff; text-decoration: none; font-weight: 600;
    background: rgba(255,255,255,0.15); padding: 5px 14px;
    border-radius: 4px; border: 1px solid rgba(255,255,255,0.4);
}
.auth-nav-link:hover { background: rgba(255,255,255,0.3); text-decoration: none; }
.auth-nav-btn {
    background: none; border: 1px solid rgba(255,255,255,0.5); color: #fff;
    font-weight: 600; cursor: pointer; font-size: inherit;
    padding: 5px 14px; border-radius: 4px;
}
.auth-nav-btn:hover { background: rgba(255,255,255,0.2); }

.logo {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.logo a {
    color: inherit;
    text-decoration: none;
}

.logo a:hover {
    opacity: 0.85;
}

.tagline { font-size: .95rem; opacity: .85; }

.game-info {
    font-size: .9rem;
    display: flex;
    gap: 1.5rem;
    background: rgba(255,255,255,.15);
    padding: .4rem .9rem;
    border-radius: 999px;
}

/* ── Main ─────────────────────────────────────────────────────── */
main {
    flex: 1;
    max-width: 880px;
    width: 100%;
    margin: 2rem auto;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ── Card ─────────────────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
}

.card h2 {
    font-size: 1.35rem;
    margin-bottom: 1.25rem;
    color: var(--primary);
}

/* ── Form elements ────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1.1rem;
}

label {
    display: block;
    font-weight: 600;
    font-size: .88rem;
    margin-bottom: .35rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

input[type="text"],
textarea {
    width: 100%;
    padding: .65rem .9rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color .15s;
    background: var(--bg);
    color: var(--text);
}

input[type="text"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
}

textarea { resize: vertical; font-family: inherit; }

.item-input-row {
    display: flex;
    gap: .5rem;
}
.item-input-row input { flex: 1; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: .65rem 1.4rem;
    border: none;
    border-radius: 8px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .08s;
}
.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }

.btn-secondary {
    background: var(--border);
    color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: #cbd5e1; }

.btn-full { width: 100%; margin-top: .75rem; }

.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Progress bar ─────────────────────────────────────────────── */
.item-count-bar {
    font-size: .85rem;
    color: var(--muted);
    margin-bottom: .6rem;
}

.progress-wrap {
    height: 6px;
    background: var(--border);
    border-radius: 99px;
    margin-top: .3rem;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 99px;
    transition: width .25s;
}

/* ── Item list ────────────────────────────────────────────────── */
.item-list {
    list-style: none;
    max-height: 220px;
    overflow-y: auto;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.item-list:empty { display: none; }

.item-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem .8rem;
    border-bottom: 1px solid var(--border);
    font-size: .92rem;
    gap: .5rem;
}

.item-list li:last-child { border-bottom: none; }

.item-list li .item-text { flex: 1; }

.item-list li .remove-btn {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 .2rem;
    flex-shrink: 0;
}

/* ── Bulk section ─────────────────────────────────────────────── */
.bulk-section { margin-bottom: 1rem; }
.bulk-section details summary { cursor: pointer; color: var(--primary); font-size: .9rem; margin-bottom: .5rem; }
.bulk-section textarea { margin-bottom: .5rem; }

/* ── Share card ───────────────────────────────────────────────── */
.share-card { text-align: center; }

.game-code {
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: 6px;
    color: var(--primary);
    background: var(--bg);
    border-radius: var(--radius);
    padding: .75rem 2rem;
    display: inline-block;
    margin: .75rem auto 1.25rem;
}

.share-link-row {
    display: flex;
    gap: .5rem;
    margin-bottom: .75rem;
}

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

/* ── Errors / status ──────────────────────────────────────────── */
.error-msg {
    background: #fef2f2;
    border: 1.5px solid #fca5a5;
    color: var(--danger);
    border-radius: 8px;
    padding: .6rem .9rem;
    font-size: .9rem;
    margin-top: .6rem;
}

.status-msg {
    text-align: center;
    font-size: .95rem;
    margin-top: .75rem;
    min-height: 1.4em;
    color: var(--success);
}

/* ── Hint ─────────────────────────────────────────────────────── */
.hint { color: var(--muted); font-weight: 400; font-size: .85em; }

/* ── Bingo board ──────────────────────────────────────────────── */
.bingo-header-cell {
    background: var(--primary);
    color: #fff;
    text-align: center;
    font-size: 1.6rem;
    font-weight: 900;
    padding: .6rem .3rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.5rem;
}

.bingo-board {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
}

.bingo-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: clamp(.6rem, 1.5vw, .85rem);
    font-weight: 500;
    padding: .3rem;
    transition: background .18s, border-color .18s, transform .1s;
    word-break: break-word;
    line-height: 1.25;
    user-select: none;
}

.bingo-cell:hover:not(.free-space) {
    border-color: var(--primary);
    transform: scale(1.04);
}

.bingo-cell.marked {
    background: var(--marked-bg);
    border-color: var(--marked-bg);
    color: var(--marked-fg);
    transform: scale(.97);
}

.bingo-cell.free-space {
    background: var(--free-bg);
    border-color: var(--free-bg);
    color: var(--free-fg);
    cursor: default;
    font-weight: 700;
    font-size: clamp(.7rem, 1.6vw, .9rem);
}

.bingo-cell.winning-cell {
    background: var(--success) !important;
    border-color: var(--success) !important;
    color: #fff !important;
    animation: pulse 0.6s ease-in-out infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to   { transform: scale(1.06); }
}

/* ── Board actions ────────────────────────────────────────────── */
.board-actions {
    display: flex;
    gap: .75rem;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 560px;
    margin: 1.5rem auto 0;
}

.return-link-row {
    max-width: 560px;
    margin: 1.5rem auto 0;
    padding: .9rem 1rem;
    background: var(--bg);
    border-radius: 8px;
}

.return-link-label {
    display: block;
    margin-bottom: .3rem;
    text-transform: none;
    letter-spacing: 0;
    font-size: .85rem;
}

.return-link-controls {
    display: flex;
    align-items: center;
    gap: .5rem;
}

#playerReturnLink {
    flex: 1;
    min-width: 0;
    font-size: .88rem;
    padding: .45rem .7rem;
}

.return-link-help {
    margin-top: .45rem;
    font-size: .82rem;
    color: var(--muted);
}

/* ── Win banner ───────────────────────────────────────────────── */
.bingo-banner {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn .3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; } to { opacity: 1; }
}

.bingo-banner-inner {
    background: #fff;
    border-radius: 20px;
    padding: 3rem 4rem;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.bingo-letters {
    display: flex;
    justify-content: center;
    gap: .4rem;
    margin-bottom: .75rem;
}

.bingo-letters span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    font-size: 2.2rem;
    font-weight: 900;
    border-radius: 12px;
    color: #fff;
    animation: letterPop .5s ease both;
}

.bingo-letters span:nth-child(1) { background: #ef4444; animation-delay: 0s; }
.bingo-letters span:nth-child(2) { background: #f97316; animation-delay: .08s; }
.bingo-letters span:nth-child(3) { background: #eab308; animation-delay: .16s; }
.bingo-letters span:nth-child(4) { background: #22c55e; animation-delay: .24s; }
.bingo-letters span:nth-child(5) { background: #3b82f6; animation-delay: .32s; }

@keyframes letterPop {
    0%   { transform: scale(0) rotate(-15deg); opacity: 0; }
    70%  { transform: scale(1.15) rotate(5deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

.bingo-banner-inner p {
    font-size: 1.15rem;
    margin: .75rem 0 1.5rem;
    color: var(--muted);
}

.win-actions {
    display: flex;
    gap: .75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ── Utilities ────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Footer ───────────────────────────────────────────────────── */
footer {
    text-align: center;
    padding: 1.2rem;
    font-size: .85rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 600px) {
    main { margin: 1rem auto; }
    .bingo-cell { font-size: clamp(.55rem, 2.5vw, .75rem); }
    .bingo-header-cell { font-size: clamp(1.1rem, 5vw, 1.6rem); padding: .4rem .2rem; }
    .bingo-letters span { width: 48px; height: 48px; font-size: 1.8rem; }
    .bingo-banner-inner { padding: 2rem 1.5rem; }
    .game-code { font-size: 2.2rem; letter-spacing: 4px; }
    .board-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .board-actions .btn { width: 100%; text-align: center; }
    .return-link-controls {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ── Game Setup Panel ─────────────────────────────────────────── */
.setup-panel h2 { color: var(--primary); }
.setup-panel h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: .6rem;
}

.setup-info {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    background: var(--bg);
    border-radius: 8px;
    padding: .9rem 1rem;
    margin-bottom: 1.25rem;
    font-size: .93rem;
}

/* ── Prominent game code block ────────────────────────────────── */
.setup-code-block {
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    margin-bottom: .5rem;
    text-align: center;
    color: #fff;
}
.setup-removal-date {
    text-align: center;
    font-size: .75rem;
    color: #6b7280;
    margin: 0 0 1.25rem;
}
.setup-code-label {
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: .8;
    margin-bottom: .3rem;
}
.setup-code-value {
    font-size: 2.6rem;
    font-weight: 900;
    letter-spacing: 8px;
    line-height: 1;
    margin-bottom: .9rem;
    font-variant-numeric: tabular-nums;
}
.setup-code-actions {
    display: flex;
    gap: .6rem;
    justify-content: center;
    flex-wrap: wrap;
}
.setup-code-actions .btn {
    background: rgba(255,255,255,.18);
    border: 1px solid rgba(255,255,255,.4);
    color: #fff;
    font-size: .82rem;
}
.setup-code-actions .btn:hover {
    background: rgba(255,255,255,.32);
}

.setup-share {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.setup-share input {
    flex: 1;
    min-width: 0;
    font-size: .88rem;
    padding: .4rem .7rem;
}

.btn-sm {
    padding: .4rem .9rem;
    font-size: .85rem;
}

.setup-section {
    margin-bottom: 1.25rem;
}

.setup-word-list,
.setup-player-list {
    list-style: none;
    max-height: 260px;
    overflow-y: auto;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: .9rem;
}

.setup-word-list li,
.setup-player-list li {
    padding: .45rem .8rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.setup-word-list li:last-child,
.setup-player-list li:last-child { border-bottom: none; }

.setup-player-list li.empty-msg { color: var(--muted); font-style: italic; }

.setup-hint { font-size: .85rem; color: var(--muted); margin: -.25rem 0 .75rem; }

/* Player list rows with inline actions */
.setup-player-list li.player-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .35rem .5rem;
    padding: .55rem .8rem;
}

/* Name always takes a full line on its own when wrapping */
.player-row-name {
    flex: 1 1 120px;
    min-width: 0;
    font-size: .9rem;
    color: var(--text);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-bingo-badge {
    font-size: .75rem;
    font-weight: 700;
    color: #166534;
    background: #dcfce7;
    border: 1px solid #86efac;
    border-radius: 999px;
    padding: .15rem .55rem;
    white-space: nowrap;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

.player-bingo-time {
    font-size: .7rem;
    font-weight: 400;
    color: #15803d;
    opacity: .85;
}

.player-host-badge {
    font-size: .7rem;
    font-weight: 600;
    color: #4338ca;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 999px;
    padding: .1rem .45rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Actions sit beside the name on wide screens, drop below on narrow */
.player-row-actions {
    display: flex;
    gap: .4rem;
    flex-shrink: 0;
    flex-wrap: nowrap;
}

.player-row-actions .btn {
    font-size: .78rem;
    padding: .28rem .7rem;
    line-height: 1.3;
    white-space: nowrap;
}

/* On screens narrower than 480px push actions to their own line */
@media (max-width: 480px) {
    .player-row-name {
        flex: 1 1 100%;
    }
    .player-bingo-badge {
        /* badge sits on the name line — keep it there by being a sibling
           before actions; CSS order keeps it right after the name */
        margin-bottom: .1rem;
    }
    .player-row-actions {
        flex: 0 0 100%;
        justify-content: flex-start;
    }
    .player-row-actions .btn {
        flex: 1;
        text-align: center;
    }
}
.btn-copy-link {
    background: #f0fdf4;
    border: 1px solid #86efac;
    color: #166534;
}
.btn-copy-link:hover { background: #dcfce7; }
.btn-copy-link.copied {
    background: #166534;
    color: #fff;
    border-color: #166534;
}
.btn-view-board {
    background: #eff6ff;
    border: 1px solid #93c5fd;
    color: #1e40af;
}
.btn-view-board:hover { background: #dbeafe; }

/* Player recovery links (kept for compatibility) */
.player-links-list { list-style: none; margin: 0; padding: 0; }
.player-link-entry {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem 0;
    border-bottom: 1px solid var(--border);
}
.player-link-entry:last-child { border-bottom: none; }
.player-link-name { font-weight: 600; min-width: 100px; color: #374151; font-size: .9rem; flex-shrink: 0; }
.player-link-input {
    flex: 1;
    font-size: .78rem;
    padding: .3rem .5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f9fafb;
    color: var(--muted);
    min-width: 0;
}

/* Board viewer modal overlay */
.board-viewer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.board-viewer-overlay.hidden { display: none; }
.board-viewer-inner {
    background: #fff;
    border-radius: 14px;
    padding: 1.5rem;
    max-width: 440px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.board-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.board-viewer-header h3 { margin: 0; color: var(--primary); font-size: 1.1rem; }
.board-viewer-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 0 .25rem;
}
.board-viewer-close:hover { color: var(--text); }
.viewer-board {
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
    gap: 4px;
}
.viewer-board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
    pointer-events: none;
    user-select: none;
}
.viewer-board .static-header {
    background: var(--primary);
    color: #fff;
    font-size: 1.25rem;
    font-weight: 900;
    text-align: center;
    border-radius: 6px;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.viewer-board .static-cell {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: clamp(.45rem, 1.5vw, .72rem);
    font-weight: 500;
    text-align: center;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: .15rem;
    line-height: 1.2;
    color: #374151;
    word-break: break-word;
    overflow: hidden;
}
.viewer-board .static-cell.marked {
    background: #4f46e5;
    border-color: #4f46e5;
    color: #fff;
    font-weight: 700;
}
.viewer-board .static-cell.free-space {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
    font-weight: 800;
}
.viewer-board .static-cell.winning-cell {
    background: #10b981;
    border-color: #059669;
    color: #fff;
    font-weight: 700;
}
.board-viewer-caption {
    text-align: center;
    font-size: .78rem;
    color: var(--muted);
    font-style: italic;
    margin: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
    min-width: 1.5em;
    padding: .1em .45em;
    vertical-align: middle;
    margin-left: .35rem;
}

.setup-actions { margin-top: .5rem; }

/* ── Scoreboard ───────────────────────────────────────────────── */
.scoreboard-subtitle {
    font-size: .93rem;
    color: var(--muted);
    margin-bottom: .9rem;
}

.scoreboard-list {
    list-style: none;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.scoreboard-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .55rem .9rem;
    border-bottom: 1px solid var(--border);
    font-size: .93rem;
    gap: .75rem;
    transition: background .15s;
}

.scoreboard-entry:last-child { border-bottom: none; }

.scoreboard-entry.scoreboard-winner {
    background: #f0fdf4;
}

.scoreboard-name {
    flex: 1;
    font-weight: 500;
    color: var(--text);
}

.scoreboard-winner .scoreboard-name {
    font-weight: 700;
    color: var(--success);
}

.scoreboard-badge {
    display: inline-flex;
    align-items: center;
    background: var(--success);
    color: #fff;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
    padding: .2em .7em;
    white-space: nowrap;
    flex-shrink: 0;
}

.scoreboard-list .empty-msg {
    padding: .55rem .9rem;
    color: var(--muted);
    font-style: italic;
    font-size: .9rem;
}
