:root {
    --bg: #eef1f6;
    --surface: #ffffff;
    --surface-soft: #f7f8fb;
    --ink: #172033;
    --muted: #6b768d;
    --line: #d9deea;
    --accent: #6d5dfc;
    --accent-strong: #5547d8;
    --green: #24a978;
    --green-soft: #e7fff5;
    --warning: #ffb84d;
    --danger: #d9485f;
    --danger-soft: #fff0f2;
    --dark: #111827;
    --radius: 8px;
    --shadow: 0 12px 30px rgba(17, 24, 39, .08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
    color: var(--ink);
}

body {
    min-height: 100vh;
    margin: 0;
    background: linear-gradient(180deg, #f8fafc 0%, var(--bg) 52%, #e8ecf4 100%);
    color: var(--ink);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

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

.shell {
    width: min(100%, 520px);
    min-height: 100vh;
    margin: 0 auto;
    background: var(--surface-soft);
    box-shadow: 0 0 0 1px rgba(17, 24, 39, .05);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 62px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.brand,
.topbar-user,
.player-main,
.game-header-row,
.section-heading,
.link-row,
.dock-tools,
.finished-dock {
    display: flex;
    align-items: center;
}

.brand {
    gap: 9px;
    min-width: 0;
    font-weight: 850;
    font-size: 19px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent), var(--green));
    color: #fff;
    font-size: 12px;
    font-weight: 900;
}

.brand-mark.small {
    width: 36px;
    height: 36px;
}

.topbar-user {
    gap: 8px;
}

.avatar-link,
.icon-button {
    min-width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-size: 12px;
    font-weight: 850;
}

.icon-button {
    padding: 0 10px;
}

.main {
    padding: 14px 14px 92px;
}

.auth-page .main {
    padding-bottom: 24px;
}

.game-page .main {
    padding: 8px;
}

.flash {
    margin: 10px 14px 0;
    padding: 11px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-size: 14px;
    font-weight: 750;
}

.flash-success {
    border-color: #a8efcf;
    background: #effdf6;
    color: #08784f;
}

.flash-danger {
    border-color: #ffc6d0;
    background: var(--danger-soft);
    color: #9e2135;
}

.flash-info {
    border-color: #cbd7ff;
    background: #f0f3ff;
    color: #3542a3;
}

.auth-panel,
.stack,
.player-list,
.game-list,
.check-list,
.radio-list {
    display: grid;
    gap: 12px;
}

.auth-panel {
    padding-top: 24px;
}

.auth-copy {
    padding: 12px 2px 6px;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    border: 1px solid #dfe4f2;
    border-radius: 999px;
    background: #fff;
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 850;
}

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

.auth-copy h1,
.page-title h1 {
    margin: 12px 0 8px;
    font-size: 34px;
    line-height: 1.03;
}

.auth-copy p,
.page-title p,
.game-title p,
.empty-text {
    margin-bottom: 0;
    color: var(--muted);
    line-height: 1.45;
}

.page-title {
    margin: 6px 0 16px;
}

.page-title h1 {
    font-size: 30px;
}

.form-card,
.panel,
.empty-state,
.dev-note,
.winner-banner {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.form-card,
.panel {
    display: grid;
    gap: 14px;
    padding: 16px;
}

.panel h2,
.section-heading h2 {
    margin: 0;
    font-size: 18px;
}

label,
.field-group {
    display: grid;
    gap: 7px;
}

label > span,
.label-text {
    color: #46546c;
    font-size: 12px;
    font-weight: 850;
}

.input {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    padding: 12px;
    outline: none;
}

.input:focus,
.score-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(109, 93, 252, .15);
}

.button,
.next-button,
.tool-button,
.text-button {
    min-height: 44px;
    border: 0;
    border-radius: var(--radius);
    font-weight: 900;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 14px;
    text-align: center;
}

.primary,
.next-button {
    background: var(--accent);
    color: #fff;
}

.primary:hover,
.next-button:hover {
    background: var(--accent-strong);
}

.secondary {
    background: #edf0f8;
    color: #2d3851;
}

.link-row {
    justify-content: space-between;
    gap: 10px;
    color: var(--accent-strong);
    font-size: 14px;
    font-weight: 800;
}

.dev-note {
    display: grid;
    gap: 8px;
    padding: 12px;
    background: #fffbea;
    color: #6b4a00;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.metric-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}

.metric-strip div {
    min-width: 0;
    padding: 12px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.metric-strip strong {
    display: block;
    font-size: 22px;
}

.metric-strip span,
.game-row small,
.player-main small,
.section-heading span,
.choice span {
    color: var(--muted);
    font-size: 12px;
}

.compact-form {
    display: grid;
    gap: 12px;
}

.section-block {
    margin-top: 16px;
}

.section-block.embedded {
    margin-top: 0;
}

.section-heading {
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.empty-state {
    padding: 16px;
    color: var(--muted);
    line-height: 1.45;
}

.empty-state a {
    color: var(--accent-strong);
    font-weight: 850;
}

.player-row,
.game-row,
.check-row,
.radio-row {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.player-row {
    display: grid;
    gap: 12px;
    padding: 12px;
}

.player-main {
    gap: 10px;
    min-width: 0;
}

.player-main strong,
.game-row strong,
.name-cell {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-dot {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--dot, var(--accent));
    color: #fff;
    font-size: 12px;
    font-weight: 900;
}

.player-actions {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.player-actions details {
    min-width: 0;
}

.player-actions summary {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    border-radius: var(--radius);
    background: #eef1fb;
    color: var(--accent-strong);
    font-size: 13px;
    font-weight: 900;
    list-style: none;
}

.player-actions details form {
    display: grid;
    gap: 10px;
    width: min(280px, calc(100vw - 70px));
    margin-top: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
}

.text-button {
    min-height: 36px;
    padding: 0 10px;
    background: transparent;
    color: var(--muted);
}

.text-button.danger,
.tool-button.danger {
    color: var(--danger);
}

.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.game-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 12px;
}

.game-row > div {
    min-width: 0;
}

.game-row.finished {
    opacity: .82;
}

.tag {
    flex: 0 0 auto;
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius: 999px;
    background: var(--green-soft);
    color: #08784f;
    padding: 6px 9px;
    font-size: 12px;
    font-weight: 850;
}

.tag.muted {
    background: #edf0f8;
    color: #5d6880;
}

.game-form {
    margin-bottom: 20px;
}

.choice-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin: 0;
    padding: 0;
    border: 0;
}

.choice-grid legend {
    grid-column: 1 / -1;
    color: #46546c;
    font-size: 12px;
    font-weight: 850;
}

.choice {
    position: relative;
    min-height: 92px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.choice input {
    position: absolute;
    inset: 10px 10px auto auto;
}

.choice:has(input:checked) {
    border-color: var(--accent);
    background: #f3f1ff;
    box-shadow: inset 0 0 0 1px var(--accent);
}

.choice strong {
    display: block;
    max-width: calc(100% - 24px);
    margin-bottom: 6px;
}

.check-row,
.radio-row {
    min-height: 54px;
    padding: 10px 12px;
}

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

.check-row input[type="checkbox"],
.radio-row input[type="radio"] {
    width: 22px;
    height: 22px;
    accent-color: var(--green);
}

.participant-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 86px;
    align-items: center;
}

.participant-choice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
}

.seat-picker {
    display: grid;
    gap: 4px;
}

.seat-picker span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
}

.seat-picker select {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    padding: 7px 8px;
    font-weight: 850;
}

.seat-picker select:disabled {
    background: #f2f4f8;
    color: #a0a9ba;
}

.turn-preview {
    display: grid;
    gap: 8px;
    min-height: 42px;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: turn;
}

.turn-preview li {
    counter-increment: turn;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 8px 10px;
    font-weight: 850;
}

.turn-preview li::before {
    content: counter(turn);
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--green-soft);
    color: #08784f;
    font-size: 12px;
    font-weight: 950;
}

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

.radio-row span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
}

.bottom-nav {
    position: sticky;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    padding: 8px;
    background: rgba(255, 255, 255, .96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.nav-item {
    display: grid;
    place-items: center;
    gap: 2px;
    min-height: 52px;
    border-radius: var(--radius);
    color: #7b879c;
    font-size: 11px;
}

.nav-item span {
    font-size: 12px;
    font-weight: 950;
}

.nav-item.active {
    background: #f0efff;
    color: var(--accent-strong);
}

.game-layout {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: calc(100dvh - 78px);
}

.game-header {
    flex: 0 0 auto;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.back-link {
    display: inline-flex;
    margin-bottom: 8px;
    color: var(--accent-strong);
    font-size: 13px;
    font-weight: 900;
}

.game-header-row {
    justify-content: space-between;
    gap: 10px;
}

.game-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.game-title h1 {
    min-width: 0;
    margin: 0 0 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 17px;
}

.game-title p {
    font-size: 12px;
}

.turn-badge {
    flex: 0 0 auto;
    max-width: 38%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid #b8f4dc;
    border-radius: 999px;
    background: var(--green-soft);
    color: #08784f;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 950;
}

.turn-badge.done {
    border-color: #d7deea;
    background: #eef1f6;
    color: #596680;
}

.winner-banner {
    flex: 0 0 auto;
    display: grid;
    gap: 2px;
    padding: 10px 12px;
    background: #111827;
    color: #fff;
}

.winner-banner span {
    color: #c6cedd;
    font-size: 12px;
}

.score-area {
    flex: 2 1 0;
    min-height: 0;
    display: flex;
}

.score-card {
    min-height: 0;
    flex: 1 1 auto;
    display: flex;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.score-board-scroll {
    flex: 1 1 auto;
    overflow: auto;
}

.score-grid,
.total-grid {
    display: grid;
    grid-template-columns: 44px repeat(var(--player-count), minmax(84px, 1fr));
    min-width: max(100%, calc(44px + (var(--player-count) * 84px)));
}

.score-cell {
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    padding: 8px 6px;
    border-right: 1px solid #e7ebf3;
    border-bottom: 1px solid #e7ebf3;
    text-align: center;
    font-size: 13px;
    font-weight: 800;
}

.score-cell.head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f6f7fb;
    color: #536077;
    font-size: 12px;
    font-weight: 950;
}

.round-cell,
.round-head {
    background: #fbfcff;
    color: #8a95aa;
}

.active-col {
    background: #effdf6;
    box-shadow: inset 0 3px 0 var(--green);
}

.current-turn {
    color: #08784f;
}

.empty {
    color: #a8b2c3;
}

.total-grid {
    position: sticky;
    bottom: 0;
    z-index: 3;
    background: var(--dark);
    color: #fff;
}

.total-grid .score-cell {
    min-height: 50px;
    border-color: rgba(255, 255, 255, .12);
    display: grid;
    gap: 2px;
}

.total-grid small {
    color: #adb7c8;
    font-size: 10px;
    font-weight: 850;
}

.total-grid strong {
    font-size: 16px;
}

.active-total {
    background: #173a2b;
}

.input-dock {
    flex: 1 0 208px;
    min-height: 208px;
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 -10px 28px rgba(17, 24, 39, .08);
}

.score-form {
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 10px;
    align-items: end;
}

.score-input {
    width: 100%;
    min-height: 58px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    padding: 10px;
    text-align: center;
    font-size: 26px;
    font-weight: 950;
    outline: none;
}

.next-button {
    min-height: 58px;
    padding: 10px;
    background: var(--green);
}

.dock-tools {
    justify-content: space-between;
    gap: 8px;
}

.dock-tools form {
    flex: 1 1 auto;
    min-width: 0;
}

.tool-button {
    width: 100%;
    min-height: 40px;
    padding: 8px;
    border: 1px solid #dfe5ef;
    background: #f7f8fb;
    color: #596680;
    font-size: 12px;
}

.finished-dock {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
}

@media (min-width: 760px) {
    .shell {
        margin-top: 20px;
        margin-bottom: 20px;
        min-height: calc(100vh - 40px);
        border-radius: 12px;
        overflow: clip;
    }

    .auth-copy h1,
    .page-title h1 {
        font-size: 38px;
    }

    .player-row {
        grid-template-columns: 1fr auto;
        align-items: start;
    }
}
