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

:root {
  --bg:       #100d0a;
  --surface:  #17130f;
  --surface2: #201a14;
  --border:   #332a20;
  --text:     #ecdfd0;
  --muted:    #8a7a67;
  --accent:   #e8a13c;
  --accent2:  #6fbf6a;
  --danger:   #d8613f;
  --mono: 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

/* ── Header ──────────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 20px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.hd-logo {
  font-size: 16px;
  color: var(--accent);
  line-height: 1;
  user-select: none;
}

.hd-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.hd-sub {
  font-size: 12.5px;
  color: var(--muted);
  flex: 1;
}

.hd-link {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 9px;
}
.hd-link:hover { color: var(--accent); border-color: var(--accent); }

/* ── Layout ──────────────────────────────────────────────────────────── */

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */

aside {
  width: 250px;
  min-width: 250px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.sb-group { display: flex; flex-direction: column; gap: 4px; }

.preset-btn {
  text-align: left;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: var(--sans);
}
.preset-btn:hover { border-color: var(--accent); color: var(--accent); }
.preset-btn:focus-visible, .mat-btn:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.mat-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 7px;
  cursor: pointer;
  color: var(--text);
  font-family: var(--sans);
  text-align: left;
}
.mat-btn:hover { border-color: var(--muted); }
.mat-btn.mat-selected { border-color: var(--accent); background: #2a2014; }

.mat-swatch {
  width: 13px; height: 13px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.15);
  background-image:
    linear-gradient(45deg, #333 25%, transparent 25%), linear-gradient(-45deg, #333 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #333 75%), linear-gradient(-45deg, transparent 75%, #333 75%);
  background-size: 6px 6px;
  background-position: 0 0, 0 3px, 3px -3px, -3px 0px;
}

.mat-name { font-size: 11.5px; flex: 1; }
.mat-key {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  min-width: 14px;
  text-align: center;
}

.sb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.sb-label { font-size: 12px; color: var(--muted); width: 40px; }
.sb-value { font-family: var(--mono); font-size: 12px; width: 20px; text-align: right; }

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.gravity-btn {
  margin-top: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12.5px;
  text-align: left;
}
.gravity-btn:hover { border-color: var(--accent); }
#gravity-icon { color: var(--accent); font-weight: 700; }

.field-notes {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.field-notes summary {
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.notes-list { margin-top: 10px; display: flex; flex-direction: column; gap: 7px; }
.note-row {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.4;
}
.note-row strong { color: var(--text); }
.note-swatch {
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-top: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.15);
}

/* ── Main ────────────────────────────────────────────────────────────── */

main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 18px;
  gap: 12px;
  overflow: auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar button {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 13px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: var(--sans);
}
.toolbar button:hover { border-color: var(--accent); }
.btn-play { border-color: var(--accent2); color: var(--accent2); }
.btn-play.btn-paused { border-color: var(--accent); color: var(--accent); }
#step-btn:disabled, #load-state-btn:disabled { opacity: 0.35; cursor: not-allowed; }
#save-state-btn:hover, #load-state-btn:hover:not(:disabled) { border-color: var(--accent2); color: var(--accent2); }

.speed-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.speed-wrap input { width: 70px; }
#speed-val { font-family: var(--mono); width: 22px; }

.stats {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  margin-left: 4px;
}

.kb-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
kbd {
  font-family: var(--mono);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 10px;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 940px;
  margin: 0 auto;
  background: #0a0704;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.5), 0 8px 30px rgba(0,0,0,0.35);
  cursor: none;
}

canvas#grid {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.brush-cursor {
  position: absolute;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.1s;
  mix-blend-mode: difference;
}

/* ── Footer ──────────────────────────────────────────────────────────── */

footer {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}
footer a { text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  aside {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }
  .kb-hint { display: none; }
}
