/* ─── Theme Variables ─────────────────────────────────────────────────────── */
:root {
    --primary:     #4361ee;
    --accent:      #4895ef;
    --success:     #4caf50;
    --warning:     #ff9800;
    --danger:      #f44336;
    --gold:        #ffd700;
    --silver:      #c0c0c0;
    --bronze:      #cd7f32;
    --radius:      14px;
    --radius-sm:   8px;
    --shadow:      0 8px 32px rgba(0,0,0,.22);
    --shadow-sm:   0 2px 12px rgba(0,0,0,.15);
    --transition:  .22s cubic-bezier(.4,0,.2,1);
}

html.dark-theme, html.dark-theme body {
    --bg:           #0d0b20;
    --text:         #f0f0ff;
    --text-muted:   rgba(240,240,255,.5);
    --card-bg:      rgba(28,26,58,.9);
    --card-border:  rgba(100,100,220,.18);
    --input-bg:     rgba(25,23,50,.8);
    --input-border: rgba(100,100,220,.3);
    --row-hover:    rgba(67,97,238,.12);
}

html.light-theme, html.light-theme body {
    --bg:           #eef0fc;
    --text:         #1a1a2e;
    --text-muted:   rgba(26,26,46,.5);
    --card-bg:      rgba(255,255,255,.97);
    --card-border:  rgba(0,0,0,.07);
    --input-bg:     #fff;
    --input-border: rgba(0,0,0,.14);
    --row-hover:    rgba(67,97,238,.07);
}

/* default dark */
:root {
    --bg:           #0d0b20;
    --text:         #f0f0ff;
    --text-muted:   rgba(240,240,255,.5);
    --card-bg:      rgba(28,26,58,.9);
    --card-border:  rgba(100,100,220,.18);
    --input-bg:     rgba(25,23,50,.8);
    --input-border: rgba(100,100,220,.3);
    --row-hover:    rgba(67,97,238,.12);
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
}

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.page-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px 60px;
}

/* ─── Nav ─────────────────────────────────────────────────────────────────── */
.topnav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--card-border);
}

.nav-back {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    border: 1px solid transparent;
}
.nav-back:hover {
    color: var(--text);
    background: var(--card-bg);
    border-color: var(--card-border);
}

.nav-center {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary);
}

.theme-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    font-size: .95rem;
    transition: all var(--transition);
}
.theme-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ─── Search ──────────────────────────────────────────────────────────────── */
.search-section {
    text-align: center;
    padding: 40px 0 32px;
}

.search-wrap {
    display: flex;
    align-items: center;
    max-width: 560px;
    margin: 0 auto 12px;
    background: var(--card-bg);
    border: 1.5px solid var(--card-border);
    border-radius: 50px;
    padding: 6px 6px 6px 20px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.search-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67,97,238,.15);
}

.search-icon { color: var(--text-muted); font-size: .9rem; margin-right: 10px; }

#clan-search-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}
#clan-search-input::placeholder { color: var(--text-muted); }

#clan-search-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 40px;
    padding: 10px 22px;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    font-family: inherit;
}
#clan-search-btn:hover { background: #3451d1; transform: translateX(1px); }

.search-hint { font-size: .85rem; color: var(--text-muted); }

/* ─── State boxes ─────────────────────────────────────────────────────────── */
.state-box {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.error-state { color: var(--danger); }
.error-state i { font-size: 2.5rem; opacity: .7; }

.spinner-ring {
    width: 48px;
    height: 48px;
    border: 3px solid var(--card-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Hero ────────────────────────────────────────────────────────────────── */
.clan-hero {
    position: relative;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    animation: fadeUp .4s ease both;
}

@keyframes fadeUp {
    from { opacity:0; transform: translateY(18px); }
    to   { opacity:1; transform: translateY(0); }
}

.hero-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(67,97,238,.18), rgba(72,149,239,.08));
    pointer-events: none;
}

.hero-content {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 24px;
    padding: 32px;
    flex-wrap: wrap;
}

.hero-avatar {
    position: relative;
    width: 96px;
    height: 96px;
    border-radius: 20px;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid var(--card-border);
}
.hero-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}
.avatar-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
}

.hero-info { flex: 1; min-width: 200px; }

.hero-badges {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

h1 {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -.02em;
    margin-bottom: 6px;
    line-height: 1.1;
}

.clan-desc {
    color: var(--text-muted);
    font-size: .9rem;
    margin-bottom: 14px;
    max-width: 480px;
}

.hero-medals {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.medal-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .95rem;
    font-weight: 600;
}

.hero-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-left: auto;
}

.btn-fav, .btn-share {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1.5px solid var(--card-border);
    background: var(--card-bg);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-fav:hover  { color: var(--gold);    border-color: var(--gold);    background: rgba(255,215,0,.08); }
.btn-share:hover{ color: var(--primary); border-color: var(--primary); }
.btn-fav.active { color: var(--gold);    border-color: var(--gold);    background: rgba(255,215,0,.12); }

/* ─── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.badge-rank    { background: rgba(67,97,238,.2);   color: var(--accent); border: 1px solid rgba(67,97,238,.3); }
.badge-level   { background: rgba(255,215,0,.12);  color: var(--gold);   border: 1px solid rgba(255,215,0,.2); }
.badge-country { background: rgba(255,255,255,.07);color: var(--text);   border: 1px solid var(--card-border); }
.badge-small   { background: var(--card-border);   color: var(--text-muted); padding: 3px 10px; font-size: .75rem; border-radius: 12px; }

/* ─── Stats Grid ──────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    animation: fadeUp .4s ease both;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card:nth-child(1) { animation-delay: .05s; }
.stat-card:nth-child(2) { animation-delay: .10s; }
.stat-card:nth-child(3) { animation-delay: .15s; }
.stat-card:nth-child(4) { animation-delay: .20s; }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(67,97,238,.15);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.stat-body  { flex: 1; min-width: 0; }
.stat-label { display: block; font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.stat-sub   { display: block; font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

.stat-bar-wrap {
    height: 4px;
    background: rgba(255,255,255,.1);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}
.stat-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 2px;
    transition: width .6s cubic-bezier(.4,0,.2,1);
}

/* ─── Mid Grid ────────────────────────────────────────────────────────────── */
.mid-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
    margin-bottom: 20px;
}

/* ─── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    animation: fadeUp .4s ease both;
    animation-delay: .25s;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--card-border);
    flex-wrap: wrap;
    gap: 10px;
}
.card-header h3 {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-header h3 i { color: var(--primary); }

/* ─── Chart ───────────────────────────────────────────────────────────────── */
.chart-note { font-size: .78rem; color: var(--text-muted); }

.chart-container {
    padding: 24px 22px 12px;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: .9rem;
    padding: 20px;
}
.chart-empty i { font-size: 2rem; opacity: .4; display: block; margin-bottom: 10px; }

.chart-legend {
    padding: 8px 22px 16px;
    display: flex;
    gap: 16px;
    font-size: .78rem;
    color: var(--text-muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot  { width: 8px; height: 8px; border-radius: 50%; }

/* ─── Contributors ────────────────────────────────────────────────────────── */
.contribs-list {
    list-style: none;
    padding: 8px 0;
    max-height: 380px;
    overflow-y: auto;
}
.contribs-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    transition: background var(--transition);
    border-bottom: 1px solid var(--card-border);
}
.contribs-list li:last-child { border-bottom: none; }
.contribs-list li:hover { background: var(--row-hover); }

.contrib-rank {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background: var(--card-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 700;
    flex-shrink: 0;
    color: var(--text-muted);
}
.contrib-rank.gold   { background: rgba(255,215,0,.2);   color: var(--gold);   }
.contrib-rank.silver { background: rgba(192,192,192,.2); color: var(--silver); }
.contrib-rank.bronze { background: rgba(205,127,50,.2);  color: var(--bronze); }

.contrib-info  { flex: 1; min-width: 0; }
.contrib-id    { font-size: .82rem; font-weight: 600; }
.contrib-bar-wrap { height: 3px; background: rgba(255,255,255,.08); border-radius: 2px; margin-top: 4px; }
.contrib-bar   { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 2px; }
.contrib-pts   { font-size: .85rem; font-weight: 700; color: var(--accent); flex-shrink: 0; }

/* ─── Members table ───────────────────────────────────────────────────────── */
.members-card  { margin-bottom: 20px; }

.members-filters {
    display: flex;
    gap: 6px;
}
.filter-btn {
    background: none;
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    border-radius: 20px;
    padding: 5px 14px;
    font-size: .78rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.filter-btn.active, .filter-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.members-table-wrap {
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}
.members-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}
.members-table th {
    position: sticky;
    top: 0;
    background: var(--card-bg);
    padding: 12px 16px;
    text-align: left;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--card-border);
    z-index: 1;
}
.members-table td {
    padding: 11px 16px;
    border-bottom: 1px solid var(--card-border);
    vertical-align: middle;
}
.members-table tr:last-child td { border-bottom: none; }
.members-table tbody tr:hover   { background: var(--row-hover); }

.role-badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.role-owner   { background: rgba(255,215,0,.15);   color: var(--gold);   }
.role-officer { background: rgba(72,149,239,.15);  color: var(--accent); }
.role-member  { background: rgba(255,255,255,.07); color: var(--text-muted); }

/* ─── Nearby ──────────────────────────────────────────────────────────────── */
.nearby-card   { margin-bottom: 20px; }
.nearby-list   { padding: 12px 0; }

.nearby-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 22px;
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
    transition: background var(--transition);
    text-decoration: none;
    color: var(--text);
}
.nearby-item:last-child  { border-bottom: none; }
.nearby-item:hover       { background: var(--row-hover); }
.nearby-item.is-current  {
    background: rgba(67,97,238,.1);
    border-left: 3px solid var(--primary);
    padding-left: 19px;
}

.nearby-rank {
    width: 36px;
    text-align: right;
    font-weight: 700;
    font-size: .9rem;
    color: var(--text-muted);
    flex-shrink: 0;
}
.nearby-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
}
.nearby-icon img { width: 100%; height: 100%; object-fit: cover; display: none; }

.nearby-info  { flex: 1; }
.nearby-name  { font-weight: 700; font-size: .9rem; }
.nearby-pts   { font-size: .78rem; color: var(--text-muted); }

.nearby-gap {
    font-size: .78rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 10px;
    flex-shrink: 0;
}
.gap-above { background: rgba(76,175,80,.12);  color: var(--success); }
.gap-below { background: rgba(244,67,54,.12);  color: var(--danger);  }
.gap-self  { background: rgba(67,97,238,.15);  color: var(--primary); }

/* ─── History panel ───────────────────────────────────────────────────────── */
.history-panel { margin-bottom: 20px; }

.history-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 20px;
}

.history-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 7px 14px;
    font-size: .85rem;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text);
}
.history-chip:hover { border-color: var(--primary); color: var(--primary); }
.chip-fallback {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .65rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}
.chip-time { font-size: .72rem; color: var(--text-muted); margin-left: 2px; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn-ghost {
    background: none;
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    padding: 7px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: .85rem;
    transition: all var(--transition);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

.btn-ghost-sm {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: .8rem;
    font-family: inherit;
    transition: color var(--transition);
    padding: 2px 4px;
}
.btn-ghost-sm:hover { color: var(--danger); }

/* ─── Toast ───────────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text);
    padding: 12px 22px;
    border-radius: 10px;
    font-size: .88rem;
    font-weight: 500;
    box-shadow: var(--shadow);
    transform: translateY(20px);
    opacity: 0;
    transition: all .25s ease;
    pointer-events: none;
    z-index: 9999;
}
.toast.visible { transform: translateY(0); opacity: 1; }

/* ─── Footer ──────────────────────────────────────────────────────────────── */
footer {
    text-align: center;
    padding: 24px 0 8px;
    color: var(--text-muted);
    font-size: .82rem;
    border-top: 1px solid var(--card-border);
    margin-top: 40px;
}
footer i      { color: var(--danger); }
footer strong { color: var(--text); }

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
    .mid-grid { grid-template-columns: 1fr; }
    h1 { font-size: 1.6rem; }
    .hero-content { padding: 20px; gap: 16px; }
    .hero-avatar  { width: 72px; height: 72px; }
}
@media (max-width: 560px) {
    .page-wrapper  { padding: 0 12px 40px; }
    .stats-grid    { grid-template-columns: 1fr 1fr; }
    .hero-actions  { flex-direction: row; }
}
/* ─── Member username cells ───────────────────────────────────────────────── */
.member-name-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.member-username {
    font-weight: 600;
    font-size: .9rem;
    line-height: 1.2;
}
.member-uid {
    font-size: .72rem;
    color: var(--text-muted);
    font-family: monospace;
}
.username-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.username-link:hover { text-decoration: underline; }

/* ─── Name skeleton loader ────────────────────────────────────────────────── */
.name-skeleton {
    display: inline-block;
    width: 90px;
    height: 13px;
    border-radius: 6px;
    background: linear-gradient(90deg,
        var(--input-bg) 25%,
        var(--card-border) 50%,
        var(--input-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    vertical-align: middle;
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── Battle points bar in members table ─────────────────────────────────── */
.pts-cell {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 80px;
}
.pts-bar-wrap {
    height: 4px;
    background: rgba(255,255,255,.08);
    border-radius: 3px;
    overflow: hidden;
}
.pts-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 3px;
    transition: width .4s ease;
}

/* ─── Member avatar in table ──────────────────────────────────────────────── */
.member-avatar-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}
.member-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--input-bg);
    border: 2px solid var(--card-border);
}
.member-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.member-avatar-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .9rem;
    color: var(--accent);
    background: var(--primary-dim, rgba(99,102,241,.15));
}
.avatar-skeleton {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
        var(--input-bg) 25%,
        var(--card-border) 50%,
        var(--input-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 50%;
}
.member-name-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}