:root {
  --bg: #14171c;
  --panel: #1b1f26;
  --panel-2: #232831;
  --panel-3: #2b313c;
  --line: #303746;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #ef4444;
  --accent-2: #f87171;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --info: #60a5fa;
  --radius: 7px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.muted {
  color: var(--muted);
}

.spacer {
  flex: 1;
}

/* ---------- buttons and fields ---------- */

.btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) {
  background: var(--panel-3);
  border-color: #414a5c;
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
}
.btn.icon {
  width: 30px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.icon svg {
  width: 16px;
  height: 16px;
}
.btn.big {
  height: 40px;
  padding: 0 18px;
  font-size: 14px;
}
.btn.small {
  height: 26px;
  padding: 0 9px;
  font-size: 12px;
}
.btn.danger:hover:not(:disabled) {
  border-color: var(--err);
  color: var(--accent-2);
}

input[type='number'],
input[type='text'],
select,
textarea {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11141a;
  min-width: 0;
  user-select: text;
  -webkit-user-select: text;
}
textarea {
  height: auto;
  padding: 6px 8px;
  resize: vertical;
}
input:focus,
select:focus,
textarea:focus,
.btn:focus-visible,
.tool:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}
input[type='number']::-webkit-inner-spin-button {
  opacity: 0.4;
}
input[type='checkbox'] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  margin: 0;
}
input[type='range'] {
  accent-color: var(--accent);
  flex: 1;
  min-width: 0;
}

/* ---------- top bar ---------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 50px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.1px;
  margin-right: 4px;
}
.group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pageno {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
}
.pageno input {
  width: 46px;
  text-align: center;
}
.inline {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}
.zoompct {
  width: 46px;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 600;
}
.chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.chip.none {
  border-color: rgba(239, 68, 68, 0.7);
  background: rgba(239, 68, 68, 0.14);
}
.chip.none .dot {
  background: var(--err);
}
.chip.unchecked {
  border-color: rgba(245, 158, 11, 0.7);
  background: rgba(245, 158, 11, 0.13);
}
.chip.unchecked .dot {
  background: var(--warn);
}
.chip.checked {
  border-color: rgba(34, 197, 94, 0.6);
  background: rgba(34, 197, 94, 0.12);
}
.chip.checked .dot {
  background: var(--ok);
}
.chip:hover {
  filter: brightness(1.15);
}

/* ---------- banner ---------- */

/* ---------- tabs: one per open drawing ---------- */
#tabbar {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 5px 8px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
  overflow-x: auto;
}
#tabbar[hidden] {
  display: none;
}
.tab-doc {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 5px 5px 6px 12px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 12.5px;
  flex: none;
}
.tab-doc:hover {
  background: var(--panel-2);
  color: var(--text);
}
.tab-doc.on {
  background: var(--panel-2);
  border-color: var(--line);
  color: #fff;
}
.tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab-dirty {
  color: #f59e0b;
  font-size: 9px;
}
.tab-x {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 1px 5px 2px;
  border-radius: 4px;
}
.tab-x:hover {
  background: var(--panel-3);
  color: #fff;
}
.tab-add {
  align-self: center;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 10px 4px;
}
.tab-add:hover {
  color: #fff;
}

#banner {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
  flex: none;
  font-size: 13px;
}
#banner[hidden] {
  display: none;
}
#banner .msg {
  flex: 1;
}
#banner .msg b {
  font-weight: 700;
}
#banner.need {
  background: #4a1d1f;
  border-bottom-color: #7f2b2e;
}
#banner.check {
  background: #45320f;
  border-bottom-color: #7a5a17;
}
#banner.rev {
  background: #3b1f4a;
  border-bottom-color: #6b3a85;
}
#banner.pick {
  background: #12324a;
  border-bottom-color: #1f5580;
}
#banner .step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
#banner .x {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
}

/* ---------- layout ---------- */

main {
  display: flex;
  flex: 1;
  min-height: 0;
}

#tools {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 78px;
  padding: 8px 6px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  flex: none;
  overflow-y: auto;
}
.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 2px 5px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  position: relative;
}
.tool svg {
  width: 22px;
  height: 22px;
}
.tool kbd {
  position: absolute;
  top: 3px;
  right: 5px;
  font: 600 9px/1 -apple-system, 'Segoe UI', sans-serif;
  color: #667085;
}
.tool:hover:not(:disabled) {
  background: var(--panel-2);
  color: var(--text);
}
.tool.active {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.6);
  color: #fff;
}
.tool.active kbd {
  color: #fca5a5;
}
.tool:disabled {
  opacity: 0.35;
  cursor: default;
}
.tool-sep {
  height: 1px;
  margin: 5px 6px;
  background: var(--line);
  flex: none;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  background: #2b3039;
  overflow: hidden;
}
#canvas {
  position: absolute;
  inset: 0;
  display: block;
  outline: none;
  touch-action: none;
}

#empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 50% 40%, #252a33, #171a20);
}
.empty-card {
  width: min(520px, 90%);
  text-align: center;
}
.empty-card h1 {
  margin: 0 0 18px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.2px;
}
.steps {
  margin: 0 auto 24px;
  padding: 0;
  list-style: none;
  counter-reset: s;
  text-align: left;
  width: fit-content;
  color: #c3c9d4;
  font-size: 14px;
}
.steps li {
  counter-increment: s;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
}
.steps li::before {
  content: counter(s);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--panel-3);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  flex: none;
}
.steps b {
  color: #fff;
}
.empty-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 14px;
}

#drop-hint {
  position: absolute;
  inset: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #38bdf8;
  border-radius: 14px;
  background: rgba(14, 116, 144, 0.28);
  font-size: 20px;
  font-weight: 700;
  pointer-events: none;
}
#drop-hint[hidden],
#empty[hidden] {
  display: none;
}

#busy {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(17, 21, 27, 0.92);
  border: 1px solid var(--line);
  font-size: 12px;
  pointer-events: none;
}
#busy[hidden] {
  display: none;
}
.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid #475063;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#scalebar {
  position: absolute;
  left: 14px;
  bottom: 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 5px 9px 6px;
  border-radius: 6px;
  background: rgba(17, 21, 27, 0.86);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
}
#scalebar[hidden] {
  display: none;
}
#scalebar .bar {
  height: 7px;
  border: 2px solid #fff;
  border-top: 0;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: 70%;
  padding: 9px 14px;
  border-radius: 8px;
  background: rgba(17, 21, 27, 0.96);
  border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 12px;
}
#toast[hidden] {
  display: none;
}
#toast.ok {
  border-color: rgba(34, 197, 94, 0.6);
}
#toast.err {
  border-color: rgba(239, 68, 68, 0.7);
}
#toast a {
  color: #7dd3fc;
  cursor: pointer;
  text-decoration: underline;
  white-space: nowrap;
}

#text-entry {
  position: absolute;
  min-width: 180px;
  height: auto;
  padding: 4px 6px;
  border: 2px solid #38bdf8;
  border-radius: 5px;
  background: #fff;
  color: #b91c1c;
  font-weight: 700;
  resize: none;
  overflow: hidden;
}
#text-entry[hidden] {
  display: none;
}

/* ---------- side panel ---------- */

#side {
  display: flex;
  flex-direction: column;
  width: 312px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  flex: none;
  min-height: 0;
}
#props {
  padding: 12px 14px 14px;
  border-bottom: 1px solid var(--line);
  max-height: 56%;
  overflow-y: auto;
  flex: none;
}
#props h2,
.pane h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
#props h2 .sw {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
#props p {
  margin: 0 0 10px;
}
.field {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.field > label {
  color: var(--muted);
}
.field .unit {
  display: flex;
  align-items: center;
  gap: 6px;
}
.field .unit input {
  flex: 1;
}
.field .unit span {
  color: var(--muted);
  width: 22px;
  font-size: 12px;
  flex: none;
}
#props {
  overflow-x: hidden;
}
.field.stack {
  grid-template-columns: 1fr;
}
.readout {
  display: flex;
  justify-content: space-between;
  padding: 6px 9px;
  margin: 8px 0;
  border-radius: 6px;
  background: var(--panel-2);
}
.readout b {
  font-variant-numeric: tabular-nums;
}
.row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.row .btn {
  flex: 1;
}
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  cursor: pointer;
}
.hintbox {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--panel-2);
  color: #c3c9d4;
  font-size: 12px;
}
.hintbox.warn {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fcd9a0;
}
.hintbox.good {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
}
.hintbox.bad {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

#tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.tab {
  flex: 1;
  height: 36px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
}
.tab:hover {
  color: var(--text);
}
.copy-row select {
  flex: 1;
  min-width: 0;
  height: 28px;
}
.side-toggle {
  flex: none;
  width: 32px;
  height: 36px;
  border: 0;
  border-left: 1px solid var(--line);
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.side-toggle:hover {
  color: #fff;
  background: var(--panel-2);
}
/* Folded side panel: only the button to bring it back. */
body.side-collapsed #side {
  width: 33px;
}
body.side-collapsed #side #props,
body.side-collapsed #side #tab-body,
body.side-collapsed #tabs .tab {
  display: none;
}
body.side-collapsed #tabs {
  border-bottom: 0;
}
body.side-collapsed .side-toggle {
  border-left: 0;
}
.tab.active {
  color: #fff;
  border-bottom-color: var(--accent);
}
.count {
  display: inline-block;
  min-width: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--err);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
}
.count.warn {
  background: var(--warn);
  color: #1b1300;
}
.count.ok {
  background: var(--ok);
  color: #052e12;
}
.count[hidden] {
  display: none;
}
#tab-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px 16px;
}
.pane table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
  font-variant-numeric: tabular-nums;
}
.pane th {
  text-align: right;
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  padding: 3px 4px;
  border-bottom: 1px solid var(--line);
}
.pane th:first-child,
.pane td:first-child {
  text-align: left;
}
.pane td {
  text-align: right;
  padding: 4px 4px;
  border-bottom: 1px solid #262b35;
}
.pane tr.total td {
  font-weight: 700;
  border-bottom: 0;
  border-top: 1px solid var(--line);
}
.pane .sw {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 7px;
  vertical-align: -1px;
}
.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 12px;
}
.seg button {
  flex: 1;
  height: 26px;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}
.seg button.on {
  background: var(--panel-3);
  color: #fff;
  font-weight: 600;
}
.emptynote {
  color: var(--muted);
  text-align: center;
  padding: 18px 8px;
}

.issue {
  display: flex;
  gap: 9px;
  width: 100%;
  padding: 8px 9px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 6px;
  background: var(--panel-2);
  text-align: left;
  cursor: pointer;
}
.issue:hover {
  background: var(--panel-3);
}
.issue.error {
  border-left-color: var(--err);
}
.issue.warn {
  border-left-color: var(--warn);
}
.issue.info {
  border-left-color: var(--info);
  cursor: default;
}
.issue.info.go {
  cursor: pointer;
}
.issue b {
  display: block;
  font-weight: 600;
}
.issue span {
  color: var(--muted);
  font-size: 12px;
}
.allgood {
  padding: 12px;
  border-radius: 6px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
  margin-bottom: 8px;
}

.rules-warn {
  padding: 9px 10px;
  margin-bottom: 12px;
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fcd9a0;
  font-size: 12px;
}
.rules-ok {
  padding: 9px 10px;
  margin-bottom: 12px;
  border-radius: 6px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
  font-size: 12px;
}
.rule-class {
  margin: 12px 0 6px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 7px;
}
.rule {
  display: grid;
  grid-template-columns: 1fr 70px 26px 20px;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.rule label {
  color: #c3c9d4;
}
.rule input[type='number'] {
  text-align: right;
}
.rule .u {
  color: var(--muted);
  font-size: 11px;
}
.rule.unconfirmed input[type='number'] {
  border-color: rgba(245, 158, 11, 0.6);
}

.keys {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
  margin-bottom: 16px;
}
.keys kbd,
kbd.k {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel-2);
  font: 600 11px/1.5 -apple-system, 'Segoe UI', sans-serif;
  text-align: center;
  white-space: nowrap;
}
.legend {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 6px 8px;
  align-items: center;
  margin-bottom: 16px;
}
.legend svg {
  width: 22px;
  height: 22px;
}

/* ---------- status bar ---------- */

#status {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 30px;
  padding: 0 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  flex: none;
}
#hint {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #c3c9d4;
}
#coords {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pill {
  height: 20px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.on {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.6);
  color: #bae6fd;
}

/* ---------- dialogs ---------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop {
  background: rgba(8, 10, 13, 0.6);
}
.dlg {
  width: 520px;
  padding: 20px 22px 18px;
}
.dlg.small {
  width: 420px;
}
.dlg header h2 {
  margin: 0;
  font-size: 18px;
}
.dlg header p {
  margin: 4px 0 0;
}
.dlg section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.dlg section[hidden] {
  display: none;
}
.dlg h3 {
  margin: 0 0 9px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dlg h3 .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--panel-3);
  font-size: 11px;
}
.dlg h3 .tag {
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.dlg p {
  margin: 0 0 9px;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.pick {
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.pick small {
  color: var(--muted);
  font-weight: 400;
  margin-left: 5px;
}
.pick:hover {
  background: var(--panel-3);
}
.pick.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.pick.on small {
  color: #fee2e2;
}
.note {
  margin: 9px 0 0 !important;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fcd9a0;
  font-size: 12px;
}
.note[hidden] {
  display: none;
}
.custom {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
  color: var(--muted);
}
.custom input {
  width: 96px;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  cursor: pointer;
}
.check[hidden] {
  display: none;
}
.dlg footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.bigfield {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 12px 0 4px;
  font-size: 15px;
  color: var(--muted);
}
.bigfield input {
  flex: 1;
  height: 42px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}
.bigfield[hidden] {
  display: none;
}
.result {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 7px;
  font-size: 13px;
}
.result[hidden],
.choices[hidden] {
  display: none;
}
.result.pass {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: #bbf7d0;
}
.result.close {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fcd9a0;
}
.result.fail {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fecaca;
}
.result b {
  font-size: 14px;
}
.choices {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 12px;
}
.choices label {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
.choices label:has(input:checked) {
  border-color: var(--accent);
  background: rgba(239, 68, 68, 0.1);
}
.choices input {
  margin-top: 2px;
  accent-color: var(--accent);
}
.choices small {
  display: block;
  color: var(--muted);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: #3a4252;
  border-radius: 5px;
  border: 2px solid var(--panel);
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- share / mode switch ---------- */

#btn-share {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
#btn-pin.on {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.6);
  background: rgba(251, 191, 36, 0.12);
}
#btn-pin.on svg {
  fill: currentColor;
}
.seg.mode {
  margin: 0;
  width: 150px;
  flex: none;
}
.seg.mode button {
  height: 28px;
}
.seg.mode button.on {
  background: var(--accent);
  color: #fff;
}

/* View mode: a plain viewer. Everything for drawing is put away. */
body.viewmode #tools,
body.viewmode #side,
body.viewmode #banner,
body.viewmode #history,
body.viewmode #hazard-wrap,
body.viewmode #btn-save,
body.viewmode #toggle-ortho,
body.viewmode #toggle-snap {
  display: none !important;
}
body.viewmode #scale-chip {
  pointer-events: none;
}

/* ---------- library ---------- */

#library {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  background: radial-gradient(1200px 600px at 50% 0%, #232832, #171a20);
  z-index: 5;
}
.lib-wrap {
  width: min(860px, 100% - 48px);
  margin: 0 auto;
  padding: 28px 0 60px;
}
.lib-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.lib-head h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.2px;
}
.lib-search-row {
  margin: 14px 0 0;
}
.lib-search {
  width: 100%;
  height: 34px;
  padding: 0 12px;
  font-size: 14px;
}
.lib-section {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 26px 0 8px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
}
.lib-section h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}
.lib-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.lib-row:hover,
.lib-row:focus-visible {
  background: var(--panel-2);
  border-color: var(--line);
  outline: none;
}
.lib-row.gone {
  opacity: 0.5;
}
.lib-doc svg {
  width: 20px;
  height: 24px;
  color: #f87171;
  display: block;
}
.lib-main {
  flex: 1;
  min-width: 0;
}
.lib-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-path {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-when {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.lib-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  flex: none;
}
.lib-btn svg {
  width: 15px;
  height: 15px;
}
.lib-btn:hover {
  background: var(--panel-3);
  color: #fff;
}
.lib-btn.on {
  color: #fbbf24;
}
.lib-btn.on svg {
  fill: currentColor;
}
.lib-btn.x {
  font-size: 17px;
}
.lib-move {
  height: 26px;
  max-width: 150px;
  font-size: 12px;
  flex: none;
}
.lib-folder-block {
  margin-bottom: 4px;
}
.lib-folder {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.lib-folder:hover {
  background: var(--panel-2);
}
.lib-folder.drop,
.lib-loose.drop {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
}
.lib-caret {
  width: 12px;
  color: var(--muted);
}
.lib-folder-icon svg {
  width: 18px;
  height: 15px;
  color: #fbbf24;
  display: block;
}
.lib-count {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.lib-dir-path {
  flex: 1;
  min-width: 0;
  font-weight: 400;
}
.lib-dir.gone {
  opacity: 0.5;
}
.lib-folder-body {
  margin-left: 22px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
}
.lib-loose {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 12px;
}
.lib-sub {
  margin: 8px 10px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.lib-link {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
}
.lib-link:hover {
  color: #fff;
  text-decoration: underline;
}
.lib-input {
  flex: 1;
  max-width: 320px;
}
.lib-empty {
  padding: 14px 10px;
  color: var(--muted);
}
.lib-empty.small {
  padding: 8px 10px;
  font-size: 12px;
}
.lib-welcome {
  margin-top: 60px;
  text-align: center;
}
.lib-welcome h2 {
  margin: 0 0 18px;
  font-size: 22px;
}

/* While the library is showing, only the essentials stay in the top bar. */
body.in-library #tools,
body.in-library #side,
body.in-library #banner,
body.in-library #pager,
body.in-library #zoomer,
body.in-library #history,
body.in-library #scale-chip,
body.in-library #hazard-wrap,
body.in-library #mode,
body.in-library #btn-pin,
body.in-library #btn-save,
body.in-library #btn-export,
body.in-library #btn-share,
body.in-library #scalebar,
body.in-library #coords,
body.in-library .pill {
  display: none !important;
}
#btn-library.active {
  background: var(--panel-3);
  border-color: #56607a;
}
#drop-hint {
  z-index: 10;
}
#toast,
#busy {
  z-index: 20;
}

/* ---------- sprinkler legend symbols ---------- */

canvas.sym,
.sym.svg {
  display: block;
  background: #ffffff;
  border-radius: 5px;
}
.sym.svg {
  width: 28px;
  height: 28px;
  padding: 3px;
}
.legend {
  grid-template-columns: 30px 1fr;
}
.kinds {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
}
.kind {
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
}
.kind:hover {
  background: var(--panel-3);
}
.kind.on {
  border-color: var(--accent);
  background: rgba(239, 68, 68, 0.16);
}
.kind-name {
  margin-top: 2px;
  font-weight: 600;
}

/* ---------- typing a dimension's value ---------- */

#dim-edit {
  position: absolute;
  z-index: 15;
  width: 214px;
  padding: 9px 10px 8px;
  border: 1px solid #f59e0b;
  border-radius: 9px;
  background: var(--panel);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -100%);
}
#dim-edit .de-row {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}
#dim-input {
  flex: 1;
  height: 34px;
  font-size: 17px;
  font-weight: 700;
}
#dim-caption {
  margin-top: 6px;
  font-size: 12px;
  color: #fcd9a0;
}
#dim-swap {
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: #7dd3fc;
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
}

/* ---------- web version: iPad, iPhone and small windows ----------
   html.touch is set by web/api.js on touch screens; body.web by the web build. */
body.web {
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  box-sizing: border-box;
  -webkit-touch-callout: none;
}
html.touch .btn,
html.touch .tool,
html.touch .lib-row,
html.touch .lib-btn,
html.touch .tab-doc {
  min-height: 36px;
}
html.touch .tab-x {
  font-size: 19px;
  padding: 4px 8px;
}

@media (max-width: 1100px) {
  #topbar {
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  #topbar > * {
    flex: none;
  }
  #topbar .spacer {
    flex: 1 0 8px;
  }
  .brand span {
    display: none;
  }
  main {
    position: relative;
  }
  /* The side panel slides over the drawing instead of squeezing it. */
  body:not(.side-collapsed) #side {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    width: min(312px, 88vw);
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.45);
  }
  body.side-collapsed #side {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 6;
    background: transparent;
    border-left: 0;
  }
  #hint {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #banner {
    flex-wrap: wrap;
    font-size: 12px;
  }
  .dlg,
  .dlg.small {
    width: min(520px, 92vw);
    box-sizing: border-box;
  }
}

@media (max-width: 760px) {
  #tools {
    width: 52px;
    padding: 6px 3px;
    overflow-y: auto;
  }
  #tools .tool span,
  #tools .tool kbd {
    display: none;
  }
  #status .pill {
    padding: 0 8px;
  }
  #coords {
    display: none;
  }
  .lib-wrap {
    width: calc(100% - 24px);
  }
  .lib-head {
    flex-wrap: wrap;
  }
  .lib-head h1 {
    width: 100%;
  }
}
