:root {
    --bg: #0f1623;
    --surface: #1a2332;
    --surface-hover: #223044;
    --border: #2a3a4e;
    --text: #e8edf3;
    --text-muted: #8899aa;
    --accent: #f5a623;
    --accent-hover: #e6961a;
    --blue: #4a9eff;
    --green: #2ecc71;
    --red: #e74c3c;
}

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

html {
    background: #0f1623;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Hero */
.hero {
    text-align: center;
    padding: 3rem 0 2rem;
}

.hero h1 {
    font-size: 2.5rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Search */
.search-box {
    display: flex;
    gap: 0.5rem;
    max-width: 500px;
    margin: 2rem auto;
}

.search-box input {
    flex: 1;
    padding: 0.85rem 1.2rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-box button {
    padding: 0.85rem 1.8rem;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #000;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.search-box button:hover {
    background: var(--accent-hover);
}

/* Error */
.error-msg {
    text-align: center;
    background: rgba(231, 76, 60, 0.15);
    border: 1px solid var(--red);
    color: var(--red);
    padding: 0.8rem 1.2rem;
    border-radius: 8px;
    max-width: 500px;
    margin: 1rem auto;
}

/* Back link */
.back-link {
    display: inline-block;
    color: var(--blue);
    text-decoration: none;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.back-link:hover {
    text-decoration: underline;
}

/* Clan header */
header:not(.hero) h1 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 2rem;
    color: var(--text);
}

.clan-badge {
    width: 48px;
    height: 48px;
}

.clan-flag {
    margin-left: auto;
}

.clan-flag + .clan-tag {
    margin-left: 0.4rem;
}

.clan-tag {
    display: inline-block;
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: monospace;
    background: rgba(255, 255, 255, 0.07);
    padding: 0.2em 0.6em;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Stats grid */
.clan-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin: 2rem 0;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    transition: border-color 0.2s;
}

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

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Clan description */
.clan-description {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.2rem 1.5rem;
    margin-bottom: 2rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Members table */
.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.section-header h2 {
    font-size: 1.3rem;
    margin: 0;
}

.members-section {
    margin-top: 2rem;
}

.members-section h2 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.week-nav {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.week-arrow {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: border-color 0.2s, opacity 0.2s;
}

.week-arrow:hover:not(:disabled) {
    border-color: var(--accent);
}

.week-arrow:disabled {
    opacity: 0.3;
    cursor: default;
}

.week-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-right: 0.3rem;
}

.week-link {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: border-color 0.2s, color 0.2s;
}

.week-link:hover {
    border-color: var(--accent);
    color: var(--text);
}

.week-active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

thead th {
    background: var(--bg);
    padding: 0.8rem 1rem;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.th-group {
    text-align: center;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

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

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

.rank {
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    width: 40px;
}

.player-name {
    font-weight: 600;
}

.player-tag {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
    font-weight: 400;
}

.trophies {
    color: var(--accent);
    font-weight: 600;
}

/* Roles */
.role {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: capitalize;
}

.role-leader {
    background: rgba(245, 166, 35, 0.2);
    color: var(--accent);
}

.role-coLeader {
    background: rgba(74, 158, 255, 0.2);
    color: var(--blue);
}

.role-elder {
    background: rgba(46, 204, 113, 0.2);
    color: var(--green);
}

.role-member {
    background: rgba(136, 153, 170, 0.15);
    color: var(--text-muted);
}

/* Type badge */
.stat-value.type-open, .mini-value.type-open {
    color: var(--green);
}

.stat-value.type-inviteOnly, .mini-value.type-inviteOnly {
    color: var(--blue);
}

.stat-value.type-closed, .mini-value.type-closed {
    color: var(--red);
}

/* Current war section */
.current-war-section {
    margin-top: 2rem;
}

.current-war-section .section-header {
    margin-bottom: 1rem;
}

.section-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Past wars */
.past-wars-section {
    margin-top: 2rem;
}

.past-wars-section h2 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.past-wars-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.75rem;
}

.past-war-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.8rem 1rem;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.2s;
}

.past-war-card:hover {
    border-color: var(--accent);
}

.past-war-card-current {
    border-color: var(--accent);
}

.past-war-colosseum {
    background: rgba(197, 123, 42, 0.15);
}


.pw-week {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    flex: 1;
}

.pw-rank {
    font-weight: 800;
    font-size: 1rem;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
}

.pw-fame {
    font-size: 0.85rem;
    color: var(--text-muted);
    width: 100%;
    text-align: right;
}

.pw-colosseum {
    float: left;
    font-size: 1.1rem;
}

.pw-trophy {
    font-weight: 700;
    font-size: 0.9rem;
}

/* War log */
.warlog-section {
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.warlog-section h2 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.warlog-subtitle {
    font-size: 1rem;
    color: var(--text-muted);
    margin: 1.5rem 0 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}

.warlog-subtitle:first-of-type {
    margin-top: 0;
}

.war-entry-summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 0.75rem;
}

.war-entry-summary .war-summary {
    cursor: default;
}

.war-entry-summary .war-summary:hover {
    background: transparent;
}

a.war-entry-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

a.war-entry-link .war-summary {
    cursor: pointer;
}

.war-details-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
}

a.war-entry-link:hover {
    border-color: var(--accent);
}

.war-entry {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.war-entry[open] {
    border-color: var(--accent);
}

.war-summary {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.2rem;
    cursor: pointer;
    list-style: none;
    transition: background 0.15s;
    position: relative;
}

.war-summary::-webkit-details-marker {
    display: none;
}

details.war-entry > .war-summary::after {
    content: "▼";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0.3rem;
    font-size: 0.6rem;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.15s;
}

details.war-entry[open] > .war-summary::after {
    content: "▲";
}

details.war-entry > .war-summary:hover::after {
    opacity: 1;
}

.war-summary:hover {
    background: var(--surface-hover);
}

.war-rank {
    font-weight: 800;
    font-size: 1.2rem;
    min-width: 3rem;
    text-align: center;
    padding: 0.3rem 0.5rem;
    border-radius: 8px;
    flex-shrink: 0;
}

.war-rank-1 {
    background: rgba(245, 166, 35, 0.2);
    color: var(--accent);
}

.war-rank-2 {
    background: rgba(74, 158, 255, 0.2);
    color: var(--blue);
}

.war-rank-3 {
    background: rgba(46, 204, 113, 0.2);
    color: var(--green);
}

.war-rank-4,
.war-rank-5 {
    background: rgba(136, 153, 170, 0.15);
    color: var(--text-muted);
}

.war-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.war-season {
    font-weight: 600;
    font-size: 0.95rem;
}

.war-fame {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.war-trophy-change {
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.positive {
    color: var(--green);
}

.negative {
    color: var(--red);
}

.activity {
    color: var(--text-muted);
}

.activity-old {
    color: var(--red);
}

.war-details {
    padding: 0 1.2rem 1.2rem;
}

.war-details h3 {
    font-size: 1rem;
    margin: 1.2rem 0 0.6rem;
    color: var(--text-muted);
}

.war-details h3:first-child {
    margin-top: 0;
}

.war-self {
    background: rgba(245, 166, 35, 0.08);
}

.war-self td {
    font-weight: 700;
    color: var(--accent);
}

.clan-row {
    cursor: pointer;
}

.clan-row:hover td {
    background: rgba(255, 255, 255, 0.05);
}

/* Warlog loader */
.warlog-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Footer */
footer {
    text-align: center;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
}

footer a {
    color: var(--blue);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Alt search link */
.alt-search {
    text-align: center;
    margin: 1.5rem 0;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
}

.alt-search span {
    font-size: 0.9rem;
}

.link-advanced {
    color: var(--blue);
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
}

.link-advanced:hover {
    text-decoration: underline;
}

/* Page title */
.page-title {
    font-size: 1.8rem;
    color: var(--accent);
    margin-bottom: 1.5rem;
}

/* Advanced search form */
.adv-search {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.8rem;
    margin-bottom: 2rem;
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group.full {
    flex: 1 1 100%;
}

.form-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.required {
    color: var(--accent);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-group input[type="text"]:focus,
.form-group input[type="number"]:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238899aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

.form-group select option {
    background: var(--surface);
    color: var(--text);
}

.btn-search {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.9rem;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #000;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-search:hover {
    background: var(--accent-hover);
}

/* Results */
.results-section {
    margin-top: 1.5rem;
}

.results-section h2 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.no-results {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

/* Clan cards grid */
.clan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.clan-card {
    display: block;
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.2rem;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    overflow: hidden;
}

.clan-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--flag-url) no-repeat center / cover;
    opacity: 0.1;
    pointer-events: none;
}

.clan-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.clan-card-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.clan-card-badge {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.clan-card-name {
    display: block;
    font-weight: 700;
    font-size: 1.05rem;
}

.clan-card-tag {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.clan-card-stats {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.mini-stat {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.mini-value {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent);
}

.mini-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Dual range slider */
.dual-range {
    padding: 0.4rem 0 0.2rem;
}

.range-values {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.range-val-min {
    color: var(--blue);
}

.range-val-max {
    color: var(--accent);
}

.range-track {
    position: relative;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
}

.range-fill {
    position: absolute;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--blue), var(--accent));
    border-radius: 3px;
    pointer-events: none;
}

.range-track input[type="range"] {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    transform: translateY(-50%);
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    margin: 0;
    height: 6px;
}

.range-track input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--text);
    border: 3px solid var(--accent);
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s, border-color 0.15s;
}

.range-track input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    border-color: var(--accent-hover);
}

.range-track input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--text);
    border: 3px solid var(--accent);
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s, border-color 0.15s;
}

.range-track input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
    border-color: var(--accent-hover);
}

.thumb-min::-webkit-slider-thumb {
    border-color: var(--blue) !important;
}

.thumb-min::-moz-range-thumb {
    border-color: var(--blue) !important;
}

@media (max-width: 600px) {
    .hero h1 {
        font-size: 1.8rem;
    }

    .search-box {
        flex-direction: column;
    }

    .clan-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-row {
        flex-direction: column;
    }

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

    .clan-card-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Sortable table headers */
.sortable-header {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.2em;
}

.sortable-header:hover {
    color: var(--accent);
}

.sortable-header.sort-asc::after {
    content: "▲";
    position: absolute;
    right: 0.2em;
    font-size: 0.8em;
}

.sortable-header.sort-desc::after {
    content: "▼";
    position: absolute;
    right: 0.2em;
    font-size: 0.8em;
}
