:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --ink: #1d1f20;
  --ink-2: #5d6266;
  --line: #e2ddd4;
  --accent: #3f6f5e;
  --accent-ink: #ffffff;
  --error: #c2412d;
  --warn: #b7791f;
  --ok: #2f7a55;
  --fixed: #e46a4a;
  --movable: #e0a33a;
  --shadow: 0 10px 30px rgba(30, 25, 15, 0.12);
  --radius: 14px;
  --sheet-h: 42vh;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181a;
    --surface: #1f2224;
    --surface-2: #2a2e31;
    --ink: #eceae6;
    --ink-2: #a3a8ac;
    --line: #33383b;
    --accent: #7fb8a3;
    --accent-ink: #0f1a16;
    --error: #ef7d6a;
    --warn: #e2b153;
    --ok: #77c49b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181a;
  --surface: #1f2224;
  --surface-2: #2a2e31;
  --ink: #eceae6;
  --ink-2: #a3a8ac;
  --line: #33383b;
  --accent: #7fb8a3;
  --accent-ink: #0f1a16;
  --error: #ef7d6a;
  --warn: #e2b153;
  --ok: #77c49b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Inter Tight", system-ui, -apple-system, sans-serif;
  display: grid;
  grid-template-rows: auto 1fr auto;
  /* One column that never grows past the screen, so a long row of design buttons scrolls
     inside its bar instead of widening the page (and pushing the 3D view off-centre). */
  grid-template-columns: minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, textarea { font: inherit; color: inherit; }

/* Top bar */
.top {
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  z-index: 3;
}
.brand { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.title { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.who { color: var(--ink-2); font-size: 13px; }
.who a { color: inherit; }
.designs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.designs::-webkit-scrollbar { display: none; }
.designs button {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.designs button[aria-current="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* 3D stage */
.stage { position: relative; min-height: 0; min-width: 0; overflow: hidden; }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.label-layer { position: absolute; inset: 0; pointer-events: none; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-2); }
.views {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  z-index: 2;
}
.views button {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.views button.on { border-color: var(--accent); color: var(--accent); }
.views [data-toggle="labels"] { margin-left: auto; }
.placeholder-banner {
  position: absolute;
  left: 12px;
  bottom: 12px;
  right: 12px;
  background: color-mix(in srgb, var(--warn) 18%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  z-index: 2;
  width: fit-content;
}

/* Labels in the 3D view */
.tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.08);
  white-space: nowrap;
  transform: translateY(-50%);
}
.tag-fixed { background: var(--fixed); color: #fff; border-color: transparent; }
.tag-movable { background: var(--movable); color: #1a1a1a; }
.tag-opening { background: rgba(40, 60, 80, 0.75); color: #fff; }
.labels-off .tag { display: none; }

/* Bottom sheet */
.sheet {
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius) var(--radius) 0 0;
  margin-top: -14px;
  z-index: 3;
  max-height: var(--sheet-h);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  transition: max-height 0.25s ease;
}
.sheet.small { max-height: 92px; }
.grip { border: 0; background: none; padding: 8px 0 2px; cursor: pointer; display: grid; place-items: center; }
.grip span { width: 40px; height: 4px; border-radius: 4px; background: var(--line); }
.sheet-head { padding: 0 16px; }
.sheet-head h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.sheet-head p { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); }
.tabs button {
  border: 0;
  background: none;
  padding: 8px 10px;
  border-bottom: 2px solid transparent;
  color: var(--ink-2);
  font-weight: 500;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; line-height: 18px; text-align: center; background: var(--error); color: #fff; }
.badge:empty { display: none; }
.badge.ok { background: var(--ok); }
.badge.quiet { background: var(--surface-2); color: var(--ink-2); }
.panel { overflow-y: auto; padding: 10px 16px 16px; min-height: 0; }
.checks, .notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.checks li { display: grid; grid-template-columns: 10px 1fr; gap: 10px; align-items: start; font-size: 14px; }
.checks li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--ok); }
.checks li.error::before { background: var(--error); }
.checks li.warn::before { background: var(--warn); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.facts .cost-head { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-weight: 600; color: var(--ink); }
.facts .cost-item { font-size: 13px; }
.facts dd.cost-item { text-align: right; }
.facts .cost-note { grid-column: 1 / -1; color: var(--ink-2); font-size: 12px; margin-top: 6px; }
.notes li { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.notes .meta { color: var(--ink-2); font-size: 12px; display: flex; justify-content: space-between; gap: 8px; }
.notes .meta button { border: 0; background: none; color: var(--ink-2); cursor: pointer; padding: 0; font-size: 12px; }
.notes p { margin: 2px 0 0; white-space: pre-wrap; }
.note-form { display: flex; gap: 8px; margin-top: 10px; }
.note-form textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--bg);
}
.note-form button { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 0 16px; font-weight: 600; cursor: pointer; }
.empty { color: var(--ink-2); font-size: 14px; }

@media (min-width: 900px) {
  body { grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: auto 1fr; }
  .top { grid-column: 1 / -1; flex-direction: row; align-items: center; }
  .designs { margin: 0; padding: 0; }
  .stage { grid-column: 1; }
  .sheet { grid-column: 2; grid-row: 2; max-height: none; margin-top: 0; border-radius: 0; border-top: 0; border-left: 1px solid var(--line); box-shadow: none; }
  .grip { display: none; }
  .sheet-head { padding-top: 16px; }
}
/* The "Details" switch hides the sheet (bottom on a phone, side panel on a wide screen). */
.details-off .sheet { display: none; }
@media (min-width: 900px) {
  body.details-off { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .sheet { transition: none; }
}
