:root {
    color-scheme: light;
    --bg: #f6f7f2;
    --text: #17211d;
    --muted: #536059;
    --line: #b8c4bb;
    --surface: #fff;
    --surface-alt: #edf3ef;
    --accent: #0f766e;
    --accent-strong: #0b4f4a;
    --button-alt: #40534c;
    --locked-bg: #d5ddd8;
    --locked-text: #66736c;
    --warn: #a33b20
}

html[data-theme=dark] {
    color-scheme: dark;
    --bg: #111816;
    --text: #eaf1ed;
    --muted: #a9b8b0;
    --line: #31443d;
    --surface: #18231f;
    --surface-alt: #20322c;
    --accent: #2fb8a9;
    --accent-strong: #6bd4c8;
    --button-alt: #3e5f56;
    --locked-bg: #24332e;
    --locked-text: #8ea099;
    --warn: #ff9b7d
}

* {
    box-sizing: border-box
}

[hidden] {
    display: none !important
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif
}

main {
    width: min(1480px, calc(100% - 32px));
    margin: 0 auto;
    padding: 22px 0 30px
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 18px
}

h1,
h2,
p {
    margin: 0
}

h1 {
    font-size: 1.7rem
}

h2 {
    font-size: 1rem
}

p {
    color: var(--muted)
}

.themeSwitch {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 700;
    white-space: nowrap
}

.themeSwitch input {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    opacity: 0
}

.themeSwitch span {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    transition: background .15s ease
}

.themeSwitch span::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    background: var(--muted);
    transition: transform .15s ease, background .15s ease
}

.themeSwitch input:checked+span {
    background: var(--accent)
}

.themeSwitch input:checked+span::after {
    transform: translateX(20px);
    background: #fff
}

.themeSwitch input:focus-visible+span {
    outline: 2px solid var(--accent-strong);
    outline-offset: 2px
}

.gameTabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-top: 1px solid var(--line);
    padding: 16px 0
}

.gameTab {
    background: var(--button-alt)
}

.gameTab.active {
    background: var(--accent)
}

.gameTab.locked {
    background: var(--locked-bg);
    color: var(--locked-text);
    cursor: not-allowed
}

.gameIntro {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: end;
    border-top: 1px solid var(--line);
    padding: 16px 0
}

.gameIntro h2 {
    font-size: 1.35rem
}

.eyebrow {
    color: var(--accent-strong);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase
}

.controls,
.workspace,
.editor,
.glossary,
.gameInfo,
.output {
    border-top: 1px solid var(--line);
    padding: 16px 0
}

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

.gameInfo p:last-child {
    max-width: 980px;
    white-space: pre-line
}

.controls {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) 240px;
    gap: 12px;
    align-items: end
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: .9rem
}

.check {
    grid-template-columns: auto 1fr;
    align-items: center;
    color: var(--text)
}

input,
select,
textarea,
button {
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit
}

input,
select,
textarea {
    background: var(--surface);
    color: var(--text);
    padding: 9px 10px
}

.bitmaskEditor {
    display: grid;
    gap: 8px;
    min-width: min(620px, 100%)
}

.bitmaskToolbar {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) auto auto;
    gap: 8px;
    align-items: center
}

.bitmaskDecimal {
    width: 100%
}

.bitmaskGrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 6px;
    max-height: 260px;
    overflow: auto;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface-alt)
}

.bitmaskItem {
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 7px;
    min-width: 0;
    color: var(--text);
    font-size: .86rem
}

.bitmaskItem span {
    overflow-wrap: anywhere
}

textarea {
    width: 100%;
    min-height: 440px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .9rem
}

button {
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    padding: 9px 12px
}

button:hover {
    background: var(--accent-strong);
    color: var(--bg)
}

button.secondary {
    background: var(--button-alt)
}

.workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px
}

.pane {
    min-width: 0
}

.paneHead,
.output {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center
}

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

.editor .paneHead,
.glossary .paneHead {
    margin-bottom: 10px
}

.presetRow {
    margin-bottom: 10px
}

.tableWrap {
    max-height: 360px;
    overflow: auto;
    border: 1px solid var(--line);
    background: var(--surface)
}

.glossaryWrap {
    max-height: 430px
}

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

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 8px;
    text-align: left;
    vertical-align: top
}

th {
    position: sticky;
    top: 0;
    background: var(--surface-alt);
    z-index: 1
}

td:first-child {
    width: 30%;
    overflow-wrap: anywhere;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace
}

td:nth-child(2) {
    width: 30%;
    overflow-wrap: anywhere
}

.editor td:nth-child(3) {
    width: 110px
}

.editor td:nth-child(4) {
    width: 30%
}

.glossary td:nth-child(2) {
    width: 70%
}

td input,
td select {
    width: 100%
}

#status {
    min-height: 24px;
    color: var(--muted)
}

#status.error {
    color: var(--warn);
    font-weight: 700
}

@media (max-width:980px) {

    .controls,
    .workspace,
    .gameIntro {
        grid-template-columns: 1fr
    }

    .gameIntro {
        align-items: stretch;
        flex-direction: column
    }

    .topbar,
    .paneHead,
    .output {
        align-items: stretch;
        flex-direction: column
    }

    .themeSwitch {
        align-self: flex-start
    }

    textarea {
        min-height: 300px
    }
}

.suggestions {
    border-top: 1px solid var(--line);
    padding: 16px 0
}

.suggestionForm {
    display: grid;
    gap: 12px;
    margin-top: 12px;
    max-width: 960px
}

.suggestionForm textarea {
    min-height: 260px
}

.suggestionOutput {
    border-top: 0;
    padding: 4px 0 0
}

.qaPanel {
    border-top: 1px solid var(--line);
    margin-top: 20px;
    padding-top: 16px;
    max-width: 960px
}

.qaList {
    display: grid;
    gap: 10px;
    margin-top: 12px
}

.qaItem {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px
}

.qaItem h3 {
    font-size: 1rem;
    margin: 0 0 6px
}

.qaItem p {
    margin: 0
}

#suggestionStatus {
    min-height: 24px;
    color: var(--muted)
}

#suggestionStatus.error {
    color: var(--warn);
    font-weight: 700
}

@media (max-width:980px) {
    .suggestionForm textarea {
        min-height: 220px
    }
}
