:root {
  --bg: #15171c; --bg2: #1d2027; --bg3: #262a33; --line: #343a46; --fg: #e6e8ee; --fg2: #a3aab8;
  --accent: #6cc0ff; --accent2: #3a7bd5; --ok: #57c785; --warn: #f0b95a; --err: #f06a6a;
  --radius: 8px; --mono: ui-monospace, Consolas, monospace;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body { font-size: 14px; overflow: hidden; }
#app { height: 100%; }
h1 { font-size: 18px; margin: 0; font-weight: 600; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg2); margin: 0 0 8px; }
h3 .hint { text-transform: none; letter-spacing: 0; }
a { color: var(--accent); }
code { font-family: var(--mono); background: var(--bg3); padding: 1px 4px; border-radius: 4px; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.hint { color: var(--fg2); font-size: 12px; }
.err { color: var(--err); font-size: 12px; min-height: 1em; }
.warn { color: var(--warn); font-size: 12px; white-space: pre-line; }
.stats { font-family: var(--mono); font-size: 12px; color: var(--fg2); margin: 6px 0; white-space: pre-line; }

.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.status { font-size: 12px; color: var(--fg2); }

.btn { background: var(--bg3); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 12px; cursor: pointer; font: inherit; font-size: 13px; }
.btn:hover { border-color: var(--accent2); }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: #7a3a3a; }
.btn.tiny { padding: 3px 8px; font-size: 12px; }
.btn.big { width: 100%; padding: 12px; font-size: 15px; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.badge { background: var(--accent2); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; margin-left: 4px; }
.btnrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg.wide { display: flex; }
.seg.wide .seg-btn { flex: 1; }
.seg-btn { background: var(--bg3); color: var(--fg2); border: 0; padding: 5px 10px; cursor: pointer; font: inherit; font-size: 12px; }
.seg-btn.active { background: var(--accent2); color: #fff; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg2); cursor: pointer; }
select, input[type=text] { background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; width: 100%; }
input[type=range] { width: 100%; accent-color: var(--accent2); }
label.row, div.row { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 8px; margin: 6px 0; font-size: 12px; color: var(--fg2); }
label.field { display: block; margin: 8px 0; font-size: 12px; color: var(--fg2); }
label.field input, label.field select { margin-top: 4px; }
.presets .btn { margin-right: 4px; }

/* species */
.species-main { padding: 24px; overflow: auto; }
.lead { max-width: 760px; color: var(--fg2); }
.species-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin: 20px 0; max-width: 1100px; }
.species-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; cursor: pointer; text-align: left; color: var(--fg); font: inherit; }
.species-card:hover { border-color: var(--accent); }
.species-card:disabled { opacity: .45; cursor: not-allowed; }
.species-card .name { font-size: 16px; font-weight: 600; }
.species-card .meta { color: var(--fg2); font-size: 12px; margin-top: 6px; }
.species-card .thumb { width: 100%; aspect-ratio: 1; background: var(--bg3); border-radius: 8px; margin-bottom: 8px; image-rendering: pixelated; object-fit: contain; }
.howto { max-width: 760px; color: var(--fg2); background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-top: 12px; }
.howto summary { cursor: pointer; color: var(--fg); }

/* editor */
.editor-grid { flex: 1; display: grid; grid-template-columns: minmax(240px, var(--lf, 1fr)) 10px minmax(240px, var(--rf, 1.3fr)) 300px; gap: 0 4px; padding: 8px; min-height: 0; }
.editor-grid.max-3d { grid-template-columns: 1fr 0 0 300px; }
.editor-grid.max-2d { grid-template-columns: 0 0 1fr 300px; }
/* explicit placement so hiding a pane never shifts the others into the collapsed columns */
.editor-grid > .pane-3d { grid-column: 1; } .editor-grid > .gutter { grid-column: 2; } .editor-grid > .pane-2d { grid-column: 3; } .editor-grid > .pane-tools-side { grid-column: 4; }
.editor-grid.max-3d .pane-2d, .editor-grid.max-2d .pane-3d, .editor-grid.max-3d .gutter, .editor-grid.max-2d .gutter { visibility: hidden; border: 0; }
.gutter { cursor: col-resize; position: relative; border-radius: 4px; }
.gutter::after { content: ''; position: absolute; left: 3px; right: 3px; top: 0; bottom: 0; border-radius: 4px; background: var(--line); opacity: .5; transition: .15s; }
.gutter:hover::after, .gutter.dragging::after { background: var(--accent2); opacity: 1; }
body.resizing { cursor: col-resize; user-select: none; }
.btn.maxi { margin-left: auto; }
.editor-grid.max-3d .pane-3d .btn.maxi, .editor-grid.max-2d .pane-2d .btn.maxi { background: var(--accent2); color: #fff; border-color: var(--accent2); }
.pane { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.pane-tools { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.pane-footer { padding: 6px 8px; border-top: 1px solid var(--line); font-size: 12px; }
.pane-3d canvas { flex: 1; width: 100%; min-height: 0; display: block; background: radial-gradient(circle at 50% 40%, #2b3140, #14161b); touch-action: none; }
.pane-3d canvas.painting { cursor: crosshair; }
.pal-row { display: grid; grid-template-columns: 110px 1fr 66px; gap: 6px; align-items: center; margin: 3px 0; }
.pal-row label { color: var(--fg2); }
.swatch6 { display: inline-grid; grid-template-columns: repeat(6, 1fr); height: 18px; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.swatch6 i { display: block; }
.overlays summary { cursor: pointer; color: var(--fg2); margin-top: 4px; }
.overlay-list { display: flex; flex-wrap: wrap; gap: 4px 10px; max-height: 90px; overflow: auto; margin-top: 4px; }
.overlay-list label { font-size: 11px; color: var(--fg2); display: inline-flex; gap: 4px; align-items: center; }

.canvas2d-wrap { flex: 1; overflow: hidden; position: relative; background: #0d0e11 repeating-conic-gradient(#181a1f 0 25%, #121317 0 50%) 0 0 / 16px 16px; touch-action: none; }
#canvas2d { position: absolute; left: 0; top: 0; image-rendering: pixelated; cursor: crosshair; }
.canvas2d-wrap.panning #canvas2d { cursor: grab; }

.pane-tools-side { overflow-y: auto; padding: 0; }
.box { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.toolgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool { background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; color: var(--fg); padding: 7px; cursor: pointer; font: inherit; font-size: 12px; }
.tool.active { border-color: var(--accent); background: #2b3a4d; }
.chan-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.chan { border: 2px solid transparent; border-radius: 6px; padding: 8px 4px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; background: var(--c); color: #111; }
.chan.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.band-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin: 6px 0; }
.band { height: 30px; border-radius: 4px; border: 2px solid var(--line); background: var(--v); cursor: pointer; }
.band.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* pack */
.pack-main { padding: 20px; overflow: auto; }
.pack-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 900px; }
.pack-actions { display: flex; gap: 10px; align-items: center; margin: 12px 0; }
.pack-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.pack-item { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; grid-template-columns: 72px 1fr; gap: 10px; }
.pack-item img { width: 72px; height: 72px; image-rendering: pixelated; background: repeating-conic-gradient(#2a2d35 0 25%, #1c1e24 0 50%) 0 0 / 12px 12px; border-radius: 6px; }
.pack-item .n { font-family: var(--mono); font-weight: 600; word-break: break-all; }
.pack-item .m { color: var(--fg2); font-size: 12px; margin: 4px 0; }
.pack-item .a { display: flex; gap: 4px; flex-wrap: wrap; }
.pack-empty { color: var(--fg2); padding: 30px; text-align: center; grid-column: 1 / -1; }

dialog { background: var(--bg2); color: var(--fg); border: 1px solid var(--line); border-radius: 12px; padding: 18px 22px; min-width: 320px; }
dialog::backdrop { background: rgba(0,0,0,.55); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #2c3140; color: var(--fg); padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); opacity: 0; pointer-events: none; transition: .2s; max-width: 80vw; white-space: pre-line; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--err); }

/* skin mode (full-colour species): hide palette-driven controls */
body.skin-mode .genetics-only, body.skin-mode .pane-3d .pal-row, body.skin-mode .overlays, body.skin-mode #channel-palettes, body.skin-mode [data-view2d=channels], body.skin-mode #shade-band, body.skin-mode #shade-base { display: none !important; }
input[type=color] { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); padding: 2px; cursor: pointer; }

/* − / + steppers around sliders */
.stepper { display: flex; align-items: center; gap: 5px; min-width: 0; }
.stepper input[type=range] { flex: 1; min-width: 0; }
.step-btn { width: 22px; height: 22px; flex: none; border-radius: 5px; border: 1px solid var(--line); background: var(--bg3); color: var(--fg); cursor: pointer; font-size: 14px; line-height: 1; padding: 0; }
.step-btn:hover { border-color: var(--accent2); color: var(--accent); }
.step-btn:active { background: var(--accent2); color: #fff; }
