:root {
    --bg: #c8ccd6;
    --shadow-dark: #a0a4ae;
    --shadow-light: #f0f4fc;
    --text-primary: #2a3040;
    --text-secondary: #505868;
    --text-muted: #808898;
    --accent: #5a7aed;
    --danger: #c0392b;
    --neu-raised: 5px 5px 10px var(--shadow-dark), -5px -5px 10px var(--shadow-light);
    --neu-raised-sm: 3px 3px 6px var(--shadow-dark), -3px -3px 6px var(--shadow-light);
    --neu-pressed: inset 3px 3px 6px var(--shadow-dark), inset -3px -3px 6px var(--shadow-light);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background:
        radial-gradient(ellipse at 20% 10%, rgba(255,255,255,0.35) 0%, transparent 50%),
        repeating-linear-gradient(
            135deg,
            rgba(255,255,255,0.12) 0px,
            rgba(255,255,255,0) 1px,
            rgba(0,0,0,0.08) 1px,
            rgba(0,0,0,0) 2px
        ),
        linear-gradient(135deg, #f0f2f6 0%, #d8dce4 25%, #c4c8d2 50%, #aeb2bc 80%, #a0a4ae 100%);
    background-attachment: fixed;
    min-height: 100vh;
    color: var(--text-secondary);
    line-height: 1.6;
    padding-top: 56px;
}

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

/* ── Header ── */
header {
    background: var(--bg);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--neu-raised);
}

header h1 {
    color: var(--text-primary);
    text-align: center;
    font-size: 1.8rem;
    font-weight: 600;
}

/* ── Class Cards ── */
.class-cards {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.class-card {
    background: var(--bg);
    border-radius: 16px;
    width: 110px;
    height: 110px;
    min-width: 110px;
    min-height: 110px;
    max-width: 110px;
    max-height: 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-shadow: var(--neu-raised-sm);
    transition: box-shadow 0.2s, transform 0.2s;
    cursor: pointer;
    padding: 0.6rem;
}

.class-card:hover {
    box-shadow: var(--neu-pressed);
    transform: translateY(-2px);
}

.class-card.selected {
    box-shadow: var(--neu-pressed);
    border: 2px solid var(--accent);
    transform: translateY(-1px);
}

.class-card img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    margin-bottom: 4px;
    object-fit: cover;
    border: 2px solid var(--shadow-light);
}

.class-card h3 {
    color: var(--text-primary);
    margin-bottom: 2px;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.1;
}

.class-card .count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 700;
    color: var(--danger);
}

/* ── Class Colors ── */
.class-elf { border-left: 4px solid #27ae60; }
.class-royal { border-left: 4px solid #e74c3c; }
.class-witch { border-left: 4px solid #3498db; }
.class-dragon { border-left: 4px solid #f39c12; }
.class-nightmare { border-left: 4px solid #9b59b6; }
.class-bishop { border-left: 4px solid #f1c40f; }
.class-nemesis { border-left: 4px solid #1abc9c; }
.class-neutral { border-left: 4px solid #95a5a6; }

/* ── Charts ── */
.charts-section {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.chart-container {
    flex: 1 1 0;
    min-width: 300px;
    max-width: 500px;
    background: var(--bg);
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: var(--neu-raised);
}

.chart-container h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
}

.chart-container canvas {
    max-height: 300px;
}

/* ── Card Stats Section ── */
.card-stats-section {
    margin-top: 1.5rem;
    background: var(--bg);
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: var(--neu-raised);
}

.card-stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.card-stats-title-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.card-stats-header h3 {
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0;
}

.neutral-toggle {
    display: none;
    align-items: center;
    gap: 0.4rem;
    background: var(--bg);
    box-shadow: var(--neu-pressed);
    border-radius: 12px;
    padding: 0.3rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-secondary);
    border: none;
}

.neutral-toggle input {
    accent-color: var(--accent);
}

.stats-summary {
    display: flex;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.stats-summary span {
    background: var(--bg);
    box-shadow: var(--neu-pressed);
    padding: 0.3rem 0.75rem;
    border-radius: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

/* ── Card List ── */
.card-list-container {
    border-radius: 12px;
    padding: 0.75rem;
}

.card-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    min-height: 200px;
    opacity: 1;
    transition: opacity 0.1s;
}

.card-list.loading {
    opacity: 0.7;
}

.card-item {
    background: var(--bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--neu-raised-sm);
    display: flex;
    flex-direction: column;
    height: 370px;
}

.card-img-wrap {
    width: 100%;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    background: var(--shadow-dark);
    height: 70%;
}

.card-full-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem 0.25rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    min-height: 36px;
    flex-wrap: wrap;
    overflow: visible;
}

.card-name {
    flex: 1;
    text-align: left;
    font-size: 0.9rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-count {
    font-family: 'JetBrains Mono', monospace;
    color: var(--danger);
    font-size: 1rem;
    font-weight: 700;
    margin-left: 0.5rem;
}

.card-carry-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0.25rem 0.5rem 0.5rem;
    gap: 2px;
}

.card-carry-info .carry-row {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
}

.card-carry-info .trend-item {
    padding: 2px 0.5rem;
    font-size: 0.85rem;
    border-radius: 8px;
    background: var(--bg);
    box-shadow: var(--neu-pressed);
    min-width: 38px;
    text-align: center;
    white-space: nowrap;
}

.trend-num-3 { color: #e17055; font-weight: bold; }
.trend-num-2 { color: #fdcb6e; font-weight: bold; }
.trend-num-1 { color: #74b9ff; font-weight: bold; }
.trend-num-0 { color: #636e72; font-weight: bold; }

/* ── Footer ── */
.attribution {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--shadow-dark);
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.8;
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .charts-section {
        flex-direction: column;
        align-items: center;
    }
    .chart-container {
        max-width: 100%;
    }
    .class-cards {
        flex-direction: column;
        align-items: center;
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.4rem;
    }
    .card-list {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.75rem;
    }
    .card-list {
        grid-template-columns: 1fr;
    }
}
