:root {
  color-scheme: light;
  --bg: #f7f6f1;
  --paper: #ffffff;
  --ink: #1f3a32;
  --accent: #b03a2e;
  --muted: #6b6b65;
  --border: #d8d6cc;
  --furniture: #5a7a6f;
  --furniture-fill: rgba(90, 122, 111, 0.18);
  --halo: #b03a2e;
  font-family: -apple-system, system-ui, "SF Pro Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* canvas handles its own gestures */
}

body {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  font-size: 15px;
}

/* ─── Top bar ────────────────────────────────────────────────────────── */
header.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.topbar .brand {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
}
.floor-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 999px;
  padding: 3px;
  border: 1px solid var(--border);
}
.ft-btn {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 6px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: 999px;
  cursor: pointer;
  min-height: 34px;
  transition: background 0.15s, color 0.15s;
}
.ft-btn[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

/* ─── Stage (canvas) ─────────────────────────────────────────────────── */
main.stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  touch-action: none;
}
main.stage svg {
  display: block;
  width: 100%;
  height: 100%;
  background: white;
}

/* ─── FAB ────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  background: var(--ink);
  color: var(--paper);
  font-size: 32px;
  font-weight: 300;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(31, 58, 50, 0.35), 0 2px 6px rgba(0,0,0,0.15);
  cursor: pointer;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
}
.fab:active { transform: scale(0.92); }

/* ─── Selected-item toolbar (above FAB) ──────────────────────────────── */
.selected-tools {
  position: fixed;
  left: max(20px, env(safe-area-inset-left));
  bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  z-index: 25;
}
.selected-tools[hidden] { display: none; }
.st-btn {
  appearance: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 22px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}
.st-btn:active { transform: scale(0.92); }
.st-btn.st-danger { background: var(--accent); color: var(--paper); }

/* ─── Bottom sheet ───────────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.25s;
}
.sheet-backdrop[hidden] { display: none; }
.sheet-backdrop.open { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.25);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
  max-height: 80vh;
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(.2,.8,.2,1);
}
.sheet[hidden] { display: none; }
.sheet.open { transform: translateY(0); }
.sheet-handle {
  align-self: center;
  width: 44px;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin: 10px 0 4px 0;
}
.sheet-title {
  margin: 8px 20px 12px 20px;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}
.sheet-tabs {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.sheet-tabs::-webkit-scrollbar { display: none; }
.sheet-tab {
  appearance: none;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 38px;
}
.sheet-tab[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.sheet-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 8px 16px 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.sheet-item {
  appearance: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 72px;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.sheet-item:active { transform: scale(0.97); background: #eceae0; }
.sheet-item .si-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
}
.sheet-item .si-dims {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ─── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100px + env(safe-area-inset-bottom));
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.toast[hidden] { display: none; }
.toast.show { opacity: 1; }

/* Landscape: shrink topbar a bit */
@media (max-height: 480px) and (orientation: landscape) {
  header.topbar { padding: 6px 14px; padding-top: calc(6px + env(safe-area-inset-top)); }
  .topbar .brand { font-size: 15px; }
  .fab { width: 52px; height: 52px; font-size: 28px; }
}
