/* PixelWorld UI */
:root {
  --bg: #0c0e16;
  --panel: #161a26;
  --panel2: #1d2230;
  --line: #2a3142;
  --text: #e7ecf5;
  --muted: #8893a8;
  --accent: #57d08a;
  --accent2: #4aa3ff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
  /* the page now scrolls: the main view fills the screen, controls sit below it */
  overflow-x: hidden;
  overflow-y: auto;
}
header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #11131d, #0c0e16);
  border-bottom: 1px solid var(--line);
  /* keep the title + HUD pinned while you scroll down to the controls */
  position: sticky;
  top: 0;
  z-index: 10;
}
h1 {
  font-size: 20px;
  margin: 0;
  letter-spacing: 0.5px;
  font-weight: 800;
}
h1 span { color: var(--accent); }

.hud {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.hud span { color: var(--text); white-space: nowrap; }
.hud .muted { color: var(--muted); }

main {
  display: grid;
  grid-template-columns: 168px 1fr;
  gap: 12px;
  padding: 12px;
  /* fill the screen below the (sticky) header, so the controls land below the fold */
  height: calc(100vh - 55px);
}
/* when the palette is collapsed the canvas takes the freed width */
main:has(#palette.collapsed) { grid-template-columns: 40px 1fr; }

/* palette ------------------------------------------------------------- */
.palette {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
}
.palette-toggle {
  align-self: flex-end;
  background: var(--panel2);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  flex: none;
}
.palette-toggle:hover { color: var(--text); border-color: var(--accent2); }
.palette-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.palette.collapsed { padding: 8px 6px; align-items: center; }
.palette.collapsed .palette-items { display: none; }
.swatch {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  position: relative;
}
.swatch:hover { background: var(--panel2); }
.swatch.active {
  background: var(--panel2);
  border-color: var(--accent);
}
.swatch .chip {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  flex: none;
}
.swatch .name { flex: 1; }
.swatch .key {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
}

/* stage / canvas ------------------------------------------------------ */
.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05060a;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}
.scroll-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  background: rgba(12, 14, 22, 0.7);
  padding: 3px 10px;
  border-radius: 12px;
  pointer-events: none;
}
#world {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  touch-action: none;
}

/* controls (a panel BELOW the main view — scroll down to reach it) ----- */
.controls {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0 12px 12px;
  padding: 14px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 22px;
}
.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 180px;
}
.ctrl-group.help { flex: 1; min-width: 240px; max-width: 520px; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }
.btn {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: var(--accent2); }
.btn.primary { background: #20303f; }
.btn.primary.on { background: #1f3a2c; border-color: var(--accent); }

.slider {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.slider span { color: var(--text); float: right; }
.slider input { width: 100%; accent-color: var(--accent); }
.check { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.check input { accent-color: var(--accent); }

.help { font-size: 12px; color: var(--muted); border-left: 1px solid var(--line); padding-left: 18px; }
.help p { margin: 0 0 8px; }
.help b { color: var(--text); }
.muted { color: var(--muted); }

@media (max-width: 720px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: calc(100vh - 55px); }
  main:has(#palette.collapsed) { grid-template-columns: 1fr; }
  /* on a narrow screen an expanded palette lays its swatches out in a row */
  .palette:not(.collapsed) .palette-items { flex-direction: row; flex-wrap: wrap; }
  .help { border-left: none; padding-left: 0; }
}
