:root {
    --bg: #090b12;
    --panel: #111827;
    --panel2: #151f31;
    --text: #eef2ff;
    --muted: #9aa7bd;
    --line: rgba(255,255,255,.08);
    --accent: #cca457;
    --accent2: #e1c47f;
    --accent-deep: #a8823d;
    --accent-soft: rgba(204,164,87,.12);
    --accent-soft-2: rgba(204,164,87,.16);
    --accent-soft-3: rgba(204,164,87,.24);
    --accent-glow: rgba(204,164,87,.18);
    --accent-line: rgba(225,196,127,.65);
    --good: #22c55e;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top left, rgb(255 173 14 / 45%), #00000000 35%), #1c1a11;
    color: var(--text);
    min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
.landing { display: grid; place-items: center; padding: 24px; }
.login-card {
    width: min(520px, 100%);
    padding: 36px;
    border: 1px solid var(--line);
    border-radius: 26px;
    background: rgba(17,24,39,.82);
    box-shadow: 0 24px 80px rgba(0,0,0,.45);
    text-align: center;
}
.brand-mark {
    width: 70px; height: 70px; border-radius: 22px;
    display: grid; place-items: center; margin: 0 auto 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    font-weight: 900; letter-spacing: -1px;
}
.button {
    display: inline-flex; align-items: center; justify-content: center;
    margin-top: 18px; padding: 13px 18px; border-radius: 14px;
    text-decoration: none; font-weight: 800;
}
.button-discord { background: #5865f2; color: white; }
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; justify-content: space-between; align-items: center;
    gap: 18px; padding: 16px 24px;
    background: rgba(9,11,18,.82); backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
}
.topbar span { color: var(--muted); margin-left: 8px; }
.topbar nav { display: flex; gap: 14px; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); text-decoration: none; font-weight: 700; }
.topbar nav a:hover { color: var(--text); }
.shell { max-width: 1320px; margin: 0 auto; padding: 30px 20px 60px; }
.hero {
    display: flex; justify-content: space-between; align-items: center; gap: 20px;
    margin-bottom: 18px;
}
.player { display: flex; align-items: center; gap: 16px; }
.player img { width: 74px; height: 74px; border-radius: 24px; border: 1px solid var(--line); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(28px, 5vw, 46px); }
h2 { margin-bottom: 0; }
.eyebrow { color: var(--accent2); text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 900; margin-bottom: 5px; }
.muted { color: var(--muted); margin-bottom: 0; }
.notice, .empty {
    color: var(--muted);
    border: 1px solid var(--line);
    background: rgba(255,255,255,.03);
    border-radius: 14px;
    padding: 12px 14px;
}
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.card {
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(21,31,49,.94), rgba(17,24,39,.94));
    border-radius: 22px;
    box-shadow: 0 16px 50px rgba(0,0,0,.22);
}
.stat { padding: 22px; }
.stat span { display: block; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.stat strong { font-size: clamp(24px, 4vw, 36px); }
.stat small { display: block; color: var(--muted); margin-top: 8px; font-weight: 700; }
.section-card { padding: 22px; margin-top: 16px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 18px; }
.pill { border: 1px solid var(--line); color: var(--accent2); background: var(--accent-soft); padding: 7px 10px; border-radius: 999px; font-size: 12px; font-weight: 900; }
.dept-list { display: grid; gap: 12px; }
.dept-row { display: grid; gap: 8px; }
.dept-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.dept-meta strong { color: var(--text); }
.bar { height: 10px; background: rgba(255,255,255,.06); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: inherit; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 580px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
code { background: rgba(255,255,255,.06); border: 1px solid var(--line); padding: 3px 6px; border-radius: 8px; color: var(--accent2); }
@media (max-width: 980px) { .grid, .two-col { grid-template-columns: 1fr 1fr; } .hero { align-items: flex-start; flex-direction: column; } }
@media (max-width: 650px) { .grid, .two-col { grid-template-columns: 1fr; } .topbar { align-items: flex-start; flex-direction: column; } .dept-meta { flex-direction: column; } }

.notice-warning ul {
    margin: 8px 0 0;
    padding-left: 20px;
}

.notice-warning li {
    margin: 4px 0;
}

.small-muted { font-size: 13px; margin-top: 8px; }
.stacked-head { align-items: flex-start; }
.section-stats {
    display: flex;
    align-items: stretch;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}
.mini-stat {
    min-width: 160px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255,255,255,.035);
}
.mini-stat span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 5px;
}
.mini-stat strong {
    font-size: 20px;
}
.dept-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 20px;
    padding: 3px 5px;
    border-radius: 999px;
    border: 1px solid var(--dept-border, var(--accent));
    background: var(--dept-bg, var(--accent));
    color: var(--dept-text, #141008);
    box-shadow: 0 0 20px var(--dept-glow, rgba(204,164,87,.22));
    font-size: 13px;
    font-weight: 900;
    line-height: 1.1;
    white-space: nowrap;
}
@media (max-width: 760px) {
    .stacked-head { flex-direction: column; }
    .section-stats { width: 100%; justify-content: stretch; }
    .mini-stat { flex: 1 1 100%; }
}


.money-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.inventory-stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.lock-status {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid var(--line);
    font-size: 12px;
    font-weight: 900;
    color: var(--muted);
    background: rgba(255,255,255,.04);
}
.lock-status.locked { color: #fca5a5; background: rgba(239,68,68,.12); }
.lock-status.unlocked { color: #86efac; background: rgba(34,197,94,.12); }
.stat-note { margin-top: 10px; color: var(--muted); font-size: 12px; font-weight: 700; }
.nav-active { color: var(--text) !important; }
@media (max-width: 980px) { .money-grid, .inventory-stats-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 650px) { .money-grid, .inventory-stats-grid { grid-template-columns: 1fr; } }

/* Mobile/responsive cleanup */
html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}
img, svg { max-width: 100%; height: auto; }
.card, .notice, .empty, .section-card, .stat, .mini-stat { min-width: 0; }
.topbar {
    width: 100%;
    flex-wrap: wrap;
}
.topbar > div { min-width: 0; }
.topbar strong, .topbar span {
    overflow-wrap: anywhere;
}
.topbar nav {
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
}
.topbar nav a {
    white-space: nowrap;
    padding: 8px 10px;
    border-radius: 999px;
}
.topbar nav a:hover,
.topbar nav a.nav-active {
    background: rgba(255,255,255,.045);
}
.shell {
    width: min(1320px, 100%);
    padding: clamp(16px, 2.4vw, 30px) clamp(12px, 2vw, 20px) 60px;
}
.hero { width: 100%; }
.player { min-width: 0; }
.player > div { min-width: 0; }
h1, h2 { overflow-wrap: anywhere; }
.grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
    gap: clamp(14px, 2vw, 18px);
}
.money-grid,
.inventory-stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}
.cards + .cards,
.money-grid + .inventory-stats-grid {
    margin-top: 18px;
}
.stat {
    min-height: 148px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: clamp(18px, 2.2vw, 24px);
}
.stat span,
.stat small { overflow-wrap: anywhere; }
.stat strong {
    line-height: 1.1;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.two-col {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
}
.table-wrap {
    width: 100%;
    max-width: 100%;
}
.table-wrap table {
    max-width: 100%;
}

@media (max-width: 760px) {
    .topbar {
        padding: 12px;
        gap: 10px;
    }
    .topbar span {
        display: block;
        margin-left: 0;
        margin-top: 2px;
    }
    .topbar nav {
        width: 100%;
        flex-wrap: nowrap;
        gap: 8px;
    }
    .shell {
        padding: 14px 10px 42px;
    }
    .hero {
        gap: 12px;
        margin-bottom: 12px;
    }
    .player {
        gap: 12px;
        align-items: flex-start;
    }
    .player img {
        width: 58px;
        height: 58px;
        border-radius: 18px;
    }
    h1 { font-size: clamp(26px, 9vw, 34px); }
    .section-card { padding: 16px; }
    .section-head { flex-direction: column; align-items: flex-start; }
    .section-stats { width: 100%; justify-content: stretch; }
    .mini-stat { flex: 1 1 100%; }
    .stat { min-height: 132px; }

    table.responsive-table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }
    table.responsive-table thead {
        display: none;
    }
    table.responsive-table,
    table.responsive-table tbody,
    table.responsive-table tr,
    table.responsive-table td {
        display: block;
        width: 100%;
    }
    table.responsive-table tr {
        margin-bottom: 12px;
        padding: 10px 12px;
        border: 1px solid var(--line);
        border-radius: 16px;
        background: rgba(255,255,255,.025);
    }
    table.responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 14px;
        padding: 9px 0;
        border-bottom: 1px solid var(--line);
        text-align: right;
        overflow-wrap: anywhere;
    }
    table.responsive-table td:last-child {
        border-bottom: 0;
    }
    table.responsive-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: .07em;
        text-align: left;
        flex: 0 0 44%;
    }
}

@media (max-width: 430px) {
    .login-card { padding: 24px 18px; }
    .stat { min-height: 120px; }
    .pill { width: 100%; text-align: center; justify-content: center; }
    table.responsive-table td {
        flex-direction: column;
        gap: 4px;
        text-align: left;
    }
    table.responsive-table td::before {
        flex-basis: auto;
    }
}


/* Player search page */
.search-card { margin-bottom: 16px; }
.search-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
}
.search-form input[type="search"] {
    width: 100%;
    min-width: 0;
    color: var(--text);
    background: rgba(255,255,255,.045);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px 16px;
    font: inherit;
    font-weight: 700;
    outline: none;
}
.search-form input[type="search"]:focus {
    border-color: var(--accent-line);
    box-shadow: 0 0 0 4px var(--accent-soft-2);
}
.button-primary {
    border: 0;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
}
.button-small {
    margin-top: 0;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--accent-soft-2);
    border: 1px solid var(--accent-soft-3);
    color: var(--text);
    font-size: 13px;
}

@media (max-width: 650px) {
    .search-form {
        grid-template-columns: 1fr;
    }
    .search-form .button {
        width: 100%;
    }
}

/* Calendar week selector */
.range-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 240px) auto auto;
    gap: 12px;
    align-items: end;
    margin: 0 0 18px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255,255,255,.025);
}
.range-form label,
.week-field label {
    display: block;
    color: var(--text);
    font-weight: 900;
    margin-bottom: 4px;
}
.range-form small,
.form-note {
    display: block;
    color: var(--muted);
}
.range-form input[type="date"],
.week-field input[type="date"] {
    width: 100%;
    min-width: 0;
    color: var(--text);
    color-scheme: dark;
    background: rgba(255,255,255,.045);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 13px 14px;
    font: inherit;
    font-weight: 800;
    outline: none;
}
.range-form input[type="date"]:focus,
.week-field input[type="date"]:focus {
    border-color: var(--accent-line);
    box-shadow: 0 0 0 4px var(--accent-soft-2);
}
.search-form-wide {
    grid-template-columns: minmax(240px, 1fr) minmax(180px, 240px) auto auto;
}
.week-field {
    min-width: 0;
}
.form-note {
    margin-top: 10px;
}

@media (max-width: 860px) {
    .range-form,
    .search-form-wide {
        grid-template-columns: 1fr 1fr;
    }
    .range-form .button,
    .search-form-wide .button {
        width: 100%;
    }
}

@media (max-width: 650px) {
    .range-form,
    .search-form-wide {
        grid-template-columns: 1fr;
    }
}

/* Form alignment cleanup patch */
.search-form,
.range-form {
    align-items: end;
}

.search-form-wide {
    grid-template-columns: minmax(260px, 1fr) minmax(210px, 240px) minmax(88px, auto) minmax(84px, auto);
    align-items: end;
}

.search-form input[type="search"],
.range-form input[type="date"],
.week-field input[type="date"] {
    height: 52px;
    min-height: 52px;
    line-height: 1.2;
}

.search-form .button,
.range-form .button {
    height: 52px;
    min-height: 52px;
    margin-top: 0;
    padding: 0 18px;
    white-space: nowrap;
}

.search-form .button-small,
.range-form .button-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 900;
}

.week-field label,
.range-form label {
    min-height: 18px;
    line-height: 18px;
}

.form-note {
    margin-top: 12px;
}

@media (max-width: 860px) {
    .search-form-wide,
    .range-form {
        grid-template-columns: 1fr 1fr;
        align-items: end;
    }

    .search-form-wide input[type="search"] {
        grid-column: 1 / -1;
    }

    .search-form-wide .button,
    .range-form .button {
        width: 100%;
    }
}

@media (max-width: 650px) {
    .search-form-wide,
    .range-form {
        grid-template-columns: 1fr;
    }

    .search-form .button,
    .range-form .button {
        width: 100%;
    }
}

/* Center leftover inventory stat rows and fit as many cards per row as possible */
.inventory-stats-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: stretch;
    gap: clamp(14px, 2vw, 18px);
}

.inventory-stats-grid > .card {
    flex: 1 1 320px;
    width: min(100%, 420px);
    max-width: 420px;
}

.money-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: stretch;
    gap: clamp(14px, 2vw, 18px);
}

.money-grid > .card {
    flex: 1 1 320px;
    width: min(100%, 420px);
    max-width: 420px;
}

@media (max-width: 760px) {
    .inventory-stats-grid > .card,
    .money-grid > .card {
        flex-basis: 100%;
        max-width: 100%;
    }
}

/* Hard restore for the player search form in case older CSS was installed over it */
.search-card .search-form {
    width: 100%;
}

.search-card input[type="search"],
.search-card input[type="date"] {
    appearance: none;
}


/* Player leaderboard */
.leaderboard-card { margin-top: 16px; }
.leaderboard-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 18px;
}
.leaderboard-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255,255,255,.035);
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 900;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.leaderboard-tab:hover,
.leaderboard-tab.active {
    color: var(--text);
    border-color: var(--accent-soft-3, rgba(204,164,87,.24));
    background: var(--accent-soft, rgba(204,164,87,.12));
}
.leaderboard-table th:first-child,
.leaderboard-table td:first-child {
    width: 82px;
    white-space: nowrap;
}
@media (max-width: 650px) {
    .leaderboard-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 4px;
        scrollbar-width: thin;
    }
    .leaderboard-tab {
        white-space: nowrap;
        flex: 0 0 auto;
    }
}



/* Logged-in user's rank for the selected leaderboard tab */
.leaderboard-self-rank {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
    gap: 12px;
    margin: 0 0 18px;
}

.leaderboard-self-rank > div {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--accent-soft, rgba(204,164,87,.12));
    padding: 14px 16px;
    min-width: 0;
}

.leaderboard-self-rank span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 6px;
}

.leaderboard-self-rank strong {
    display: block;
    font-size: clamp(24px, 4vw, 34px);
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.leaderboard-self-rank small {
    display: block;
    color: var(--muted);
    font-weight: 800;
    margin-top: 6px;
    overflow-wrap: anywhere;
}

/* Login logo brandmark */
.brand-mark {
    color: transparent;
    font-size: 0;
    line-height: 0;
    background: transparent url('crplogo.png') center / contain no-repeat;
    box-shadow: 0 18px 50px rgba(204,164,87,.22);
    border: 1px solid rgba(225,196,127,.34);
}

.brand-mark::before {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
}
