:root {
  --bg: #14161a;
  --panel: #1c1f25;
  --panel-2: #23272f;
  --line: #2f343d;
  --text: #e6e9ee;
  --dim: #8d95a3;
  --accent: #7c8cf8;
  --accent-2: #4ad6a8;
  --warn: #f0a35e;
  --err: #f07070;
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
header h1 { font-size: 0.95rem; font-weight: 500; margin: 0; letter-spacing: 0.01em; }
header h1 b { color: var(--accent); font-weight: 600; }
header h1 span { color: var(--dim); font-weight: 400; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; }
.env { font-size: 0.75rem; color: var(--dim); font-family: ui-monospace, monospace; }
.env .ok { color: var(--accent-2); }
.env .warn { color: var(--warn); }

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(320px, 1fr) 270px;
  gap: 1px;
  background: var(--line);
}

.panel {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.panel.params { overflow-y: auto; padding-bottom: 1.5rem; }

.panel-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--dim);
  font-weight: 600;
}
.params .panel-head { margin-top: 0.6rem; border-top: 1px solid var(--line); }
.params .panel-head:first-child { margin-top: 0; border-top: none; }

.tools { margin-left: auto; display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem; }
.tools .label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--dim); }
button.brush { min-width: 1.9rem; font-variant-numeric: tabular-nums; }
.tools input[type="number"] {
  font: inherit; font-size: 0.78rem; width: 3.4rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; padding: 0.22rem 0.35rem;
  font-variant-numeric: tabular-nums;
}
.sep { width: 1px; height: 16px; background: var(--line); }

button {
  font: inherit;
  font-size: 0.76rem;
  white-space: nowrap;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.26rem 0.5rem;
  cursor: pointer;
}
/* Icon-only buttons stay square so the row keeps its rhythm. */
button.icon { min-width: 1.85rem; text-align: center; font-size: 0.9rem; line-height: 1; }
button:hover { border-color: var(--dim); }
/* The active state must not change the text metrics, or the whole toolbar
   shifts by a couple of pixels every time you pick a tool. */
button.active { background: var(--accent); border-color: var(--accent); color: #10131a; }
button.primary { background: var(--accent); border-color: var(--accent); color: #10131a; }
button.ghost { background: transparent; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.canvas-wrap { flex: 1; min-height: 0; position: relative; overflow: hidden; }
canvas#grid { display: block; cursor: crosshair; touch-action: none; }

/* The opening menu, floating over the grid at the edge you clicked. */
.popover {
  position: absolute;
  z-index: 5;
  width: 15rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 8px 24px #0009;
  padding-bottom: 0.5rem;
}
.popover-head {
  padding: 0.45rem 0.85rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--dim);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.popover-note { margin: 0.1rem 0 0.4rem; padding: 0 0.85rem; font-size: 0.68rem; line-height: 1.45; color: #6f7787; }
.popover-actions { display: flex; gap: 0.4rem; padding: 0 0.85rem; }
.popover-actions button { flex: 1; }

.three { flex: 1; min-height: 0; position: relative; }
.three canvas { display: block; }

.hint {
  margin: 0;
  padding: 0.5rem 0.85rem;
  font-size: 0.72rem;
  color: var(--dim);
  border-top: 1px solid var(--line);
  line-height: 1.5;
}
kbd {
  font: inherit; font-size: 0.68rem;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 3px; padding: 0 0.25rem;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; padding: 0.5rem 0.85rem 0.1rem; font-size: 0.76rem; color: var(--dim); }
.field span { display: flex; justify-content: space-between; }
.field output { color: var(--text); font-family: ui-monospace, monospace; }
.field small { font-size: 0.68rem; line-height: 1.45; color: #6f7787; }
.field input[type="text"],
.field input[type="number"] {
  font: inherit; font-size: 0.8rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; padding: 0.3rem 0.45rem;
  width: 100%;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }

.check {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.35rem 0.85rem; font-size: 0.76rem; color: var(--dim); cursor: pointer;
}
.check input { accent-color: var(--accent); }
.tools .check { padding: 0; }

.row { display: grid; grid-template-columns: 1fr 1fr; }
.sub { border-left: 2px solid var(--line); margin: 0.2rem 0 0.2rem 0.85rem; }
.hidden { display: none; }

.exports { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.6rem 0.85rem; }
.exports button { flex: 1 1 auto; }

.job {
  margin: 0 0.85rem; padding: 0.5rem 0.6rem;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px;
  font-size: 0.72rem; color: var(--dim); line-height: 1.5;
  font-family: ui-monospace, monospace;
  word-break: break-word;
}
.job .ok { color: var(--accent-2); }
.job .err { color: var(--err); }
.job a { color: var(--accent); }

@media (max-width: 1100px) {
  body { overflow: auto; height: auto; }
  main { grid-template-columns: 1fr; }
  .panel.editor, .panel.viewer { min-height: 60vh; }
}

/* ---------- credits ---------- */
.credits {
  margin: 1rem 0.75rem 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
  font-size: 0.68rem;
  line-height: 1.45;
  color: var(--dim);
}
.credits a { color: var(--dim); text-decoration: underline; }
.credits a:hover { color: var(--text); }
