:root {
    color-scheme: dark;
    --bg: #050507;
    --surface: #111114;
    --surface-raised: #1c1c1e;
    --surface-pressed: #252529;
    --line: rgba(255, 255, 255, 0.12);
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --accent: #7c5cfc;
    --accent-pressed: #6849e8;
    --status: #32d6c5;
    --danger: #ff453a;
    --warning: #ffd60a;
    --radius-shell: 32px;
    --radius-group: 24px;
    --radius-control: 14px;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
    font-synthesis: none;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-width: 320px;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
    font: inherit;
}

button,
a,
input,
textarea {
    -webkit-tap-highlight-color: transparent;
}

button {
    color: inherit;
}

img {
    display: block;
}

.app-shell {
    width: min(100% - 32px, 980px);
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    padding:
        max(18px, env(safe-area-inset-top))
        0
        max(32px, env(safe-area-inset-bottom));
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
    margin-bottom: clamp(48px, 9vw, 92px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 11px;
    background: var(--accent);
}

.brand-mark img {
    width: 22px;
    filter: brightness(0) invert(1);
}

.connection-state {
    display: inline-flex;
    min-height: 32px;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--status);
}

.connection-state.is-offline .status-dot {
    background: var(--danger);
}

.view {
    width: 100%;
}

.home-view {
    max-width: 820px;
    margin: 0 auto;
}

.intro {
    max-width: 630px;
    margin-bottom: 32px;
}

.eyebrow {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

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

h1 {
    margin: 10px 0 12px;
    font-size: clamp(42px, 8vw, 72px);
    font-weight: 750;
    letter-spacing: -0.055em;
    line-height: 0.98;
}

.intro p {
    max-width: 570px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: clamp(17px, 2.4vw, 20px);
    line-height: 1.45;
}

.entry-surface {
    display: grid;
    grid-template-columns: 1fr 1px 1fr;
    gap: 28px;
    padding: clamp(24px, 4vw, 36px);
    border: 1px solid var(--line);
    border-radius: var(--radius-shell);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.surface-separator {
    background: var(--line);
}

.entry-form {
    min-width: 0;
}

.section-heading {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}

.section-heading h2 {
    margin-bottom: 3px;
    font-size: 20px;
    letter-spacing: -0.025em;
}

.section-heading p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 13px;
}

.icon-tile {
    display: grid;
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    place-items: center;
    border-radius: 15px;
    background: var(--surface-raised);
}

.icon-tile.accent {
    background: var(--accent);
}

.icon-tile img {
    width: 24px;
    filter: brightness(0) invert(1);
}

label {
    display: block;
    margin: 0 0 8px 2px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
}

input,
textarea {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    outline: none;
    background: var(--surface-raised);
    color: var(--text);
    padding: 0 15px;
    transition: border-color 160ms ease, background-color 160ms ease;
}

textarea {
    min-height: 88px;
    resize: vertical;
    padding-top: 13px;
}

input::placeholder,
textarea::placeholder {
    color: #6e6e73;
}

input:focus,
textarea:focus {
    border-color: var(--accent);
    background: var(--surface-pressed);
}

.field-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 108px;
    gap: 12px;
}

.code-field input,
.room-code {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.11em;
}

.button {
    display: inline-flex;
    width: 100%;
    min-height: 50px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
    border: 0;
    border-radius: var(--radius-control);
    padding: 0 18px;
    font-weight: 720;
    cursor: pointer;
    transition: background-color 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.button img {
    width: 21px;
    filter: brightness(0) invert(1);
}

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

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

.button.secondary {
    background: var(--surface-raised);
}

.button.secondary:hover {
    background: var(--surface-pressed);
}

.button.danger {
    background: rgba(255, 69, 58, 0.16);
    color: #ff6961;
}

.button:active {
    transform: scale(0.985);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.46;
}

.mode-preview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    margin-top: 18px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-group);
    background: var(--line);
}

.mode-preview > div {
    display: grid;
    min-height: 104px;
    align-content: center;
    justify-items: center;
    gap: 4px;
    background: var(--bg);
}

.mode-preview strong {
    font-size: 14px;
}

.mode-preview > div > span:last-child {
    color: var(--muted);
    font-size: 12px;
}

.mode-icon {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    color: var(--accent);
    font-size: 18px;
    font-weight: 750;
}

.mode-icon img {
    width: 24px;
    filter: invert(43%) sepia(93%) saturate(2641%) hue-rotate(232deg) brightness(101%);
}

.room-view {
    max-width: 820px;
    margin: 0 auto;
}

.room-bar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 24px;
}

.room-code {
    margin: 5px 0 -4px;
    font-size: clamp(44px, 9vw, 72px);
}

.room-actions {
    display: flex;
    gap: 8px;
}

.icon-button {
    display: grid;
    width: 46px;
    min-width: 46px;
    height: 46px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--surface);
    cursor: pointer;
}

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

.icon-button.danger {
    color: var(--danger);
}

.icon-button img {
    width: 21px;
    filter: brightness(0) invert(1);
}

.icon-button.danger img {
    filter: invert(42%) sepia(98%) saturate(2171%) hue-rotate(337deg) brightness(110%);
}

.lobby-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
    gap: 16px;
}

.group {
    border: 1px solid var(--line);
    border-radius: var(--radius-group);
    background: var(--surface);
    overflow: hidden;
}

.group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 62px;
    padding: 0 20px;
    border-bottom: 1px solid var(--line);
}

.group-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 17px;
}

.group-header img {
    width: 21px;
    filter: brightness(0) invert(1);
}

.count-badge {
    min-width: 28px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--surface-raised);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.player-list {
    margin: 0;
    padding: 8px;
    list-style: none;
}

.player {
    display: flex;
    min-height: 52px;
    align-items: center;
    gap: 12px;
    padding: 7px 10px;
    border-radius: 14px;
}

.player + .player {
    border-top: 1px solid var(--line);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.avatar {
    display: grid;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 50%;
    background: var(--surface-raised);
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
}

.player-name {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    font-size: 15px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-meta {
    color: var(--muted);
    font-size: 12px;
}

.settings-body {
    display: grid;
    gap: 18px;
    padding: 20px;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    padding: 3px;
    border-radius: 15px;
    background: var(--bg);
}

.segment {
    min-height: 44px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-weight: 700;
    cursor: pointer;
}

.segment.is-active {
    background: var(--surface-raised);
    color: var(--text);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.setting-row strong {
    display: block;
    margin-bottom: 2px;
    font-size: 14px;
}

.setting-row span {
    color: var(--muted);
    font-size: 12px;
}

.switch {
    position: relative;
    width: 51px;
    height: 31px;
    flex: 0 0 auto;
}

.switch input {
    position: absolute;
    opacity: 0;
}

.switch-track {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 999px;
    background: #39393d;
    transition: background-color 160ms ease;
}

.switch-track::after {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: white;
    content: "";
    transition: transform 160ms ease;
}

.switch input:checked + .switch-track {
    background: var(--accent);
}

.switch input:checked + .switch-track::after {
    transform: translateX(20px);
}

.switch input:focus-visible + .switch-track {
    outline: 2px solid var(--text);
    outline-offset: 2px;
}

.category-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.chip {
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    padding: 0 12px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
}

.chip.is-active {
    border-color: transparent;
    background: var(--accent);
    color: white;
}

.host-actions {
    margin-top: 16px;
}

.waiting-note,
.adult-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border-radius: var(--radius-control);
    padding: 12px 14px;
    background: var(--surface-raised);
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.adult-note {
    color: #ffe47a;
}

.adult-note img,
.waiting-note img {
    width: 19px;
    flex: 0 0 auto;
    filter: brightness(0) invert(1);
}

.game-surface {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-shell);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.game-stage {
    min-height: 460px;
    display: grid;
    align-content: center;
    padding: clamp(24px, 6vw, 54px);
    text-align: center;
}

.phase-icon {
    display: grid;
    width: 64px;
    height: 64px;
    margin: 0 auto 22px;
    place-items: center;
    border-radius: 20px;
    background: var(--surface-raised);
}

.phase-icon img {
    width: 31px;
    filter: brightness(0) invert(1);
}

.game-stage h2 {
    margin-bottom: 10px;
    font-size: clamp(30px, 6vw, 48px);
    letter-spacing: -0.045em;
}

.game-stage > p {
    max-width: 540px;
    margin-right: auto;
    margin-bottom: 24px;
    margin-left: auto;
    color: var(--muted);
    line-height: 1.5;
}

.secret-card {
    max-width: 560px;
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-group);
    background: var(--bg);
    padding: clamp(24px, 5vw, 42px);
}

.secret-label {
    display: block;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.secret-value {
    display: block;
    font-size: clamp(30px, 8vw, 52px);
    font-weight: 760;
    letter-spacing: -0.04em;
    line-height: 1.05;
}

.secret-value.imposter {
    color: #a996ff;
}

.progress-line {
    width: 100%;
    height: 5px;
    margin-top: 24px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-raised);
}

.progress-line span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--status);
    transition: width 220ms ease;
}

.answers,
.vote-list,
.reveal-list {
    display: grid;
    max-width: 580px;
    gap: 8px;
    margin: 20px auto 0;
}

.answer-row,
.vote-option,
.reveal-row {
    display: flex;
    min-height: 52px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--bg);
    padding: 10px 14px;
    text-align: left;
}

.answer-row strong,
.reveal-row strong {
    flex: 0 0 34%;
}

.answer-row span,
.reveal-row span {
    color: var(--muted);
    text-align: right;
}

.vote-option {
    width: 100%;
    color: var(--text);
    font-weight: 680;
    cursor: pointer;
}

.vote-option:hover {
    background: var(--surface-raised);
}

.game-actions {
    display: flex;
    max-width: 560px;
    gap: 10px;
    margin: 24px auto 0;
}

.game-actions .button {
    margin-top: 0;
}

.toast {
    position: fixed;
    z-index: 20;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    max-width: min(390px, calc(100vw - 32px));
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #242428;
    box-shadow: var(--shadow);
    padding: 13px 16px;
    font-size: 14px;
    font-weight: 600;
}

dialog {
    width: min(560px, calc(100% - 24px));
    max-height: calc(100dvh - 24px);
    border: 0;
    border-radius: var(--radius-shell);
    background: var(--surface);
    color: var(--text);
    padding: 0;
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.72);
}

.dialog-surface {
    display: grid;
    gap: 22px;
    padding: 24px;
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dialog-header h2 {
    margin: 4px 0 0;
}

.dialog-surface h3 {
    margin-bottom: 14px;
    font-size: 16px;
}

.dialog-surface label:not(:first-of-type) {
    margin-top: 12px;
}

.dialog-count {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

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

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 3px;
}

@media (max-width: 720px) {
    .app-shell {
        width: min(100% - 24px, 620px);
    }

    .topbar {
        margin-bottom: 42px;
    }

    .connection-state > span:last-child {
        display: none;
    }

    .entry-surface {
        grid-template-columns: 1fr;
        gap: 26px;
        border-radius: 28px;
    }

    .surface-separator {
        width: 100%;
        height: 1px;
    }

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

    .mode-preview > div {
        grid-template-columns: 34px auto 1fr;
        min-height: 62px;
        justify-items: start;
        padding: 0 18px;
    }

    .mode-preview > div > span:last-child {
        justify-self: end;
    }

    .lobby-layout {
        grid-template-columns: 1fr;
    }

    .room-bar {
        align-items: center;
    }

    .game-stage {
        min-height: 420px;
    }
}

@media (max-width: 430px) {
    .field-row {
        grid-template-columns: 1fr;
    }

    .room-actions {
        gap: 5px;
    }

    .icon-button {
        width: 44px;
        min-width: 44px;
        height: 44px;
    }

    .game-actions {
        flex-direction: column;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
