:root {
    --pink: #ff3b9d;
    --ink: #222336;
    --paper: #f7f7fb;
    --surface: #ffffff;
    --surface-muted: #f4f3f8;
    --surface-hover: #faf9fc;
    --line: #e7e4eb;
    --muted: #6e6a77;
    --header-bg: #242638;
    --header-ink: #ffffff;
    --input-bg: #ffffff;
    --input-border: #c9c4ce;
    --secondary-bg: #565260;
    --secondary-ink: #ffffff;
    --pending-bg: #f0eff3;
    --pending-ink: #77727e;
    --overlay-bg: #181927b8;
    --shadow: #2426380a;
    --sticky-shadow: #24263824;
    --success: #168a52;
    --success-bg: #e8f7ef;
    --danger: #d52d62;
    --danger-bg: #ffedf4;
    --info: #3973b8;
    --info-bg: #ebf3ff;
}

html {
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --ink: #f2f1f7;
    --paper: #11131b;
    --surface: #1b1e29;
    --surface-muted: #262936;
    --surface-hover: #232632;
    --line: #343847;
    --muted: #aaa7b4;
    --header-bg: #171923;
    --header-ink: #f8f7fb;
    --input-bg: #141720;
    --input-border: #4a4e60;
    --secondary-bg: #454959;
    --secondary-ink: #ffffff;
    --pending-bg: #30333e;
    --pending-ink: #c5c2cc;
    --overlay-bg: #090a0ee0;
    --shadow: #00000030;
    --sticky-shadow: #00000066;
    --success: #51cf8a;
    --success-bg: #173729;
    --danger: #ff6b96;
    --danger-bg: #43202e;
    --info: #75aef0;
    --info-bg: #1c3149;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: Inter, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.45;
    text-rendering: optimizeLegibility;
    font-feature-settings: "liga" 1, "calt" 1;
}

@supports (font-variation-settings: normal) {
    body {
        font-family: InterVariable, Inter, "Segoe UI", sans-serif;
        font-optical-sizing: auto;
    }
}

header {
    height: 62px;
    background: var(--header-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 max(5vw, 24px);
}

header a {
    color: var(--header-ink);
    text-decoration: none;
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

main {
    max-width: 1240px;
    margin: 36px auto 48px;
    padding: 0 24px;
}

.hero {
    border-left: 7px solid var(--pink);
    padding: 4px 0 4px 24px;
    min-width: 0;
}

.eyebrow, .section-kicker {
    margin: 0;
    color: var(--pink);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
}

h1 {
    font-size: clamp(30px, 3vw, 38px);
    margin: 6px 0 16px;
    letter-spacing: -.025em;
}

h2 {
    margin: 3px 0 0;
    font-size: 20px;
    letter-spacing: -.01em;
}

.level {
    font-weight: 700;
}

.metric strong {
    font-size: 58px;
    color: var(--pink);
    line-height: 1;
}

.metric span {
    font-size: 20px;
}

.game-summary {
    display: flex;
    align-items: stretch;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
}

.metric {
    display: flex;
    align-items: baseline;
    align-self: center;
    gap: 4px;
    padding-right: 6px;
}

.game-timer {
    width: fit-content;
    display: grid;
    grid-template-columns: auto auto;
    align-items: center;
    column-gap: 8px;
    margin: 0;
    padding: 9px 12px;
    color: var(--ink);
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.game-timer-icon {
    grid-row: 1 / 3;
    font-size: 20px;
}

.game-timer-label {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.1;
}

.game-timer strong {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 18px;
    line-height: 1.25;
    font-variant-numeric: tabular-nums;
}

.game-timer.is-expired strong {
    color: var(--danger);
}

.remaining-stat {
    min-width: 92px;
    display: grid;
    align-content: center;
    padding: 9px 14px;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.remaining-stat span, .snapshot-time span {
    color: var(--muted);
    font-size: 11px;
}

.remaining-stat strong {
    font-size: 20px;
    line-height: 1.15;
}

.hero-footer {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px 18px;
    margin-top: 20px;
}

.hero-footer form {
    margin: 0;
}

.hero-footer .secondary {
    margin: 0;
}

.snapshot-time {
    display: grid;
    gap: 1px;
    margin: 0;
    color: var(--ink);
    font-size: 12px;
}

.snapshot-time time {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.card, .login-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 24px;
    margin-top: 26px;
    box-shadow: 0 8px 24px var(--shadow);
}

.code-form, .settings {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.settings {
    flex-wrap: wrap;
    align-items: end;
}

.settings label {
    display: grid;
    flex: 1 1 320px;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.settings .hint {
    flex-basis: 100%;
    margin: 0;
}

.settings .checkbox-field {
    display: flex;
    flex: 0 0 100%;
    align-items: center;
}

input, select, button {
    font: inherit;
    border-radius: 7px;
    padding: 11px 13px;
    border: 1px solid var(--input-border);
}

input, select {
    background: var(--input-bg);
    color: var(--ink);
}

input {
    width: 100%;
    min-width: 0;
}

button {
    border: 0;
    background: var(--pink);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

button:disabled {
    opacity: .62;
    cursor: wait;
}

.secondary {
    background: var(--secondary-bg);
    color: var(--secondary-ink);
    margin-top: 12px;
}

.danger {
    background: #b82742;
}

.hint, .notice, .empty-state, .login-copy {
    color: var(--muted);
}

.notice {
    background: color-mix(in srgb, var(--pink) 10%, var(--surface));
    padding: 14px;
    border-radius: 8px;
    transition: opacity .25s ease, transform .25s ease;
}

.notice.is-dismissing {
    opacity: 0;
    transform: translateY(-5px);
}

.notice-error {
    color: var(--danger);
    background: var(--danger-bg);
}

.login-shell {
    min-height: 68vh;
    display: grid;
    place-items: center;
}

.login-card {
    width: min(100%, 470px);
    margin: 0;
    padding: clamp(24px, 5vw, 42px);
}

.login-copy {
    margin-bottom: 24px;
}

.login-form {
    display: grid;
    gap: 16px;
}

.login-form label {
    display: grid;
    gap: 6px;
    font-size: 14px;
    font-weight: 700;
}

.login-form button {
    margin-top: 4px;
}

.login-card .hint {
    margin: 20px 0 0;
    font-size: 13px;
}

.overview-card {
    width: min(100%, 1040px);
    margin-inline: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 290px);
    gap: clamp(22px, 4vw, 46px);
    align-items: center;
    padding: clamp(22px, 3vw, 32px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 12px 36px var(--shadow);
}

.profile-card {
    min-width: 0;
    align-self: center;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: none;
}

.profile-card-copy {
    min-width: 0;
}

.profile-name {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: 10px;
}

.profile-name strong {
    max-width: 190px;
    overflow-wrap: anywhere;
}

.profile-team {
    display: grid;
    gap: 2px;
    margin: 16px 0 0 17px;
}

.profile-team span {
    color: var(--muted);
    font-size: 11px;
}

.profile-team strong {
    overflow-wrap: anywhere;
}

.profile-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px var(--success-bg);
}

.logout-form {
    margin: 0;
}

.icon-button {
    width: 38px;
    height: 38px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    padding: 8px;
    color: var(--muted);
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.icon-button:hover {
    color: var(--ink);
    background: var(--surface-hover);
}

.icon-button:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--pink) 38%, transparent);
    outline-offset: 2px;
}

.icon-button svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.header-icon-button {
    color: var(--header-ink);
    background: #ffffff14;
    border-color: #ffffff24;
}

.header-icon-button:hover {
    color: var(--header-ink);
    background: #ffffff24;
}

[data-theme-icon] {
    display: none;
}

html[data-theme-mode="light"] [data-theme-icon="light"],
html[data-theme-mode="dark"] [data-theme-icon="dark"],
html[data-theme-mode="auto"] [data-theme-icon="auto"] {
    display: block;
}

[data-theme-icon="dark"] {
    fill: currentColor;
    stroke: none;
}

[data-theme-icon="auto"] path {
    fill: currentColor;
    stroke: none;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.35fr);
    gap: 22px;
}

.code-entry-card {
    position: sticky;
    top: 10px;
    z-index: 10;
    box-shadow: 0 10px 32px var(--sticky-shadow);
}

.data-card {
    min-width: 0;
    padding: 0;
    overflow: hidden;
}

.card-heading {
    min-height: 78px;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
}

.count-badge {
    background: var(--header-bg);
    color: var(--header-ink);
    border-radius: 999px;
    padding: 7px 11px;
    font-size: 13px;
    font-weight: 800;
}

.table-scroll {
    width: 100%;
    max-width: 100%;
    max-height: 590px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
}

.codes-table-scroll {
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
}

.game-table, .admin-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    max-width: 100%;
    font-size: clamp(12px, .9vw, 13px);
}

.game-table th, .admin-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-muted);
    color: var(--muted);
    font-size: .86em;
    text-transform: uppercase;
    letter-spacing: .035em;
}

.game-table th, .game-table td, .admin-table th, .admin-table td {
    text-align: left;
    border-bottom: 1px solid var(--line);
    padding: clamp(7px, .75vw, 10px) clamp(7px, .9vw, 12px);
    vertical-align: middle;
    white-space: nowrap;
}

.game-table tbody tr:last-child td, .admin-table tbody tr:last-child td {
    border-bottom: 0;
}

.game-table tbody tr:hover td, .admin-table tbody tr:hover td {
    background: var(--surface-hover);
}

.codes-table tr.is-accepted td:first-child {
    box-shadow: inset 4px 0 var(--success);
}

.codes-table tr.is-pending td:first-child {
    box-shadow: inset 4px 0 var(--line);
}

.slot-number {
    font-weight: 800;
}

.code-value {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-weight: 700;
}

.date-cell {
    white-space: nowrap;
    color: var(--muted);
    font-size: .92em;
}

.status {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: .92em;
    font-weight: 800;
    white-space: nowrap;
}

.game-table td.result-cell, .admin-table td.result-cell {
    min-width: 180px;
    max-width: 360px;
    white-space: normal;
    overflow-wrap: anywhere;
}

.result-cell .status {
    display: inline-block;
    max-width: 100%;
    border-radius: 12px;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
}

.status.accepted {
    background: var(--success-bg);
    color: var(--success);
}

.status.rejected {
    background: var(--danger-bg);
    color: var(--danger);
}

.status.completed, .status.info {
    background: var(--info-bg);
    color: var(--info);
}

.status.pending {
    background: var(--pending-bg);
    color: var(--pending-ink);
}

.event-accepted .code-value {
    color: var(--success);
}

.event-rejected .code-value {
    color: var(--danger);
}

.event-completed .code-value {
    color: var(--info);
}

.inline {
    display: inline-flex;
    gap: 5px;
    margin: 2px;
}

.inline button, .inline select {
    padding: 6px 8px;
    font-size: 12px;
}

.inline .admin-action-button {
    margin-top: 0;
}

.code-access-form, .checkbox-field {
    align-items: center;
}

.checkbox-field {
    display: inline-flex;
    gap: 7px;
    white-space: nowrap;
}

.checkbox-field input[type="checkbox"] {
    width: auto;
    min-width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
}

.empty-state {
    padding: 4px 20px 22px;
}

.admin-card {
    padding: 0;
    overflow: hidden;
}

.admin-card > h2 {
    padding: 20px 20px 14px;
}

.admin-table-scroll {
    max-height: none;
}

.request-overlay {
    position: fixed;
    z-index: 50;
    inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(5px);
    place-items: center;
}

.request-overlay:not([hidden]) {
    display: grid;
}

.request-overlay-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--surface);
    border-radius: 14px;
    padding: 20px 24px;
    box-shadow: 0 22px 70px #0004;
}

.mini-spinner {
    width: 26px;
    height: 26px;
    border: 3px solid var(--line);
    border-top-color: var(--pink);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

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

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

@media (max-width: 760px) {
    .events-table-scroll {
        max-height: none;
        overflow: visible;
    }

    .events-table,
    .events-table tbody {
        display: block;
        width: 100%;
    }

    .events-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .events-table tbody {
        padding: 8px;
    }

    .events-table tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "time result"
            "code result"
            "user user"
            "provider provider";
        gap: 5px 12px;
        padding: 11px 12px;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 11px;
    }

    .events-table tbody tr + tr {
        margin-top: 8px;
    }

    .events-table tbody tr:hover td {
        background: transparent;
    }

    .events-table tbody td {
        display: block;
        min-width: 0;
        padding: 0;
        border: 0;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .events-table tbody td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 1px;
        color: var(--muted);
        font-family: Inter, "Segoe UI", sans-serif;
        font-size: 9px;
        font-weight: 800;
        line-height: 1.2;
        text-transform: uppercase;
        letter-spacing: .035em;
    }

    .events-table .event-time {
        grid-area: time;
        align-self: start;
    }

    .events-table .event-code {
        grid-area: code;
        color: var(--ink);
        font-size: 13px;
    }

    .events-table .event-user {
        grid-area: user;
    }

    .events-table .event-provider {
        grid-area: provider;
    }

    .game-table.events-table td.event-result {
        grid-area: result;
        align-self: start;
        min-width: 0;
        max-width: min(48vw, 230px);
        text-align: right;
    }

    .events-table .event-result::before {
        text-align: right;
    }

    .events-table .event-result .status {
        display: inline-flex;
        width: auto;
        max-width: 100%;
        justify-content: center;
        border-radius: 8px;
        padding: 5px 8px;
        white-space: normal;
        overflow-wrap: normal;
        word-break: normal;
        text-wrap: pretty;
        line-height: 1.25;
        text-align: center;
    }

    .events-table .event-provider br + .date-cell {
        display: inline-block;
        margin-top: 2px;
    }
}

@media (max-width: 680px) {
    header {
        height: 54px;
        padding: 0 14px;
        font-size: 13px;
    }

    .header-actions {
        gap: 8px;
    }

    .header-icon-button {
        width: 34px;
        height: 34px;
        padding: 7px;
    }

    main {
        margin: 22px auto;
        padding: 0 10px;
    }

    .overview-card {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        padding: 10px;
        border-radius: 14px;
    }

    .hero {
        border-left-width: 4px;
        padding: 4px 0 4px 12px;
    }

    .hero .eyebrow {
        font-size: 10px;
    }

    .hero h1 {
        margin: 2px 0 7px;
        font-size: clamp(18px, 5.8vw, 24px);
    }

    .hero .level {
        margin: 5px 0;
        font-size: 14px;
    }

    .hero .metric {
        display: flex;
        align-items: baseline;
        gap: 3px;
    }

    .hero .metric strong {
        font-size: 36px;
    }

    .hero .metric span {
        font-size: 15px;
    }

    .game-summary {
        display: grid;
        grid-template-columns: max-content max-content;
        justify-content: start;
        gap: 8px;
        margin-top: 8px;
    }

    .hero .metric {
        grid-column: 1 / -1;
        padding: 0;
    }

    .game-timer {
        padding: 6px 8px;
        column-gap: 6px;
    }

    .game-timer-icon {
        font-size: 16px;
    }

    .game-timer-label {
        font-size: 9px;
    }

    .game-timer strong {
        font-size: 14px;
    }

    .remaining-stat {
        min-width: 58px;
        padding: 5px 8px;
    }

    .remaining-stat span {
        font-size: 9px;
    }

    .remaining-stat strong {
        font-size: 16px;
    }

    .hero-footer {
        display: grid;
        gap: 6px;
        margin-top: 10px;
    }

    .hero-footer .secondary {
        padding: 8px 10px;
        font-size: 13px;
    }

    .snapshot-time {
        font-size: 9px;
        line-height: 1.25;
    }

    .snapshot-time span {
        font-size: 8px;
    }

    .profile-card {
        width: 100%;
        align-self: stretch;
        align-items: center;
        gap: 10px;
        padding: 11px 2px 2px 12px;
        background: transparent;
        border: 0;
        border-top: 1px solid var(--line);
        border-radius: 0;
    }

    .profile-card-copy {
        display: flex;
        align-items: center;
        flex: 1;
        gap: 14px;
    }

    .profile-card .eyebrow {
        display: none;
    }

    .profile-name {
        align-items: center;
        gap: 6px;
        margin: 0;
        font-size: 12px;
        line-height: 1.25;
    }

    .profile-name strong {
        max-width: none;
    }

    .profile-team {
        display: flex;
        align-items: baseline;
        gap: 4px;
        margin: 0;
        font-size: 11px;
        line-height: 1.2;
    }

    .profile-team span {
        font-size: 9px;
    }

    .profile-dot {
        width: 7px;
        height: 7px;
        margin: 0;
        flex: 0 0 auto;
    }

    .profile-icon-button {
        width: 30px;
        height: 30px;
        padding: 6px;
    }

    .card {
        padding: 16px;
    }

    .data-card, .admin-card {
        padding: 0;
    }

    .settings {
        flex-direction: column;
    }

    .code-entry-card {
        position: sticky;
        top: 6px;
        z-index: 10;
        margin: 16px -2px 0;
        padding: 12px;
        box-shadow: 0 10px 32px var(--sticky-shadow);
    }

    .code-entry-card h2 {
        font-size: 15px;
        margin-bottom: 8px;
    }

    .code-entry-card .hint {
        display: none;
    }

    .code-form {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px;
        margin-top: 0;
    }

    .code-form input, .code-form button {
        padding: 9px 8px;
        font-size: 13px;
    }

    .card-heading {
        min-height: 66px;
        padding: 13px 10px;
    }

    .table-scroll {
        overflow-x: auto;
    }

    .codes-table-scroll {
        overflow-x: auto;
        overflow-y: hidden;
    }

    .game-table, .admin-table {
        width: 100%;
        font-size: clamp(8px, 2.45vw, 10px);
    }

    .game-table th, .game-table td, .admin-table th, .admin-table td {
        padding: 6px clamp(3px, 1vw, 5px);
        letter-spacing: 0;
    }

    .status {
        padding: 3px 5px;
    }

    .codes-table th:first-child, .codes-table td:first-child {
        padding-left: 7px;
    }

    .inline {
        gap: 3px;
        margin: 1px;
    }

    .inline button, .inline select {
        padding: 4px;
        font-size: inherit;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mini-spinner {
        animation-duration: 3s;
    }
}
