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

:root {
    --bg: #0f1114;
    --surface: #1a1d23;
    --surface-hover: #22262e;
    --border: #2a2e36;
    --text: #e4e4e7;
    --text-muted: #8b8d94;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --dem: #3b82f6;
    --rep: #ef4444;
    --ind: #a855f7;
    --green: #22c55e;
    --success: #22c55e;
    --error: #ef4444;
    --radius: 8px;
}

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

header {
    text-align: center;
    padding: 2rem 1rem 1rem;
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 2rem;
    letter-spacing: 0.05em;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

main {
    max-width: 640px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* Utility */
.hidden { display: none !important; }

/* Notices */
.notice {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
}

.notice h2 {
    margin-bottom: 0.5rem;
}

.notice p {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* Buttons */
button {
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
}

.btn-primary {
    display: block;
    width: 100%;
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    margin-top: 1rem;
    transition: background 0.15s;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#btn-grant-location {
    padding: 0.6rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
}

#btn-back {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.9rem;
    padding: 0;
}

/* Race picker */
h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

.race-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.race-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.race-card:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
}

.race-card .race-name {
    font-weight: 600;
}

.race-card .race-meta {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Ranking */
.race-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.race-header h2 {
    margin-bottom: 0;
}

.instructions {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.candidate-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.candidate-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    cursor: grab;
    user-select: none;
    transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}

.candidate-card:active {
    cursor: grabbing;
}

.candidate-card.dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

.candidate-card.drag-over {
    border-color: var(--accent);
    background: var(--surface-hover);
    box-shadow: 0 0 0 1px var(--accent);
}

.candidate-rank {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-muted);
    min-width: 1.5rem;
    text-align: center;
}

.candidate-info {
    flex: 1;
}

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

.candidate-party {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    color: white;
}

.candidate-party.D { background: var(--dem); }
.candidate-party.R { background: var(--rep); }
.candidate-party.I { background: var(--ind); }
.candidate-party.G { background: var(--green); }

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

.drag-handle {
    color: var(--text-muted);
    font-size: 1.2rem;
}

/* Submit status */
#submit-status {
    margin-top: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    text-align: center;
    font-size: 0.9rem;
}

#submit-status.success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

#submit-status.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Aggregate */
.agg-race {
    margin-bottom: 1.5rem;
}

.agg-race h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.agg-meta {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
}

.agg-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0;
}

.agg-rank {
    font-weight: 700;
    min-width: 1.5rem;
    text-align: center;
}

.agg-name {
    flex: 1;
    font-weight: 500;
}

.agg-bar-wrap {
    flex: 2;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.agg-bar {
    height: 100%;
    border-radius: 4px;
    opacity: 0.8;
}

.agg-pct {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 3rem;
    text-align: right;
}
