* {
    margin: 0;
    box-sizing: border-box;
}
body {
    background: #111;
    color: #eee;
    font-family: system-ui, sans-serif;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Top Toolbar ── */
#toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    background: #1a1a1e;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    flex-wrap: wrap;
    min-height: 36px;
    z-index: 20;
}
#toolbar button,
#toolbar select {
    font-size: 12px;
    padding: 3px 8px;
    border: 1px solid #555;
    background: #222;
    color: #ddd;
    border-radius: 4px;
    cursor: pointer;
}
#toolbar button:hover {
    background: #333;
}
#toolbar button.active {
    background: #6e8efb;
    color: #fff;
    border-color: #6e8efb;
}
#btn-record.active {
    background: #d32f2f;
    border-color: #d32f2f;
    animation: rec-pulse 1.2s infinite;
}
@keyframes rec-pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}
#toolbar input[type="range"] {
    width: 70px;
}
#toolbar input[type="number"],
#toolbar input[type="text"] {
    font-size: 12px;
    padding: 2px 5px;
    background: #222;
    color: #ddd;
    border: 1px solid #555;
    border-radius: 4px;
}
#toolbar label {
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 4px;
}
#toolbar .toolbar-inline-control {
    display: inline-grid;
    grid-template-columns: auto 86px 34px;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
#btn-pheromone-alpha-toggle {
    min-width: 74px;
    text-align: center;
}
#btn-pheromone-visibility-toggle {
    min-width: 98px;
    text-align: center;
}
#btn-color-gradient-toggle {
    min-width: 88px;
    text-align: center;
}
.toolbar-sep {
    width: 1px;
    height: 20px;
    background: #444;
    margin: 0 2px;
}

/* ── Left Panel ── */
#left-panel {
    position: fixed;
    top: 36px;
    left: 0;
    width: 300px;
    background: #1a1a1e;
    border-right: 1px solid #333;
    padding: 10px;
    z-index: 15;
    transform: translateX(-100%);
    transition: transform 0.2s;
    overflow-y: auto;
    max-height: calc(100vh - 36px);
}
#left-panel.open {
    transform: translateX(0);
}
#left-panel h3 {
    font-size: 10px;
    margin: 10px 0 4px;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
#left-panel h3:first-child {
    margin-top: 0;
}
.mode-btn {
    display: block;
    width: 100%;
    text-align: left;
    font-size: 10px;
    padding: 5px 8px;
    margin: 2px 0;
    border: 1px solid #444;
    background: #222;
    color: #ccc;
    border-radius: 4px;
    cursor: pointer;
}
.mode-btn:hover {
    background: #333;
}
.mode-btn.active {
    background: #6e8efb;
    color: #fff;
    border-color: #6e8efb;
}
#left-panel label {
    font-size: 10px;
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 4px 0;
}
#left-panel input[type="range"] {
    width: 80px;
}
#left-panel button.clear-btn {
    font-size: 10px;
    padding: 3px 8px;
    border: 1px solid #555;
    background: #333;
    color: #ddd;
    border-radius: 4px;
    cursor: pointer;
    margin: 2px 0;
}
#left-panel .tools-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 2px 0;
}
#left-panel .tools-toggle-label {
    flex: 0 0 98px;
    min-width: 98px;
    max-width: 98px;
    font-size: 10px;
    color: #ccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#left-panel .tools-toggle-row button {
    flex: 0 0 152px;
    width: 152px;
    min-width: 152px;
    max-width: 152px;
    font-size: 10px;
    padding: 3px 8px;
    border: 1px solid #555;
    background: #333;
    color: #ddd;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
}

/* ── Right Panel ── */
#panel {
    position: fixed;
    top: 36px;
    right: 0;
    width: 340px;
    background: #1a1a1e;
    border-left: 1px solid #333;
    padding: 6px 8px;
    z-index: 15;
    transform: translateX(100%);
    transition: transform 0.2s;
    overflow-y: auto;
    max-height: calc(100vh - 36px);
}
#panel.open {
    transform: translateX(0);
}
.panel-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 6px;
}
.panel-tabs button {
    flex: 1;
    font-size: 10px;
    padding: 3px 4px;
    border: 1px solid #555;
    background: #222;
    color: #ccc;
    border-radius: 4px;
    cursor: pointer;
}
.panel-tabs button.active {
    background: #6e8efb;
    color: #fff;
    border-color: #6e8efb;
}
/* tab visibility managed by JS inline styles */
.panel-section {
    margin-bottom: 6px;
    border: 1px solid #2a2a2e;
    border-radius: 4px;
    padding: 4px 6px;
}
.panel-section h4 {
    font-size: 10px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 3px;
    border-bottom: 1px solid #2a2a2e;
    padding-bottom: 2px;
}
.panel-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 2px 0;
    font-size: 10px;
}
.panel-row label {
    font-size: 10px;
}
.panel-row input[type="range"] {
    flex: 1;
    max-width: 100px;
}
.panel-row input[type="number"] {
    width: 52px;
    font-size: 10px;
    padding: 1px 3px;
    background: #222;
    color: #ddd;
    border: 1px solid #555;
    border-radius: 3px;
}
.panel-row input[type="color"] {
    width: 28px;
    height: 18px;
    border: 1px solid #555;
    background: none;
    cursor: pointer;
    padding: 0;
}
.panel-row button {
    font-size: 10px;
    padding: 2px 6px;
    border: 1px solid #555;
    background: #333;
    color: #ddd;
    border-radius: 4px;
    cursor: pointer;
}
.panel-row select {
    font-size: 10px;
    padding: 1px 4px;
    background: #222;
    color: #ddd;
    border: 1px solid #555;
    border-radius: 3px;
}

/* ── Compact 2-column grid for merged settings ── */
.panel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 8px;
}
.panel-grid .panel-row {
    margin: 0;
}
.panel-grid .span-2 {
    grid-column: 1 / -1;
}

/* ── Swatch color picker ── */
.swatch-picker {
    position: relative;
    display: inline-block;
}
.swatch-btn {
    width: 22px;
    height: 18px;
    border: 1px solid #555;
    border-radius: 3px;
    cursor: pointer;
    padding: 0;
    vertical-align: middle;
}
.swatch-btn:hover {
    border-color: #999;
}
.swatch-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 30;
    background: #222;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 4px;
    width: 160px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.swatch-dropdown.open {
    display: block;
}
.swatch-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 2px;
}
.swatch-cell {
    width: 22px;
    height: 18px;
    border: 1px solid #444;
    border-radius: 2px;
    cursor: pointer;
    padding: 0;
}
.swatch-cell:hover {
    border-color: #fff;
    transform: scale(1.15);
}
.swatch-custom-btn {
    display: block;
    width: 100%;
    margin-top: 3px;
    font-size: 9px;
    padding: 2px;
    background: #333;
    color: #aaa;
    border: 1px solid #555;
    border-radius: 3px;
    cursor: pointer;
    text-align: center;
}
.swatch-custom-btn:hover {
    background: #444;
    color: #ddd;
}

/* ── Range inputs: thinner track ── */
input[type="range"] {
    height: 14px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 3px;
    background: #555;
    border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #aaa;
    margin-top: -3.5px;
    cursor: pointer;
}
input[type="range"]::-moz-range-track {
    height: 3px;
    background: #555;
    border-radius: 2px;
    border: none;
}
input[type="range"]::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #aaa;
    border: none;
    cursor: pointer;
}

/* ── Sliders (dynamically built) ── */
#sliders {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.slider-block {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
}
.slider-block label {
    min-width: 60px;
}
.slider-block input {
    flex: 1;
}
.slider-block .val {
    min-width: 30px;
    text-align: right;
}

/* ── Canvas Container ── */
#canvas-container {
    flex: 1;
    overflow: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0a0f;
}
#canvas-container::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}
#canvas-container canvas {
    display: block;
    border: none;
}
#perf-hud {
    position: fixed;
    top: 42px;
    right: 8px;
    z-index: 16;
    font-size: 11px;
    color: #cfd8dc;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 4px;
    padding: 3px 6px;
    pointer-events: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Optional mode: panels never cover the canvas area */
body.no-cover #canvas-container {
    transition: margin 0.18s ease;
}
body.no-cover #left-panel.open ~ #canvas-container {
    margin-left: 300px;
}
body.no-cover #text-panel.open ~ #canvas-container {
    margin-left: 300px;
}
body.no-cover #panel.open ~ #canvas-container {
    margin-right: 340px;
}

/* ── Color scheme presets ── */
#scheme-presets {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin: 4px 0;
}
.color-preset {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s;
}
.color-preset:hover {
    border-color: #fff;
}

/* ── Text Panel (left, separate from tools) ── */
#text-panel {
    position: fixed;
    top: 36px;
    left: 0;
    width: 300px;
    background: #1a1a1e;
    border-right: 1px solid #333;
    padding: 10px;
    z-index: 15;
    transform: translateX(-100%);
    transition: transform 0.2s;
    overflow-y: auto;
    max-height: calc(100vh - 36px);
}
#text-panel.open {
    transform: translateX(0);
}
#text-overlay-wrap {
    position: static;
    display: none;
    flex-direction: column;
    background: rgba(26, 26, 30, 0.98);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 10px;
    width: 100%;
    max-width: 100%;
}
#text-overlay-wrap.active {
    display: flex;
}
#text-overlay-header {
    font-size: 11px;
    color: #aaa;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
#text-overlay {
    width: 100%;
    min-height: 80px;
    max-height: 200px;
    overflow: auto;
    background: #222;
    color: #fff;
    padding: 8px 10px;
    border: 1px solid #555;
    border-radius: 3px;
    outline: none;
    white-space: pre-wrap;
    line-height: 1.4;
    resize: vertical;
    font-size: 13px;
    font-family: system-ui, sans-serif;
}
#text-minibar {
    display: flex;
    gap: 4px;
    padding: 6px 0 0 0;
    flex-wrap: wrap;
    align-items: center;
}
#text-minibar label {
    font-size: 11px;
    color: #aaa;
    display: flex;
    align-items: center;
    gap: 4px;
}
#text-minibar select,
#text-minibar input,
#text-minibar button {
    font-size: 11px;
    padding: 3px 6px;
    background: #333;
    color: #ddd;
    border: 1px solid #555;
    border-radius: 3px;
}
#text-minibar button.active {
    background: #6e8efb;
    color: #fff;
}
#text-minibar .text-align-group {
    display: inline-flex;
    gap: 2px;
    align-items: center;
}
#text-minibar .text-align-btn {
    min-width: 24px;
    padding: 3px 5px;
}
#text-minibar #text-letter-spacing,
#text-minibar #text-line-height {
    text-align: right;
}
#text-position-hint {
    font-size: 10px;
    color: #888;
    margin-top: 6px;
}

/* ── Modal ── */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    z-index: 50;
}
.modal.open {
    display: flex;
}
.modal-card {
    width: min(760px, 92vw);
    max-height: 82vh;
    overflow: auto;
    background: #1a1a1e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 14px;
    color: #ddd;
}
.modal-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.modal-top h2 {
    font-size: 16px;
}
.notes-pre {
    white-space: pre-wrap;
    font-size: 12px;
    line-height: 1.45;
    color: #ccc;
    background: #111;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 10px;
}

/* ── Color Preview Modal ── */
#color-preview-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
}
#color-preview-modal.open {
    display: flex;
}
.color-preview-card {
    width: min(1400px, 96vw);
    max-height: 90vh;
    background: #1a1a1e;
    border: 1px solid #555;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.color-preview-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid #333;
}
.color-preview-top h2 {
    font-size: 16px;
}
.color-preview-body {
    display: flex;
    gap: 16px;
    padding: 12px;
    overflow-y: auto;
    flex: 1;
}
.color-preview-left {
    flex: 0 0 420px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#color-preview-canvas {
    width: 400px;
    height: 300px;
    border: 1px solid #555;
    background: #0a0a0f;
}
.preview-info {
    font-size: 10px;
    color: #888;
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
}
.color-preview-right {
    flex: 1 1 680px;
    min-width: 560px;
    overflow-y: auto;
    padding-right: 6px;
}
.color-preview-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    padding: 10px 14px;
    border-top: 1px solid #333;
}
.color-preview-footer button,
.color-preview-top button {
    font-size: 12px;
    padding: 3px 8px;
    border: 1px solid #555;
    background: #222;
    color: #ddd;
    border-radius: 4px;
    cursor: pointer;
}
.color-preview-footer button:hover,
.color-preview-top button:hover {
    background: #333;
}
.preview-control-groups {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.preview-control-groups .panel-section {
    margin-bottom: 0;
    overflow: visible;
}
#color-preview-modal .panel-row {
    display: grid;
    grid-template-columns: 150px 56px minmax(240px, 1fr) 40px;
    align-items: center;
    column-gap: 6px;
    row-gap: 0;
    min-height: 24px;
    overflow: visible;
}
#color-preview-modal .panel-row > label:first-child {
    grid-column: 1;
    width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#color-preview-modal .preview-swatch-slot {
    grid-column: 2;
    display: inline-block;
    width: 56px;
    height: 1px;
}
#color-preview-modal .panel-row input[type="range"] {
    grid-column: 3;
    min-width: 0;
    max-width: none;
    width: 100%;
}
#color-preview-modal .panel-grid {
    grid-template-columns: 1fr;
    gap: 4px 0;
}
#color-preview-modal .panel-row select,
#color-preview-modal .panel-row input[type="text"],
#color-preview-modal .panel-row input[type="number"] {
    grid-column: 3;
    min-width: 0;
    width: 100%;
}
#color-preview-modal .panel-row .swatch-picker {
    grid-column: 2;
    justify-self: start;
}
#color-preview-modal .swatch-dropdown {
    z-index: 130;
}
#color-preview-modal .preview-swatch-pair {
    grid-column: 2;
    display: inline-flex;
    gap: 4px;
    align-items: center;
    width: 56px;
    min-width: 56px;
}
#color-preview-modal .preview-swatch-pair span {
    min-width: 0;
    text-align: initial;
}
#color-preview-modal .panel-row span[id$="-val"] {
    grid-column: 4;
    min-width: 32px;
    text-align: right;
    width: 32px;
    white-space: nowrap;
}
#color-preview-modal .panel-row .preview-fill {
    grid-column: 3;
}
#color-preview-modal .panel-row .preview-value-slot {
    grid-column: 4;
}
#color-preview-modal .panel-row.preview-checkbox-row {
    grid-template-columns: 1fr;
}
#color-preview-modal .panel-row.preview-checkbox-row > label:first-child {
    grid-column: 1;
    width: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#color-preview-modal .panel-row.preview-presets-row {
    grid-template-columns: 150px minmax(180px, 1fr) auto auto;
}
#color-preview-modal .panel-row.preview-presets-row > label:first-child {
    grid-column: 1;
}
#color-preview-modal .panel-row.preview-presets-row > select,
#color-preview-modal .panel-row.preview-presets-row > input[type="text"] {
    grid-column: 2;
}
#color-preview-modal .panel-row.preview-presets-row > button:nth-of-type(1) {
    grid-column: 3;
}
#color-preview-modal .panel-row.preview-presets-row > button:nth-of-type(2),
#color-preview-modal .panel-row.preview-presets-row > span {
    grid-column: 4;
}
#preview-user-preset-msg {
    font-size: 9px;
    color: #999;
    min-width: 0;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#preview-copy-status {
    font-size: 10px;
    color: #9ad3ff;
    min-width: 70px;
    text-align: left;
}
@media (max-width: 980px) {
    .color-preview-body {
        flex-direction: column;
    }
    .color-preview-left {
        flex: none;
        width: 100%;
        align-items: center;
    }
    .color-preview-right {
        min-width: 0;
    }
    #color-preview-modal .panel-row {
        grid-template-columns: 128px 56px minmax(120px, 1fr) 40px;
    }
}

/* ── Misc ── */
#tick-display {
    font-size: 11px;
    color: #888;
    margin-top: 6px;
}
#model-info {
    font-size: 11px;
    color: #888;
    margin-top: 6px;
}
#model-info a {
    color: #6e8efb;
}
#render-progress {
    font-size: 11px;
    color: #8cf;
    margin: 4px 0;
}
#render-memory-hint {
    font-size: 10px;
    color: #666;
    margin: 2px 0;
}
#grid-cell-count {
    font-size: 10px;
    color: #666;
}
@keyframes hint-flash {
    0% {
        background: #6e8efb;
        color: #fff;
    }
    100% {
        background: #222;
        color: #ddd;
    }
}
.hint-flash {
    animation: hint-flash 1.5s ease-out;
}

/* ── Tool group visibility (controlled by syncToolVisibility) ── */
.tool-group-food,
.tool-group-nests,
.tool-group-obstacles,
.tool-group-nest-options,
.setting-group-food,
.setting-group-nests,
.setting-group-blank-map,
.setting-group-pheromones,
.setting-group-trails {
    /* display toggled by JS via syncToolVisibility() */
}
