:root {
    --bg: #ffffff;
    --panel: #ffffff;
    --ink: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --accent: #111827;
    --accent-dark: #000000;
    --danger: #b91c1c;
    --radius: 12px;
    --shadow: 0 6px 18px rgba(17, 24, 39, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
}

[hidden] {
    display: none !important;
}

.page {
    width: min(1200px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 32px 0 56px;
}

.page-header,
.button-row,
.grid.two,
.score-box,
.question-line,
.answer-item,
.control-header,
.control-selectors,
.control-main-header {
    display: flex;
    gap: 16px;
}

.page-header,
.answer-item,
.control-header,
.control-main-header {
    justify-content: space-between;
    align-items: flex-start;
}

.page-title {
    margin: 8px 0 0;
    font-size: clamp(1.8rem, 3vw, 2.4rem);
}

.play-page-title {
    color: var(--muted);
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.4;
}

.page-header:has(.control-header) {
    display: block;
}

.control-header {
    align-items: center;
    justify-content: flex-start;
    font-size: clamp(1.6rem, 3vw, 2.2rem);
    font-weight: 600;
}

.control-title-text {
    line-height: 1.1;
}

.back-icon-button {
    width: 42px;
    height: 42px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    font-size: 1.8rem;
    line-height: 1;
    flex: 0 0 auto;
}

.eyebrow,
.muted,
dt {
    color: var(--muted);
}

.grid.two {
    align-items: start;
}

.grid.two > * {
    flex: 1 1 0;
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.control-panel-card {
    display: block;
}

.control-panel-card .section-title-row {
    margin-bottom: 16px;
    align-items: flex-start;
}

.control-panel-card .facts {
    margin-top: 0;
}

.control-panel-card .control-panel-actions {
    margin-top: 18px;
}

.control-top-actions {
    justify-content: flex-start;
}

.control-top-actions-spaced {
    margin-top: 12px;
    margin-bottom: 14px;
}

.control-actions-grid {
    flex-wrap: wrap;
}

.control-workspace-card {
    margin-top: 28px;
}

.scoreboard-header-actions {
    align-self: flex-start;
    margin-top: 6px;
}

.scoreboard-stack {
    display: grid;
    gap: 28px;
    margin-top: 18px;
}

.scoreboard-table-card {
    padding-top: 30px;
    width: 100%;
    overflow: hidden;
}

.scoreboard-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

#scoreboard-table {
    width: max-content;
    min-width: 100%;
}

#scoreboard-table th:first-child,
#scoreboard-table td:first-child {
    min-width: 320px;
    max-width: 320px;
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--panel);
}

#scoreboard-table td:first-child {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

#scoreboard-table th:nth-child(2),
#scoreboard-table td:nth-child(2) {
    min-width: 120px;
    max-width: 120px;
    position: sticky;
    left: 320px;
    z-index: 3;
    background: var(--panel);
}

#scoreboard-table thead th:first-child,
#scoreboard-table thead th:nth-child(2) {
    z-index: 4;
}

#scoreboard-table td:first-child,
#scoreboard-table td:nth-child(2),
#scoreboard-table th:first-child,
#scoreboard-table th:nth-child(2) {
    box-shadow: 1px 0 0 var(--line);
}

.control-selectors {
    align-items: end;
}

.control-selectors label {
    flex: 1 1 0;
}

.control-main {
    display: grid;
    gap: 16px;
}

.share-layout {
    display: grid;
    grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
    gap: 24px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.36);
    display: grid;
    place-items: center;
    padding: 24px;
    z-index: 20;
}

.modal-backdrop[hidden] {
    display: none !important;
}

.modal-dialog {
    width: min(920px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(17, 24, 39, 0.18);
    padding: 24px;
}

.modal-dialog-narrow {
    width: min(520px, 100%);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.share-qr-card {
    display: grid;
    justify-items: center;
}

.share-controls {
    display: grid;
    gap: 12px;
}

.qr-frame {
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1 / 1;
    border: 1px solid var(--line);
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: #fff;
    padding: 20px;
}

.qr-frame svg {
    width: 100%;
    height: auto;
}

.stack {
    display: grid;
    gap: 12px;
}

.stack.compact {
    gap: 8px;
}

.top-gap {
    margin-top: 24px;
}

.button,
button,
select,
textarea,
input {
    font: inherit;
}

.button,
button {
    border: none;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    padding: 10px 18px;
    text-decoration: none;
    cursor: pointer;
}

.button.secondary {
    background: #f3f4f6;
    color: var(--ink);
}

.button.danger {
    background: var(--danger);
}

.button.active {
    background: var(--accent-dark);
    color: #fff;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    background: #fff;
}

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

.checkbox input {
    width: auto;
}

.facts {
    display: grid;
    gap: 10px;
    margin: 0;
}

.facts div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 8px;
}

.facts-input-row {
    align-items: center;
}

.facts-input-row dd {
    flex: 1 1 auto;
    margin: 0;
}

.inline-form {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.inline-form input {
    flex: 1 1 auto;
}

.question-card {
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.waiting-state {
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.5;
}

.score-box {
    justify-content: flex-start;
    flex-wrap: wrap;
}

.messages {
    margin: 16px 0;
    display: grid;
    gap: 8px;
}

.message {
    padding: 12px 16px;
    border-radius: 12px;
    background: #f3f4f6;
}

.message.error {
    background: #fee2e2;
}

.message.success {
    background: #dcfce7;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    text-align: center;
    white-space: nowrap;
}

th:first-child,
td:first-child {
    text-align: left;
}

.scoreboard-question-header {
    white-space: normal;
    min-width: 88px;
}

.scoreboard-question-subtitle {
    font-size: 0.8rem;
    margin-top: 4px;
}

.staff-answer-text {
    text-align: left;
    white-space: normal;
    min-width: 280px;
}

.assessment-cell {
    padding-top: 8px;
    padding-bottom: 8px;
}

.assessment-form {
    display: grid;
    gap: 0;
}

.assessment-cell input[type="checkbox"] {
    width: auto;
}

.tiny-input {
    width: 64px;
    min-width: 64px;
    text-align: center;
}

.rounds-cell {
    white-space: normal;
    min-width: 320px;
}

.rounds-cell div + div {
    margin-top: 6px;
}

.tag {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #f3f4f6;
    color: var(--ink);
    font-size: 0.85rem;
}

.narrow {
    max-width: 460px;
}

.list-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

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

.section-title-row h2 {
    margin: 0;
}

.admin-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
}

.round-editor {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    background: #ffffff;
}

.compact-grid {
    gap: 12px;
}

.question-line {
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding-bottom: 12px;
}

.question-line > * {
    flex: 1 1 0;
}

.question-meta {
    max-width: 220px;
}

@media (max-width: 900px) {
    .page-header,
    .grid.two,
    .button-row,
    .answer-item,
    .question-line,
    .control-header,
    .control-selectors,
    .control-main-header,
    .share-layout {
        flex-direction: column;
    }

    .page {
        width: min(100vw - 24px, 1200px);
    }

    .scoreboard-stack {
        gap: 20px;
        margin-top: 16px;
    }

    #scoreboard-table th:first-child,
    #scoreboard-table td:first-child {
        min-width: 220px;
        max-width: 220px;
    }

    #scoreboard-table th:nth-child(2),
    #scoreboard-table td:nth-child(2) {
        left: 220px;
    }
}
