:root {
    --color-page: #d8d8d8;
    --color-dim: #666666;
    --color-cell-hover: #00000010;

    --color-game-bg: #0c0c0c;
    --color-game-text: #e6e6e6;
    --color-game-box: #b4b4b4;
    --color-game-rest: #3a3a3a;
}

:root[data-theme="dark"] {
    --color-page: #141517;
    --color-dim: #a3a6ad;
    --color-cell-hover: #ffffff12;
}

body,
html {
    font-size: 14px;
    background-color: var(--color-page);
    color: var(--color-text);
}

body {
    display: flex;
    flex-direction: column;
}

#content {
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    direction: rtl;
}

#column {
    direction: ltr;
    width: 480px;
    max-width: 100%;
    margin: 0 auto 0 0;
    padding: 8px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.top-row .top-bar-button {
    flex-shrink: 0;
    box-shadow: 0 2px 5px var(--color-bounds);
}

#generate-btn {
    font-weight: bold;
}

#status {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    color: var(--color-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#blocks {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.block-column {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.block-column:empty {
    display: none;
}

.block {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
    background: var(--color-surface);
}

.block-head {
    min-height: 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.block-title {
    font-weight: bold;
}

.block-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.no-transition *,
.no-transition *::before,
.no-transition *::after {
    transition: none !important;
}

.block.off .block-body,
.faded {
    opacity: 0.4;
}

.block-body,
.extra-isle,
.extra-editor {
    transition: opacity 0.15s;
}

.extra-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 8px;
}

.extra-isle {
    padding: 4px;
    border-radius: 4px;
}

.extra-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.extra-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 12px;
    font-weight: bold;
    color: var(--color-dim);
    text-align: center;
}

.extra-editor {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#icon-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.damaged-row {
    display: grid;
    gap: 4px;
    padding: 4px;
    border-radius: 4px;
}

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

.grid-head {
    font-size: 12px;
    font-weight: bold;
    color: var(--color-dim);
    text-align: center;
}

.grid-bg {
    margin: -4px;
    border-radius: 4px;
}

.grid-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s, border-color 0.15s;
}

.grid-cell:hover {
    background-color: var(--color-cell-hover);
}

.grid-cell.selected {
    border-color: var(--color-proposition);
    background-color: #1179c818;
}

.grid-cell canvas {
    width: 85%;
    height: 85%;
}

.channel {
    --h: 14px;
    --rest: #cfcfcf;
    --box: #9a9a9a;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.channel-box {
    width: 40px;
    height: calc(var(--h) + 8px);
    flex-shrink: 0;
    box-sizing: border-box;
    padding: 0 4px;
    border: none;
    border-radius: 2px;
    outline: none;
    background: var(--box);
    color: var(--color-white);
    font-family: sans-serif;
    font-size: 12px;
}

.channel-box:focus {
    box-shadow: inset 0 0 0 2px var(--color-proposition);
}

.channel-slider {
    --pct: 0%;
    --fill: #ffffff;
    flex: 1;
    min-width: 24px;
    height: calc(var(--h) + 8px);
    margin: 0;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    outline: none;
    touch-action: pan-y;
}

.channel-slider::-webkit-slider-runnable-track {
    height: var(--h);
    border-radius: 1px;
    background: linear-gradient(to right, var(--fill) var(--pct), var(--rest) var(--pct));
}

.channel-slider::-moz-range-track {
    height: var(--h);
    border-radius: 1px;
    background: linear-gradient(to right, var(--fill) var(--pct), var(--rest) var(--pct));
}

.channel-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 3px;
    height: calc(var(--h) + 4px);
    margin-top: -2px;
    border-radius: 1px;
    background: var(--color-white);
    box-shadow: 0 0 0 1px #00000088;
}

.channel-slider::-moz-range-thumb {
    width: 3px;
    height: calc(var(--h) + 4px);
    border: none;
    border-radius: 1px;
    background: var(--color-white);
    box-shadow: 0 0 0 1px #00000088;
}

#intel-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    background: var(--color-game-bg);
    color: var(--color-game-text);
    border-radius: 4px;
}

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

.intel-label {
    width: 92px;
    flex-shrink: 0;
    font-size: 13px;
}

.intel-controls {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

#intel-panel .channel {
    --rest: var(--color-game-rest);
    --box: var(--color-game-box);
    flex: 1;
}

#intel-panel .channel.gamma {
    --h: 12px;
}

.intel-swatch {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

.intel-swatch::-webkit-color-swatch-wrapper {
    padding: 0;
}

.intel-swatch::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.intel-swatch::-moz-color-swatch {
    border: none;
    border-radius: 2px;
}

#editor {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.editor-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
}

.icon-name {
    min-width: 0;
    font-weight: bold;
}

.part-tabs {
    display: flex;
    margin-left: auto;
}

.part-tabs .top-bar-button {
    height: 28px;
    gap: 6px;
    border-radius: 0;
    white-space: nowrap;
}

.part-tabs .top-bar-button + .top-bar-button {
    margin-left: -1px;
}

.part-tabs .top-bar-button.active,
.part-tabs .top-bar-button.active:hover {
    position: relative;
    z-index: 1;
    border-color: var(--color-proposition);
    box-shadow: inset 0 0 0 1px var(--color-proposition);
    background-color: #1179c838;
    color: var(--color-link);
}

.part-tabs .swatch {
    width: 14px;
    height: 14px;
}

.help-desc kbd.kbd-part {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.help-desc kbd.kbd-part .swatch {
    width: 10px;
    height: 10px;
}

.help-desc kbd.kbd-part-active {
    border-color: var(--color-proposition);
    box-shadow: inset 0 0 0 1px var(--color-proposition);
    background: #1179c838;
    color: var(--color-link);
}

.part-tabs .top-bar-button:first-child {
    border-radius: 4px 0 0 4px;
}

.part-tabs .top-bar-button:last-child {
    border-radius: 0 4px 4px 0;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--color-dim);
}

.slider-label {
    width: 92px;
    flex-shrink: 0;
}

.color-row {
    flex-wrap: wrap;
    row-gap: 6px;
}

.slider-row input {
    flex: 1;
    min-width: 0;
    margin: 0;
    accent-color: var(--color-slider-accent);
    cursor: pointer;
}

.slider-value {
    width: 2.2em;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.pickers {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.picker {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.picker-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: bold;
    color: var(--color-dim);
}

.picker-body {
    display: flex;
    gap: 6px;
}

.picker-body canvas {
    display: block;
    flex-shrink: 0;
    box-sizing: border-box;
    border: 1px solid var(--color-border);
    border-radius: 3px;
    cursor: crosshair;
    touch-action: none;
}

.picker-body canvas.picker-sv {
    flex: 1;
    min-width: 0;
}

.picker-body canvas.picker-bar {
    cursor: ns-resize;
}

.faction-dot {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
    box-sizing: border-box;
    border: 1px solid var(--color-black);
    border-radius: 50%;
}

.hex-field {
    width: 120px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.swatch {
    --swatch: transparent;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
    border-radius: 3px;
    background:
        linear-gradient(var(--swatch), var(--swatch)),
        repeating-conic-gradient(#c8c8c8 0 25%, #ffffff 0 50%) 0 0 / 8px 8px;
}

.hex-input.context-menu-styled-input {
    width: 100%;
    min-width: 0;
    padding: 1px 6px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
}

.shape-field,
.json-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shape-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    font-weight: bold;
    color: var(--color-dim);
}

.path-editor-btn {
    height: 26px;
    gap: 6px;
    padding: 0 8px;
    font-size: 12px;
    font-weight: normal;
}

.shape-field textarea.context-menu-styled-input {
    width: 100%;
    height: 64px;
    padding: 4px 6px;
    resize: none;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
    line-height: 1.35;
}

.json-hint {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.json-hint.error {
    color: var(--color-button-danger-hover);
}

.json-copy-btn {
    height: 22px;
    padding: 0 10px;
    font-size: 12px;
}

.json-input.context-menu-styled-input {
    width: 100%;
    height: 200px;
    padding: 4px 6px;
    resize: none;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
    line-height: 1.35;
    white-space: pre;
}

.json-input.invalid,
.json-input.invalid:focus {
    border-color: var(--color-button-danger);
    outline: 1px solid var(--color-button-danger);
}

@media (hover: none) and (pointer: coarse), (max-width: 768px) {
    #column {
        padding-right: 32px;
    }
}

@media (max-width: 400px) {
    .intel-row {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    .intel-label {
        width: auto;
    }

    .part-tabs .top-bar-button {
        padding: 0 8px;
    }
}

.featured-modal {
    max-width: 480px;
}

.featured-modal .modal-body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.featured-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow-y: auto;
    padding-right: 8px;
}

.featured-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: var(--color-page);
    border: 1px solid var(--color-border);
    border-radius: 6px;
}

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

.featured-info {
    flex: 1;
    min-width: 0;
    line-height: 1.35;
}

.featured-name {
    font-weight: bold;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.featured-meta {
    font-size: 12px;
    color: var(--color-dim);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.featured-head .top-bar-button {
    flex-shrink: 0;
}

.featured-preview {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.featured-row {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr);
    align-items: center;
    gap: 4px;
}

.featured-letter {
    font-size: 12px;
    font-weight: bold;
    text-align: center;
}

.featured-strip {
    display: grid;
    grid-template-columns: repeat(var(--m), minmax(0, 1fr));
    gap: 2px;
    width: calc((100% - 4px - (var(--n) - 1) * 2px) * var(--m) / var(--n) + (var(--m) - 1) * 2px + 4px);
    padding: 2px;
    box-sizing: border-box;
    border-radius: 4px;
}

.featured-strip canvas {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
}

.featured-note {
    margin-top: 12px;
    color: var(--color-dim);
    text-align: center;
}
