:root {
  color-scheme: dark;
  --bg: #333;
  --panel: #1e1e1e;
  --panel-head: #262626;
  --line: #444;
  --text: #fff;
  --soft: #d4d4d4;
  --muted: #999;
  --accent: #c3c1ff;
  --mono: "Roboto Mono", ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  box-shadow: inset 0 0 100px rgb(0 0 0 / .5);
  font: 14px/1.43 var(--mono);
  text-align: center;
}
a { color: var(--text); }
p { margin: 0; }

/* ---- page ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  height: 50px;
  padding: 0 30px;
  background: #222;
  border-bottom: 1px solid #080808;
}
.brand { font-size: 18px; color: #9d9d9d; }

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 16px 20px 30px;
}
main > * { width: min(700px, 100%); }

.hint, footer { color: var(--muted); }
.summary { font-weight: 700; }

/* The grid may be wider than the text column; it scrolls inside the window if needed */
main > .grid-wrap {
  width: auto;
  max-width: 100%;
  overflow-x: auto;
}
#grid {
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* ---- controls ---- */

button, select, input { font: inherit; }
button, select {
  padding: 3px 10px;
  color: #333;
  background: #fff;
  border: 1px solid #fff;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
}
select { color-scheme: light; }
button:disabled { opacity: .65; cursor: not-allowed; }
:is(button, select, input):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input[type="range"], input[type="checkbox"] { accent-color: var(--accent); }

/* Buttons joined into one bar */
.group { display: inline-flex; }
.group > button { border-radius: 0; }
.group > button + button { border-left-color: #ddd; }
.group > button:first-child { border-radius: 4px 0 0 4px; }
.group > button:last-child { border-radius: 0 4px 4px 0; }

/* A row of controls: one part at each end, centred once it wraps on narrow screens */
.bar, .bar-part {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.bar { justify-content: space-between; }
@media (max-width: 560px) {
  .bar, .bar-part { justify-content: center; }
}
/* The setup row holds the first choices, so its buttons are larger */
.setup button {
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.43;
}
.panel-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
}
#viewButton[aria-pressed="true"] {
  color: #fff;
  background: #000;
}

.swatches { display: flex; gap: 6px; }
.swatch {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 2px solid var(--bg);
  border-radius: 50%;
  box-shadow: 0 0 0 1px #777;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px #fff; }

.error { color: #ff9d9d; font-size: 12px; }

/* ---- cards: image settings and code output ---- */

.card {
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: left;
  font-size: 12px;
}
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 7px 5px 12px;
  color: var(--soft);
  background: var(--panel-head);
  border-bottom: 1px solid var(--line);
}
.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}
.card-actions select { padding: 2px 4px; }

.image-panel { padding: 7px 10px 8px; color: var(--soft); }
.image-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 6px;
}
.row > label:first-child { min-width: 36px; }
.row input[type="range"] { flex: 1 1 120px; min-width: 100px; margin: 0; }
.row output { min-width: 26px; text-align: right; color: #b5cea8; }
.check { margin-left: 6px; cursor: pointer; }
.check input { margin: 0 3px 0 0; vertical-align: -2px; }

#output {
  height: 156px;
  margin: 0;
  padding: 3px 6px;
  overflow: auto;
  color: #ccc;
  background: #1a1a1a;
  font: 13px/1.43 var(--mono);
}
#output .kw { color: #c586c0; }
#output .ty { color: #4ec9b0; }
#output .num { color: #b5cea8; }

/* ---- dialogs: file name and history ---- */

dialog {
  width: min(600px, calc(100vw - 30px));
  margin-top: 120px;
  padding: 0;
  color: var(--soft);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 5px 15px rgb(0 0 0 / .5);
  text-align: left;
}
dialog.small { width: min(300px, calc(100vw - 30px)); }
dialog::backdrop { background: rgb(0 0 0 / .5); }

.dialog-head {
  margin: 0;
  padding: 10px 15px;
  color: #fff;
  background: var(--panel-head);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 500;
}
.dialog-body { padding: 15px; font-size: 12px; }
.dialog-body label { display: block; margin-bottom: 5px; }
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 10px 15px;
  border-top: 1px solid var(--line);
}
.dialog-foot button { padding: 3px 12px; }
button.primary { background: var(--accent); border-color: var(--accent); }

.field { display: flex; }
.field input {
  flex: 1;
  min-width: 0;
  padding: 6px 12px;
  color: #333;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px 0 0 4px;
  font-size: 14px;
  color-scheme: light;
}
.field span {
  padding: 6px 12px;
  color: #555;
  background: #eee;
  border: 1px solid #ccc;
  border-left: 0;
  border-radius: 0 4px 4px 0;
  font-size: 14px;
}

.note { margin-bottom: 10px; color: var(--muted); }
.works-list { max-height: 55vh; overflow-y: auto; }
.work {
  padding: 8px;
  margin-bottom: 8px;
  background: var(--panel-head);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.work.current { border-color: var(--accent); }
.work-thumb {
  display: block;
  max-width: 100%;
  margin-bottom: 6px;
  image-rendering: pixelated;
}
.work-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.work-info { min-width: 0; }
.work-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.work-meta { display: block; color: var(--muted); font-size: 11px; }
.work-actions { display: flex; gap: 4px; }
.work-delete.confirm {
  color: #fff;
  background: #c9302c;
  border-color: #c9302c;
}
