@font-face { font-family: "KnotsZoo-Dark"; src: url("../assets/KnotsZoo-Dark.otf") format("opentype"); font-display: block; }
@font-face { font-family: "KnotsZoo-Holy"; src: url("../assets/KnotsZoo-Holy.otf") format("opentype"); font-display: block; }
@font-face { font-family: "KnotsZoo-Rustic"; src: url("../assets/KnotsZoo-Rustic.otf") format("opentype"); font-display: block; }
@font-face { font-family: "KnotsZoo-Teeth"; src: url("../assets/KnotsZoo-Teeth.otf") format("opentype"); font-display: block; }

:root {
  --bg: #f3f1ec;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #5d6474;
  --line: #dcd8cf;
  --accent: #8a3b12;
  --accent-soft: #f4e3d7;
  --marker: #d9480f;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c; --panel: #1d2027; --text: #e7e4dd; --muted: #a2a7b3; --line: #343844;
    --accent: #f0a46c; --accent-soft: #3a2a20; --marker: #ff8a4c; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171c; --panel: #1d2027; --text: #e7e4dd; --muted: #a2a7b3; --line: #343844;
  --accent: #f0a46c; --accent-soft: #3a2a20; --marker: #ff8a4c; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex; flex-direction: column;
}
.bar { display: flex; align-items: baseline; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.bar h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }
.bar .guide { margin-left: auto; font-size: 13px; color: var(--accent); white-space: nowrap; }
.status { color: var(--muted); font-size: 13px; }
.status.error { color: #c0392b; }

.layout { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.panel { overflow-y: auto; padding: 8px 16px 32px; border-right: 1px solid var(--line); background: var(--panel); }
.panel section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }
.help { color: var(--muted); font-size: 12.5px; margin: 4px 0 10px; }
label { display: block; margin: 6px 0; }
label.check, label.inline { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; }
label output { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }
input[type=number], select, textarea {
  width: 100%; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 100%; height: 30px; border: 1px solid var(--line); border-radius: 6px; background: none; padding: 2px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row input[type=number] { width: 90px; flex: 1; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

button {
  font: inherit; padding: 5px 11px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, .knot:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.choices label, .segmented label {
  margin: 0; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 4px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-size: 13px;
}
.choices input, .segmented input { position: absolute; opacity: 0; pointer-events: none; }
.choices label:has(input:checked), .segmented label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.choices label:has(input:disabled) { opacity: .4; cursor: default; }
.choices label:has(input:focus-visible), .segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.choices.four { grid-template-columns: repeat(2, 1fr); margin-top: 4px; }
.choices.two { grid-template-columns: repeat(2, 1fr); margin-top: 4px; }
.layer .choices { margin: 6px 0 2px; }
.panel h2.sub { margin-top: 12px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }

.layer { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; margin: 8px 0; }
.layer header { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.layer header strong { flex: 1; }
.layer header button { padding: 2px 7px; }
.layer .grid2 label { margin: 3px 0; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.toolbar select { width: auto; }
.spacer { flex: 1; }
.hint { margin: 8px 16px 0; color: var(--muted); font-size: 12.5px; min-height: 1.45em; }
.canvas-wrap { position: relative; flex: 1; overflow: auto; padding: 16px; }
.knot {
  display: inline-block; position: relative; white-space: pre; line-height: 1; cursor: pointer;
  font-family: "KnotsZoo-Rustic"; padding: 0; border-radius: 4px; user-select: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.knot div { height: 1em; }
.knot.busy { opacity: .55; }
.wall-marker { position: absolute; background: var(--marker); border-radius: 3px; pointer-events: none; opacity: .85; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); width: min(720px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin-top: 0; font-size: 16px; }
dialog textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; margin-bottom: 10px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); max-height: 45vh; }
  .canvas-wrap { padding: 16px; }
  .toolbar { padding: 8px 16px; }
}
