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

html, body {
    margin: 0;
    padding: 0;
}

[hidden] {
    display: none !important;
}

/* ── Tokens ── */
:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-muted: #f0f2f7;
    --text: #1b1d24;
    --muted: #6b7080;
    --border: #e1e4ec;
    --primary: #2f5bff;
    --primary-hover: #2449d8;
    --truth: #2f5bff;
    --truth-soft: #e8edff;
    --dare: #f0475a;
    --dare-soft: #ffe9ec;
    --male: #2f7dd1;
    --female: #d1408f;
    --danger: #d1242f;
    --ok: #1a7f37;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12131a;
        --surface: #1b1d26;
        --surface-muted: #242733;
        --text: #eceef4;
        --muted: #9095a6;
        --border: #2e3240;
        --primary: #5b7cff;
        --primary-hover: #7591ff;
        --truth: #6b88ff;
        --truth-soft: #232c4d;
        --dare: #ff6474;
        --dare-soft: #4a2229;
        --male: #6aa8ef;
        --female: #ef7cba;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    }
}

body {
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

h1, h2, h3 {
    margin: 0;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 20px;
    font-weight: 700;
}

h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 12px;
}

.muted {
    color: var(--muted);
}

/* ── Buttons & Inputs ── */
.btn {
    font: inherit;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 9px 16px;
    cursor: pointer;
    background: var(--surface-muted);
    color: var(--text);
    transition: background .15s, border-color .15s, transform .05s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: .5;
    cursor: default;
}

.btn.primary {
    background: var(--primary);
    color: #fff;
}

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

.btn.ghost {
    background: transparent;
    border-color: var(--border);
}

.btn.ghost:hover:not(:disabled) {
    background: var(--surface-muted);
}

.btn.danger {
    background: var(--danger);
    color: #fff;
}

.btn.danger-ghost {
    background: transparent;
    color: var(--danger);
    border-color: var(--border);
}

.btn.danger-ghost:hover {
    background: var(--dare-soft);
}

.btn.small {
    padding: 6px 12px;
    font-size: 13px;
}

.btn.btn-block {
    width: 100%;
}

.btn.btn-lg {
    padding: 14px 28px;
    font-size: 17px;
    border-radius: var(--radius-md);
}

.icon-btn {
    font: inherit;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    font-size: 18px;
    line-height: 1;
    flex: none;
}

.icon-btn:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.input, .select, input[type=text], input[type=email], input[type=password], input[type=search], textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    width: 100%;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.select {
    width: auto;
    cursor: pointer;
}

input:focus, textarea:focus, .select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

textarea {
    resize: vertical;
    line-height: 1.5;
}

.field {
    display: grid;
    gap: 6px;
}

.field > span {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.form-stack {
    display: grid;
    gap: 14px;
    margin-top: 20px;
}

.form-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.form-error {
    color: var(--danger);
    background: var(--dare-soft);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
}

.notice {
    background: var(--surface-muted);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 14px;
    color: var(--muted);
}

.kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 5px;
    border: 1px solid currentColor;
    opacity: .6;
}

.kbd.light {
    border-color: rgba(255, 255, 255, .6);
}

.segmented {
    display: inline-flex;
    background: var(--surface-muted);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
}

.segmented button {
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
}

.segmented button.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .1);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow);
}

/* ── Brand ── */
.brand-mark {
    display: inline-flex;
    font-weight: 800;
    font-size: 22px;
    border-radius: 12px;
    overflow: hidden;
}

.brand-mark span {
    width: 40px;
    height: 44px;
    display: grid;
    place-items: center;
    color: #fff;
}

.brand-mark.small {
    font-size: 13px;
    border-radius: 7px;
}

.brand-mark.small span {
    width: 22px;
    height: 26px;
}

.brand-t {
    background: var(--truth);
}

.brand-d {
    background: var(--dare);
}

/* ── Loading & Auth ── */
.loading-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

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

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

.auth-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(400px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 32px;
    box-shadow: var(--shadow);
}

.auth-title {
    font-size: 26px;
    font-weight: 800;
    margin: 18px 0 6px;
}

/* ── App Shell ── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 24px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

.tabs {
    display: flex;
    gap: 4px;
    flex: 1;
}

.tab {
    font: inherit;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.tab:hover {
    color: var(--text);
}

.tab:focus-visible, .btn:focus-visible, .choice-btn:focus-visible, .segmented button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.tab.active {
    color: var(--text);
    background: var(--surface-muted);
}

.account {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.view {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 24px 48px;
}

.view-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.view-head p {
    margin: 4px 0 0;
}

.toolbar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 18px;
}

.toolbar .search {
    width: 240px;
    margin-left: auto;
}

/* ── Player Editor ── */
.player-editor {
    display: grid;
    gap: 8px;
}

.player-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.player-row input {
    flex: 1;
}

.gender-toggle {
    display: inline-flex;
    background: var(--surface-muted);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
    flex: none;
}

.gender-toggle button {
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
}

.gender-toggle button.active[data-value=MALE] {
    background: var(--male);
    color: #fff;
}

.gender-toggle button.active[data-value=FEMALE] {
    background: var(--female);
    color: #fff;
}

.player-editor-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    font-size: 14px;
}

/* ── Setup ── */
.setup {
    display: grid;
    place-items: start center;
}

.setup-card {
    width: min(620px, 100%);
    display: grid;
    gap: 18px;
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ── Game ── */
.game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 24px;
    align-items: start;
}

.stage {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    min-height: min(640px, calc(100vh - 140px));
    padding: 48px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 12px;
    transition: background .3s;
}

.stage.truth {
    background: linear-gradient(180deg, var(--truth-soft), var(--surface) 70%);
}

.stage.dare {
    background: linear-gradient(180deg, var(--dare-soft), var(--surface) 70%);
}

.stage-turn {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
}

.stage-player {
    font-size: clamp(40px, 6vw, 72px);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.05;
}

.stage-player.male {
    color: var(--male);
}

.stage-player.female {
    color: var(--female);
}

.stage-choose, .stage-show {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    width: 100%;
    animation: rise .35s ease;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

.stage-question {
    font-size: 22px;
    color: var(--muted);
}

.choice-buttons {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.choice-btn {
    font: inherit;
    width: 240px;
    height: 150px;
    border-radius: var(--radius-lg);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    box-shadow: var(--shadow);
    transition: transform .12s, filter .12s;
}

.choice-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    filter: brightness(1.05);
}

.choice-btn:disabled {
    opacity: .6;
    cursor: default;
}

.choice-btn.truth {
    background: var(--truth);
}

.choice-btn.dare {
    background: var(--dare);
}

.choice-label {
    font-size: 28px;
    font-weight: 800;
}

.choice-btn .kbd {
    border-color: rgba(255, 255, 255, .7);
    opacity: .85;
}

.choice-pill {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 6px 14px;
    border-radius: 999px;
    color: #fff;
}

.choice-pill.truth {
    background: var(--truth);
}

.choice-pill.dare {
    background: var(--dare);
}

.stage-text {
    font-size: clamp(24px, 3vw, 38px);
    font-weight: 600;
    line-height: 1.35;
    max-width: 900px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.game-side {
    display: grid;
    gap: 16px;
    position: sticky;
    top: 84px;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    font-size: 13px;
    font-weight: 600;
    padding: 4px 10px 4px 8px;
    border-radius: 999px;
    background: var(--surface-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chip::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
}

.chip.male::before {
    background: var(--male);
}

.chip.female::before {
    background: var(--female);
}

.chip.active {
    background: var(--text);
    color: var(--surface);
}

.history-card {
    max-height: calc(100vh - 380px);
    min-height: 160px;
    overflow-y: auto;
}

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

.history li {
    font-size: 14px;
    line-height: 1.4;
    padding-left: 10px;
    border-left: 3px solid var(--border);
}

.history li.truth {
    border-left-color: var(--truth);
}

.history li.dare {
    border-left-color: var(--dare);
}

.history-meta {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 2px;
}

.side-actions {
    display: flex;
    gap: 10px;
}

.side-actions .btn {
    flex: 1;
}

/* ── Questions ── */
.question-list {
    display: grid;
    gap: 10px;
}

.question-item {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color .15s;
}

.question-item:hover {
    border-color: var(--primary);
}

.question-badges {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: none;
    width: 92px;
}

.badge {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 3px 8px;
    border-radius: 6px;
    text-align: center;
    background: var(--surface-muted);
    color: var(--muted);
}

.badge.truth {
    background: var(--truth-soft);
    color: var(--truth);
}

.badge.dare {
    background: var(--dare-soft);
    color: var(--dare);
}

.question-text {
    flex: 1;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.token {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .88em;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--surface-muted);
    color: var(--primary);
}

.token.invalid {
    color: var(--danger);
    background: var(--dare-soft);
}

.empty {
    text-align: center;
    padding: 56px 24px;
    color: var(--muted);
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
}

.empty strong {
    display: block;
    color: var(--text);
    font-size: 17px;
    margin-bottom: 6px;
}

/* ── Import ── */
.head-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.dropzone {
    display: grid;
    justify-items: center;
    gap: 4px;
    padding: 28px 20px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: center;
    transition: border-color .15s, background .15s;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: var(--truth-soft);
}

.dropzone-file {
    margin-top: 8px;
    font-weight: 600;
    color: var(--primary);
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .9em;
    background: var(--surface-muted);
    padding: 1px 5px;
    border-radius: 4px;
}

.format-example {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    line-height: 1.6;
    background: var(--surface-muted);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin: 10px 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#import-format .muted {
    margin: 10px 0;
}

.import-stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.stat {
    font-size: 13px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--muted);
}

.stat.ok {
    background: color-mix(in srgb, var(--ok) 14%, transparent);
    color: var(--ok);
}

.stat.error {
    background: var(--dare-soft);
    color: var(--danger);
}

.import-errors {
    background: var(--dare-soft);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 13px;
    max-height: 160px;
    overflow-y: auto;
    display: grid;
    gap: 6px;
}

.import-errors div {
    color: var(--danger);
}

.import-errors code {
    display: block;
    margin-top: 2px;
    color: var(--text);
    background: transparent;
    padding: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.import-preview {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 260px;
    overflow-y: auto;
    display: grid;
    gap: 6px;
}

.import-preview li {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 14px;
    line-height: 1.45;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
}

.import-preview li.duplicate {
    opacity: .5;
}

.import-preview .question-badges {
    width: 78px;
}

.import-preview .question-text {
    flex: 1;
}

/* ── Player Lists ── */
.list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.list-card {
    cursor: pointer;
    display: grid;
    gap: 12px;
    transition: border-color .15s;
}

.list-card:hover {
    border-color: var(--primary);
}

.list-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.list-card-head strong {
    font-size: 17px;
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(10, 12, 20, .45);
    display: grid;
    place-items: center;
    padding: 24px;
    animation: fade .15s ease;
}

@keyframes fade {
    from {
        opacity: 0;
    }
}

.modal {
    width: min(680px, 100%);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    display: grid;
    gap: 18px;
    padding: 28px;
}

.modal.small {
    width: min(420px, 100%);
}

.modal p {
    margin: 0;
}

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

.spacer {
    flex: 1;
}

.token-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: -8px;
}

.token-btn {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--primary);
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
}

.token-btn:hover {
    background: var(--surface-muted);
}

.legend {
    font-size: 14px;
}

.legend summary {
    cursor: pointer;
    color: var(--muted);
    font-weight: 500;
}

.legend dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 14px;
    margin: 12px 0;
}

.legend dt {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 600;
    color: var(--primary);
}

.legend dd {
    margin: 0;
}

.preview {
    background: var(--surface-muted);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}

.preview-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 8px;
}

.preview-head .muted {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
}

.preview-text {
    line-height: 1.5;
    min-height: 1.5em;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.preview-name {
    font-weight: 700;
}

.preview-name.male {
    color: var(--male);
}

.preview-name.female {
    color: var(--female);
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: grid;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--text);
    color: var(--surface);
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow);
    animation: rise .2s ease;
}

.toast.error {
    background: var(--danger);
    color: #fff;
}

/* ── Fullscreen ── */
:fullscreen .topbar {
    display: none;
}

:fullscreen .view {
    max-width: none;
}

:fullscreen .stage {
    min-height: calc(100vh - 56px);
}

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

    .game-side {
        position: static;
    }

    .topbar {
        flex-wrap: wrap;
        gap: 12px;
    }

    .account-email {
        display: none;
    }

    .toolbar .search {
        width: 100%;
        margin-left: 0;
    }
}
