/* =================================================================
   Scorekeeper — design tokens + components
   ================================================================= */

/* ---------- Self-hosted fonts ---------- */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Material Symbols Outlined';
    font-style: normal;
    font-weight: 100 700;
    font-display: block;
    src: url('fonts/material-symbols-outlined.woff2') format('woff2');
}

.material-symbols-outlined {
    font-family: 'Material Symbols Outlined';
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

:root {
    --bg: #f7f9fb;
    --surface: #ffffff;
    --border: #e6e7eb;
    --border-strong: #d1d5db;
    --text: #191c1e;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #e0e7ff;
    --primary-text-on-soft: #3730a3;

    --success: #16a34a;
    --success-soft: #dcfce7;
    --success-text-on-soft: #166534;

    --warning: #d97706;
    --warning-soft: #fef3c7;
    --warning-text-on-soft: #92400e;

    --orange-soft: #fed7aa;
    --orange-text-on-soft: #c2410c;

    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --danger-text-on-soft: #991b1b;

    --neutral-chip-bg: #f1f2f5;
    --neutral-chip-text: #4b5563;

    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    --nav-height: 64px;
    --content-max: 640px;
}

* { box-sizing: border-box; }

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

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 8px);
    -webkit-text-size-adjust: 100%;
}

body.no-bottom-nav {
    padding-bottom: 0;
}

.tabular-nums { font-variant-numeric: tabular-nums; }

/* ---------- Top app bar ---------- */
.app-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-bar .wordmark {
    font-weight: 700;
    letter-spacing: normal;
    font-size: 1.05rem;
    color: var(--text);
    text-decoration: none;
}
.app-bar .wordmark .logo { margin-right: 0.15em; }

/* ---------- Layout ---------- */
.wrap {
    max-width: var(--content-max);
    margin: 16px auto 0;
    padding: 0 16px;
    display: grid;
    gap: 16px;
}

.wrap-narrow {
    max-width: 420px;
}

.wrap-center {
    min-height: 100vh;
    align-content: center;
}

/* ---------- Card ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.card h2,
.card h3 {
    margin: 0 0 12px;
    color: var(--text);
    font-weight: 600;
}

.card h2 { font-size: 16px; }
.card h3 { font-size: 14px; margin-top: 16px; }

.card-narrow {
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.section-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 10px;
}

/* ---------- Text ---------- */
.muted {
    color: var(--text-muted);
    font-size: 13px;
}

.muted-sm {
    color: var(--text-muted);
    font-size: 12px;
}

.danger-text { color: var(--danger); }

/* ---------- Forms ---------- */
label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="search"],
input:not([type]),
select,
textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    min-height: 44px;
    font: inherit;
    font-size: 16px; /* prevents iOS zoom */
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    transition: border-color 120ms, box-shadow 120ms;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

textarea {
    resize: vertical;
    min-height: 96px;
    padding: 12px;
    line-height: 1.5;
}

.row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.row > * {
    flex: 1 1 180px;
    min-width: 0;
}

.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.grid3 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 480px) {
    .grid2, .grid3 { grid-template-columns: 1fr; }
}

.checkbox-label {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 0;
    min-height: 44px;
    font-size: 14px;
    color: var(--text);
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-height: auto;
    flex-shrink: 0;
    margin: 0;
    accent-color: var(--primary);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 16px;
    min-height: 44px;
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: background 120ms, border-color 120ms, color 120ms;
}

.btn:hover { background: #f9fafb; }

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

.btn.danger {
    color: var(--danger);
    border-color: var(--danger);
}
.btn.danger:hover { background: var(--danger-soft); }

.btn.ghost {
    background: transparent;
    border-color: transparent;
}
.btn.ghost:hover { background: var(--neutral-chip-bg); }

.full-width { width: 100%; }

.btn-icon {
    padding: 8px;
    min-height: 40px;
    width: 40px;
}
.btn-icon .material-symbols-outlined { font-size: 20px; }

.btn-sm {
    padding: 7px 10px;
    min-height: 36px;
    font-size: 13px;
}

/* ---------- Collapsible card (details/summary) ---------- */
.card.is-collapsible { padding: 0; }

.card.is-collapsible > summary {
    list-style: none;
    cursor: pointer;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: var(--radius);
}

.card.is-collapsible > summary::-webkit-details-marker { display: none; }

.card.is-collapsible[open] > summary {
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
}

.card.is-collapsible > summary .collapsible-chevron {
    color: var(--text-faint);
    transition: transform 200ms ease;
    flex-shrink: 0;
}

.card.is-collapsible[open] > summary .collapsible-chevron {
    transform: rotate(180deg);
}

.collapsible-summary-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.collapsible-summary-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}

.card.is-collapsible > .collapsible-body {
    padding: 14px 16px 16px;
}

/* ---------- Pill group (radio-style selector) ---------- */
.pill-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.pill-option {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    padding: 8px 14px;
    border-radius: var(--radius-full);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    min-height: 36px;
    transition: border-color 120ms, background 120ms, color 120ms;
}

.pill-option:hover {
    background: var(--neutral-chip-bg);
}

.pill-option.is-active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.pill-group.is-disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ---------- Pill-styled select ---------- */
.pill-select {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-full);
    padding: 10px 40px 10px 16px;
    min-height: 44px;
    font-weight: 500;
    background-color: var(--surface);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' stroke='%234f46e5' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    -webkit-appearance: none;
    appearance: none;
}

/* ---------- Link-style button (indigo text, no chrome) ---------- */
.btn.btn-link {
    background: transparent;
    border-color: transparent;
    color: var(--primary);
    padding: 8px 10px;
    min-height: 36px;
}
.btn.btn-link:hover {
    background: var(--primary-soft);
}

/* ---------- Chips / badges ---------- */
.chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-radius: var(--radius-full);
    background: var(--neutral-chip-bg);
    color: var(--neutral-chip-text);
    white-space: nowrap;
}

.chip-green { background: var(--success-soft); color: var(--success-text-on-soft); }
.chip-amber { background: var(--warning-soft); color: var(--warning-text-on-soft); }
.chip-orange { background: var(--orange-soft); color: var(--orange-text-on-soft); }
.chip-red { background: var(--danger-soft); color: var(--danger-text-on-soft); }
.chip-indigo { background: var(--primary-soft); color: var(--primary-text-on-soft); }

.chip-outline-indigo {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

/* ---------- Progress bar ---------- */
.progress {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: #9ca3af;
    border-radius: var(--radius-full);
    transition: width 400ms ease;
}

.progress-bar.is-leader { background: var(--primary); }

/* Rommé: filling the bar means heading toward the loss ceiling. */
.progress-bar.is-romme { background: var(--danger); }
.progress-bar.is-romme.is-leader { background: var(--success); }

/* ---------- Bottom tab bar ---------- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 4px 4px env(safe-area-inset-bottom, 0px);
    display: flex;
    z-index: 20;
}

.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text-faint);
    font-size: 11px;
    font-weight: 500;
    padding: 8px 4px;
    min-height: 56px;
    border-radius: var(--radius);
    transition: color 120ms;
}

.bottom-nav a.active { color: var(--primary); }

.bottom-nav .material-symbols-outlined {
    font-size: 24px;
    font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
    transition: font-variation-settings 120ms;
}

.bottom-nav a.active .material-symbols-outlined {
    font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}

/* ---------- Sticky primary action inside a card ---------- */
.sticky-action {
    position: sticky;
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 12px);
    z-index: 5;
    margin-top: 16px;
}

/* ---------- Edit panel actions ---------- */
.edit-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

/* ---------- Auth screens (login, bootstrap) ---------- */
.auth-mark {
    text-align: center;
}

.auth-mark .wordmark {
    font-weight: 700;
    letter-spacing: 0.12em;
    font-size: 14px;
    color: var(--text);
}

.auth-heading {
    font-size: 22px;
    font-weight: 600;
    margin: 0 0 4px;
}

.auth-subheading {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 16px;
}

/* ---------- Form helpers ---------- */
.form-field + .form-field {
    margin-top: 12px;
}

.form-actions {
    margin-top: 24px;
}

.form-helper {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 12px;
}

.form-error {
    color: var(--danger);
    font-size: 14px;
    margin-bottom: 12px;
}

/* ---------- Avatar ---------- */
.avatar {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: var(--primary-soft);
    color: var(--primary-text-on-soft);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 0.02em;
}

/* ---------- Live scoreboard ---------- */
.sb-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sb-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sb-row-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.sb-name {
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.sb-total {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.sb-row.is-leader .sb-total { color: var(--primary); }

.sb-row-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
}

.sb-progress-caption .sb-total-current {
    color: var(--text);
    font-weight: 600;
}

.sb-progress-caption .sb-total-sep,
.sb-progress-caption .sb-total-target {
    color: var(--text-faint);
}

/* ---------- Add game / edit game inputs ---------- */
.ag-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ag-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ag-field input {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ---------- Game history rows ---------- */
.game-row {
    padding: 12px 8px;
    margin: 0 -8px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 120ms;
}

.game-row:hover { background: var(--neutral-chip-bg); }
.game-row:first-child { padding-top: 4px; }
.game-row:last-child { padding-bottom: 4px; border-bottom: none; }

.game-row-chevron {
    color: var(--text-faint);
    font-size: 20px;
    flex-shrink: 0;
}

.game-row-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.game-row-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 14px;
}

.game-num { font-weight: 600; color: var(--text); }
.game-winner { color: var(--text); }

.game-row-score {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------- Player standings (stats) ---------- */
.stat-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.stat-row:first-child { padding-top: 4px; }
.stat-row:last-child { padding-bottom: 4px; border-bottom: none; }

.stat-row-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.stat-row-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}

.stat-row-total {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.stat-row-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 13px;
}

.stat-metric {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
}

.stat-metric-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-faint);
}

.stat-metric-val {
    font-weight: 600;
    color: var(--text);
}

/* ---------- Rank rows (high / low scores) ---------- */
.rank-row {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.rank-row:first-child { padding-top: 4px; }
.rank-row:last-child { padding-bottom: 4px; border-bottom: none; }

.rank-pill {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    border-radius: var(--radius-full);
    background: var(--neutral-chip-bg);
    color: var(--neutral-chip-text);
    flex-shrink: 0;
}
.rank-pill.rank-gold   { background: #fef3c7; color: #92400e; }
.rank-pill.rank-silver { background: #e5e7eb; color: #4b5563; }
.rank-pill.rank-bronze { background: #fed7aa; color: #9a3412; }

.rank-row-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rank-row-score {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.rank-row-meta {
    color: var(--text-muted);
    font-size: 12px;
}

.rank-row-player {
    color: var(--text);
    font-weight: 600;
}

/* ---------- Dealer impact rows ---------- */
.di-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.di-row:first-child { padding-top: 4px; }
.di-row:last-child { padding-bottom: 4px; border-bottom: none; }

.di-row-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.di-row-name {
    font-weight: 600;
    font-size: 15px;
}

.di-row-delta {
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.di-row-meta {
    color: var(--text-muted);
    font-size: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.di-row-winners {
    color: var(--text-muted);
    font-size: 12px;
}

.delta-pos { color: var(--success); }
.delta-neg { color: var(--danger); }
.delta-neutral { color: var(--text-muted); }

/* ---------- Charts ---------- */
.chart-wrap {
    position: relative;
    width: 100%;
    max-height: 360px;
}

/* ---------- Admin list rows (sessions, users, thresholds) ---------- */
.admin-list {
    display: flex;
    flex-direction: column;
}

.admin-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.admin-row:first-child { padding-top: 4px; }
.admin-row:last-child { padding-bottom: 4px; border-bottom: none; }

.admin-row-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.admin-row-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.admin-row-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.btn-icon.ghost.danger-text { color: var(--danger); }
.btn-icon.ghost.danger-text:hover { background: var(--danger-soft); }

/* ---------- Account screen ---------- */
.account-identity {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.account-username {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

/* ---------- Toggle group (segmented control) ---------- */
.toggle-group {
    display: inline-flex;
    background: var(--neutral-chip-bg);
    padding: 3px;
    border-radius: var(--radius);
    gap: 2px;
}

.toggle-btn {
    border: none;
    background: transparent;
    padding: 6px 12px;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: calc(var(--radius) - 3px);
    cursor: pointer;
    min-height: 32px;
}

.toggle-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* ---------- Minimal table fallback ---------- */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
th, td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
th.right, td.right { text-align: right; }
th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}
.tableWrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Utilities ---------- */
.spacer { flex: 1; }
.flex-row { display: flex; gap: 12px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.text-right { text-align: right; }
