:root {
  --bg: #0e1116;
  --panel: #161a22;
  --panel-border: #272e3a;
  --text: #e7ecf3;
  --muted: #8891a0;
  --accent: #5fa8ff;
  --danger: #ff5f5f;
  --grid-line: #232a36;
  --grid-line-strong: #2c3443;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 48px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  flex: 0 0 auto;
}

.brand { font-weight: 700; letter-spacing: 0.02em; }
.brand-sub { color: var(--accent); font-weight: 500; }

.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.status .sep { opacity: 0.5; margin: 0 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #ffb84d; display: inline-block; }
.dot.ok { background: #5dd97c; }
.dot.bad { background: var(--danger); }

.topbar-actions { margin-left: auto; }

button {
  font-family: inherit;
  cursor: pointer;
  background: #1f2531;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
button:hover { background: #28303f; }
button.active { background: var(--accent); color: #06121f; border-color: var(--accent); }
button.danger { color: var(--danger); border-color: #5a2c2c; }
button.danger:hover { background: #3a1d1d; }

#main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

#palette, #editMenu {
  flex: 0 0 180px;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  padding: 12px;
  overflow-y: auto;
}
#editMenu { border-right: none; border-left: 1px solid var(--panel-border); }

.panel-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 14px 0 6px;
}
.panel-title:first-child { margin-top: 0; }

.tool {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  margin-bottom: 6px;
  padding: 8px;
}
.tool svg { width: 22px; height: 22px; flex: 0 0 auto; }
.tool span { font-size: 13px; }

#canvasWrap {
  flex: 1 1 auto;
  position: relative;
  background: #0b0d12;
  min-width: 0;
}
#stage { display: block; width: 100%; height: 100%; touch-action: none; }

#hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(15, 18, 24, 0.75);
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row button { flex: 1 1 auto; }

.segmented { display: flex; border-radius: 6px; overflow: hidden; border: 1px solid var(--panel-border); }
.segmented button { flex: 1; border: none; border-radius: 0; border-right: 1px solid var(--panel-border); }
.segmented button:last-child { border-right: none; }

.dpad { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dpad-row { display: flex; gap: 4px; }
.dpad button, .dpad-row button { width: 40px; height: 32px; }

#colorPicker { width: 40px; height: 32px; padding: 2px; }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.swatch {
  width: 20px; height: 20px; border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.25);
  cursor: pointer;
}

.muted { color: var(--muted); font-size: 12px; }

#colorOnlyField.disabled { opacity: 0.4; pointer-events: none; }
#warpToggle.active { background: var(--accent); color: #06121f; border-color: var(--accent); }

#btnDelete { width: 100%; margin-top: 6px; }

@media (max-width: 860px) {
  #palette, #editMenu { flex-basis: 140px; }
}
