:root {
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
    color: #172036;
    background: #eef2f8;
    font-synthesis: none;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    padding: 28px;
    background:
        radial-gradient(circle at top left, #dbeafe 0, transparent 34%),
        radial-gradient(circle at bottom right, #ede9fe 0, transparent 34%),
        #eef2f8;
}

button,
input {
    font: inherit;
}

button {
    color: inherit;
}

button:focus-visible,
input:focus-visible {
    outline: 3px solid rgba(91, 74, 203, 0.22);
    outline-offset: 2px;
}

.hidden {
    display: none !important;
}

.app-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
}

.auth-view {
    min-height: calc(100vh - 56px);
    display: grid;
    place-items: center;
}

.auth-card,
.topbar,
.create-card,
.list-card,
.board-card,
.players-card,
.mark-editor {
    border: 1px solid #d7deea;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 20px 50px rgba(41, 52, 78, 0.1);
}

.auth-card {
    width: min(100%, 440px);
    padding: 34px;
    border-radius: 24px;
    text-align: center;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    font-size: 25px;
    font-weight: 900;
    letter-spacing: -0.12em;
}

.brand-centered {
    justify-content: center;
    width: 58px;
    height: 58px;
    margin-bottom: 18px;
    border-radius: 17px;
    background: #f3f1ff;
}

.brand-button {
    width: 48px;
    height: 48px;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 14px;
    background: #f3f1ff;
    cursor: pointer;
}

.brand-cross,
.player-one-mark {
    color: #2563eb;
}

.brand-nought,
.player-two-mark {
    color: #db2777;
}

.eyebrow {
    margin: 0 0 7px;
    color: #5b4acb;
    font-size: 11px;
    font-weight: 850;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(28px, 5vw, 42px);
    letter-spacing: -0.045em;
}

h2 {
    margin-bottom: 8px;
    font-size: clamp(24px, 4vw, 32px);
    letter-spacing: -0.035em;
}

h3 {
    margin-bottom: 0;
    font-size: 20px;
    letter-spacing: -0.025em;
}

.auth-lead,
.welcome-row p,
.mode-panel p,
.mark-editor p {
    color: #667085;
}

.auth-lead {
    margin: 10px auto 26px;
    line-height: 1.5;
}

.auth-tabs,
.mode-switcher {
    display: grid;
    padding: 4px;
    border-radius: 12px;
    background: #eef1f6;
}

.auth-tabs {
    grid-template-columns: 1fr 1fr;
    margin-bottom: 22px;
}

.auth-tab,
.mode-button {
    padding: 10px 12px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #667085;
    font-weight: 750;
    cursor: pointer;
}

.auth-tab.active,
.mode-button.active {
    color: #172036;
    background: #fff;
    box-shadow: 0 2px 8px rgba(41, 52, 78, 0.09);
}

.auth-form {
    display: grid;
    gap: 16px;
    text-align: left;
}

label,
.field-label {
    color: #475467;
    font-size: 13px;
    font-weight: 750;
}

label > span:first-child {
    display: block;
    margin-bottom: 7px;
}

input {
    width: 100%;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 11px;
    color: #172036;
    background: #fff;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:hover,
input:focus {
    border-color: #8b7fe0;
}

.primary-button,
.secondary-button {
    padding: 12px 17px;
    border-radius: 11px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}

.primary-button {
    border: 0;
    color: #fff;
    background: #5b4acb;
}

.primary-button:hover {
    background: #4938b6;
}

.secondary-button {
    border: 1px solid #cbd5e1;
    color: #344054;
    background: #fff;
}

.secondary-button:hover {
    border-color: #8b7fe0;
    background: #f7f5ff;
}

.primary-button:active,
.secondary-button:active {
    transform: translateY(1px);
}

.primary-button:disabled,
.secondary-button:disabled {
    cursor: wait;
    opacity: 0.58;
}

.text-button,
.danger-text-button,
.back-button,
.refresh-button {
    padding: 0;
    border: 0;
    background: transparent;
    font-weight: 750;
    cursor: pointer;
}

.text-button,
.back-button,
.refresh-button {
    color: #5b4acb;
}

.danger-text-button {
    color: #b42318;
}

.form-message {
    min-height: 20px;
    margin: 16px 0 0;
    color: #b42318;
    font-size: 13px;
}

.form-message.success {
    color: #067647;
}

.topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px 18px;
    border-radius: 19px;
}

.topbar-title h1 {
    font-size: 23px;
}

.topbar-title .eyebrow {
    margin-bottom: 2px;
    font-size: 9px;
}

.account {
    display: flex;
    align-items: center;
    gap: 10px;
}

.account-copy {
    display: grid;
    justify-items: start;
    gap: 1px;
}

.account-copy strong {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-copy .text-button {
    color: #98a2b3;
    font-size: 12px;
}

.mark-button {
    display: grid;
    width: 45px;
    height: 45px;
    place-items: center;
    overflow: hidden;
    padding: 3px;
    border: 1px solid #d7deea;
    border-radius: 13px;
    background: #f8fafc;
    font-size: 23px;
    font-weight: 850;
    cursor: pointer;
}

.mark-editor {
    max-width: 470px;
    margin: 0 0 20px auto;
    padding: 17px;
    border-radius: 16px;
}

.mark-editor label {
    display: block;
    margin-bottom: 8px;
}

.mark-editor p {
    margin: 8px 0 0;
    font-size: 12px;
}

.inline-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.welcome-row {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    padding: 20px 4px;
}

.welcome-row p:last-child {
    margin-bottom: 0;
}

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

.refresh-button {
    flex: none;
    padding: 9px;
}

.create-card {
    display: grid;
    grid-template-columns: minmax(270px, 0.75fr) minmax(320px, 1.25fr);
    gap: 24px;
    margin-bottom: 20px;
    padding: 23px;
    border-radius: 20px;
}

.mode-switcher {
    grid-template-columns: 1fr;
    gap: 4px;
}

.mode-button {
    text-align: left;
}

#create-game-form {
    display: grid;
    align-content: space-between;
    gap: 18px;
}

.mode-panel {
    min-height: 72px;
}

.mode-panel p {
    margin: 4px 0 0;
    line-height: 1.5;
}

.choice-row {
    display: flex;
    gap: 9px;
    margin-top: 9px;
}

.choice-row label {
    position: relative;
    cursor: pointer;
}

.choice-row input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.choice-row span {
    display: block;
    padding: 9px 14px;
    border: 1px solid #d7deea;
    border-radius: 10px;
    background: #f8fafc;
}

.choice-row input:checked + span {
    border-color: #8b7fe0;
    color: #4938b6;
    background: #f3f1ff;
}

.game-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.list-card {
    min-height: 245px;
    padding: 21px;
    border-radius: 20px;
}

.list-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.count-badge {
    display: grid;
    min-width: 29px;
    height: 29px;
    place-items: center;
    padding: 0 7px;
    border-radius: 999px;
    color: #5b4acb;
    background: #f0edff;
    font-size: 12px;
    font-weight: 850;
}

.game-list {
    display: grid;
    gap: 9px;
}

.leaderboard-heading {
    align-items: flex-end;
}

.leaderboard-limit-form {
    display: grid;
    grid-template-columns: 72px auto;
    align-items: end;
    gap: 5px 8px;
}

.leaderboard-limit-form label {
    grid-column: 1 / -1;
}

.leaderboard-limit-form input {
    width: 72px;
    padding: 8px 10px;
}

.leaderboard-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.leaderboard-list .empty-state {
    min-height: 135px;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid #e3e8ef;
    border-radius: 13px;
    background: #fafbfc;
}

.leaderboard-rank {
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 9px;
    color: #5b4acb;
    background: #f0edff;
    font-size: 12px;
    font-weight: 850;
}

.leaderboard-login {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    color: #067647;
    font-size: 12px;
    font-weight: 800;
}

.history-card {
    min-height: 320px;
}

.history-heading {
    padding-top: 0;
}

.empty-state {
    display: grid;
    min-height: 135px;
    place-items: center;
    margin: 0;
    padding: 18px;
    border: 1px dashed #d7deea;
    border-radius: 13px;
    color: #98a2b3;
    text-align: center;
}

.game-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    border: 1px solid #e3e8ef;
    border-radius: 13px;
    background: #fafbfc;
}

.game-list-copy {
    min-width: 0;
}

.game-list-copy strong,
.game-list-copy span {
    display: block;
}

.game-list-copy strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-list-copy span {
    margin-top: 3px;
    color: #667085;
    font-size: 12px;
}

.game-list-actions {
    display: flex;
    flex: none;
    align-items: center;
    gap: 8px;
}

.small-button {
    padding: 8px 11px;
    font-size: 12px;
}

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 5px;
    border-radius: 50%;
    background: #98a2b3;
}

.status-dot.active {
    background: #12b76a;
}

.status-dot.waiting {
    background: #f79009;
}

.back-button {
    margin: 8px 0 17px;
}

.game-layout {
    display: grid;
    grid-template-columns: minmax(390px, 1.25fr) minmax(290px, 0.75fr);
    gap: 20px;
}

.board-card,
.players-card {
    border-radius: 22px;
}

.board-card {
    min-height: 525px;
    padding: 28px;
}

.players-card {
    align-self: start;
    padding: 25px;
}

.status {
    min-height: 29px;
    margin: 0 0 20px;
    text-align: center;
    font-size: 18px;
    font-weight: 800;
}

.status.error {
    color: #b42318;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: min(100%, 350px);
    margin: 0 auto;
}

.cell {
    aspect-ratio: 1;
    overflow: hidden;
    padding: 4px;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    background: #f8fafc;
    color: #172036;
    font-size: clamp(32px, 8vw, 57px);
    font-weight: 850;
    line-height: 1;
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease,
        transform 120ms ease;
}

.cell:hover:not(:disabled) {
    border-color: #5b4acb;
    background: #f0edff;
    transform: translateY(-1px);
}

.cell:disabled {
    cursor: default;
}

.cell.player-one {
    color: #2563eb;
}

.cell.player-two {
    color: #db2777;
}

.game-id {
    min-height: 16px;
    margin: 18px 0 0;
    overflow-wrap: anywhere;
    color: #98a2b3;
    font-size: 11px;
    text-align: center;
}

.players-card h2 {
    margin-bottom: 23px;
}

.player-list {
    display: grid;
    gap: 10px;
}

.player-row {
    display: grid;
    grid-template-columns: 54px 1fr;
    align-items: center;
    gap: 12px;
    padding: 13px;
    border: 1px solid #e3e8ef;
    border-radius: 14px;
    background: #fafbfc;
}

.player-row.current {
    border-color: #8b7fe0;
    background: #f7f5ff;
}

.player-mark {
    display: grid;
    width: 52px;
    height: 52px;
    place-items: center;
    overflow: hidden;
    border-radius: 12px;
    background: #fff;
    font-size: 28px;
    font-weight: 850;
}

.player-row strong,
.player-row div > span {
    display: block;
}

.player-row div > span {
    margin-top: 3px;
    color: #98a2b3;
    font-size: 12px;
}

.versus {
    color: #98a2b3;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-align: center;
    text-transform: uppercase;
}

.waiting-actions,
.finish-actions,
.repeat-actions {
    display: grid;
    gap: 10px;
    margin-top: 21px;
}

.finish-game-button {
    padding: 11px 16px;
    border: 1px solid #fecdca;
    border-radius: 11px;
    color: #b42318;
    background: #fff;
    font-weight: 800;
    cursor: pointer;
    transition: background 120ms ease, opacity 120ms ease;
}

.finish-game-button:hover {
    background: #fff4f2;
}

.finish-game-button:disabled {
    cursor: wait;
    opacity: 0.58;
}

.mark-dialog {
    width: min(430px, calc(100% - 28px));
    padding: 0;
    border: 0;
    border-radius: 21px;
    color: #172036;
    box-shadow: 0 28px 80px rgba(23, 32, 54, 0.28);
}

.mark-dialog::backdrop {
    background: rgba(23, 32, 54, 0.48);
    backdrop-filter: blur(4px);
}

.dialog-card {
    padding: 27px;
}

.dialog-card > p:not(.eyebrow) {
    color: #667085;
    line-height: 1.5;
}

.dialog-card label {
    display: block;
    margin-bottom: 7px;
}

.dialog-actions {
    display: grid;
    gap: 9px;
    margin-top: 18px;
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 20;
    max-width: min(380px, calc(100% - 44px));
    padding: 13px 16px;
    border-radius: 12px;
    color: #fff;
    background: #172036;
    box-shadow: 0 14px 35px rgba(23, 32, 54, 0.24);
    font-size: 13px;
    font-weight: 700;
}

.toast.error {
    background: #b42318;
}

@media (max-width: 820px) {
    body {
        padding: 16px;
    }

    .auth-view {
        min-height: calc(100vh - 32px);
    }

    .create-card,
    .game-layout {
        grid-template-columns: 1fr;
    }

    .mode-switcher {
        grid-template-columns: repeat(3, 1fr);
    }

    .mode-button {
        text-align: center;
    }

    .players-card {
        order: -1;
    }

    .player-list {
        grid-template-columns: 1fr auto 1fr;
        align-items: center;
    }

    .player-row {
        grid-template-columns: 42px 1fr;
        padding: 10px;
    }

    .player-mark {
        width: 40px;
        height: 40px;
        font-size: 22px;
    }
}

@media (max-width: 620px) {
    body {
        padding: 10px;
    }

    .auth-card {
        padding: 27px 19px;
        border-radius: 19px;
    }

    .topbar {
        grid-template-columns: auto 1fr;
        padding: 12px;
    }

    .topbar-title .eyebrow {
        display: none;
    }

    .topbar-title h1 {
        font-size: 20px;
    }

    .account {
        grid-column: 1 / -1;
        justify-content: flex-end;
        padding-top: 9px;
        border-top: 1px solid #eef1f6;
    }

    .game-columns {
        grid-template-columns: 1fr;
    }

    .welcome-row {
        align-items: start;
    }

    .lobby-actions {
        align-items: flex-end;
        flex-direction: column;
    }

    .leaderboard-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .create-card,
    .list-card,
    .board-card,
    .players-card {
        padding: 18px;
        border-radius: 17px;
    }

    .mode-switcher {
        grid-template-columns: 1fr;
    }

    .mode-button {
        text-align: left;
    }

    .board-card {
        min-height: auto;
    }

    .game-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .player-list {
        grid-template-columns: 1fr;
    }

    .game-list-item {
        align-items: flex-start;
        flex-direction: column;
    }

    .game-list-actions {
        width: 100%;
    }

    .game-list-actions .primary-button,
    .game-list-actions .secondary-button {
        flex: 1;
    }

    .inline-form {
        grid-template-columns: 1fr;
    }
}
