@import url('https://fonts.googleapis.com/css2?family=Lexend+Deca:wght@100..900&family=New+Amsterdam&family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap');

:root {
    --font-primary: 'Lexend Deca', sans-serif;
    --font-heading: 'New Amsterdam', sans-serif;
    --font-body: 'Open Sans', sans-serif;
    --color-coper: #c56a39;
    --color-tile: #021A54;
    --color-background: #021d5c;
    --color-ink: #ffffff;
    --color-muted: #d7dff5;
    --color-danger: #ff6347;
    --color-teal: #1ea7a1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 62.5%;
}

body {
    height: 100svh;
    font-family: var(--font-body);
    background: linear-gradient(135deg, #07153d 0%, var(--color-background) 48%, #15346f 100%);
    color: var(--color-ink);
    overflow: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.stats-page {
    height: 100svh;
    padding: clamp(1rem, 2vh, 2rem);
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    overflow: hidden;
}

.stats-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 1.2rem;
    flex: 0 0 auto;
    padding: 0.4rem 0 0.8rem;
    background: linear-gradient(135deg, #07153d 0%, var(--color-background) 48%, #15346f 100%);
}

.stats-titlebar {
    min-width: 0;
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.stats-header h1 {
    font-family: var(--font-heading);
    font-size: clamp(4rem, 8vh, 7rem);
    line-height: 0.9;
    color: var(--color-coper);
    background: linear-gradient(0deg, white 0%, var(--color-coper) 40%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stats-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.stats-user {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--color-muted);
    font-size: 1.2rem;
    font-weight: 800;
}

.btn-back,
.btn-refresh,
.btn-filter,
.btn-save,
.btn-cancel,
.btn-small {
    border: 2px solid var(--color-coper);
    border-radius: 0 1rem 0 1rem;
    background: transparent;
    color: var(--color-coper);
    text-decoration: none;
    font-weight: 800;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-back,
.btn-refresh {
    padding: 0.7rem 1.3rem;
    font-size: 1.4rem;
}

.btn-filter {
    min-height: 3.4rem;
    padding: 0.55rem 1rem;
    border-radius: 0 0.8rem 0 0.8rem;
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-size: 1.2rem;
    white-space: nowrap;
}

.btn-back:hover,
.btn-refresh:hover,
.btn-filter:hover,
.btn-filter.active,
.btn-small:hover,
.btn-cancel:hover {
    background: var(--color-coper);
    color: #fff;
}

.stats-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.stats-panel {
    height: 100%;
    min-height: 0;
    background: rgba(2, 26, 84, 0.9);
    outline: solid 2px var(--color-coper);
    border-radius: 0 2rem 0 2rem;
    padding: clamp(1rem, 2vw, 1.8rem);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.stats-table-head,
.result-card {
    display: grid;
    grid-template-columns: minmax(14rem, 1.3fr) minmax(14rem, 0.9fr) minmax(10rem, 0.7fr) minmax(24rem, 2fr) auto;
    gap: 1rem;
    align-items: center;
}

.stats-table-head {
    color: #ffffff99;
    font-size: 1.2rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0 1rem 0.4rem;
}

.stats-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    overflow: auto;
    padding: 0.2rem;
}

.result-card {
    background: #ffffff0d;
    outline: solid 1px #ffffff22;
    border-left: 0.5rem solid var(--color-teal);
    border-radius: 0 1.2rem 0 1.2rem;
    padding: 1rem;
}

.result-card.status-gameover {
    border-left-color: var(--color-danger);
}

.game-title {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.game-title strong {
    font-family: var(--font-heading);
    font-size: clamp(2.8rem, 4vh, 4.2rem);
    line-height: 1;
    color: var(--color-coper);
}

.game-title span,
.date-cell,
.status-cell {
    font-size: 1.35rem;
    color: var(--color-muted);
}

.status-cell {
    width: fit-content;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    background: rgba(30, 167, 161, 0.18);
    color: #bdf8f5;
    font-weight: 800;
}

.status-gameover .status-cell {
    background: rgba(255, 99, 71, 0.16);
    color: #ffc5bd;
}

.stats-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.stat-pill {
    padding: 0.45rem 0.65rem;
    border: 1px solid #ffffff24;
    border-radius: 0 0.8rem 0 0.8rem;
    color: #fff;
    font-size: 1.2rem;
    background: #0000001c;
}

.actions-cell {
    display: flex;
    gap: 0.6rem;
}

.btn-small {
    padding: 0.6rem 0.8rem;
    font-size: 1.2rem;
}

.btn-delete {
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.btn-delete:hover {
    background: var(--color-danger);
    color: #fff;
}

.empty-state {
    padding: 2rem;
    color: var(--color-muted);
    font-size: 1.5rem;
}

.edit-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.72);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 40;
    padding: 1rem;
}

.edit-modal.open {
    opacity: 1;
    pointer-events: auto;
}

.edit-card {
    width: min(96vw, 980px);
    max-height: 92vh;
    overflow: auto;
    background: var(--color-tile);
    outline: solid 2px var(--color-coper);
    border-radius: 0 2rem 0 2rem;
    padding: clamp(1.2rem, 2vw, 2rem);
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.edit-card h2 {
    font-family: var(--font-heading);
    font-size: clamp(4rem, 7vh, 6rem);
    color: var(--color-coper);
    line-height: 0.95;
}

.edit-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.edit-card label {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.edit-card label span {
    color: #ffffffa8;
    font-size: 1.15rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.edit-card input,
.edit-card select,
.edit-card textarea {
    width: 100%;
    border: none;
    outline: solid 1px #ffffff24;
    border-radius: 0 0.8rem 0 0.8rem;
    background: #ffffff10;
    color: #fff;
    padding: 0.9rem 1rem;
}

.edit-card select option {
    background: var(--color-tile);
}

.json-field textarea {
    min-height: 17rem;
    font-family: Consolas, monospace;
    font-size: 1.3rem;
    line-height: 1.45;
    resize: vertical;
}

.edit-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.btn-save,
.btn-cancel {
    min-height: 5rem;
    font-family: var(--font-heading);
    font-size: clamp(2.4rem, 4vh, 3.4rem);
}

.btn-save {
    background: var(--color-coper);
    color: #fff;
}

.btn-save:hover {
    background: var(--color-teal);
    border-color: var(--color-teal);
}

@media (max-width: 900px) {
    .stats-header {
        flex-wrap: wrap;
    }

    .stats-titlebar {
        width: 100%;
        order: 3;
    }

    .stats-filters {
        width: 100%;
    }

    .btn-filter {
        flex: 1 1 12rem;
    }

    .stats-table-head {
        display: none;
    }

    .result-card {
        grid-template-columns: 1fr;
        align-items: start;
    }

    .actions-cell {
        width: 100%;
    }

    .actions-cell .btn-small {
        flex: 1;
    }

    .edit-grid {
        grid-template-columns: 1fr;
    }
}
