/* Shared components: nav, buttons, forms, cards, tables, badges, toasts. */

/* ---------- Site header / nav ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.site-header-inner {
    max-width: 1100px;
    margin: 0 auto;
    height: var(--nav-height);
    padding: 0 var(--space-5);
    display: flex;
    align-items: center;
    gap: var(--space-5);
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--text);
    white-space: nowrap;
}

.brand:hover { color: var(--text); }

.brand-dot { color: var(--accent); }

.nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex: 1;
}

.nav a {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.92rem;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease);
    white-space: nowrap;
}

.nav a:hover, .nav a.active {
    color: var(--text);
    background: var(--surface-hover);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-left: auto;
}

.balance-pill {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px;
    font-weight: 700;
    font-size: 0.9rem;
    white-space: nowrap;
}

.balance-pill .coin-icon { color: var(--push); }

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: background-color var(--duration) var(--ease), transform var(--duration) var(--ease);
    flex-shrink: 0;
}

.icon-button:hover {
    background: var(--surface-hover);
    transform: translateY(-1px);
}

/* The icon is wrapped in this span rather than sitting as a direct flex
   item of the <button> - Chromium miscomputes an SVG child's intrinsic
   width to 0 when it's a direct flex item of a form control element. */
.icon-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-button svg { width: 18px; height: 18px; }

.theme-toggle .sun-icon, .theme-toggle .moon-icon {
    display: none;
}

:root:not([data-theme="light"]) .theme-toggle .sun-icon { display: block; }
:root[data-theme="light"] .theme-toggle .moon-icon { display: block; }

.nav-toggle {
    display: none;
}

@media (max-width: 860px) {
    .site-header-inner { padding: 0 var(--space-4); gap: var(--space-3); }

    .nav-toggle {
        display: inline-flex;
    }

    .nav {
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--bg-elevated);
        border-bottom: 1px solid var(--border);
        padding: var(--space-2);
        gap: 2px;
        max-height: 0;
        overflow: hidden;
        transition: max-height var(--duration) var(--ease);
    }

    .nav.open {
        max-height: 480px;
    }

    .nav a {
        padding: var(--space-3);
        border-radius: var(--radius-sm);
    }
}

/* ---------- Footer ---------- */

.site-footer {
    border-top: 1px solid var(--border);
    padding: var(--space-5);
    text-align: center;
    color: var(--text-faint);
    font-size: 0.85rem;
}

/* ---------- Flash messages ---------- */

.flashes {
    list-style: none;
    margin: 0 auto;
    max-width: 1100px;
    padding: var(--space-3) var(--space-5) 0;
}

.flashes li {
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-2);
    font-size: 0.92rem;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 11px 20px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color var(--duration) var(--ease), transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease), border-color var(--duration) var(--ease);
    text-decoration: none;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 4px 16px var(--accent-soft);
}

.btn-primary:hover { background: var(--accent-hover); color: var(--accent-text); }

.btn-secondary {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}

.btn-secondary:hover { background: var(--surface-hover); color: var(--text); }

.btn-danger {
    background: transparent;
    border-color: var(--loss);
    color: var(--loss);
}

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

.btn-block { width: 100%; }

.btn:disabled, button:disabled, input[type="submit"]:disabled {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-faint);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Base element styling so un-classed buttons/inputs from simpler templates
   still look intentional. */

button, input[type="submit"] {
    font-family: inherit;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 11px 20px;
    font-size: 0.95rem;
    font-weight: 700;
    background: var(--accent);
    color: var(--accent-text);
    cursor: pointer;
    transition: background-color var(--duration) var(--ease), transform var(--duration) var(--ease);
}

button:hover, input[type="submit"]:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

/* ---------- Forms ---------- */

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: var(--space-1);
}

input, select, textarea {
    width: 100%;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    font-family: inherit;
    font-size: 0.95rem;
    margin-bottom: var(--space-4);
    transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; min-height: 80px; }

.field { margin-bottom: var(--space-4); }
.field input, .field select, .field textarea { margin-bottom: 0; }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.checkbox-row input { width: auto; margin: 0; }

.checkbox-row label { margin: 0; cursor: pointer; }

/* Pill-style switch, an alternative to a plain checkbox for an on/off
   setting (e.g. Crash's autoplay) - visually a track + sliding thumb,
   backed by a real (visually hidden, not display:none - screen readers
   and keyboard focus still need it) checkbox input for state/a11y. */
.pill-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.pill-toggle input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
}

.pill-toggle-track {
    display: inline-block;
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--border-strong);
    border-radius: 999px;
    transition: background-color var(--duration) var(--ease);
}

.pill-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--bg-elevated);
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: transform var(--duration) var(--ease);
}

.pill-toggle input:checked + .pill-toggle-track {
    background: var(--accent);
}

.pill-toggle input:checked + .pill-toggle-track .pill-toggle-thumb {
    transform: translateX(18px);
}

.pill-toggle input:focus-visible + .pill-toggle-track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.checkbox-row label { margin: 0; }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.card-elevated {
    box-shadow: var(--shadow);
}

.auth-card {
    max-width: 420px;
    margin: var(--space-6) auto 0;
}

/* ---------- Stat cards ---------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-4);
    margin: var(--space-5) 0;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4) var(--space-5);
    transition: border-color var(--duration) var(--ease), transform var(--duration) var(--ease);
}

.stat-card:hover { border-color: var(--border-strong); }

.stat-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}

.stat-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    word-break: break-word;
}

.stat-value.positive { color: var(--win); }
.stat-value.negative { color: var(--loss); }

/* ---------- Tables ---------- */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

th, td {
    padding: 12px 16px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

tr:last-child td { border-bottom: none; }

tbody tr {
    transition: background-color var(--duration) var(--ease);
}

tbody tr:hover { background: var(--surface-hover); }

/* ---------- Badges ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.badge-win { background: var(--win-soft); color: var(--win); }
.badge-loss { background: var(--loss-soft); color: var(--loss); }
.badge-push { background: var(--push-soft); color: var(--push); }
.badge-neutral { background: var(--surface-hover); color: var(--text-muted); border: 1px solid var(--border); }

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

.toast-region {
    position: fixed;
    top: calc(var(--nav-height) + var(--space-4));
    right: var(--space-4);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-width: min(360px, calc(100vw - 2 * var(--space-4)));
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: var(--space-3) var(--space-4);
    font-size: 0.9rem;
    color: var(--text);
    animation: toast-in var(--duration) var(--ease-out);
}

.toast.toast-error { border-left-color: var(--loss); }
.toast.toast-success { border-left-color: var(--win); }

.toast.toast-leaving {
    animation: toast-out 160ms var(--ease) forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateX(16px); }
}

/* ---------- Misc ---------- */

.divider {
    height: 1px;
    background: var(--border);
    border: none;
    margin: var(--space-5) 0;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: var(--space-7) var(--space-4);
}

/* ---------- Dashboard hero / game grid ---------- */

.hero-card {
    background: linear-gradient(135deg, var(--accent-soft), transparent 60%), var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
}

.hero-card .eyebrow { margin-bottom: var(--space-2); }

.hero-balance {
    font-size: 2.4rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: var(--space-2) 0 0;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
}

.game-card {
    position: relative;
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-5);
    color: var(--text);
    overflow: hidden;
    transition: transform var(--duration) var(--ease-out), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.game-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: var(--shadow);
    color: var(--text);
}

.game-card .game-icon {
    width: 40px;
    height: 40px;
    color: var(--accent);
    margin-bottom: var(--space-4);
}

.game-card h3 { margin-bottom: var(--space-1); }

.game-card.game-card-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.game-card .badge { position: absolute; top: var(--space-4); right: var(--space-4); }
