:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2228;
  --muted: #5d6673;
  --border: #d7dbe1;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --line: #1d2228;
  --hidden-line: #c2410c;
  --error-bg: #fdecec;
  --error-text: #a11d1d;
  --drawing-bg: #ffffff;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c;
    --panel: #1e2227;
    --text: #e6e9ed;
    --muted: #9aa3ae;
    --border: #343a42;
    --accent: #5b9bf0;
    --accent-text: #0d1117;
    --line: #e6e9ed;
    --hidden-line: #f59e57;
    --error-bg: #3a1c1c;
    --error-text: #ffb4b4;
    --drawing-bg: #111417;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15181c;
  --panel: #1e2227;
  --text: #e6e9ed;
  --muted: #9aa3ae;
  --border: #343a42;
  --accent: #5b9bf0;
  --accent-text: #0d1117;
  --line: #e6e9ed;
  --hidden-line: #f59e57;
  --error-bg: #3a1c1c;
  --error-text: #ffb4b4;
  --drawing-bg: #111417;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 600; }

.status { color: var(--muted); font-size: 0.9rem; }
.status.ready { color: #2f8a4c; }

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 16px;
  padding: 16px 20px;
  max-width: 1500px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  min-width: 0;
}

fieldset { border: 0; margin: 0 0 14px; padding: 0; }
legend { font-weight: 600; margin-bottom: 8px; padding: 0; }

label {
  display: grid;
  grid-template-columns: 1fr 110px;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--text);
}

label[hidden] { display: none; }

.unit, .hint { color: var(--muted); font-size: 0.85em; }

input, select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }

.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented label {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  margin: 0;
}
.segmented input { width: auto; }
.segmented label:has(input:checked) { border-color: var(--accent); }

body:not([data-stair-type="open"]):not([data-stair-type="double"]) .open-only { display: none; }
body:not([data-stair-type="double"]) .double-only { display: none; }

button {
  padding: 7px 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.preview-panel { display: flex; flex-direction: column; gap: 10px; }

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.toolbar-actions { display: flex; gap: 8px; }

.legend { color: var(--muted); font-size: 0.9rem; display: flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 22px; height: 0; border-top: 2px solid var(--line); }
.swatch.dashed { border-top: 2px dashed var(--hidden-line); margin-left: 8px; }

.preview {
  height: min(70vh, 720px);
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--drawing-bg);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
.preview:active { cursor: grabbing; }
.preview.stale { opacity: 0.35; }
.preview svg { width: 100%; height: 100%; display: block; }
.preview .solid-line { stroke: var(--line); stroke-width: 1.2; }
.preview .hidden-line { stroke: var(--hidden-line); stroke-width: 1; }

.error {
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 6px;
  padding: 8px 12px;
}

.tier-line {
  margin: 2px 0 10px;
  padding: 6px 10px;
  border-left: 3px solid var(--accent);
  background: var(--bg);
  border-radius: 0 6px 6px 0;
  font-size: 0.9rem;
}
.tier-line:empty { display: none; }

@keyframes autofill-flash {
  from { background: color-mix(in srgb, var(--accent) 30%, var(--bg)); }
  to { background: var(--bg); }
}
input.autofilled { animation: autofill-flash 1.2s ease-out; }

.summary { margin: 0; padding-left: 18px; color: var(--muted); }
.note { color: var(--muted); font-size: 0.9rem; margin: 0; }
code { font-size: 0.9em; }

details summary { cursor: pointer; color: var(--muted); }
pre {
  max-height: 300px;
  overflow: auto;
  background: var(--bg);
  border-radius: 6px;
  padding: 10px;
  font-size: 12px;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .topbar { padding: 12px 16px; }
  .preview { height: 55vh; }
}
