:root {
    --bg: #eef3f8;
    --panel: #ffffff;
    --surface: #f7f9fc;
    --surface-strong: #eef4ff;
    --text: #111827;
    --muted: #64748b;
    --border: #cfd9e8;
    --border-soft: #e7edf5;
    --primary: #245ee8;
    --primary-dark: #1d4bb8;
    --primary-soft: #eef4ff;
    --success: #0f8f56;
    --success-soft: #eaf8f1;
    --warning: #b7791f;
    --danger: #c92a2a;
    --danger-soft: #fff1f1;
    --rank: #2563eb;
    --team: #0f8f56;
    --insight: #7c3aed;
    --admin: #374151;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 14px 34px rgba(15, 23, 42, 0.08);
    --shadow-strong: 0 2px 6px rgba(15, 23, 42, 0.07), 0 22px 46px rgba(15, 23, 42, 0.12);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
    color-scheme: light;
}

body {
    display: block;
    width: 100%;
    max-width: none;
    min-height: 100vh;
    margin: 0;
    padding: 30px 18px 44px;
    background:
        linear-gradient(180deg, #eaf1fb 0, #f7f9fc 260px, var(--bg) 100%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    line-height: 1.5;
}

body.home-body {
    display: grid;
    place-items: center;
}

h1,
h2,
h3,
h4,
p {
    letter-spacing: 0;
}

h1 {
    margin: 0 0 9px;
    color: var(--text);
    font-size: clamp(26px, 4vw, 34px);
    font-weight: 780;
    line-height: 1.2;
    text-wrap: balance;
}

h2,
.section-title {
    margin: 0;
    color: var(--text);
    font-size: 18px;
    font-weight: 720;
}

h3 {
    margin: 0 0 12px;
    color: var(--text);
    font-size: 16px;
    font-weight: 700;
}

a {
    color: inherit;
}

::selection {
    background: rgba(36, 94, 232, 0.16);
}

main,
.shell {
    width: min(1120px, 100%);
    margin: 0 auto;
}

.shell-wide {
    width: min(1280px, 100%);
}

.home-body main {
    width: min(1040px, 100%);
}

.container,
.panel,
.section {
    background: linear-gradient(180deg, #ffffff 0, #fbfdff 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.container {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: clamp(18px, 3vw, 28px);
}

.page-header,
header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(207, 217, 232, 0.7);
}

.subtitle,
.subtle {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
}

.page-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

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

.tool-card {
    position: relative;
    display: flex;
    min-height: 166px;
    padding: 19px;
    flex-direction: column;
    justify-content: space-between;
    color: inherit;
    text-decoration: none;
    background: linear-gradient(180deg, #ffffff 0, #fbfdff 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.tool-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--success));
    opacity: 0.78;
}

.tool-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: var(--shadow-strong);
}

.tool-card:focus {
    outline: none;
}

.tool-card:focus-visible {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14), var(--shadow-strong);
}

.tool-title {
    margin: 4px 0 8px;
    font-size: 20px;
    font-weight: 780;
}

.tool-desc {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.tool-action {
    margin-top: 16px;
    color: var(--primary);
    font-size: 14px;
    font-weight: 760;
}

.section,
.page-section {
    position: relative;
    margin-bottom: 16px;
    padding: 20px;
    overflow: hidden;
}

.section::before,
.page-section::before,
.panel::before,
.container::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--success));
    opacity: 0.58;
}

.panel,
.container {
    position: relative;
    overflow: hidden;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.form-grid,
.flex-container,
.toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.five {
    grid-template-columns: 120px 1fr 1fr 1fr 1fr;
}

.flex-item,
.field,
.input-group {
    min-width: 0;
}

label {
    display: block;
    margin-bottom: 6px;
    color: #53627a;
    font-size: 13px;
    font-weight: 650;
}

.field-hint {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

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

input,
select,
textarea,
.search,
.player-score,
input[type="text"],
input[type="number"],
input[type="date"],
input[type="search"] {
    width: 100%;
    min-height: 40px;
    margin: 0;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font-size: 14px;
    box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.02);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(36, 94, 232, 0.14);
}

input:disabled,
select:disabled,
textarea:disabled {
    background: #f1f5f9;
    color: var(--muted);
    cursor: not-allowed;
}

button,
.btn {
    display: inline-flex;
    width: auto;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 9px 13px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 1px 1px rgba(15, 23, 42, 0.04);
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

button:hover,
.btn:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

button:disabled,
.btn:disabled {
    cursor: not-allowed;
    opacity: 0.58;
    transform: none;
}

.btn.primary,
button.primary,
.filter-section button,
#fetch-btn,
#search-player-btn,
#match-search-btn {
    border-color: var(--primary);
    background: linear-gradient(180deg, #2f6bf0, var(--primary));
    color: #fff;
    box-shadow: 0 10px 18px rgba(36, 94, 232, 0.18);
}

.btn.primary:hover,
button.primary:hover,
.filter-section button:hover,
#fetch-btn:hover,
#search-player-btn:hover,
#match-search-btn:hover {
    background: linear-gradient(180deg, #2861df, var(--primary-dark));
}

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

.btn.danger,
button.danger {
    color: var(--danger);
}

.btn.small,
.toggle-players-btn {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
}

.filter-section {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0 0 18px;
    padding: 16px;
    background: linear-gradient(180deg, var(--surface) 0, #ffffff 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.time-period-selector {
    display: grid;
    grid-template-columns: auto minmax(150px, 1fr) auto minmax(150px, 1fr);
    align-items: center;
    gap: 10px;
    flex: 1 1 560px;
}

.time-period-selector label {
    margin: 0;
}

.table-wrap {
    overflow-x: auto;
}

table,
.data-table {
    width: 100%;
    min-width: 680px;
    border-collapse: collapse;
    background: var(--panel);
}

.data-table {
    margin-top: 0;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: none;
}

th,
td,
.data-table th,
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
    font-size: 14px;
}

th,
.data-table th {
    background: linear-gradient(180deg, #eaf2ff 0, #dfeaff 100%);
    color: #23395d;
    font-weight: 750;
}

tbody tr:nth-child(even),
.data-table tr:nth-child(even) {
    background: #f9fbfe;
}

tbody tr:hover,
.data-table tr:hover {
    background: #eef5ff;
}

.rank,
.highlight {
    color: var(--primary);
    font-weight: 750;
}

.win-rate-extreme-high {
    color: #7c3aed;
    font-weight: 750;
}

.win-rate-very-high,
.win-rate-high {
    color: var(--danger);
    font-weight: 750;
}

.win-rate-medium {
    color: var(--success);
    font-weight: 750;
}

.win-rate-low {
    color: var(--primary);
    font-weight: 750;
}

.player-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 88px 34px;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: none;
}

.player-row label {
    margin: 0;
}

.player-row:has(#room-name) {
    grid-template-columns: 84px minmax(0, 1fr);
}

.player-info {
    min-width: 0;
    color: var(--text);
    font-size: 14px;
    font-weight: 650;
    overflow-wrap: anywhere;
}

.player-score {
    width: 88px;
    text-align: center;
}

.team-label {
    width: 34px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

#fetch-btn {
    width: 100%;
    margin-top: 8px;
}

.result-container {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.team-display {
    display: grid;
    gap: 12px;
    margin-top: 14px;
}

.team-display .team {
    margin: 0;
    padding: 14px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}

.team-display .team-2-bg {
    border-left-color: var(--success);
}

.team-title,
.player-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.team-title {
    margin-bottom: 10px;
    color: var(--text);
    font-size: 15px;
    font-weight: 750;
}

.player-item {
    padding: 7px 0;
    border-bottom: 1px solid #edf1f7;
    color: var(--text);
    font-size: 14px;
}

.player-item:last-child {
    border-bottom: 0;
}

.status,
.stats-box {
    margin: 12px 0 0;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, var(--surface) 0, #ffffff 100%);
    color: var(--muted);
    font-size: 14px;
}

.status {
    display: none;
}

.status.show,
.status.loading,
.status.error,
.status.success,
.status.info {
    display: block;
}

.loading,
.status.loading,
.status.info {
    color: var(--muted);
    background: #f8fafc;
}

.error,
.status.error {
    color: var(--danger);
    background: #fff5f5;
    border-color: #ffd6d6;
}

.success,
.status.success {
    color: var(--success);
    background: var(--success-soft);
    border-color: #c7f0dc;
}

.result-options,
.map-buttons,
.button-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.button-row input,
.button-row select {
    flex: 1 1 220px;
    min-width: 180px;
}

.result-option,
.profile-option,
.match-details {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.result-option,
.profile-option {
    padding: 11px 12px;
    cursor: pointer;
    transition: border-color 0.16s ease, background 0.16s ease;
}

.result-option:hover,
.result-option.active,
.profile-option:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.profile-results-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.profile-choice {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(112px, 160px);
    align-items: center;
    gap: 10px;
}

.profile-choice strong,
.profile-choice .match-meta {
    overflow-wrap: anywhere;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.stat-card {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, #ffffff 0, #f9fbff 100%);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.stat-card span {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 12px;
}

.stat-card strong {
    color: var(--text);
    font-size: 20px;
}

.match-list {
    display: grid;
    gap: 10px;
}

.match-details {
    padding: 12px;
}

.match-line {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.match-info {
    min-width: 0;
    overflow-wrap: anywhere;
}

.match-meta {
    color: var(--muted);
    font-size: 13px;
}

.result-pill {
    display: inline-flex;
    min-width: 34px;
    min-height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 750;
}

.result-pill.win {
    background: var(--success-soft);
    color: var(--success);
}

.result-pill.loss {
    background: var(--danger-soft);
    color: var(--danger);
}

.players-list {
    display: none;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.players-list.open {
    display: grid;
    gap: 10px;
}

.player-team,
.player-opponent {
    margin: 8px 0 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
}

.civ-name {
    color: var(--muted);
    font-size: 13px;
}

.meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--border);
}

.metric {
    padding: 14px 16px;
    background: #fff;
}

.metric span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
}

.metric strong {
    font-size: 18px;
}

.empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--muted);
}

@media (max-width: 980px) {
    .tool-grid,
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .form-grid.five,
    .form-grid.three {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    body {
        padding: 18px 10px 28px;
    }

    .container,
    .section,
    .page-section {
        padding: 14px;
    }

    .page-header,
    header,
    .section-heading,
    .filter-section,
    .form-grid,
    .form-grid.five,
    .form-grid.three,
    .flex-container,
    .toolbar,
    .time-period-selector {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .page-actions,
    .button-row,
    .map-buttons {
        justify-content: stretch;
    }

    .page-actions .btn,
    .button-row .btn,
    .map-buttons button,
    .filter-section button {
        width: 100%;
    }

    .tool-grid,
    .stats-grid,
    .profile-results-grid,
    .meta {
        grid-template-columns: 1fr;
    }

    .profile-choice {
        grid-template-columns: 1fr;
    }

    .tool-card {
        min-height: 136px;
    }

    .match-line {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    table,
    .data-table {
        min-width: 640px;
    }
}
