:root {
  --bg: #16171d;
  --panel: #1f2028;
  --panel2: #282a34;
  --line: #353846;
  --text: #d8dae3;
  --dim: #8c90a3;
  --accent: #6aa8ff;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif; }
body { display: flex; flex-direction: column; overflow: hidden; }
button, select, input { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; }
button { padding: 4px 9px; cursor: pointer; }
button:hover { border-color: var(--accent); }
input[type=number], input[type=text] { padding: 3px 5px; }
input[type=checkbox] { accent-color: var(--accent); }

#topbar { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { letter-spacing: .02em; }
.menu { display: flex; gap: 4px; flex-wrap: wrap; }
.spacer { flex: 1; }
.toggle { display: flex; align-items: center; gap: 4px; color: var(--dim); cursor: pointer; user-select: none; }

#layout { flex: 1; display: flex; min-height: 0; }
#tools { width: 74px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; padding: 6px; overflow-y: auto; }
#tools button { display: flex; flex-direction: column; align-items: center; padding: 4px 0; font-size: 18px; line-height: 1.1; }
#tools button span { font-size: 10px; color: var(--dim); }
#tools button.active { background: #2e3c58; border-color: var(--accent); }
.sep { height: 1px; background: var(--line); margin: 4px 0; }
.brush { display: flex; flex-direction: column; font-size: 11px; color: var(--dim); }
.brush input { width: 100%; }
#colorPair { position: relative; width: 58px; height: 52px; margin-top: 4px; }
#colorPair div { position: absolute; width: 34px; height: 34px; border: 2px solid #000; outline: 1px solid #fff6; }
#primarySwatch { left: 0; top: 0; }
#secondarySwatch { right: 0; bottom: 0; }
.idx { text-align: center; font-size: 11px; color: var(--dim); }

#stage { flex: 1; position: relative; min-width: 0; background: #0d0e12; background-image: radial-gradient(#1a1b22 1px, transparent 1px); background-size: 16px 16px; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }

#panel { width: 300px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 0 10px 10px; }
#panel section { border-bottom: 1px solid var(--line); padding: 8px 0 10px; }
#panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin: 2px 0 8px; }
#panel h2 small { text-transform: none; letter-spacing: 0; color: var(--accent); margin-left: 6px; }
#paletteCanvas { width: 100%; aspect-ratio: 1; image-rendering: pixelated; display: block; cursor: pointer; border: 1px solid var(--line); }
.hint { color: var(--dim); font-size: 11px; margin: 6px 0; }
.row { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.row > * { flex: 1 1 auto; min-width: 0; }
#colorInput { flex: 0 0 36px; height: 28px; padding: 1px; }
#hexInput { flex: 0 0 80px; font-family: ui-monospace, monospace; }
#timeLabel { flex: 0 0 44px; text-align: right; font-family: ui-monospace, monospace; }

.cycle, .palitem { display: grid; gap: 4px; align-items: center; padding: 5px; border: 1px solid var(--line); border-radius: 5px; margin-bottom: 5px; background: var(--panel2); }
.cycle { grid-template-columns: 52px 46px minmax(0, 1fr) auto auto; }
.cycle select { width: 100%; min-width: 0; }
.cycle.sel, .palitem.sel { border-color: var(--accent); }
.cycle .range { font-family: ui-monospace, monospace; font-size: 11px; cursor: pointer; }
.cycle input[type=number] { width: 100%; }
.cycle label { font-size: 11px; color: var(--dim); display: flex; gap: 2px; align-items: center; }
.cycle button, .palitem button { padding: 2px 6px; }
.palitem { grid-template-columns: 1fr 104px auto; cursor: pointer; }
.palitem input { width: 100%; }
.empty { color: var(--dim); font-size: 12px; }

#status { display: flex; gap: 18px; padding: 3px 10px; background: var(--panel); border-top: 1px solid var(--line); color: var(--dim); font-size: 12px; font-family: ui-monospace, monospace; }
#stMsg { color: var(--accent); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; }
dialog form { display: flex; flex-direction: column; gap: 8px; min-width: 220px; }
dialog h3 { margin: 0 0 4px; }
dialog label { display: flex; justify-content: space-between; gap: 10px; }
dialog input { width: 90px; }
dialog menu { display: flex; justify-content: flex-end; gap: 6px; padding: 0; margin: 6px 0 0; }

@media (max-width: 820px) {
  #layout { flex-direction: column; }
  #tools { width: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); }
  #tools button { width: 52px; }
  #stage { min-height: 50vh; }
  #panel { width: auto; border-left: 0; }
}
body.hide-panels #tools, body.hide-panels #panel { display: none; }
.lbl { flex: 0 0 auto !important; color: var(--dim); font-size: 11px; display: flex; align-items: center; gap: 3px; }
.num { flex: 0 0 46px !important; }
#layerList { margin-top: 6px; max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 5px; }
.layer { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
.layer:last-child { border-bottom: 0; }
.layer.sel { background: #2e3c58; }
.layer.hidden .thumb, .layer.hidden .lname { opacity: .45; }
.layer.drop-above { box-shadow: inset 0 2px 0 var(--accent); }
.layer.drop-below { box-shadow: inset 0 -2px 0 var(--accent); }
.layer .eye { flex: 0 0 24px; padding: 0; height: 24px; border: 0; background: transparent; color: var(--text); }
.layer .thumb { flex: 0 0 44px; width: 44px; height: 44px; image-rendering: pixelated; background: #222; border: 1px solid var(--line); }
.layer .lname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .lmeta { color: var(--dim); font-size: 11px; }
.lrename { flex: 1; min-width: 0; }
.layerbtns button { padding: 3px 4px; font-size: 12px; }
