:root {
  --bg-panel: #2b2b2b;
  --bg-panel-2: #333333;
  --bg-workspace: #3a3a3a;
  --border: #1e1e1e;
  --border-light: #4a4a4a;
  --text: #d8d8d8;
  --text-dim: #9a9a9a;
  --accent: #4a90d9;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-panel);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  user-select: none;
}

.hidden { display: none !important; }

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 8px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
#topbar .spacer { flex: 1; }
.icon-btn {
  width: 28px;
  height: 26px;
  border: none;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  padding: 4px;
}
.icon-btn svg { width: 100%; height: 100%; fill: var(--text-dim); }
.icon-btn:hover:not(:disabled) { background: var(--bg-panel-2); }
.icon-btn:hover:not(:disabled) svg { fill: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }

#app-logo { width: 16px; height: 16px; display: block; margin-right: -4px; }
#app-title { font-weight: 600; color: var(--text-dim); }
#doc-info { color: var(--text-dim); font-size: 12px; }
#zoom-readout { min-width: 48px; text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.menu-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 13px;
}
.menu-btn:hover { background: var(--bg-panel-2); }

.menu-root { position: relative; }
.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  min-width: 220px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
  padding: 4px 0;
}
.menu-root.open .menu-dropdown { display: block; }
.menu-dropdown button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  padding: 7px 14px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}
.menu-dropdown button:hover { background: var(--accent); color: #fff; }
.menu-dropdown .shortcut { color: var(--text-dim); margin-left: 24px; }
.menu-dropdown button:hover .shortcut { color: #e8e8e8; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.menu-check { visibility: hidden; width: 16px; display: inline-block; }
.backdrop-item.checked .menu-check,
.check-item.checked .menu-check { visibility: visible; }
.menu-dropdown .backdrop-item,
.menu-dropdown .check-item { justify-content: flex-start; }

/* ---------- Layout ---------- */
#main {
  display: flex;
  height: calc(100% - 34px);
}

/* ---------- Toolbar ---------- */
#toolbar {
  width: 44px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 8px;
  gap: 4px;
}
.tool-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tool-btn svg { width: 20px; height: 20px; fill: var(--text-dim); }
.tool-btn:hover { background: var(--bg-panel-2); }
.tool-btn:hover svg { fill: var(--text); }
.tool-btn.active { background: var(--accent); }
.tool-btn.active svg { fill: #fff; }
.tool-sep { width: 26px; height: 1px; background: var(--border-light); margin: 6px 0; }
.tool-btn.placeholder {
  border: 1px dashed var(--border-light);
  opacity: 0.35;
  cursor: default;
}
#fg-swatch {
  width: 26px;
  height: 26px;
  border: 2px solid #fff;
  outline: 1px solid var(--border);
  background: #000;
  cursor: default;
}

.toolbar-spacer { flex: 1; }
#settings-btn, #about-btn { margin-bottom: 4px; }

/* ---------- About dialog ---------- */
.modal-dim {
  position: fixed;
  inset: 0;
  z-index: 220;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
#about-dialog {
  position: relative;
  width: 340px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  padding: 24px 28px;
}
#about-logo { width: 44px; height: 44px; display: block; margin-bottom: 10px; }
#about-dialog h2 { font-size: 20px; margin-bottom: 4px; }
#about-dialog .tagline { color: var(--text-dim); font-size: 13px; margin-bottom: 14px; }
#about-dialog ul { margin: 0 0 16px 18px; padding: 0; font-size: 13px; line-height: 1.7; }
#about-dialog .credit { font-size: 12px; color: var(--text-dim); }
#about-dialog .credit a { color: var(--accent); text-decoration: none; }
#about-dialog .credit a:hover { text-decoration: underline; }
#about-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  border-radius: 4px;
}
#about-close:hover { background: rgba(255,255,255,0.08); color: var(--text); }

#feature-dialog {
  position: relative;
  width: 420px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  padding: 24px 28px;
}
#feature-dialog h2 { font-size: 17px; margin-bottom: 4px; }
.feat-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 14px 0 8px;
}
#feature-list {
  margin: 0 0 4px 2px;
  padding: 0;
  list-style: none;
  font-size: 12.5px;
  line-height: 1.65;
}
#feature-list strong { color: var(--text); }
#feature-list span { color: var(--text-dim); }
#feature-dialog .tagline { color: var(--text-dim); font-size: 12.5px; margin-bottom: 12px; }
#community-link {
  display: inline-block;
  margin: 2px 0 6px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 13px;
}
#community-link:hover { background: #5a9de0; }
.dlg-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  border-radius: 4px;
}
.dlg-close:hover { background: rgba(255,255,255,0.08); color: var(--text); }

/* ---------- Workspace ---------- */
#workspace {
  flex: 1;
  position: relative;
  background: var(--bg-workspace);
  overflow: hidden;
  min-width: 0;
}
#viewport-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
#viewport-canvas.panning { cursor: grab; }
#viewport-canvas.panning:active { cursor: grabbing; }
#viewport-canvas.eyedropper { cursor: copy; }
#workspace-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #6a6a6a;
  font-size: 15px;
  pointer-events: none;
}

/* ---------- Right panel ---------- */
#panel {
  width: 240px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
}
.panel-section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
/* Subtle top highlight makes each divider read as a groove between sections */
.panel-section + .panel-section {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.panel-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  border-radius: 3px;
  margin-left: -4px;
  padding: 2px 4px;
}
.panel-section h3:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.panel-section h3 button { margin-left: auto; }
.sec-chevron {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  display: inline-flex;
}
.sec-chevron svg { width: 100%; height: 100%; fill: currentColor; transition: transform 0.12s; }
.panel-section.collapsed .sec-chevron svg { transform: rotate(-90deg); }
.panel-section.collapsed h3 { margin-bottom: 0; }
/* !important so id-selector display rules (#layer-list etc.) can't win */
.panel-section.collapsed > *:not(h3) { display: none !important; }
.panel-section h3 button {
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  color: var(--text);
  border-radius: 3px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.panel-section h3 button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Color picker */
#sv-canvas { display: block; border-radius: 3px; cursor: crosshair; margin-bottom: 6px; }
#hue-canvas { display: block; border-radius: 3px; cursor: crosshair; margin-bottom: 6px; }
#color-row { display: flex; gap: 8px; align-items: center; }
#color-swatch {
  width: 28px; height: 28px;
  border: 1px solid var(--border-light);
  border-radius: 3px;
  background: #000;
}
#hex-input {
  flex: 1;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  color: var(--text);
  border-radius: 3px;
  padding: 5px 8px;
  font-family: Consolas, monospace;
  font-size: 12px;
}

/* Settings */
.setting-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}
.setting-row label { width: 52px; color: var(--text-dim); font-size: 12px; flex-shrink: 0; }
.setting-row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.setting-row input[type=number] {
  width: 48px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  color: var(--text);
  border-radius: 3px;
  padding: 3px 4px;
  font-size: 12px;
}
.setting-row.checkboxes { flex-direction: column; align-items: flex-start; gap: 4px; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); cursor: pointer; }
.chk input { accent-color: var(--accent); }

/* Layers panel */
#layer-controls { margin-bottom: 8px; }
#layer-blend {
  width: 100%;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  color: var(--text);
  border-radius: 3px;
  padding: 5px 6px;
  font-size: 12px;
  margin-bottom: 6px;
}
#layer-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-panel-2);
  padding: 3px;
  min-height: 46px;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 5px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid transparent;
  position: relative;
}
.layer-row:hover { background: #3d3d3d; }
.layer-row.active { background: #44546a; border-color: var(--accent); }
.layer-row.dragging { opacity: 0.4; }
.layer-row.drop-above::before,
.layer-row.drop-below::after {
  content: '';
  position: absolute;
  left: 2px; right: 2px;
  height: 2px;
  background: var(--accent);
}
.layer-row.drop-above::before { top: -2px; }
.layer-row.drop-below::after { bottom: -2px; }
.layer-eye {
  width: 22px; height: 22px;
  flex-shrink: 0;
  border: none;
  background: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
}
.layer-eye svg { width: 100%; height: 100%; fill: #666; }
.layer-eye.on svg { fill: var(--text); }
.layer-eye:hover { background: rgba(255,255,255,0.08); }
.layer-thumb {
  width: 48px; height: 36px;
  flex-shrink: 0;
  border: 1px solid var(--border-light);
  border-radius: 2px;
  background: #888;
}
.layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.layer-rename {
  flex: 1;
  min-width: 0;
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 3px;
  padding: 3px 5px;
  font-size: 12px;
}
#layer-toolbar {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  align-items: center;
}
#layer-toolbar .spacer { flex: 1; }
#layer-toolbar button {
  width: 28px; height: 26px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  cursor: pointer;
  padding: 3px;
}
#layer-toolbar button svg { width: 100%; height: 100%; fill: var(--text-dim); }
#layer-toolbar button:hover { background: var(--accent); border-color: var(--accent); }
#layer-toolbar button:hover svg { fill: #fff; }
#layer-toolbar button:disabled { opacity: 0.35; cursor: default; }
#layer-toolbar button:disabled:hover { background: var(--bg-panel-2); border-color: var(--border-light); }
#layer-toolbar button:disabled:hover svg { fill: var(--text-dim); }

/* Brush grid */
#brush-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.brush-item {
  border: 2px solid transparent;
  border-radius: 4px;
  background: #e8e8e8;
  cursor: pointer;
  padding: 0;
  aspect-ratio: 1;
  overflow: hidden;
  position: relative;
}
.brush-item canvas { width: 100%; height: 100%; display: block; }
.brush-item.active { border-color: var(--accent); }
.brush-item:hover { outline: 1px solid var(--border-light); }
#brush-status { margin-top: 8px; color: var(--text-dim); font-size: 11px; line-height: 1.4; }
.brush-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}
.brush-item:hover .brush-del { display: flex; }
.brush-del:hover { background: #d9534a; }

/* ---------- Modal ---------- */
#modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
#newdoc-dialog {
  width: 380px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  padding: 18px 20px;
}
#newdoc-dialog h2 { font-size: 15px; margin-bottom: 14px; font-weight: 600; }
.dlg-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.dlg-row > label:first-child { width: 78px; color: var(--text-dim); flex-shrink: 0; }
.dlg-row input[type=number], .dlg-row select, .dlg-row input[type=text] {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--text);
  border-radius: 3px;
  padding: 6px 8px;
  font-size: 13px;
}
.dlg-row input[type=number] { width: 100px; }
.dlg-row select { flex: 1; }
#unit-select { flex: 0 0 auto; width: 70px; }
#unit-echo { color: var(--text-dim); width: 70px; padding-left: 4px; }
.radio-group { display: flex; gap: 16px; }
.radio-group label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.radio-group input { accent-color: var(--accent); }
#pixel-echo { color: var(--text-dim); font-size: 12px; margin-left: 86px; }
.dlg-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.dlg-buttons button {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--text);
  border-radius: 4px;
  padding: 7px 16px;
  font-size: 13px;
  cursor: pointer;
}
.dlg-buttons button:hover { background: #3f3f3f; }
.dlg-buttons button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.dlg-buttons button.primary:hover { background: #5a9de0; }

/* ---------- Brush popover ---------- */
#brush-popover {
  position: fixed;
  z-index: 250;
  width: 250px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  box-shadow: 0 10px 32px rgba(0,0,0,0.6);
  padding: 12px 14px;
}
#brush-popover h4 {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 18px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  max-width: 60vw;
  font-size: 13px;
  white-space: pre-line;
}
