:root {
    --color-bg: #f5f4f1;
    --color-surface: #ffffff;
    --color-text: #1c1b19;
    --color-muted: #6b6660;
    --color-border: #e5e2dc;
    --color-accent: #a8791f;
    --color-accent-soft: #f4e9d6;
    --color-success: #1f9d55;
    --color-success-soft: #e7f7ee;
    --color-danger: #c0392b;
    --radius-md: 12px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(20, 18, 14, 0.06);
    --shadow-md: 0 8px 24px rgba(20, 18, 14, 0.08);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--color-accent);
}

.wrap {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 16px 60px;
}

/* ---------- Header ---------- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 4px 22px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: 0.75rem;
    color: var(--color-muted);
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.user-chip {
    font-size: 0.8rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 6px 12px;
    color: var(--color-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-chip strong {
    color: var(--color-text);
}

.icon-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-muted);
    font-size: 0.95rem;
}

.icon-btn:hover {
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

/* ---------- Status bar ---------- */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.85rem;
    color: var(--color-muted);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    gap: 8px;
}

.status-bar b {
    color: var(--color-text);
}

.bingo-banner {
    display: none;
    background: linear-gradient(135deg, var(--color-accent-soft), #fff);
    border: 1px solid var(--color-accent);
    color: var(--color-accent);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-weight: 600;
    text-align: center;
}

.bingo-banner.show {
    display: block;
    animation: pop 0.35s ease;
}

@keyframes pop {
    from { transform: scale(0.96); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ---------- Board grid ---------- */
.board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.tile {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    box-shadow: var(--shadow-sm);
}

.tile:hover:not(.tile-center):not(.tile-checked) {
    border-color: var(--color-accent);
    transform: translateY(-1px);
}

.tile:active:not(.tile-center):not(.tile-checked) {
    transform: translateY(0);
}

.tile-text {
    font-size: clamp(0.55rem, 1.6vw, 0.72rem);
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.tile-center {
    background: var(--color-accent-soft);
    border-color: var(--color-accent);
    cursor: default;
}

.tile-center svg {
    width: 40%;
    height: 40%;
    color: var(--color-accent);
}

.tile-checked {
    border-color: var(--color-success);
    background: var(--color-success-soft);
    cursor: default;
}

.tile-checked .tile-text {
    color: #14532d;
}

.tile-checkmark {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 16px;
    height: 16px;
    color: var(--color-success);
}

.tile-checked-by {
    position: absolute;
    bottom: 3px;
    left: 0;
    right: 0;
    font-size: clamp(0.45rem, 1.3vw, 0.6rem);
    color: var(--color-success);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 4px;
}

.tile-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ---------- Buttons / links ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

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

.btn-primary {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
}

.btn-primary:hover {
    background: #8f6819;
    color: #fff;
}

.btn-block {
    width: 100%;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
    font-size: 0.85rem;
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 18, 14, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 50;
}

.modal-overlay.show {
    display: flex;
}

.modal-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-md);
    max-height: 85vh;
    overflow-y: auto;
}

.modal-card h2 {
    margin-top: 0;
    font-size: 1.1rem;
}

.modal-card p {
    color: var(--color-muted);
    font-size: 0.9rem;
}

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    font-size: 0.8rem;
    color: var(--color-muted);
    margin-bottom: 6px;
}

.field input, .field select, .field textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
}

.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid var(--color-accent-soft);
    border-color: var(--color-accent);
}

.toast-stack {
    position: fixed;
    top: 16px;
    right: 16px;
    left: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
    z-index: 100;
    pointer-events: none;
}

.toast {
    background: var(--color-text);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    box-shadow: var(--shadow-md);
    max-width: 320px;
    animation: pop 0.2s ease;
}

.toast.error {
    background: var(--color-danger);
}

.toast.success {
    background: var(--color-success);
}

/* ---------- History ---------- */
.history-item {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 14px;
    background: var(--color-surface);
}

.history-item summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
}

.history-meta {
    font-size: 0.8rem;
    color: var(--color-muted);
    margin: 6px 0 12px;
}

.mini-board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}

.mini-tile {
    aspect-ratio: 1 / 1;
    border-radius: 5px;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
}

.mini-tile.checked {
    background: var(--color-success);
    border-color: var(--color-success);
}

.mini-tile.center {
    background: var(--color-accent-soft);
    border-color: var(--color-accent);
}

/* ---------- Gate page ---------- */
.gate-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.gate-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    max-width: 380px;
    width: 100%;
    box-shadow: var(--shadow-md);
    text-align: center;
}

.gate-card .brand {
    justify-content: center;
    margin-bottom: 18px;
}

.gate-error {
    background: #fdecea;
    color: var(--color-danger);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 0.85rem;
    margin-bottom: 14px;
}

/* ---------- Admin ---------- */
.admin-layout {
    max-width: 1080px;
    margin: 0 auto;
    padding: 24px 16px 60px;
}

.tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0;
}

.tab-btn {
    background: none;
    border: none;
    padding: 10px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-tile {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
}

.stat-tile .value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--color-accent);
}

.stat-tile .label {
    font-size: 0.78rem;
    color: var(--color-muted);
    margin-top: 4px;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

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

table.data-table th {
    color: var(--color-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.bar-track {
    background: var(--color-bg);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
    width: 100%;
}

.bar-fill {
    height: 100%;
    background: var(--color-accent);
    border-radius: 999px;
}

.row-actions {
    display: flex;
    gap: 6px;
}

.row-actions button {
    border: 1px solid var(--color-border);
    background: #fff;
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
}

.row-actions button:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.badge.muted {
    background: var(--color-border);
    color: var(--color-muted);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

@media (max-width: 480px) {
    .tile-text {
        -webkit-line-clamp: 4;
    }
}
