:root {
    color-scheme: light;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.1);
    --danger: #dc2626;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --surface: rgba(255, 255, 255, 0.92);
    --surface-solid: #ffffff;
    --background: linear-gradient(160deg, #f8fafc 0%, #e2e8f0 45%, #f8fafc 100%);
    --shadow: 0 20px 40px rgba(15, 23, 42, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--background);
    color: var(--text-primary);
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    clip: rect(1px, 1px, 1px, 1px);
    padding: 0;
    border: 0;
    height: 1px;
    width: 1px;
    overflow: hidden;
}

/* ---------- Page ---------- */

.page {
    width: min(1040px, 100%);
    padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem) 3rem;
    display: grid;
    gap: 1.5rem;
}

.page__header {
    text-align: center;
    display: grid;
    gap: 0.5rem;
}

.page__header h1 {
    margin: 0;
    font-size: clamp(2rem, 5vw, 3rem);
    letter-spacing: -0.02em;
}

.page__header p {
    margin: 0;
    color: var(--text-secondary);
}

/* ---------- Buttons ---------- */

.btn {
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.6rem 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 140ms ease, transform 100ms ease, box-shadow 140ms ease;
}

.btn:active {
    transform: scale(0.97);
}

.btn:focus-visible,
.tabs button:focus-visible,
.link-button:focus-visible,
.attendance button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.45);
    outline-offset: 2px;
}

.btn--primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
}

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

.btn--primary:disabled {
    background: var(--text-muted);
    box-shadow: none;
    cursor: not-allowed;
}

.btn--ghost {
    background: var(--surface-solid);
    border-color: var(--border);
    color: var(--text-secondary);
}

.btn--ghost:hover {
    border-color: #cbd5e1;
    color: var(--text-primary);
}

.btn--danger:hover {
    color: var(--danger);
    border-color: #fecaca;
}

.btn--big {
    font-size: 1.25rem;
    padding: 0.85rem 2.4rem;
}

.link-button {
    border: none;
    background: none;
    padding: 0.2rem 0.3rem;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
}

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

/* ---------- Class bar ---------- */

.class-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.class-bar__select {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.class-bar__select select {
    min-width: 12rem;
    padding: 0.55rem 0.8rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-solid);
    font-weight: 600;
    color: var(--text-primary);
}

.class-bar__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ---------- Tabs ---------- */

.tabs {
    display: inline-flex;
    justify-self: center;
    padding: 4px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.06);
}

.tabs button {
    border: none;
    background: none;
    padding: 0.55rem 1.3rem;
    border-radius: 999px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
}

.tabs button[aria-selected="true"] {
    background: var(--surface-solid);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

/* ---------- Stage ---------- */

.stage {
    position: relative;
    background: var(--surface);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: clamp(1.25rem, 4vw, 2.5rem);
    min-height: 22rem;
}

.stage:fullscreen {
    border-radius: 0;
    padding: 4vh 4vw;
    background: #fff;
    overflow: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stage__fullscreen {
    position: absolute;
    top: 0.9rem;
    right: 0.9rem;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.05);
    color: var(--text-secondary);
    display: grid;
    place-items: center;
    cursor: pointer;
}

.stage__fullscreen:hover {
    background: rgba(15, 23, 42, 0.1);
    color: var(--text-primary);
}

.stage__fullscreen svg {
    width: 22px;
    height: 22px;
}

.panel {
    display: grid;
    gap: 1.25rem;
}

/* ---------- Pick ---------- */

.pick-display {
    min-height: clamp(8rem, 22vw, 14rem);
    display: grid;
    place-items: center;
    text-align: center;
}

.pick-display__name {
    font-size: clamp(2.8rem, 10vw, 7rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.05;
    overflow-wrap: anywhere;
}

.stage:fullscreen .pick-display__name {
    font-size: clamp(4rem, 14vw, 12rem);
}

.pick-display__name.is-empty {
    font-size: clamp(1.4rem, 4vw, 2rem);
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0;
}

.pick-display__name.is-rolling {
    color: var(--text-muted);
}

.pick-display__name.is-picked {
    color: var(--accent);
    animation: pop 380ms cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

@keyframes pop {
    from {
        transform: scale(0.85);
    }
    to {
        transform: scale(1);
    }
}

.pick-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 1rem 1.5rem;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
}

.toggle input {
    width: 1.15rem;
    height: 1.15rem;
    accent-color: var(--accent);
}

.pick-status {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.pick-history {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
}

.pick-history li {
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-weight: 600;
    font-size: 0.9rem;
}

/* ---------- Groups ---------- */

.group-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
}

.segmented {
    display: inline-flex;
    padding: 4px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.06);
}

.segmented label {
    cursor: pointer;
}

.segmented input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented span {
    display: block;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.segmented input:checked + span {
    background: var(--surface-solid);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.segmented input:focus-visible + span {
    outline: 3px solid rgba(37, 99, 235, 0.45);
}

.stepper {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-solid);
    overflow: hidden;
}

.stepper__btn {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
}

.stepper__btn:hover {
    background: rgba(15, 23, 42, 0.05);
}

.stepper input {
    width: 3.2rem;
    border: none;
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
    background: none;
    -moz-appearance: textfield;
    appearance: textfield;
}

.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.group-summary {
    margin: 0;
    text-align: center;
    color: var(--text-secondary);
    min-height: 1.5em;
}

.group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 0.9rem;
}

.stage:fullscreen .group-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    font-size: 1.25rem;
}

.group-card {
    --group-color: var(--accent);
    border-radius: 16px;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-top: 6px solid var(--group-color);
    padding: 0.9rem 1rem 1rem;
    animation: rise 320ms ease both;
}

.group-card h3 {
    margin: 0 0 0.5rem;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--group-color);
}

.group-card ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.25rem;
    font-weight: 600;
    font-size: 1.05em;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* ---------- Roster ---------- */

.roster {
    background: var(--surface);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: clamp(1.25rem, 4vw, 2rem);
    display: grid;
    gap: 1rem;
}

.roster__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.25rem 1rem;
}

.roster__head h2 {
    margin: 0;
    font-size: 1.3rem;
}

.roster__privacy {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.roster__body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    gap: 1.25rem;
}

.roster__input,
.roster__attendance {
    display: grid;
    gap: 0.4rem;
    align-content: start;
}

.roster__input > span,
.roster__attendance-head > span {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.roster__attendance-head .link-button {
    white-space: nowrap;
}

.roster__attendance-head small {
    font-weight: 400;
    color: var(--text-muted);
}

.roster__attendance-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
}

.roster textarea {
    width: 100%;
    resize: vertical;
    min-height: 14rem;
    padding: 0.75rem 0.9rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-solid);
    line-height: 1.5;
}

.roster textarea:focus {
    outline: 3px solid rgba(37, 99, 235, 0.3);
    border-color: var(--accent);
}

.attendance {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-content: flex-start;
}

.attendance button {
    border: 1px solid var(--border);
    background: var(--surface-solid);
    border-radius: 999px;
    padding: 0.35rem 0.8rem;
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
}

.attendance button:hover {
    border-color: #cbd5e1;
}

.attendance button[aria-pressed="true"] {
    background: rgba(15, 23, 42, 0.04);
    color: var(--text-muted);
    text-decoration: line-through;
    border-style: dashed;
}

.attendance__empty {
    color: var(--text-muted);
    font-size: 0.95rem;
}

@media (max-width: 720px) {
    .roster__body {
        grid-template-columns: 1fr;
    }

    .class-bar {
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
