:root {
    --felt:#1E3A2E;
    --felt-deep:#132A20;
    --felt-light:#2E5443;
    --parchment:#F4EEDD;
    --parchment-dim:#E9E0C8;
    --card:#FFFDF6;
    --ink:#211D16;
    --ink-soft:#5C5748;
    --ink-faint:#8B8676;
    --gold:#C69A3E;
    --gold-soft:#E4C879;
    --burgundy:#7A2E2E;
    --burgundy-soft:#F1DEDA;
    --sage:#7C9174;
    --sage-soft:#E4ECDF;

    --radius-card:14px;
    --radius-pill:999px;
    --radius-input:10px;
    --shadow-soft:0 2px 0 rgba(33,29,22,.06), 0 1px 3px rgba(33,29,22,.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--parchment);
    color: var(--ink);
    font-family: 'Inter', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .logo, .game-cover span {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 .4em;
}

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

.mono, .stat-value, .token, .ranking-count { font-family: 'JetBrains Mono', monospace; }

/* ---------- Layout shell ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--felt);
    color: var(--parchment);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-logo {
    font-family: 'Fraunces', serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 24px;
    padding: 0 8px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar-nav a {
    padding: 10px 12px;
    border-radius: var(--radius-input);
    color: var(--parchment-dim);
    font-weight: 500;
    font-size: .95rem;
}

.sidebar-nav a:hover { background: var(--felt-light); color: #fff; }
.sidebar-nav a.active { background: var(--gold); color: var(--felt-deep); font-weight: 600; }

.sidebar-sep { height: 1px; background: var(--felt-light); margin: 10px 8px; }

.sidebar-logout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 8px 0;
    border-top: 1px solid var(--felt-light);
    margin-top: 10px;
}

.sidebar-user { font-size: .82rem; color: var(--parchment-dim); }

.content {
    flex: 1;
    padding: 28px 32px 90px;
    min-width: 0;
}

/* ---------- Mobile nav ---------- */
.mobile-topbar { display: none; }
.mobile-menu { display: none; }
.bottom-nav { display: none; }

@media (max-width: 900px) {
    .sidebar { display: none; }
    .content { padding: 16px 16px 90px; }

    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: var(--felt);
        color: #fff;
        padding: 14px 16px;
        position: sticky;
        top: 0;
        z-index: 20;
    }
    .mobile-logo { font-family: 'Fraunces', serif; font-weight: 700; }
    .btn-icon {
        background: none; border: none; color: #fff; font-size: 1.3rem; cursor: pointer;
    }

    .mobile-menu {
        display: none;
        flex-direction: column;
        background: var(--felt-deep);
        position: sticky;
        top: 52px;
        z-index: 19;
        padding: 8px;
    }
    .mobile-menu.open { display: flex; }
    .mobile-menu a, .mobile-menu button {
        color: var(--parchment-dim);
        padding: 12px 10px;
        border-radius: var(--radius-input);
        text-align: left;
        background: none;
        border: none;
        font-size: 1rem;
        font-family: inherit;
    }
    .mobile-menu a:hover, .mobile-menu button:hover { background: var(--felt-light); color: #fff; }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: var(--felt);
        z-index: 20;
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 8px rgba(0,0,0,.15);
    }
    .bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        font-size: .68rem;
        color: var(--parchment-dim);
        padding: 6px 2px;
        border-radius: var(--radius-input);
    }
    .bottom-nav a span { font-size: 1.15rem; }
    .bottom-nav a.active { color: var(--gold-soft); }
    .bottom-nav-cta {
        background: var(--gold);
        color: var(--felt-deep) !important;
        border-radius: var(--radius-pill);
        margin: 0 4px;
        font-weight: 700;
    }
}

/* ---------- Common page structure ---------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty-hint { color: var(--ink-faint); font-style: italic; }

.flash {
    padding: 12px 16px;
    border-radius: var(--radius-input);
    margin-bottom: 18px;
    font-weight: 500;
}
.flash-success { background: var(--sage-soft); color: #365235; }
.flash-error { background: var(--burgundy-soft); color: var(--burgundy); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius-input);
    border: none;
    font-family: inherit;
    font-weight: 600;
    font-size: .92rem;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
}
.btn-gold { background: var(--gold); color: var(--felt-deep); }
.btn-gold:hover { background: var(--gold-soft); }
.btn-outline { background: var(--card); color: var(--ink); border: 1px solid var(--parchment-dim); }
.btn-outline:hover { border-color: var(--gold); }
.btn-burgundy-outline { background: var(--card); color: var(--burgundy); border: 1px solid var(--burgundy-soft); }
.btn-burgundy-outline:hover { background: var(--burgundy-soft); }
.btn-block { width: 100%; justify-content: center; }
.btn-small { padding: 6px 12px; font-size: .82rem; }
.btn-link { background: none; border: none; color: var(--gold-soft); cursor: pointer; font-size: .82rem; text-decoration: underline; }
@media (max-width: 900px) { .btn-block-mobile { width: 100%; justify-content: center; } }

/* ---------- Cards / panels ---------- */
.panel {
    background: var(--card);
    border: 1px solid var(--parchment-dim);
    border-radius: var(--radius-card);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-soft);
}

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel-wide { grid-column: 1 / -1; }
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ---------- Stat cards ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
@media (max-width: 700px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
    border-radius: var(--radius-card);
    padding: 18px;
    box-shadow: var(--shadow-soft);
}
.stat-value { font-size: 1.7rem; font-weight: 600; }
.stat-label { font-size: .8rem; opacity: .85; margin-top: 4px; }

.stat-card-felt { background: var(--felt); color: #fff; }
.stat-card-burgundy { background: var(--burgundy); color: #fff; }
.stat-card-sage { background: var(--sage); color: #fff; }
.stat-card-card { background: var(--card); color: var(--ink); border: 1px solid var(--parchment-dim); }

/* ---------- Alerts ---------- */
.alerts-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.badge-alert {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: var(--radius-pill);
    font-weight: 600; font-size: .85rem;
}
.badge-burgundy { background: var(--burgundy-soft); color: var(--burgundy); }
.badge-sage { background: var(--sage-soft); color: #365235; }

/* ---------- Tokens ---------- */
.tokens { display: flex; gap: 6px; flex-wrap: wrap; }
.tokens-wrap { margin: 12px 0; }
.token {
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--card); border: 1px solid var(--parchment-dim);
    border-radius: var(--radius-pill);
    padding: 4px 10px;
    font-size: .78rem;
    box-shadow: var(--shadow-soft);
}
.token-gold { background: var(--gold-soft); border-color: var(--gold); }
.token-burgundy { background: var(--burgundy-soft); color: var(--burgundy); }
.token-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-gold { background: var(--gold); }
.dot-sage { background: var(--sage); }
.dot-burgundy { background: var(--burgundy); }

/* ---------- Games grid / cards ---------- */
.games-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }

.game-card {
    background: var(--card);
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--parchment-dim);
    display: block;
}
.game-cover {
    height: 130px;
    display: flex; align-items: flex-end;
    padding: 14px;
}
.game-cover span { color: #fff; font-size: 1.05rem; text-shadow: 0 1px 3px rgba(0,0,0,.3); }
.gradient-felt { background: linear-gradient(135deg, var(--felt), var(--felt-light)); }
.gradient-burgundy { background: linear-gradient(135deg, var(--burgundy), #a04747); }
.gradient-sage { background: linear-gradient(135deg, var(--sage), #5f7458); }
.gradient-gold { background: linear-gradient(135deg, var(--gold), #a87c26); }

.game-card-body { padding: 14px; }
.game-card-body h3 { font-size: 1rem; margin-bottom: 8px; }
.game-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.game-card-meta { font-size: .75rem; color: var(--ink-faint); }

.game-detail-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .game-detail-grid { grid-template-columns: 1fr; } }
.game-detail-image { width: 100%; height: 220px; object-fit: cover; border-radius: var(--radius-card); margin-bottom: 14px; }
.game-description { color: var(--ink-soft); line-height: 1.5; }

.status-pill { padding: 3px 10px; border-radius: var(--radius-pill); font-size: .72rem; font-weight: 600; }
.status-available { background: var(--sage-soft); color: #365235; }
.status-loaned { background: var(--burgundy-soft); color: var(--burgundy); }
.status-neutral { background: var(--parchment-dim); color: var(--ink-soft); }

/* ---------- Forms ---------- */
.form-card, .form-card-nested { background: var(--card); border: 1px solid var(--parchment-dim); border-radius: var(--radius-card); padding: 20px; margin-bottom: 20px; }
.form-row { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.form-row-inline { justify-content: center; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .form-grid-2 { grid-template-columns: 1fr; } }

label { font-weight: 600; font-size: .85rem; color: var(--ink-soft); }

input[type=text], input[type=number], input[type=date], input[type=datetime-local],
input[type=password], input[type=search], input[type=email], select, textarea {
    padding: 10px 12px;
    border-radius: var(--radius-input);
    border: 1px solid var(--parchment-dim);
    background: #fff;
    font-family: inherit;
    font-size: .95rem;
    color: var(--ink);
    width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
input[type=color] { width: 46px; height: 40px; padding: 2px; border-radius: var(--radius-input); border: 1px solid var(--parchment-dim); }
input[type=file] { padding: 6px; }

.checkbox-inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.checkbox-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.checkbox-pill {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--parchment); border: 1px solid var(--parchment-dim);
    border-radius: var(--radius-pill); padding: 7px 12px; font-size: .85rem; font-weight: 500; cursor: pointer;
}
.checkbox-pill input { width: auto; }

.form-hint { font-size: .78rem; color: var(--ink-faint); }
.form-image-preview { max-width: 160px; border-radius: var(--radius-input); margin-top: 8px; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.filter-bar select, .filter-bar input { width: auto; min-width: 140px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }
.inline-form input[type=text] { width: auto; flex: 1; min-width: 160px; }
.inline-form-vertical { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius-card); overflow: hidden; box-shadow: var(--shadow-soft); }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--parchment-dim); font-size: .88rem; }
.table th { background: var(--parchment-dim); font-weight: 600; color: var(--ink-soft); }
.table tr.row-late { background: var(--burgundy-soft); }
.table-actions { display: flex; gap: 6px; }

/* ---------- Rankings ---------- */
.ranking-list { list-style: decimal; padding-left: 20px; margin: 0; }
.ranking-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--parchment-dim); }
.ranking-count { color: var(--ink-faint); font-size: .8rem; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--parchment-dim); }
.tabs a { padding: 10px 16px; font-weight: 600; color: var(--ink-faint); font-size: .88rem; }
.tabs a.active { color: var(--gold); border-bottom: 2px solid var(--gold); }

/* ---------- Players ---------- */
.players-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.player-card { background: var(--card); border: 1px solid var(--parchment-dim); border-radius: var(--radius-card); padding: 14px; box-shadow: var(--shadow-soft); }
.player-card-main { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.player-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; flex-shrink: 0;
}
.player-edit { margin-top: 10px; font-size: .82rem; }
.player-edit summary { cursor: pointer; color: var(--ink-faint); }

.players-checklist { display: flex; flex-direction: column; gap: 8px; }
.player-row { background: var(--parchment); border-radius: var(--radius-input); padding: 8px; }
.score-row { display: flex; gap: 10px; align-items: center; margin-top: 8px; padding-left: 4px; }
.score-row input[type=number] { width: 90px; }
.quick-add-player { display: flex; gap: 8px; margin-top: 12px; }
.quick-add-player input { flex: 1; }

.kv-list { list-style: none; padding: 0; margin: 0; }
.kv-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--parchment-dim); }

/* ---------- Login ---------- */
.login-body {
    margin: 0; min-height: 100vh;
    background: var(--felt);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Inter', sans-serif;
}
.login-card {
    background: var(--parchment);
    border-radius: var(--radius-card);
    padding: 36px 30px;
    width: 100%; max-width: 360px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.login-logo { font-size: 2.4rem; margin-bottom: 6px; }
.login-card h1 { font-family: 'Fraunces', serif; margin-bottom: 4px; }
.login-sub { color: var(--ink-faint); margin-bottom: 20px; font-size: .88rem; }
.login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }

.page-empty { text-align: center; padding: 60px 20px; }
.page-empty h1 { font-size: 3rem; }
