:root {
    --bg: #09111d;
    --panel: #122034;
    --panel-2: #0e1a2c;
    --line: rgba(255, 255, 255, 0.12);
    --text: #f2f6ff;
    --muted: #a8b8d1;
    --ok: #23c26b;
    --warn: #f8b835;
    --err: #ef476f;
    --btn: #3ec4a6;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
    background: radial-gradient(circle at 10% 0%, #213f68 0%, #0a1524 45%, #060b13 100%);
}

.admin-shell {
    width: min(1320px, 100%);
    max-width: 1320px;
    margin: 0 auto;
    padding: 24px;
    display: grid;
    gap: 18px;
    min-width: 0;
}

.admin-shell.narrow {
    max-width: 560px;
    min-height: 100vh;
    align-content: center;
}

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

.topbar h1 {
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
}

.topbar-actions .muted {
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: right;
}

.topbar-actions .quick-access-link {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text);
}

.topbar-actions .quick-access-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.small {
    font-size: 0.85rem;
}

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

.card,
.metric {
    background: linear-gradient(170deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    min-width: 0;
}

.metric h3 {
    margin: 0;
    font-size: 0.9rem;
    color: var(--muted);
}

.metric p {
    margin: 8px 0 0;
    font-size: 1.8rem;
    font-weight: 700;
}

.grid {
    display: grid;
    gap: 14px;
}

.stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.stats-grid .metric {
    padding: 10px 12px;
    border-radius: 10px;
    min-width: 0;
}

.stats-grid .metric h3 {
    font-size: 0.78rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.stats-grid .metric p {
    margin-top: 6px;
    font-size: 1.35rem;
}

.two-col {
    grid-template-columns: 1fr;
}

h2 {
    margin: 0 0 12px;
}

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

.stack.compact {
    margin-bottom: 14px;
}

label {
    display: grid;
    gap: 6px;
    font-size: 0.92rem;
}

.admin-fieldset {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.admin-fieldset legend {
    padding: 0 6px;
    font-weight: 700;
}

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

input,
select,
button {
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    padding: 10px 12px;
    font: inherit;
}

input {
    color: var(--text);
    background: rgba(5, 14, 24, 0.8);
}

select {
    color: var(--text);
    background: rgba(5, 14, 24, 0.8);
}

button,
.link-btn {
    color: #062018;
    border: 0;
    background: linear-gradient(145deg, var(--btn), #21b993);
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 10px 14px;
    border-radius: 10px;
}

.small-btn {
    padding: 7px 10px;
    font-size: 0.82rem;
}

.small-btn.link-btn {
    border-radius: 8px;
}

.inline-form {
    margin: 0;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-edit {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
}

.inline-edit input {
    width: 84px;
    padding: 7px 8px;
    font-size: 0.82rem;
}

.users-actions-cell {
    min-width: 300px;
}

.users-actions-cell .inline-edit {
    margin-bottom: 8px;
}

.users-actions-cell .inline-edit input,
.users-actions-cell .inline-edit select {
    width: auto;
    min-width: 120px;
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    max-width: 100%;
    min-width: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 820px;
}

th,
td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    vertical-align: top;
    font-size: 0.9rem;
    overflow-wrap: anywhere;
    word-break: break-word;
}

th {
    color: var(--muted);
    background: rgba(255, 255, 255, 0.03);
}

.search-row {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.search-row input {
    flex: 1;
}

.participants-toolbar {
    margin-bottom: 10px;
}

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

.admin-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(2, 8, 23, 0.72);
}

.admin-modal.hidden {
    display: none;
}

.admin-modal-card {
    position: relative;
    width: min(860px, 100%);
    max-height: min(86vh, 900px);
    overflow: auto;
    display: grid;
    gap: 14px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #0f1b2d;
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.48);
}

.admin-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 999px;
}

.draw-winner-card {
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.05);
}

.draw-winner-card h4 {
    margin: 8px 0;
    font-size: 1.4rem;
}

.draw-winner-card p {
    margin: 4px 0;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-won {
    background: rgba(34, 197, 94, 0.18);
    color: #86efac;
}

.status-muted {
    background: rgba(168, 184, 209, 0.14);
    color: var(--muted);
}

.stacked-form {
    display: grid;
    gap: 10px;
}

.danger-btn {
    background: #b42318;
}

.columns-picker {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(8, 18, 32, 0.45);
    padding: 10px;
}

.columns-picker summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--text);
    outline: none;
}

.columns-picker-grid {
    margin-top: 10px;
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.columns-picker-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    color: var(--muted);
}

.columns-picker-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}

.participants-col-hidden {
    display: none;
}

.hidden {
    display: none;
}

.participant-review-row td {
    background: rgba(255, 255, 255, 0.03);
}

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

.participant-review-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    background: rgba(8, 18, 32, 0.6);
}

.participant-review-card h4 {
    margin: 0 0 10px;
}

.participant-review-list {
    margin: 0;
    padding-left: 18px;
    display: grid;
    gap: 10px;
}

.reward-editor-grid {
    margin-top: 14px;
    display: grid;
    gap: 12px;
    grid-template-columns: 1fr;
}

.reward-editor-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    background: rgba(8, 18, 32, 0.65);
    display: grid;
    gap: 8px;
}

.reward-editor-card h3 {
    margin: 0 0 4px;
    font-size: 1rem;
}

.row-2,
.row-3 {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr;
}

.pager {
    margin-top: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.pager-links {
    display: flex;
    gap: 8px;
}

.alert {
    margin: 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid transparent;
}

.alert.success {
    background: rgba(35, 194, 107, 0.15);
    border-color: rgba(35, 194, 107, 0.4);
}

.alert.warn {
    background: rgba(248, 184, 53, 0.15);
    border-color: rgba(248, 184, 53, 0.4);
}

.alert.error {
    background: rgba(239, 71, 111, 0.14);
    border-color: rgba(239, 71, 111, 0.35);
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tab-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    border: 1px solid var(--line);
}

.tab-btn.is-active {
    background: linear-gradient(145deg, var(--btn), #21b993);
    color: #062018;
}

.settings-form {
    gap: 14px;
}

.settings-subtabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px;
    background: rgba(8, 18, 32, 0.45);
}

.settings-subtab-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.84rem;
    line-height: 1.2;
}

.settings-subtab-btn.is-active {
    background: linear-gradient(145deg, var(--btn), #21b993);
    color: #062018;
}

.settings-group {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    display: grid;
    gap: 8px;
    background: rgba(8, 18, 32, 0.45);
}

.settings-group h3 {
    margin: 0;
    font-size: 1rem;
}

.settings-group .small {
    margin-top: -2px;
}

.drop-participants-form {
    margin-top: 14px;
    border: 1px solid rgba(239, 71, 111, 0.45);
    border-radius: 10px;
    padding: 12px;
    background: rgba(79, 16, 29, 0.24);
    display: grid;
    gap: 8px;
}

.danger-btn {
    width: 100%;
    background: linear-gradient(145deg, #f24f6f, #cf2447);
    color: #fff4f6;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    border: 1px solid rgba(255, 157, 177, 0.4);
}

.settings-subpanel {
    display: none;
}

.settings-subpanel.is-active {
    display: grid;
}

.settings-textarea {
    min-height: 92px;
    color: var(--text);
    background: rgba(5, 14, 24, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    resize: vertical;
}

.tab-panel {
    display: none;
}

.tab-panel.is-active {
    display: block;
}

.grid.tab-panel.is-active {
    display: grid;
}

.question-manager {
    display: grid;
    gap: 12px;
}

.question-manager-header,
.question-manager-actions,
.match-question-heading,
.match-answer-section-heading,
.match-question-summary-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.question-manager-header,
.match-answer-section-heading {
    justify-content: space-between;
    flex-wrap: wrap;
}

.question-manager-header h2,
.match-answer-section-heading h3,
.match-answer-create h3 {
    margin: 0;
}

.question-manager-header p,
.match-answer-section-heading p {
    margin: 4px 0 0;
}

.question-manager-actions .link-btn {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--line);
}

.match-question-editor {
    overflow: clip;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(8, 18, 32, 0.52);
}

.match-question-editor[open] {
    border-color: rgba(62, 196, 166, 0.55);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
}

.match-question-editor summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 15px 16px;
    cursor: pointer;
    list-style: none;
}

.match-question-editor summary::-webkit-details-marker {
    display: none;
}

.match-question-editor summary::after {
    content: "+";
    display: grid;
    place-items: center;
    flex: 0 0 26px;
    width: 26px;
    height: 26px;
    margin-left: 4px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--btn);
    font-size: 1.2rem;
    line-height: 1;
}

.match-question-editor[open] summary::after {
    content: "−";
}

.match-question-summary-copy {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.match-question-summary-copy strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.match-question-number,
.match-answer-count {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.match-question-summary-meta {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.84rem;
    white-space: nowrap;
}

.match-question-editor-body {
    display: grid;
    gap: 14px;
    padding: 16px;
    border-top: 1px solid var(--line);
}

.match-answer-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 10px;
}

.match-answer-editor,
.match-answer-create {
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.035);
}

.match-answer-editor {
    margin: 0;
    min-width: 0;
}

.match-answer-label-input {
    min-height: 62px;
    color: var(--text);
    background: rgba(5, 14, 24, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    line-height: 1.35;
    resize: vertical;
}

.match-media-state {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 8px;
    border: 1px solid rgba(62, 196, 166, 0.34);
    border-radius: 9px;
    background: rgba(62, 196, 166, 0.08);
}

.match-media-state img {
    width: 64px;
    height: 64px;
    flex: 0 0 64px;
    object-fit: cover;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.09);
}

.match-media-state span {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.match-media-state strong {
    font-size: 0.82rem;
}

.match-media-state small {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.76rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.match-answer-media-state img {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
}

.match-media-empty {
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
    font-style: italic;
}

.content-settings-group {
    margin: 0;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.content-settings-group legend {
    padding: 0 8px;
    font-weight: 700;
}

.match-answer-editor .two-col {
    grid-template-columns: 1fr;
}

.match-answer-editor input,
.match-answer-editor select {
    width: 100%;
    min-width: 0;
}

.match-answer-editor input[type="file"] {
    max-width: 100%;
    padding-right: 6px;
}

.match-answer-editor .topbar-actions {
    align-items: stretch;
    flex-wrap: wrap;
}

.match-answer-editor .topbar-actions button {
    flex: 1 1 128px;
    min-width: 0;
}

.match-answer-editor .danger-btn {
    width: auto;
    padding: 10px 12px;
}

.match-answer-create {
    display: grid;
    gap: 10px;
}

.admin-container {
    width: min(1240px, calc(100% - 32px));
    margin: 24px auto;
    display: grid;
    gap: 18px;
}

.admin-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.flash {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
}

.flash-success {
    background: rgba(35, 194, 107, 0.15);
    border-color: rgba(35, 194, 107, 0.4);
}

.flash-error {
    background: rgba(239, 71, 111, 0.14);
    border-color: rgba(239, 71, 111, 0.35);
}

.quiz-admin-card {
    display: grid;
    gap: 16px;
}

.quiz-admin-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.quiz-admin-card-head h2,
.quiz-admin-card-head h3,
.quiz-admin-panel h3,
.quiz-answer-add-admin h4 {
    margin: 0;
}

.quiz-admin-form,
.quiz-admin-panel {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
    background: rgba(8, 18, 32, 0.42);
}

.quiz-admin-grid,
.quiz-answer-form-admin {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.quiz-admin-span-2 {
    grid-column: 1 / -1;
}

.quiz-admin-sections {
    display: grid;
    gap: 14px;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
}

.quiz-answer-list-admin {
    display: grid;
    gap: 10px;
}

.quiz-answer-item-admin,
.quiz-answer-add-admin {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    display: grid;
    gap: 10px;
}

.quiz-answer-actions-admin,
.quiz-admin-delete,
.quiz-answer-delete-admin {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.quiz-admin-delete .danger-btn,
.quiz-answer-delete-admin .danger-btn {
    width: auto;
}

@media (max-width: 880px) {
    .admin-header,
    .quiz-admin-card-head {
        flex-direction: column;
    }

    .quiz-admin-sections,
    .quiz-admin-grid,
    .quiz-answer-form-admin {
        grid-template-columns: 1fr;
    }

    .quiz-admin-span-2 {
        grid-column: auto;
    }
}

.terms-input {
    min-height: 320px;
    color: var(--text);
    background: rgba(5, 14, 24, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    resize: vertical;
}

.js-terms-source-wrap.is-hidden,
.terms-source-wrap.is-hidden {
    display: none;
}

.terms-editor-wrap {
    display: none;
}

.terms-editor-wrap.is-ready {
    display: grid;
    gap: 10px;
}

.terms-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.terms-tool-btn,
.terms-tool-select {
    border-radius: 8px;
    border: 1px solid var(--line);
    background: rgba(8, 18, 32, 0.65);
    color: var(--text);
    padding: 8px 10px;
    font-size: 0.86rem;
    line-height: 1;
}

.terms-tool-btn {
    cursor: pointer;
    min-width: 42px;
}

.terms-tool-btn:hover {
    border-color: rgba(62, 196, 166, 0.7);
}

.terms-editor {
    min-height: 320px;
    color: var(--text);
    background: rgba(5, 14, 24, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    padding: 12px;
    font: inherit;
    line-height: 1.45;
    overflow: auto;
}

.terms-editor:focus {
    outline: 2px solid rgba(62, 196, 166, 0.45);
    outline-offset: 1px;
}

.terms-editor p,
.terms-editor h2,
.terms-editor h3,
.terms-editor ul,
.terms-editor ol {
    margin: 0 0 12px;
}

.terms-editor a {
    color: #7dd7ff;
    text-decoration: underline;
}

@media (min-width: 1120px) {
    .two-col {
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .reward-editor-grid {
        grid-template-columns: 1fr 1fr;
    }

    .row-2 {
        grid-template-columns: repeat(2, 1fr);
    }

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

@media (max-width: 760px) {
    .admin-shell {
        padding: 16px;
    }

    .card,
    .metric {
        padding: 12px;
    }

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

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

    .columns-picker-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 1100px) {
    .stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

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

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