:root {
    --bg: #f0f2f5;
    --bg-card: #ffffff;
    --bg-card-hover: #f8f9fa;
    --text: #1a1d23;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border: #e2e8f0;
    --primary: #3b6fd4;
    --primary-fg: #ffffff;
    --primary-light: rgba(59, 111, 212, 0.1);
    --gold: #d4940a;
    --gold-light: rgba(212, 148, 10, 0.1);
    --green: #38a169;
    --green-light: rgba(56, 161, 105, 0.08);
    --red: #e53e3e;
    --red-light: rgba(229, 62, 62, 0.08);
    --purple: #805ad5;
    --input-bg: #ffffff;
    --input-border: #cbd5e0;
    --header-bg: #ffffff;
    --header-border: #e2e8f0;
    --badge-bg: #edf2f7;
    --badge-text: #4a5568;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --radius: 8px;
    --radius-sm: 6px;
}

.dark {
    --bg: #0f1318;
    --bg-card: #171c24;
    --bg-card-hover: #1e2530;
    --text: #e2e8f0;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --border: #2d3748;
    --primary: #4a7fe5;
    --primary-fg: #ffffff;
    --primary-light: rgba(74, 127, 229, 0.12);
    --gold: #d69e2e;
    --gold-light: rgba(214, 158, 46, 0.12);
    --green: #48bb78;
    --green-light: rgba(72, 187, 120, 0.1);
    --red: #fc8181;
    --red-light: rgba(252, 129, 129, 0.1);
    --purple: #b794f4;
    --input-bg: #1a202c;
    --input-border: #4a5568;
    --header-bg: #141920;
    --header-border: #2d3748;
    --badge-bg: #2d3748;
    --badge-text: #a0aec0;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.25);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

h1, h2, h3, h4, .font-heading {
    font-family: 'Oxanium', sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

.top-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: var(--primary-fg);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-badge {
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
}

.clan-badge-lg {
    width: 56px;
    height: 56px;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-text {
    font-family: 'Oxanium', sans-serif;
    font-weight: 700;
    font-size: 14px;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

.nav-btn.active {
    background: var(--badge-bg);
    color: var(--text);
}

.nav-btn.icon-btn {
    padding: 8px;
}

.nav-label {
    display: none;
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.copyright-text {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.6;
    white-space: nowrap;
    user-select: none;
}

.icon-sun, .icon-moon { display: none; }
.dark .icon-sun { display: block; }
html:not(.dark) .icon-moon { display: block; }

.main-content {
    padding: 24px 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
}

.card-body {
    padding: 16px;
}

.card-body.no-pt {
    padding-top: 0;
}

.card-body.flush {
    padding: 0;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-card .stat-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-card .stat-value {
    font-family: 'Oxanium', sans-serif;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-card .stat-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.detail-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.detail-row + .detail-row {
    border-top: 1px solid var(--border);
}

.detail-label {
    font-size: 13px;
    color: var(--text-muted);
}

.detail-value {
    font-size: 13px;
    font-weight: 600;
}

.member-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    transition: background 0.15s;
    cursor: pointer;
}

.member-row:hover {
    background: var(--bg-card-hover);
}

.member-row + .member-row {
    border-top: 1px solid var(--border);
}

.rank-num {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    width: 20px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.rank-change {
    flex-shrink: 0;
    width: 12px;
    display: flex;
    align-items: center;
}

.rank-up { color: var(--green); }
.rank-down { color: var(--red); }
.rank-same { color: var(--text-muted); }

.member-info {
    flex: 1;
    min-width: 0;
}

.member-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.member-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
    flex-wrap: wrap;
}

.member-meta span {
    font-size: 11px;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.member-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.member-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.member-stat-val {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.member-stat-label {
    font-size: 10px;
    color: var(--text-muted);
}

.chevron {
    color: var(--text-muted);
    flex-shrink: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-default {
    background: var(--badge-bg);
    color: var(--badge-text);
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-gold {
    background: var(--gold-light);
    color: var(--gold);
}

.badge-green {
    background: var(--green-light);
    color: var(--green);
}

.badge-red {
    background: var(--red-light);
    color: var(--red);
}

.badge-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.badge-leader { background: var(--gold-light); color: var(--gold); }
.badge-coLeader { background: var(--primary-light); color: var(--primary); }
.badge-elder { background: rgba(128,90,213,0.1); color: var(--purple); }
.badge-member { background: var(--badge-bg); color: var(--badge-text); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s, background 0.15s;
    white-space: nowrap;
    font-family: inherit;
}

.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--primary);
    color: var(--primary-fg);
}

.btn-secondary {
    background: var(--badge-bg);
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-icon {
    padding: 8px;
    width: 36px;
    height: 36px;
}

.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.input-wrapper {
    position: relative;
}

.input-wrapper .input-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.input {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.input:focus {
    border-color: var(--primary);
}

.input.has-icon {
    padding-left: 36px;
}

.label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.text-link {
    color: var(--primary);
    font-size: 12px;
}

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

.icon-gold { color: var(--gold); }
.icon-green { color: var(--green); }
.icon-red { color: var(--red); }
.icon-blue { color: var(--primary); }
.icon-purple { color: var(--purple); }
.icon-muted { color: var(--text-muted); }

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-xs { font-size: 11px; }
.text-sm { font-size: 13px; }
.text-lg { font-size: 18px; }
.text-xl { font-size: 22px; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.tabular { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.shrink-0 { flex-shrink: 0; }
.min-w-0 { min-width: 0; }
.w-full { width: 100%; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.p-3 { padding: 12px; }
.p-4 { padding: 16px; }
.p-6 { padding: 24px; }
.py-4 { padding-top: 16px; padding-bottom: 16px; }

.space-y-2 > * + * { margin-top: 8px; }
.space-y-3 > * + * { margin-top: 12px; }
.space-y-4 > * + * { margin-top: 16px; }
.space-y-6 > * + * { margin-top: 24px; }

.hidden { display: none; }

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

.war-clan-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
}

.war-clan-card.our-clan {
    border-color: rgba(74, 127, 229, 0.3);
}

.rank-badge {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.rank-1 { background: rgba(214,158,46,0.15); color: var(--gold); }
.rank-2 { background: rgba(160,174,192,0.15); color: var(--text-secondary); }
.rank-3 { background: rgba(237,137,54,0.15); color: #ed8936; }
.rank-default { background: var(--badge-bg); color: var(--text-muted); }

.battle-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.battle-win {
    border-color: rgba(72,187,120,0.2);
    background: var(--green-light);
}

.battle-loss {
    border-color: rgba(252,129,129,0.2);
    background: var(--red-light);
}

.battle-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.battle-icon.win {
    background: rgba(72,187,120,0.2);
    color: var(--green);
}

.battle-icon.loss {
    background: rgba(252,129,129,0.2);
    color: var(--red);
}

.battle-icon.draw {
    background: var(--badge-bg);
    color: var(--text-muted);
}

.deck-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.deck-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.deck-card img {
    width: 56px;
    height: 56px;
    object-fit: contain;
}

.warlog-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: inherit;
    font-family: inherit;
}

.warlog-own-clan {
    background: rgba(74, 127, 229, 0.05);
}

.warlog-participants-table {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.warlog-table-header {
    display: grid;
    grid-template-columns: 36px 1fr 64px 72px;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-card-hover);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.warlog-table-row {
    display: grid;
    grid-template-columns: 36px 1fr 64px 72px;
    gap: 8px;
    padding: 6px 12px;
    font-size: 13px;
    align-items: center;
    border-top: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    transition: background 0.1s;
}

.warlog-table-row:hover {
    background: var(--bg-card-hover);
}

.warlog-table-row.warlog-inactive {
    opacity: 0.45;
}

.warlog-inactive-divider {
    padding: 6px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-card-hover);
}

.warlog-col-rank {
    text-align: center;
}

.warlog-col-battles,
.warlog-col-fame {
    text-align: right;
}

.badge-silver {
    background: rgba(160,174,192,0.15);
    color: var(--text-secondary);
}

.badge-bronze {
    background: rgba(237,137,54,0.15);
    color: #ed8936;
}

.activity-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 600px;
}

.activity-table thead th {
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.activity-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.1s;
}

.activity-table tbody tr:hover {
    background: var(--bg-card-hover);
}

.activity-table tbody tr:last-child {
    border-bottom: none;
}

.activity-col-name {
    text-align: left;
    padding: 7px 12px;
    min-width: 140px;
    max-width: 180px;
}

.activity-col-week {
    text-align: right;
    padding: 5px 10px;
    min-width: 56px;
    vertical-align: middle;
}

.activity-low-decks {
    outline: 2px solid rgba(220, 60, 60, 0.5);
    outline-offset: -2px;
}

.activity-fame {
    display: block;
    font-weight: 500;
    line-height: 1.3;
}

.activity-decks {
    display: block;
    font-size: 10px;
    opacity: 0.7;
    line-height: 1.2;
}

.activity-col-total {
    text-align: right;
    padding: 7px 12px;
    min-width: 64px;
    border-left: 2px solid var(--border);
}

.activity-member-link {
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 170px;
}

.activity-member-link:hover {
    color: var(--primary);
}

.activity-left-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
    opacity: 0.5;
}

.activity-row-left {
    opacity: 0.5;
}

.message-box {
    text-align: center;
    padding: 32px 16px;
}

.message-box svg {
    margin: 0 auto 12px;
    color: var(--text-muted);
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}

.alert-success {
    background: var(--green-light);
    color: var(--green);
    border: 1px solid rgba(72,187,120,0.2);
}

.alert-error {
    background: var(--red-light);
    color: var(--red);
    border: 1px solid rgba(252,129,129,0.2);
}

.setup-main {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.setup-container {
    width: 100%;
    max-width: 480px;
}

.setup-header {
    text-align: center;
    margin-bottom: 24px;
}

.setup-icon {
    width: 48px;
    height: 48px;
    background: var(--primary);
    color: var(--primary-fg);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.setup-divider {
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--text-muted);
    font-size: 14px;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
}

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

.donate-col {
    display: none;
}

@media (min-width: 640px) {
    .nav-label { display: inline; }
    .donate-col { display: flex; }
    .deck-grid { grid-template-columns: repeat(8, 1fr); }
}

@media (min-width: 768px) {
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
    .stat-grid-4 { grid-template-columns: repeat(4, 1fr); }
}
