:root {
  --page: #121212;
  --surface: #1c1c1c;
  --line: #2c2c2c;
  --line-strong: #474747;
  --text: #e8e8e8;
  --muted: #8a8a8a;
  --accent: #3f9a6e;
  --accent-hover: #4cb383;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, sans-serif;
}
a { color: var(--accent-hover); }
.top {
  height: 48px; display: flex; align-items: center; gap: 6px;
  padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.top a { color: var(--muted); text-decoration: none; }
.top a:hover { color: var(--text); }

/* index page */
.list { max-width: 760px; margin: 0 auto; padding: 24px 20px; }
.list h1 { font-size: 20px; margin: 0 0 16px; }
.list ul { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.list li { padding: 14px 0; border-bottom: 1px solid var(--line); }
.list li a { font-weight: 600; font-size: 15px; }
.list li p { margin: 4px 0 0; color: var(--muted); }

/* editor */
.editor { display: grid; grid-template-columns: 360px 1fr; min-height: calc(100vh - 48px); }
.controls { border-right: 1px solid var(--line); background: var(--surface); padding: 8px 16px 32px; overflow-y: auto; max-height: calc(100vh - 48px); position: sticky; top: 0; }
fieldset { border: 0; border-bottom: 1px solid var(--line); margin: 0; padding: 12px 0 16px; display: grid; gap: 10px; }
legend { font-weight: 600; font-size: 14px; padding: 0; float: left; width: 100%; margin-bottom: 2px; }
label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text); }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.row { display: flex; gap: 10px; align-items: end; }
.row > label { flex: 1; min-width: 0; }
.row > label.check { flex: 0 0 auto; padding-bottom: 6px; }
.row.wrap { flex-wrap: wrap; gap: 6px; }

input[type=text], input[type=number], select, textarea {
  width: 100%; background: var(--page); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 8px; font: inherit;
}
textarea { resize: vertical; }
input[type=color] { width: 100%; height: 32px; padding: 2px; background: var(--page); border: 1px solid var(--line-strong); border-radius: 6px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); margin: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button, .button {
  background: var(--page); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 6px 12px; font: inherit; cursor: pointer; text-decoration: none;
  transition: border-color .15s, background .15s; white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }

details summary { cursor: pointer; color: var(--text); font-size: 13px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; padding-top: 8px; }
#bf.checks { max-height: 220px; overflow-y: auto; }
#bf label { font-size: 15px; }
.swatches { display: flex; gap: 4px; }
.swatches span { width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--line-strong); }

.preview { padding: 16px 24px 32px; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.toolbar label { width: 170px; }
.spacer { flex: 1; }
.frame { position: relative; width: 100%; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 6px; margin: 0 auto; }
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.frame[data-bg=dark] { background: #000; }
.frame[data-bg=light] { background: #f2f2f2; }
.frame[data-bg=checker] { background: repeating-conic-gradient(#2a2a2a 0 25%, #1f1f1f 0 50%) 0 0 / 24px 24px; }
.frame[data-bg=game] {
  background:
    linear-gradient(to top, #2b3a24 0 22%, transparent 22%),
    linear-gradient(to top, #5a6b78 0 40%, transparent 40%),
    linear-gradient(#6d8fae, #b9c9d4);
}
.stats { color: var(--muted); font-size: 12px; margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.out { margin-top: 16px; max-width: 900px; }
.out > label { color: var(--text); font-weight: 600; }
.out .row input { font-family: ui-monospace, monospace; font-size: 12px; }
.steps { color: var(--muted); padding-left: 20px; margin: 12px 0 0; }
.steps li { margin: 4px 0; }
.steps b { color: var(--text); font-weight: 600; }

@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); order: 2; }
  .preview { order: 1; padding: 12px 16px; }
  .toolbar label { width: calc(50% - 4px); }
  .spacer { display: none; }
}
