:root {
  --bg: #1b1a17;
  --btn: #2e2b26;
  --entry: #24211c;
  --text: #ffffff;
  --accent: #1b1a17;
  --warn: #d16b5a;
  --line: #3a362f;
  --muted: #9a9385;
  --paper: #f4f1ea;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px; background: var(--bg); color: var(--text);
  font: 16px/1.3 system-ui, "Segoe UI", Arial, sans-serif; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
button, .btn, input { font: inherit; color: var(--text); border: 0; border-radius: 4px; }
button, .btn { background: var(--btn); padding: 8px 14px; cursor: pointer; text-decoration: none;
  transition: background .12s, color .12s, box-shadow .12s;
  box-shadow: inset 0 0 0 1px var(--accent); }
button:hover:not(:disabled), .btn:hover { background: var(--paper); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
button:disabled { opacity: .4; cursor: not-allowed; }
input { background: var(--entry); width: 5em; padding: 8px; text-align: center; box-shadow: inset 0 0 0 1px var(--line); }
.lbl { display: inline-flex; align-items: center; gap: 6px; }
:focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }
#note { min-height: 1.3em; margin: 0; color: var(--warn); }

#plots { flex: 1; min-height: 0; display: grid; grid-template: 1fr 1fr / 1fr 1fr; gap: 10px; }
.cell { position: relative; min-height: 180px; background: var(--paper); border-radius: 4px; overflow: hidden; box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.cell canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cell.empty { background: #e7e2d7 url(../assets/add.png) center / contain no-repeat; }
.cell.empty canvas { display: none; }
#plots:not(.delete) .cell.empty, #plots.delete .cell:not(.empty) { cursor: pointer; }
#plots:not(.delete) .cell.empty:hover { outline: 2px solid var(--paper); }
#plots.delete .cell:not(.empty):hover { outline: 2px solid var(--warn); }

dialog { background: #26231e; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 20px 24px; }
dialog::backdrop { background: rgba(10, 9, 7, .65); }
dialog h2 { margin: 0 0 6px; font-size: 1.25rem; }
.hint { margin: 0 0 14px; color: var(--muted); max-width: 36ch; }
.sgrid { display: grid; grid-template-columns: 3.2em repeat(4, 64px); gap: 8px; align-items: center; justify-items: center; }
.sgrid span { color: var(--muted); }
.node { width: 48px; height: 48px; border-radius: 50%; background: var(--entry); border: 2px solid var(--line); padding: 0;
  transition: background .12s, border-color .12s; }
.node:hover:not(:disabled) { border-color: var(--paper); }
.node.on { background: var(--paper); border-color: var(--paper); }
.msg { min-height: 1.3em; color: var(--warn); margin: 10px 0 0; }
.row { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

@media (max-width: 700px) { #plots { grid-template: repeat(4, minmax(220px, 1fr)) / 1fr; } }

[hidden] { display: none !important; }
select { font: inherit; color: var(--text); background: var(--entry); border: 0; border-radius: 4px; padding: 8px; box-shadow: inset 0 0 0 1px var(--line); }
#startDialog label { display: block; margin-bottom: 4px; }
.startbody { display: flex; flex-wrap: wrap; gap: 20px; }
#startPreview { width: 350px; height: 250px; max-width: 100%; background: var(--paper); border-radius: 4px; }
.startctl { display: flex; flex-direction: column; gap: 8px; width: 240px; }
#dRange { width: 100%; padding: 0; accent-color: var(--paper); background: none; }
.rng { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; }
#dLabel { margin: 0; }
#formulaInput { width: 100%; text-align: left; }
.startctl .hint { margin: 0; font-size: .85rem; }
.startctl button { align-self: flex-start; }
.startctl select { width: 100%; }
.doc picture img {
  display: block;
  max-width: 70%;
  width: auto;
  height: auto;
  margin: 12px auto;
  border-radius: 6px;
  background: var(--paper);
}
.doc picture.img_half img {
  max-width: 50%;
}
@media (max-width: 700px) {
  .doc picture img {
    max-width: 100%;
  }
}