:root {
    --ink: #1c1c1e;
    --paper: #faf8f5;
    --card: #ffffff;
    --line: #e3dfd8;
    --accent: #b5502e;
    --accent-soft: #f2e4dc;
    --marked: #2f6b4f;
    --marked-soft: #e2efe7;
    --muted: #7a766f;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(28, 28, 30, 0.06), 0 4px 14px rgba(28, 28, 30, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background: var(--paper);
    color: var(--ink);
    min-height: 100vh;
}

.wrap {
    max-width: 640px;
    margin: 0 auto;
    padding: 32px 20px 64px;
}

.wrap.wide {
    max-width: 900px;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
    margin: 0 0 6px;
}

h1 {
    font-size: 26px;
    margin: 0 0 4px;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 18px;
    margin: 0 0 12px;
}

.page-title {
    font-size: 20px;
}

p.subtitle {
    color: var(--muted);
    margin: 0 0 28px;
    font-size: 15px;
}

.card-box {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 15px;
    background: var(--paper);
    color: var(--ink);
    margin-bottom: 16px;
    font-family: inherit;
}

input:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    background: #fff;
}

button,
.btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

button:hover,
.btn:hover {
    opacity: 0.9;
}

button:focus-visible,
.btn:focus-visible,
input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn.secondary {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}

.btn.small {
    padding: 7px 12px;
    font-size: 13px;
}

.error-msg {
    background: #fbeae5;
    color: #8a2f16;
    border: 1px solid #f0c6b8;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 18px;
}

.success-msg {
    background: var(--marked-soft);
    color: #1d4a35;
    border: 1px solid #bcdccb;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 18px;
}

/* ---------- Bingo grid ---------- */

.card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.card-header .name {
    font-weight: 600;
}

.progress-pill {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    background: var(--accent-soft);
    padding: 5px 10px;
    border-radius: 999px;
}

.bingo-banner {
    background: var(--marked-soft);
    color: #1d4a35;
    border: 1px solid #bcdccb;
    padding: 14px 16px;
    border-radius: var(--radius);
    font-weight: 700;
    font-size: 18px;
    text-align: center;
    margin-bottom: 18px;
    letter-spacing: 0.02em;
}

.grid {
    display: grid;
    gap: 8px;
}

.cell {
    aspect-ratio: 1 / 1;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 8px;
    font-size: 13px;
    line-height: 1.25;
    cursor: pointer;
    user-select: none;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
    color: var(--ink);
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
}

.cell:hover {
    border-color: var(--accent);
}

.cell:active {
    transform: scale(0.97);
}

.cell.marked {
    background: var(--marked-soft);
    border-color: var(--marked);
    color: #1d4a35;
    font-weight: 600;
}

.cell.free {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 700;
    cursor: default;
}

.cell:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.share-block {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.share-block img {
    border: 1px solid var(--line);
    border-radius: 8px;
}

.code-display {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.08em;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 8px 14px;
    border-radius: 8px;
    display: inline-block;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 18px;
}

.card-footer .muted {
    margin: 0;
}

.share-btn {
    flex-shrink: 0;
}

.hide-mobile {
    display: inline;
}

/* ---------- Toasts ---------- */

.toast-container {
    position: fixed;
    top: 16px;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    pointer-events: none;
}

.toast {
    background: var(--marked);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    padding: 10px 18px;
    border-radius: 999px;
    box-shadow: var(--shadow);
    max-width: 320px;
    text-align: center;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-out {
    opacity: 0;
    transform: translateY(-8px);
}

/* ---------- Share modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(28, 28, 30, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-box {
    position: relative;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    max-width: 360px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-box h2 {
    font-size: 18px;
    margin-right: 24px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    padding: 4px 8px;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--ink);
}

.share-link-row {
    display: flex;
    gap: 8px;
    margin-top: 18px;
}

.share-link-row input {
    margin-bottom: 0;
    font-size: 13px;
}

.share-link-row button {
    flex-shrink: 0;
}

/* ---------- Admin ---------- */

table.list {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table.list th,
table.list td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
}

table.list th {
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

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

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.topbar a {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 600px) {
    html, body {
        height: 100%;
        overflow: hidden;
    }

    .wrap {
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        padding: 10px 8px;
        overflow: hidden;
    }

    .topbar {
        margin-bottom: 8px;
        flex-shrink: 0;
    }

    .topbar > div:first-child {
        min-width: 0;
        overflow: hidden;
    }

    .topbar .eyebrow,
    .topbar h1 {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar h1 {
        font-size: 16px;
    }

    .topbar .eyebrow {
        font-size: 10px;
        margin-bottom: 2px;
    }

    .bingo-banner {
        padding: 8px 10px;
        font-size: 14px;
        margin-bottom: 8px;
        flex-shrink: 0;
    }

    .card-header {
        margin-bottom: 8px;
        flex-shrink: 0;
    }

    .card-header .name {
        font-size: 14px;
    }

    .progress-pill {
        font-size: 11px;
        padding: 4px 8px;
    }

    .grid {
        gap: 6px;
        margin: auto;
        flex-shrink: 0;
        --cell-w: min(
            calc((100vw - 16px - (var(--grid-size) - 1) * 6px) / var(--grid-size)),
            calc((100dvh - var(--chrome-h, 130px) - (var(--grid-size) - 1) * 6px) / var(--grid-size))
        );
        width: calc(var(--cell-w) * var(--grid-size) + (var(--grid-size) - 1) * 6px);
        aspect-ratio: 1 / 1;
    }

    .cell {
        font-size: clamp(8px, calc(var(--cell-w) * 0.16), 13px);
        padding: 2px;
        line-height: 1.1;
        border-radius: 6px;
    }

    .card-footer {
        flex-shrink: 0;
        margin-top: 8px;
    }

    .hide-mobile {
        display: none;
    }
}
