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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f6f8;
    color: #1a1a2e;
    padding: 16px;
    min-height: 100vh;
}

.container {
    max-width: 960px;
    margin: 0 auto;
}

header {
    margin-bottom: 20px;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.subtitle {
    color: #6b7280;
    font-size: 0.875rem;
    margin-top: 4px;
}

/* Pill buttons */
.pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.pill-row--compact {
    margin-bottom: 0;
    flex-shrink: 0;
    flex-grow: 0;
}

.pill {
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    border: 2px solid #d1d5db;
    border-radius: 20px;
    background: #fff;
    color: #374151;
    cursor: pointer;
    min-height: 40px;
    transition: all 0.15s;
    white-space: nowrap;
}

.pill:hover {
    border-color: #6366f1;
    color: #6366f1;
}

.pill.active {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
}

.pill--small {
    padding: 5px 12px;
    font-size: 0.8rem;
    min-height: 32px;
}

/* Search row */
.search-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

#name-search {
    flex: 1;
    padding: 10px 14px;
    font-size: 1rem;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    min-height: 40px;
    transition: border-color 0.15s;
}

#name-search:focus {
    outline: none;
    border-color: #6366f1;
}

/* Name list */
.name-list-section {
    margin-bottom: 16px;
}

.name-list-header {
    margin-bottom: 8px;
}

.name-list-loading {
    text-align: center;
    padding: 24px;
    color: #6b7280;
    font-size: 0.9rem;
}

.name-list-loading[hidden] {
    display: none;
}

.name-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
}

.name-btn {
    padding: 7px 10px;
    font-size: 0.85rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    min-height: 38px;
    transition: background 0.1s, border-color 0.1s;
    text-align: center;
}

.name-btn:hover {
    background: #eef2ff;
    border-color: #6366f1;
}

.name-btn.active {
    background: #eef2ff;
    border-color: #6366f1;
    font-weight: 600;
}

.name-list-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 16px;
    color: #9ca3af;
    font-size: 0.875rem;
}

/* Active name chips */
.active-names {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    min-height: 0;
}

.name-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #fff;
    cursor: default;
}

.name-chip button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    opacity: 0.8;
    padding: 0 2px;
    min-width: 20px;
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.name-chip button:hover {
    opacity: 1;
}

/* Chart */
.chart-container {
    position: relative;
    width: 100%;
    height: 50vh;
    min-height: 300px;
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    border: 1px solid #e5e7eb;
    margin-bottom: 24px;
}

.loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.85);
    font-size: 0.95rem;
    color: #6b7280;
    z-index: 10;
    border-radius: 12px;
}

.loading[hidden] {
    display: none;
}

.chart-controls {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.chart-controls .pill-row {
    width: fit-content;
}

/* Year range slider */
.year-slider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding: 0 4px;
}

.year-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    min-width: 36px;
    text-align: center;
}

.range-slider {
    position: relative;
    flex: 1;
    height: 36px;
    display: flex;
    align-items: center;
}

.range-track {
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    pointer-events: none;
}

.range-fill {
    position: absolute;
    height: 4px;
    background: #6366f1;
    border-radius: 2px;
    pointer-events: none;
}

.range-slider input[type="range"] {
    position: absolute;
    left: 0;
    width: 100%;
    height: 36px;
    margin: 0;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    z-index: 2;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #6366f1;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    cursor: pointer;
    pointer-events: auto;
}

.range-slider input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #6366f1;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    cursor: pointer;
    pointer-events: auto;
}

/* Desktop */
@media (min-width: 600px) {
    body {
        padding: 32px 24px;
    }

    h1 {
        font-size: 1.75rem;
    }

    .chart-container {
        height: 55vh;
        min-height: 400px;
    }

    .name-list {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}
