/* Theme tokens. The dark set below is the default and the original look; the
   light set overrides it when core/theme.js puts data-theme="light" on <html>.
   The canvas is painted from a matching palette in core/theme.js - CSS can't
   reach into it - so a color that exists on both sides needs changing twice. */
/* Theme tokens. Dark is the default; the light set overrides it when
   core/theme.js puts data-theme="light" on <html>. The canvas is painted from a
   matching palette in core/theme.js - CSS can't reach into it - so a color that
   exists on both sides needs changing twice.
   Every panel is solid (no see-through glass): surfaces step up in lightness
   from the page (--bg) to cards (--panel) to controls (--surface). */
:root {
  --bg: #121522;
  --fg: #e8eaf6;
  --fg-muted: #a2a8c6;
  --fg-faint: #6e7596;
  --fg-fainter: #7c84a6;
  --sep: #444b68;

  --panel: #1b1f31;
  --surface: #262b42;
  --surface-hover: #30364f;
  --surface-sunken: #161a2a;
  --surface-sunken-hover: #1d2236;
  --surface-row-hover: #232842;

  --border: #2c3250;
  --border-strong: #3b4266;
  --hairline: rgba(160, 175, 255, 0.14);
  --hairline-soft: rgba(160, 175, 255, 0.22);
  --hairline-softer: rgba(160, 175, 255, 0.3);

  --panel-bg: var(--panel);
  --modal-bg: var(--panel);
  --panel-border: var(--border);
  --side-panel-bg: var(--panel);
  --hud-bg: var(--panel);
  --toast-bg: #262b42;
  --menu-bg: var(--panel);
  --scrim: rgba(6, 8, 18, 0.55);
  --input-bg: #12162a;

  --shadow-modal: rgba(0, 0, 0, 0.55);
  --shadow-panel: rgba(0, 0, 0, 0.4);
  --shadow-float: rgba(0, 0, 0, 0.45);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.28);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.35), 0 18px 48px rgba(0, 0, 0, 0.45);

  --accent: #7b61ff;
  --accent-hover: #6a4ef5;
  --accent-2: #20c4e8;
  --accent-grad: linear-gradient(135deg, #8b5cf6 0%, #6366f1 45%, #06b6d4 100%);
  --accent-soft: rgba(123, 97, 255, 0.14);
  --accent-soft-strong: rgba(123, 97, 255, 0.22);
  --accent-fg: #b4a6ff;
  --on-accent: #fff;

  --warn: #ffb020;
  --warn-bar-bg: #2e2412;
  --on-warn: #1e1f22;
  --swatch-ring: #fff;

  --danger-bg: #43202b;
  --danger-fg: #ff7a8a;

  /* One color per tool: the rail, the menu tiles and the status bar use it */
  --t-select: #8b7bff;
  --t-wall: #ff8a4c;
  --t-area: #2dd4bf;
  --t-door: #f4a261;
  --t-window: #38bdf8;
  --t-object: #c084fc;
  --t-label: #f472b6;
  --t-measure: #facc15;
  --t-terrain: #4ade80;
  --t-electrical: #fde047;
  --t-hydraulic: #60a5fa;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  /* Interface size multiplier, driven by the Settings slider
     (ui/settingsPanel.js applyUiScale). Every control size that should follow
     it is written as calc(<px> * var(--ui-scale)). The canvas is deliberately
     excluded - it is drawn in world units and has its own zoom. */
  --ui-scale: 1;
}

:root[data-theme="light"] {
  --bg: #eef0f8;
  --fg: #1b1e33;
  --fg-muted: #565d7e;
  --fg-faint: #858ba8;
  --fg-fainter: #8c92ae;
  --sep: #b9bed4;

  --panel: #ffffff;
  --surface: #f0f1f9;
  --surface-hover: #e5e7f5;
  --surface-sunken: #f6f7fc;
  --surface-sunken-hover: #eceefa;
  --surface-row-hover: #eef0fa;

  --border: #e0e3f0;
  --border-strong: #cbd0e4;
  --hairline: rgba(40, 50, 120, 0.12);
  --hairline-soft: rgba(40, 50, 120, 0.18);
  --hairline-softer: rgba(40, 50, 120, 0.22);

  --toast-bg: #ffffff;
  --scrim: rgba(30, 35, 70, 0.32);
  --input-bg: #ffffff;

  --shadow-modal: rgba(30, 35, 80, 0.2);
  --shadow-panel: rgba(30, 35, 80, 0.14);
  --shadow-float: rgba(30, 35, 80, 0.16);
  --shadow-1: 0 1px 2px rgba(30, 35, 80, 0.08), 0 4px 14px rgba(30, 35, 80, 0.1);
  --shadow-2: 0 2px 6px rgba(30, 35, 80, 0.1), 0 18px 48px rgba(30, 35, 80, 0.18);

  --accent: #6447ff;
  --accent-hover: #5236f0;
  --accent-soft: rgba(100, 71, 255, 0.1);
  --accent-soft-strong: rgba(100, 71, 255, 0.16);
  --accent-fg: #5236f0;
  --on-accent: #fff;

  --warn: #b3720a;
  --warn-bar-bg: #fff6e6;
  --on-warn: #2a1c05;
  --swatch-ring: #23252a;

  --danger-bg: #fde3e6;
  --danger-fg: #c8283c;

  --t-select: #6447ff;
  --t-wall: #ea6a24;
  --t-area: #0d9488;
  --t-door: #c9772f;
  --t-window: #0284c7;
  --t-object: #9333ea;
  --t-label: #db2777;
  --t-measure: #b88a00;
  --t-terrain: #16a34a;
  --t-electrical: #ca9a04;
  --t-hydraulic: #2563eb;
}

* { box-sizing: border-box; }

/* `hidden` always wins: several panels lay their children out as flex rows,
   and an author display would otherwise outrank the browser's own rule */
[hidden] { display: none !important; }

/* Native controls in the theme's colors */
input[type="range"],
input[type="checkbox"],
input[type="radio"] { accent-color: var(--accent); }

select,
input[type="number"],
input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  background: var(--input-bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font-family: inherit;
}
select:focus,
input[type="number"]:focus,
input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft-strong);
}
select option { background: var(--panel); color: var(--fg); }

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Nothing in the editor is prose to be copied, and every floating thing in it
   is drag-to-move: press a label, move a few pixels, and the browser starts a
   text selection instead - a blue smear across the UI, and on the command bar
   a selection that fights the drag. Killed app-wide; the fields you actually
   type into opt back in below, which also keeps the long-press paste callout
   on iOS where it is wanted. */
html {
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea,
select,
[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

kbd {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 5px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 600;
  color: var(--fg-muted);
}

/* ---------- HUD ---------- */
/* A <button>: clicking it opens the Controls panel, same as Esc. The ID beats
   the generic `button` rule on every property it sets, so the look below is
   unchanged from when this was a div - except font-family, which a button
   would otherwise take from the browser instead of the page. */
#hud {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: calc(34px * var(--ui-scale));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 14px 3px 4px;
  font-family: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: left;
  color: var(--fg-muted);
  box-shadow: var(--shadow-1);
}

#hud:hover {
  background: var(--panel);
  border-color: var(--border-strong);
}

/* View mode (and the locked viewer) has no Controls to open - see
   refreshViewModeBar. Keep it fully legible rather than fading it out like an
   ordinary disabled button, since it is still showing live grid/zoom values. */
#hud:disabled {
  opacity: 1;
  cursor: default;
}

#hud .sep { color: var(--sep); }
#hud .hint { color: var(--fg-muted); }
#hudTool {
  font-weight: 650;
  color: var(--tc, var(--accent));
  background: color-mix(in srgb, var(--tc, var(--accent)) 16%, transparent);
  border-radius: 999px;
  padding: 3px 11px;
}
#hud #gridLabel, #hud #zoomLabel { color: var(--fg); font-weight: 600; }

.hud-mode-badge {
  font-weight: 600;
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 4px;
  padding: 1px 6px;
}

/* ---------- View mode bar ---------- */
#viewModeBar {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 130;
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--warn-bar-bg);
  border: 1px solid var(--warn);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12.5px;
  color: var(--fg);
  box-shadow: 0 10px 30px var(--shadow-panel);
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100vw - 24px);
}

#viewModeBar.open {
  display: flex;
}

.view-mode-label {
  font-weight: 600;
  color: var(--warn);
  white-space: nowrap;
}

.view-sub-tools {
  display: flex;
  gap: 4px;
}

.view-sub-tool {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
}

.view-sub-tool.active {
  background: var(--warn);
  border-color: var(--warn);
  color: var(--on-warn);
  font-weight: 600;
}

.pen-color-swatches {
  display: flex;
  gap: 6px;
}

.pen-color-swatches.dim {
  opacity: 0.35;
  pointer-events: none;
}

.pen-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.pen-swatch.active {
  border-color: var(--swatch-ring);
}

#viewModeBar button {
  font-size: 12px;
  padding: 4px 10px;
}

/* Standalone exported viewer (state.viewerLocked): there's no edit mode to
   get back to, so hide the affordances that imply there is one. */
body.viewer-locked #hud .hint,
body.viewer-locked #hud .sep:has(+ .hint) { display: none; }
body.viewer-locked #exitViewModeBtn { display: none; }
/* The standalone export is a file:// page with no server behind it, so an
   Account button there could only ever fail. The export reuses this very DOM
   (see the Export HTML button in ui/controlsModal.js), hence hiding rather
   than omitting. */
body.viewer-locked #accountBtn,
body.viewer-locked #accountOverlay,
body.viewer-locked #usersBtn,
body.viewer-locked #usersOverlay,
/* An exported file:// viewer has no worker and no manifest to install from. */
body.viewer-locked #installRow { display: none !important; }

button:disabled {
  opacity: 0.4;
  cursor: default;
}
button:disabled:hover {
  background: var(--surface);
}

/* ---------- Canvas ---------- */
/* touch-action: none hands every gesture to core/touchGestures.js - without it
   the browser claims one-finger drags for scrolling and pinch for page zoom,
   and the canvas never sees them. The tap-highlight/callout suppressions stop
   mobile Safari and Chrome painting a grey flash or a text-selection bubble
   over the plan on each tap. */
#canvasWrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  cursor: default;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

canvas {
  display: block;
  touch-action: none;
}

/* ---------- Modal ---------- */
#modalOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
}

#modalOverlay.open {
  display: flex;
}

#modalPanel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 20px 14px;
  width: min(860px, calc(100vw - 32px));
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.icon-btn:hover {
  background: var(--surface);
  color: var(--fg);
}

.modal-status {
  margin: 0;
  font-size: 12.5px;
  color: var(--fg-muted);
  min-height: 1.4em;
}

.modal-footer {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--fg-faint);
  text-align: center;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-faint);
}

.modal-divider {
  width: 100%;
  border: none;
  border-top: 1px solid var(--border);
  margin: 2px 0;
}

/* ---------- Menu (the Controls window) ---------- */
.menu-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.menu-brand h2 { font-size: 17px; }
/* the window scrolls as a whole; its sections keep their natural height */
#modalPanel > * { flex-shrink: 0; }

/* what the current tool does, tinted with its color */
.menu-status {
  background: color-mix(in srgb, var(--tc, var(--accent)) 12%, transparent);
  border-left: 3px solid var(--tc, var(--accent));
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--fg);
  line-height: 1.45;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.menu-card {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.menu-card-wide { grid-column: 1 / -1; }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 6px;
}

.tool-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 14px 6px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--fg);
}
.tool-tile.tool[data-icon] { flex-direction: column; }
.tool-tile .ico { width: 24px; height: 24px; color: var(--tc); }
.tool-tile kbd {
  position: absolute;
  top: 5px;
  right: 5px;
  font-size: 9.5px;
  padding: 0 4px;
  background: transparent;
  border-color: var(--border);
  color: var(--fg-faint);
}
.tool-tile:hover {
  background: color-mix(in srgb, var(--tc) 10%, var(--panel));
  border-color: color-mix(in srgb, var(--tc) 60%, transparent);
}
button.tool-tile.active {
  background: var(--tc);
  border-color: var(--tc);
  color: var(--on-tc);
  font-weight: 650;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--tc) 40%, transparent);
}
.tool-tile.active .ico, .tool-tile.active kbd { color: inherit; border-color: currentColor; }

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.menu-list > button,
.menu-split > button {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 10px;
  text-align: left;
  color: var(--fg);
}
.menu-list button .ico { color: var(--accent-fg); }
.menu-list button span { flex: 1; }
.menu-list button kbd {
  background: transparent;
  border: none;
  padding: 0;
  font-weight: 500;
  color: var(--fg-faint);
}
.menu-list > button:hover,
.menu-split > button:hover {
  background: var(--surface-hover);
  border-color: transparent;
}
.menu-split {
  display: flex;
  align-items: center;
  gap: 4px;
}
.menu-split > button { flex: 1; min-width: 0; }
.menu-split select { flex: none; padding: 4px 6px; font-size: 12px; }
.menu-list .danger-btn .ico { color: var(--danger-fg); }
.menu-list > .danger-btn:hover { background: var(--danger-bg); color: var(--danger-fg); }

/* Touch Mode and Install side by side, under the cards */
.menu-device {
  background: transparent;
  border: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.hotkeys-list {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
}

.hotkeys-list li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hotkeys-list li span {
  color: var(--fg-muted);
}

/* Section headings inside the list. A plain <li> rather than a nested list, so
   the flex column keeps one consistent rhythm and the rows stay alignable. */
.hotkeys-heading {
  margin-top: 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hotkeys-list .hotkeys-heading:first-child {
  margin-top: 0;
}

.group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.button-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Program row: one line, never wrapped - #modalPanel is widened to suit. The
   scroll is a fallback for viewports too narrow to hold the row at all,
   rather than something the normal layout relies on. */
.button-row-single {
  flex-wrap: nowrap;
  overflow-x: auto;
  /* stretch, not center: a native <select> is a couple of px taller than a
     button at the same padding, so letting every control fill the row's
     height keeps them flush without hardcoding one */
  align-items: stretch;
}

.button-row button {
  flex: 1 1 auto;
  white-space: nowrap;
}

/* The Program section stacks two of these rows (file actions, then exports). */
.section .button-row + .button-row {
  margin-top: 6px;
}

button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: calc(6px * var(--ui-scale)) calc(12px * var(--ui-scale));
  font-family: inherit;
  font-size: calc(13px * var(--ui-scale));
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

/* a button with an icon (data-icon, see ui/icons.js) lays the two out in a row */
button[data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ico {
  width: 18px;
  height: 18px;
  flex: none;
  display: block;
}

button:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

/* Each tool has its own color (--t-* in the theme tokens) */
.tool[data-tool="select"], body[data-tool="select"] { --tc: var(--t-select); }
.tool[data-tool="wall"], body[data-tool="wall"] { --tc: var(--t-wall); }
.tool[data-tool="area"], body[data-tool="area"] { --tc: var(--t-area); }
.tool[data-tool="door"], body[data-tool="door"] { --tc: var(--t-door); }
.tool[data-tool="window"], body[data-tool="window"] { --tc: var(--t-window); }
.tool[data-tool="object"], body[data-tool="object"] { --tc: var(--t-object); }
.tool[data-tool="label"], body[data-tool="label"] { --tc: var(--t-label); }
.tool[data-tool="measure"], body[data-tool="measure"] { --tc: var(--t-measure); }
.tool[data-tool="terrain"], body[data-tool="terrain"] { --tc: var(--t-terrain); }
.tool[data-tool="electrical"], body[data-tool="electrical"] { --tc: var(--t-electrical); }
.tool[data-tool="hydraulic"], body[data-tool="hydraulic"] { --tc: var(--t-hydraulic); }
:root { --on-tc: #121522; }
:root[data-theme="light"] { --on-tc: #fff; }

button.tool.active {
  background: var(--tc, var(--accent));
  border-color: var(--tc, var(--accent));
  color: var(--on-tc);
}

button.primary {
  background: var(--accent-grad);
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 600;
}
button.primary:hover {
  background: var(--accent-grad);
  filter: brightness(1.1);
}

/* ---------- Prompt dialog ---------- */
#promptOverlay,
#choiceOverlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
}

#promptOverlay.open,
#choiceOverlay.open {
  display: flex;
}

#promptPanel,
#choicePanel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 18px 20px;
  min-width: min(280px, 100%);
  box-shadow: 0 20px 60px var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prompt-label {
  font-size: 13px;
  color: var(--fg);
}

.prompt-input {
  background: var(--input-bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
}
.prompt-input:focus {
  outline: none;
  border-color: var(--accent);
}

.prompt-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

#choicePanel { max-width: min(380px, calc(100vw - 32px)); }
.choice-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.choice-actions button { text-align: left; padding: 9px 12px; }
.choice-actions button.danger {
  background: var(--danger-bg);
  color: var(--danger-fg);
  border-color: var(--danger-fg);
}

/* ---------- Object picker (rules shared with the texture picker) ---------- */
#texturePickerOverlay,
#objectPickerOverlay {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
}

#texturePickerOverlay.open,
#objectPickerOverlay.open {
  display: flex;
}

#texturePickerPanel,
#objectPickerPanel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 18px 20px;
  min-width: min(300px, 100%);
  max-width: 380px;
  max-height: 70vh;
  box-shadow: 0 20px 60px var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.object-picker-breadcrumb {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--fg-muted);
}

.object-picker-back {
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12.5px;
  padding: 2px 4px;
}
.object-picker-back:hover {
  text-decoration: underline;
}

.object-picker-category {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.object-picker-category::after {
  content: '\203A';
  color: var(--fg-faint);
  font-size: 15px;
}

.object-picker-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 40vh;
}

.object-picker-row {
  padding: 8px 10px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
}

.object-picker-row:hover,
.object-picker-row.active {
  border-color: var(--accent);
  background: var(--accent-soft-strong);
}

.texture-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.texture-picker-swatch {
  width: 56px;
  height: 32px;
  border-radius: 4px;
  border: 1px solid var(--border);
  flex: none;
}

.texture-picker-clear {
  color: var(--fg-muted);
  font-style: italic;
}

/* ---------- Saves list ---------- */
#savesOverlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
}

#savesOverlay.open {
  display: flex;
}

#savesPanel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 18px 20px;
  min-width: min(340px, 100%);
  max-width: 420px;
  max-height: 70vh;
  box-shadow: 0 20px 60px var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.saves-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  max-height: 50vh;
}

.saves-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.save-name {
  flex: 1;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.save-name:hover {
  color: var(--accent);
}

.save-date {
  font-size: 11px;
  color: var(--fg-faint);
  white-space: nowrap;
}

.save-actions {
  display: flex;
  gap: 4px;
}

.save-actions button {
  padding: 4px 8px;
  font-size: 11.5px;
}

/* ---------- Settings ---------- */
#settingsOverlay,
#stlOverlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
}

#settingsOverlay.open,
#stlOverlay.open {
  display: flex;
}

#settingsPanel,
#stlPanel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 18px 20px;
  min-width: min(340px, 100%);
  max-width: 420px;
  box-shadow: 0 20px 60px var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* The 3D options are a taller stack than Settings and would run off the
     bottom of a phone held sideways. */
  max-height: 90vh;
  overflow-y: auto;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--fg);
}

.settings-row label {
  white-space: nowrap;
}

/* Six rows of differing label widths leave a ragged edge down the middle, so
   here the label takes the slack and every control lines up on the right.
   Scoped to this panel: Settings has two number rows and a slider, whose
   flex:1 would end up splitting the row with the label. */
#stlPanel .settings-row label {
  flex: 1;
}

.settings-row input[type="range"] {
  flex: 1;
}

.settings-row input[type="number"] {
  width: 80px;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 13px;
}

.settings-row span {
  min-width: 34px;
  text-align: right;
  color: var(--fg-muted);
  font-size: 12px;
}

/* ---------- Hotkeys ---------- */
#hotkeysOverlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
}

#hotkeysOverlay.open {
  display: flex;
}

#hotkeysPanel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 18px 20px;
  min-width: min(340px, 100%);
  max-width: 420px;
  max-height: 70vh;
  box-shadow: 0 20px 60px var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#hotkeysPanel .hotkeys-list {
  overflow-y: auto;
  max-height: 55vh;
}

/* ---------- Theme toggle ---------- */
/* The switch normally lives in the Settings panel (#themeSettingBtn). The
   floating top-right button only shows in the standalone exported viewer,
   which has no Settings panel - above the side panels (z 120) so it stays
   reachable while one is open. */
#themeToggle {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 140;
  width: 32px;
  height: 32px;
  padding: 0;
  align-items: center;
  justify-content: center;
  background: var(--hud-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg-muted);
}

body.viewer-locked #themeToggle {
  display: flex;
}

#themeToggle:hover {
  background: var(--surface-hover);
  color: var(--fg);
}

#themeToggle svg {
  width: 16px;
  height: 16px;
  display: block;
}

.theme-setting-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Built-in 3D view ---------- */
/* The 2D/3D switch takes the top-right corner the theme toggle vacated. */
#view3dBtn {
  height: 36px;
  margin-left: 4px;
  padding: 0 14px 0 11px;
  background: var(--accent-grad);
  border: none;
  border-radius: var(--r-md);
  color: #fff;
  font-size: 13px;
  font-weight: 650;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.45);
}

#view3dBtn:hover {
  background: var(--accent-grad);
  filter: brightness(1.12);
}

/* No 3D in the exported viewer for now - it shares this DOM (see the Export
   HTML button), so hide rather than omit. */
body.viewer-locked #view3dBtn { display: none; }

/* Above panels and the HUD (so nothing 2D peeks through), below modal
   overlays (z 200+) - a prompt opened elsewhere still wins. */
#view3d {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 160;
  /* the canvas draws every pixel; this only shows for a frame at entry */
  background: var(--bg);
  touch-action: none;
}

#view3d.open { display: block; }

/* Opening the 3D view: the screen blurs under a spinner until the scene can
   be used (the spinner turns on the compositor, so it keeps turning while
   the scene is being built) */
#view3dVeil {
  position: fixed;
  inset: 0;
  z-index: 170;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 16, 30, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: progress;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}
#view3dVeil.show { opacity: 1; visibility: visible; transition: none; }
.veil-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #8b5cf6;
  border-right-color: #06b6d4;
  border-radius: 50%;
  animation: toast-spin 0.8s linear infinite;
  will-change: transform;
}
#view3dVeil:not(.show) .veil-spinner { animation: none; }

#view3dSky,
#view3dSkyGl,
#view3dGl,
#view3dCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
#view3dSky,
#view3dSkyGl,
#view3dGl { pointer-events: none; }
/* layered over the sky: see-through except where they draw */
#view3dGl,
#view3dCanvas { background: transparent; }

#view3dBar {
  position: fixed;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 2px;
  height: calc(46px * var(--ui-scale));
  max-width: calc(100vw - 320px);
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0 5px;
  font-size: 12px;
  box-shadow: var(--shadow-1);
}
#view3dBar button {
  height: calc(34px * var(--ui-scale));
  padding: 0 11px;
  background: transparent;
  border-color: transparent;
  color: var(--fg-muted);
  white-space: nowrap;
}
#view3dBar button:hover { background: var(--surface); color: var(--fg); }
#view3dBar button.active {
  background: var(--accent-soft-strong);
  color: var(--accent-fg);
  font-weight: 600;
}
#view3dBar #view3dExitBtn {
  background: var(--accent-grad);
  color: #fff;
  font-weight: 650;
  padding: 0 14px 0 9px;
}
#view3dBar #view3dExitBtn:hover { filter: brightness(1.12); }
#view3dBar .app-divider { margin: 0 3px; }

#view3d .view3d-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  max-width: calc(100vw - 140px);
  padding: 6px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-1);
  color: var(--fg-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}


/* Cinematic: a vignette and a film grain over the whole 3D view. The grain
   jumps about a few times a second like real film's - moved by the
   compositor, so it costs the 3D drawing nothing */
#view3dFilm {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 45%, rgba(0,0,0,0.22) 75%, rgba(0,0,0,0.55) 100%);
}
#view3dFilm::after {
  content: '';
  position: absolute;
  inset: -128px;
  background: var(--grain);
  background-size: 128px 128px;
  opacity: 0.13;
  mix-blend-mode: overlay;
  animation: film-grain 0.5s steps(1) infinite;
  will-change: transform;
}
@keyframes film-grain {
  0% { transform: translate(0, 0); }
  17% { transform: translate(-37px, 23px); }
  33% { transform: translate(51px, -61px); }
  50% { transform: translate(-83px, -17px); }
  67% { transform: translate(29px, 77px); }
  83% { transform: translate(-11px, -97px); }
}
#view3dFilm[hidden]::after { animation: none; }
@media (prefers-reduced-motion: reduce) {
  #view3dFilm::after { animation: none; }
}
#view3dFilm[hidden] { display: none; }

/* The minimap (ui/minimap.js): bottom-left, just the plan over the view,
   a little see-through - a soft shadow keeps its lines readable on any sky */
#view3dMinimap {
  position: absolute;
  left: 14px;
  bottom: 14px;
  pointer-events: none;
  line-height: 0;
  opacity: 0.82;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.55)) drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
}

/* walking: no cursor over the view, a crosshair in the middle instead */
#view3d.walking #view3dCanvas { cursor: none; }
#view3dCrosshair {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  pointer-events: none;
  background:
    linear-gradient(rgba(255,255,255,0.85), rgba(255,255,255,0.85)) center / 2px 18px no-repeat,
    linear-gradient(rgba(255,255,255,0.85), rgba(255,255,255,0.85)) center / 18px 2px no-repeat;
  filter: drop-shadow(0 0 1px rgba(0,0,0,0.8));
}
#view3d.walking #view3dCrosshair { display: block; }
body.touch-mode #view3d.walking #view3dCrosshair { display: none; }

/* 3D Layers list: a dropdown under the top bar's Layers button */
#view3dLayers {
  position: fixed;
  top: calc(12px + 52px * var(--ui-scale));
  left: 12px;
  z-index: 5;
  display: none;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 12px;
  box-shadow: var(--shadow-2);
  font-size: 13px;
}
#view3dLayers.open { display: flex; }
#view3dLayers .layer3d-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin-bottom: 4px;
}
.layer3d-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.layer3d-row:hover { background: var(--surface); }
.layer3d-row input { accent-color: var(--accent); }
.layer3d-row.off { color: var(--fg-faint); cursor: default; }
body.touch-mode .layer3d-row { padding: 9px 2px; }

/* Saved views: a row of chips under the top-left bar */
#view3dViews {
  position: fixed;
  top: calc(18px + 46px * var(--ui-scale));
  left: 12px;
  right: 300px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  background: transparent;
  pointer-events: none;   /* the gaps between chips stay the 3D canvas */
}
#view3dViews > *, #view3dViewList > * { pointer-events: auto; }
#view3dViewList { display: contents; }
#view3dViews button {
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 12px;
  box-shadow: var(--shadow-1);
}
#view3dSaveView { border-radius: 999px; padding: 5px 13px 5px 9px; color: var(--accent-fg); font-weight: 600; gap: 5px; }
#view3dSaveView .ico { width: 15px; height: 15px; }
.view-chip {
  display: inline-flex;
  align-items: stretch;
}
.view-chip .view-go {
  border-radius: 999px 0 0 999px;
  padding: 5px 10px 5px 12px;
  color: var(--fg);
  font-weight: 600;
}
.view-chip .view-go small { font-weight: 400; color: var(--fg-muted); margin-left: 6px; }
.view-chip .view-del {
  border-radius: 0 999px 999px 0;
  border-left: none;
  padding: 5px 9px 5px 6px;
  color: var(--fg-muted);
}
.view-chip .view-del:hover { color: var(--danger-fg); }
.view-chip.active .view-go,
.view-chip.active .view-del { border-color: var(--accent); background: var(--accent-soft-strong); }
.view-chip.active .view-go { color: var(--accent-fg); }
body.touch-mode #view3dViews { top: 64px; right: 12px; }

#view3dSunBar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 12px 12px;
  font-size: 12px;
  box-shadow: var(--shadow-1);
}

#view3dSunBar .sun-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-faint);
}
#view3dSunBar .sun-title .ico { width: 16px; height: 16px; color: #fbbf24; }

#view3dSunBar .sun-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#view3dSunBar label {
  width: 52px;
  color: var(--fg-muted);
}

#view3dSunBar input[type="range"] {
  width: 130px;
}

#view3dSunBar input[type="number"],
#view3dSunBar select {
  width: 72px;
  background: var(--input-bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
}
#view3dSunBar button { padding: 4px 12px; font-size: 12px; }

#view3dSunBar .sun-value {
  width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- Render Prompt wizard (ui/renderPrompt.js) ---------- */
/* above the 3D view (z 160), below the toast */
#renderPromptOverlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--scrim);
}

#renderPromptOverlay.open { display: flex; }

#renderPromptPanel {
  background: var(--modal-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 18px 20px 16px;
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  box-shadow: 0 20px 60px var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#renderPromptPanel .rp-step {
  margin-left: 6px;
  font-size: 12px;
  font-weight: 400;
  color: var(--fg-faint);
}

#renderPromptPanel .rp-question {
  margin: 4px 0 0;
  font-size: 15px;
  font-weight: 600;
}

#renderPromptPanel .rp-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#renderPromptPanel .rp-chip {
  border-radius: 999px;
  padding: 8px 14px;
}

#renderPromptPanel .rp-chip.selected {
  background: var(--accent-soft-strong);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

#renderPromptPanel textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  font-size: 13px;
  line-height: 1.45;
  padding: 8px 10px;
}

#renderPromptPanel .rp-notes { min-height: 90px; }
#renderPromptOutput { min-height: 260px; }

#renderPromptPanel .rp-actions,
#renderPromptPanel .rp-nav {
  display: flex;
  gap: 8px;
}

#renderPromptPanel .rp-nav {
  justify-content: space-between;
  margin-top: 4px;
}

#renderPromptPanel .rp-primary,
#renderPromptNext {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

#renderPromptPanel .rp-primary:hover,
#renderPromptNext:hover { background: var(--accent-grad); filter: brightness(1.1); }

body.touch-mode #view3dBtn,
body.touch-mode #view3dExitBtn,
body.touch-mode #renderPromptBtn {
  min-height: calc(40px * var(--ui-scale));
  padding: calc(8px * var(--ui-scale)) calc(14px * var(--ui-scale));
}

/* the hint is mouse wording; a phone doesn't need it and hasn't the room */
body.touch-mode #view3d .view3d-hint { display: none; }

.theme-setting-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* ---------- Toast ---------- */
/* Bottom-right: the top-right corner belongs to #themeToggle, and the scale
   bar already owns bottom-left. */
#toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  z-index: 300;
  max-width: calc(100vw - 32px);
  background: var(--toast-bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-2);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Layers side panel ---------- */
#exportPanel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 120;
  width: min(300px, 100%);
  background: var(--side-panel-bg);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

/* Shadow only while open: parked off-screen at right: 0 these panels would
   still cast their leftward shadow across the visible page edge. */
#exportPanel.open {
  transform: translateX(0);
  box-shadow: -20px 0 60px var(--shadow-panel);
}

#layersPanel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  width: min(300px, 100%);
  background: var(--side-panel-bg);
  border-left: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  overflow-y: auto;
}

#layersPanel.open {
  transform: translateX(0);
  box-shadow: -20px 0 60px var(--shadow-panel);
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* In the standalone viewer #themeToggle floats at top-right on z-index 140,
   above these panels (120), so without reserving the corner it sits on top of
   the header's close button and swallows the tap. Sized for the touch-mode
   toggle, which is the largest it gets. */
body.viewer-locked .side-panel-header {
  padding-right: calc(44px * var(--ui-scale) + 8px);
}

.side-panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.side-panel-add {
  align-self: flex-start;
}

.layers-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layers-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.layers-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.layers-row.dragging {
  opacity: 0.4;
}

.layers-row.drag-over {
  border-color: var(--accent);
  box-shadow: inset 0 2px 0 var(--accent);
}

.layer-drag-handle {
  font-size: 12px;
  line-height: 1;
  color: var(--fg-faint);
  cursor: grab;
  user-select: none;
  letter-spacing: -2px;
}

.layer-visibility,
.layer-select-lock {
  padding: 4px 6px;
  font-size: 13px;
  line-height: 1;
}

.layers-row.hidden-layer .layer-name {
  color: var(--fg-faint);
  font-style: italic;
}

.layer-name {
  flex: 1;
  font-size: 13px;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.layers-row.active .layer-name {
  color: var(--accent);
  font-weight: 600;
}

.layer-level {
  font-size: 11px;
  color: var(--fg-faint);
  white-space: nowrap;
}

.layer-actions {
  display: flex;
  gap: 4px;
}

.layer-actions button {
  padding: 4px 8px;
  font-size: 11.5px;
}

.layers-move-section {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--fg-muted);
}

.layers-move-section select,
.settings-row select,
.button-row select {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 13px;
}

/* ---------- Plan Info side panel ---------- */
#infoPanel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  width: min(300px, 100%);
  background: var(--side-panel-bg);
  border-left: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  overflow-y: auto;
}

#infoPanel.open {
  transform: translateX(0);
  box-shadow: -20px 0 60px var(--shadow-panel);
}

.info-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-wires-list, .info-summary-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.info-empty {
  font-size: 12.5px;
  color: var(--fg-faint);
  font-style: italic;
}

.info-wire-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.info-wire-row:hover {
  border-color: var(--border-strong);
  background: var(--surface-sunken-hover);
}

.info-wire-row.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.info-wire-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex: none;
  box-sizing: border-box;
  border: 2px solid var(--hairline-soft);
}

.info-wire-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.info-wire-name {
  font-size: 13px;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.info-wire-sub {
  font-size: 11px;
  color: var(--fg-faint);
}

.info-wire-length {
  font-size: 12px;
  color: var(--fg-muted);
  white-space: nowrap;
  text-align: right;
}

.info-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.info-summary-label {
  color: var(--fg-muted);
}

.info-summary-value {
  color: var(--fg);
  font-weight: 500;
}

.info-summary-row.clickable {
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  margin: -2px -4px;
}

.info-summary-row.clickable:hover {
  background: var(--surface-row-hover);
}

/* ---------- Scale bar (bottom-left, always visible) ---------- */
#scaleBarWidget {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: none;
}

.scale-bar {
  height: 8px;
  border-left: 2px solid var(--fg);
  border-right: 2px solid var(--fg);
  border-bottom: 2px solid var(--fg);
}

.scale-bar-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg);
  text-shadow: 0 0 3px var(--bg), 0 0 3px var(--bg);
}

/* ---------- Right-click context menu ---------- */
.context-menu {
  position: fixed;
  z-index: 400;
  display: none;
  flex-direction: column;
  gap: 1px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 5px;
  min-width: 180px;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  box-shadow: var(--shadow-2);
}

.context-menu.open {
  display: flex;
}

.context-menu button {
  background: transparent;
  border: none;
  color: var(--fg);
  text-align: left;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

.context-menu button:hover {
  background: var(--accent-soft-strong);
  color: var(--accent-fg);
}

.context-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}

.context-menu-sublist {
  display: none;
  flex-direction: column;
  gap: 1px;
}

.context-menu-light-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  vertical-align: -1px;
}

.context-menu-sublist.open {
  display: flex;
}

.context-menu-sublist button {
  padding-left: 24px;
}

.context-menu-sublist button:disabled {
  color: var(--fg-muted);
  cursor: default;
}

.context-menu-sublist button:disabled:hover {
  background: transparent;
}

.context-menu-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px 4px 24px;
  max-width: 172px;
}

.context-menu-swatches-label {
  padding: 4px 10px 0 24px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-fainter);
}

.context-menu .context-menu-swatch {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--hairline-softer);
  border-radius: 4px;
  flex: none;
}

.context-menu .context-menu-swatch:hover {
  outline: 2px solid var(--accent);
}

.context-menu-color-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  border: none;
  padding: 0;
}

#ctxDelete:hover {
  background: var(--danger-bg);
  color: var(--danger-fg);
}


/* ---------- Toggle row (Controls window) ---------- */
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.toggle-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}

.toggle-hint {
  font-size: 11.5px;
  color: var(--fg-muted);
}

/* Install / offline row. Shares the sunken card look of .toggle-row above so
   the two read as one block of "how this app lives on your device" settings,
   but it is a stack rather than a checkbox row - its buttons come and go with
   what the browser actually supports (see ui/controlsModal.js). */
.install-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.install-row .group:empty,
.install-row .group:not(:has(button:not([hidden]))) {
  display: none;
}

/* ---------- Touch command bar ---------- */
/* Only ever visible in Touch Mode (ui/touchBar.js toggles .open). Floats over
   the canvas rather than taking layout space. The buttons live in one wrapping
   list, so the box's shape is purely a function of its size: drag it narrow and
   they stack into a vertical strip, drag it wide and short and they form a
   single horizontal row. Sits above the side panels but below modals. */
#touchBar {
  /* The button cell, defined once here: the resize snapping in ui/touchBar.js
     measures a rendered button to find it, and the touch-mode override at the
     bottom of this file used to keep its own copy of the height. */
  --touch-cell-w: calc(56px * var(--ui-scale));
  --touch-cell-h: calc(48px * var(--ui-scale));
  --touch-gap: 4px;
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 125;
  display: none;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px);
  /* The ring keeps the corner handles clear of the buttons. Dragging to move
     works from anywhere on the box, not just here - see ui/touchBar.js. */
  padding: 14px;
  /* the box owns every gesture on it: move, and resize from the corners */
  touch-action: none;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 30px var(--shadow-float);
}

#touchBar.open {
  display: block;
}

/* The bar sits at z-index 125, above the modal overlay's 100, so without this
   it floats on top of the Controls window and covers it. Centred modals only -
   the side panels (Layers, Info, Export) are at 120 and deliberately stay
   underneath, since the point of the Layers/Info buttons is to keep working
   with the bar while their panel is open. */
body:has(#modalOverlay.open) #touchBar,
body:has(#settingsOverlay.open) #touchBar,
body:has(#savesOverlay.open) #touchBar,
body:has(#accountOverlay.open) #touchBar,
body:has(#usersOverlay.open) #touchBar,
body:has(#hotkeysOverlay.open) #touchBar,
body:has(#promptOverlay.open) #touchBar,
body:has(#choiceOverlay.open) #touchBar,
body:has(#objectPickerOverlay.open) #touchBar,
body:has(#texturePickerOverlay.open) #touchBar {
  display: none;
}

/* Once dragged, the box is placed by explicit left/top from ui/touchBar.js, so
   every default anchor has to be released - including the phone rule below
   that stretches it edge to edge. */
#touchBar.positioned {
  bottom: auto;
  right: auto;
  transform: none;
}

/* Only set once the user has resized; until then the box sizes to content. */
#touchBar.sized {
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px);
}

#touchBar.dragging {
  box-shadow: 0 18px 44px var(--shadow-modal);
  opacity: 0.96;
}

#touchBar.single-row .touch-bar-items {
  flex-wrap: nowrap;
}

.touch-bar-items {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  /* Not the default `stretch`: the buttons are a fixed cell, and letting a
     single-row strip stretch them to the container's full height both looks
     wrong and hides the geometry the snapping is built on. */
  align-items: center;
  gap: var(--touch-gap);
  width: 100%;
  height: 100%;
  overflow: auto;
  scrollbar-width: none;
}

.touch-bar-items::-webkit-scrollbar {
  display: none;
}

/* Collapsed leaves just Move and Hide - a two-button pill. */
#touchBar.collapsed .touch-bar-items > :not(.touch-chrome) {
  display: none;
}

#touchBar.collapsed {
  padding: 14px;
}

#touchBar.collapsed .touch-bar-corner {
  display: none;
}

/* One fixed cell for every button, not a min-size that a long label can grow
   past. The box snaps its own width and height to whole cells (snapSize() in
   ui/touchBar.js), so a single wider button would put every column boundary in
   the wrong place and a one- or two-column strip would never come out straight.
   Labels too long for the cell are clipped below - the full text is still on
   the button's title and aria-label. */
.touch-btn {
  flex: none;
  width: var(--touch-cell-w);
  height: var(--touch-cell-h);
  overflow: hidden;
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  font-family: inherit;
}

/* Move and Hide are chrome, not commands - same footprint, quieter fill. */
.touch-btn.touch-chrome {
  background: transparent;
  border-color: transparent;
  color: var(--fg-muted);
}

.touch-btn.touch-chrome:hover {
  background: var(--surface-sunken);
}

#touchBarMove {
  touch-action: none;
  cursor: grab;
}

#touchBar.dragging #touchBarMove {
  cursor: grabbing;
}

.touch-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.touch-btn:disabled {
  opacity: 0.35;
}

/* Visibility switches. They read as a state rather than a command: a hollow
   icon and a dimmed, struck-through label while the thing is hidden. Not
   .active styling - that is reserved for "this mode is engaged", and a plan
   with everything visible would otherwise light up half the bar. */
.touch-btn.touch-view {
  border-style: dashed;
}

.touch-btn.touch-view.off {
  opacity: 0.5;
}

.touch-btn.touch-view.off .touch-btn-label {
  text-decoration: line-through;
}

.touch-btn-icon {
  flex: none;
  font-size: calc(17px * var(--ui-scale));
  line-height: 1;
}

.touch-btn-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(9.5px * var(--ui-scale));
  line-height: 1;
  letter-spacing: 0.01em;
}

/* Resize handles: one per corner, sitting in the padding ring. Drawn as a
   small bracket so the corners read as grabbable without adding chrome. */
.touch-bar-corner {
  position: absolute;
  width: 26px;
  height: 26px;
  touch-action: none;
}

.touch-bar-corner::after {
  content: '';
  position: absolute;
  width: 11px;
  height: 11px;
  border: 2px solid var(--fg-muted);
  opacity: 0.45;
}

.touch-bar-corner:hover::after {
  opacity: 0.9;
}

.touch-bar-corner[data-corner="nw"] { top: 2px; left: 2px; cursor: nwse-resize; }
.touch-bar-corner[data-corner="ne"] { top: 2px; right: 2px; cursor: nesw-resize; }
.touch-bar-corner[data-corner="sw"] { bottom: 2px; left: 2px; cursor: nesw-resize; }
.touch-bar-corner[data-corner="se"] { bottom: 2px; right: 2px; cursor: nwse-resize; }

.touch-bar-corner[data-corner="nw"]::after {
  top: 4px; left: 4px; border-right: none; border-bottom: none; border-top-left-radius: 5px;
}
.touch-bar-corner[data-corner="ne"]::after {
  top: 4px; right: 4px; border-left: none; border-bottom: none; border-top-right-radius: 5px;
}
.touch-bar-corner[data-corner="sw"]::after {
  bottom: 4px; left: 4px; border-right: none; border-top: none; border-bottom-left-radius: 5px;
}
.touch-bar-corner[data-corner="se"]::after {
  bottom: 4px; right: 4px; border-left: none; border-top: none; border-bottom-right-radius: 5px;
}

/* Phones: span the width until the user positions or resizes it themselves. */
@media (max-width: 600px) {
  #touchBar:not(.positioned):not(.sized) {
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
  }
}

/* The scale bar shares the bottom edge - lift it clear of the command bar. */
body.touch-mode #scaleBarWidget {
  bottom: 128px;
}

body.touch-mode #toast {
  bottom: 128px;
}

/* ---------- Layer reorder buttons ---------- */
/* Mouse users drag the ⋮⋮ grip; touch users get these, since HTML5 drag-and-drop
   never fires from a finger. Exactly one of the two is shown at a time. */
.layer-order-btns {
  display: none;
  flex-direction: column;
  gap: 2px;
  flex: none;
}

.layer-order-btn {
  padding: 0;
  width: 26px;
  height: 20px;
  font-size: 9px;
  line-height: 1;
  border-radius: 4px;
}

body.touch-mode .layer-drag-handle { display: none; }
body.touch-mode .layer-order-btns { display: flex; }

/* ---------- Touch Mode sizing ---------- */
/* A fingertip contact patch is ~40px; the audited targets below ranged from
   10px (the layer grip) to 32px. 44px is the floor everywhere a finger lands.
   Scoped to body.touch-mode so the mouse UI keeps its tighter proportions. */
body.touch-mode button,
body.touch-mode select,
body.touch-mode input[type="number"],
body.touch-mode input[type="text"],
body.touch-mode input[type="password"],
body.touch-mode .prompt-input {
  min-height: calc(44px * var(--ui-scale));
}

/* Mobile browsers zoom the whole page in when a focused text field's font is
   under 16px (the "type a layer name and the app zooms" effect). Keeping
   every text-entry control at 16px+ in Touch Mode stops that at the source;
   the viewport's maximum-scale=1 in index.html backs it up on iOS. */
body.touch-mode select,
body.touch-mode input[type="number"],
body.touch-mode input[type="text"],
body.touch-mode input[type="password"],
body.touch-mode .prompt-input {
  font-size: max(16px, calc(13px * var(--ui-scale)));
}

body.touch-mode button {
  padding: calc(10px * var(--ui-scale)) calc(14px * var(--ui-scale));
  font-size: calc(14px * var(--ui-scale));
}

/* The command bar sets its own tighter geometry - it is already finger-sized
   and would look absurd at the generic padding. Its height is --touch-cell-h
   on .touch-btn, so the 44px floor above is dropped here rather than restated
   at a second value that could drift from the cell. */
body.touch-mode #touchBar button {
  min-height: 0;
  padding: 4px 6px;
  font-size: inherit;
}

body.touch-mode .icon-btn {
  min-width: calc(44px * var(--ui-scale));
  min-height: calc(44px * var(--ui-scale));
  font-size: calc(24px * var(--ui-scale));
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body.touch-mode .layer-actions button,
body.touch-mode .save-actions button,
body.touch-mode #viewModeBar button,
body.touch-mode .view-sub-tool {
  min-height: 44px;
  padding: 8px 14px;
  font-size: 13px;
}

body.touch-mode .layer-visibility,
body.touch-mode .layer-select-lock {
  min-width: calc(44px * var(--ui-scale));
  min-height: calc(44px * var(--ui-scale));
  font-size: calc(18px * var(--ui-scale));
}

/* Deliberate exception to the 44px floor: a stacked ▲/▼ pair, like an iOS
   stepper. Each button is 44px wide and the pair spans 50px, so the combined
   target is comfortably finger-sized even though one arrow alone is not. */
body.touch-mode .layer-order-btn {
  width: calc(44px * var(--ui-scale));
  height: calc(24px * var(--ui-scale));
  min-height: 0;
  padding: 0;
  font-size: 12px;
}

/* Colour swatches were 18px with a 6px gap - the single worst target class. */
body.touch-mode .pen-swatch,
body.touch-mode .context-menu .context-menu-swatch {
  width: calc(40px * var(--ui-scale));
  height: calc(40px * var(--ui-scale));
  min-height: calc(40px * var(--ui-scale));
}

body.touch-mode .pen-color-swatches,
body.touch-mode .context-menu-swatches {
  gap: 10px;
}

body.touch-mode .context-menu-swatches {
  max-width: none;
}

body.touch-mode .context-menu {
  min-width: 240px;
  padding: 6px;
}

body.touch-mode .context-menu button {
  min-height: calc(48px * var(--ui-scale));
  padding: calc(12px * var(--ui-scale)) calc(14px * var(--ui-scale));
  font-size: calc(15px * var(--ui-scale));
}

body.touch-mode .context-menu-sublist button {
  padding-left: 28px;
}

body.touch-mode .object-picker-row,
body.touch-mode .texture-picker-row,
body.touch-mode .saves-row,
body.touch-mode .layers-row,
body.touch-mode .info-wire-row {
  min-height: calc(52px * var(--ui-scale));
  font-size: calc(13px * var(--ui-scale));
}

body.touch-mode .object-picker-back {
  min-height: 44px;
  padding: 8px 12px;
  font-size: 14px;
}

body.touch-mode .info-summary-row.clickable {
  min-height: 44px;
  padding: 8px 6px;
  margin: 0 -6px;
}

/* A native checkbox cannot be padded out to 44px without distorting the box,
   so it is enlarged to 28px and its <label> carries the rest of the target -
   every checkbox in the app is inside a `for=`-associated label row, and those
   rows are given a 44px floor just below. */
body.touch-mode input[type="checkbox"] {
  width: 28px;
  height: 28px;
  min-height: 0;
}

body.touch-mode .settings-row,
body.touch-mode .toggle-row {
  min-height: 44px;
}

body.touch-mode .settings-row label {
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
}

body.touch-mode input[type="range"] {
  height: 44px;
}

body.touch-mode input[type="range"]::-webkit-slider-thumb {
  width: 28px;
  height: 28px;
}

body.touch-mode input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
}

body.touch-mode .toggle-row {
  padding: 14px;
}

/* Panels get more breathing room, and their scroll gets momentum. */
body.touch-mode #layersPanel,
body.touch-mode #infoPanel,
body.touch-mode #exportPanel,
body.touch-mode #modalPanel,
body.touch-mode .object-picker-list,
body.touch-mode .saves-list,
body.touch-mode .hotkeys-list {
  -webkit-overflow-scrolling: touch;
}

body.touch-mode #hud {
  padding: calc(10px * var(--ui-scale)) calc(14px * var(--ui-scale));
  font-size: calc(13px * var(--ui-scale));
}

body.touch-mode #themeToggle {
  width: calc(44px * var(--ui-scale));
  height: calc(44px * var(--ui-scale));
}

/* ---------- Touch Mode: list rows that run out of room ---------- */
/* A layers row carries reorder, visibility, lock and delete controls. At 44px
   each they consume the whole 300px panel, leaving the name a few pixels and
   ellipsing it to nothing. Give the name its own full-width line above the
   controls instead of letting it compete with them. The saves list has the
   same shape (name, date, rename, delete) and the same problem. */
body.touch-mode .layers-row,
body.touch-mode .saves-row {
  flex-wrap: wrap;
  row-gap: 8px;
}

body.touch-mode .layer-name,
body.touch-mode .save-name {
  order: -1;
  flex: 1 0 100%;
  min-width: 0;
  font-size: calc(15px * var(--ui-scale));
  white-space: normal;
  overflow-wrap: anywhere;
}

body.touch-mode .save-date {
  order: -1;
  flex: 1 0 100%;
}

body.touch-mode .layer-actions,
body.touch-mode .save-actions {
  margin-left: auto;   /* controls trail on the second line */
}

/* ---------- Narrow screens ---------- */
/* Width-driven only, deliberately independent of Touch Mode: a desktop window
   dragged narrow gets the same treatment, and a tablet with Touch Mode turned
   off still keeps a usable layout. Finger-sizing lives under .touch-mode. */
@media (max-width: 680px) {
  /* Side panels are 300px against a ~390px viewport - take the full width
     instead of leaving a useless sliver of canvas behind them. */
  #layersPanel,
  #infoPanel,
  #exportPanel {
    width: 100%;
  }

  /* The HUD carries five separate readouts; let it wrap rather than overflow.
     Only the standalone viewer still floats #themeToggle in the top-right
     corner, so only there does the HUD leave room for it. */
  #hud {
    flex-wrap: wrap;
    max-width: calc(100vw - 24px);
  }

  body.viewer-locked #hud {
    max-width: calc(100vw - 68px);
  }

  #modalPanel {
    padding: 16px;
    max-height: 92vh;
  }

  /* Program row scrolls horizontally here (see .button-row-single) rather than
     forcing the panel wider than the screen. */
  #modalPanel .group {
    flex-wrap: wrap;
  }

  #toast {
    bottom: 12px;
    max-width: calc(100vw - 24px);
  }
}


/* ---------- Account (sign in / register) ---------- */

#accountOverlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
}

#accountOverlay.open {
  display: flex;
}

#accountPanel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 18px 20px;
  min-width: min(320px, 100%);
  max-width: 380px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#accountPanel form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* accountModal.js swaps the two halves of this panel with the hidden attribute,
   which works by way of the UA's [hidden] { display: none } - and an author
   `display: flex` above outranks it. Without this the sign-in form stayed on
   screen underneath the signed-in view. Scoped to the panel and written to
   cover any future flex/grid child that gets hidden the same way. */
#accountPanel [hidden] {
  display: none;
}

.account-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.account-field label {
  font-size: 12px;
  color: var(--fg-muted);
}

.account-field input {
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--fg);
  padding: 9px 10px;
  /* 16px stops iOS Safari zooming the whole page when the field is focused. */
  font-size: 16px;
  font-family: inherit;
  min-height: calc(38px * var(--ui-scale));
}

.account-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.account-error {
  margin: 0;
  font-size: 13px;
  color: var(--danger-fg);
}

.account-tier {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  color: var(--fg-muted);
}

.account-tier.premium {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}


/* ---------- Users (admin only) ---------- */

#usersOverlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
}

#usersOverlay.open {
  display: flex;
}

#usersPanel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 18px 20px;
  min-width: min(420px, 100%);
  max-width: 560px;
  max-height: 75vh;
  box-shadow: 0 20px 60px var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#usersPanel [hidden] {
  display: none;
}

.users-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Two columns on a roomy screen, one on a narrow one. The email gets the free
   space; the badge, meta line and controls size to their content. */
.users-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  padding: 10px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.user-email {
  font-size: 13px;
  color: var(--fg);
  overflow-wrap: anywhere;
}

.user-meta {
  grid-column: 1 / -1;
  font-size: 11.5px;
  color: var(--fg-muted);
}

.user-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-role {
  flex: 1;
  min-width: 0;
}

.user-delete {
  background: var(--danger-bg);
  color: var(--danger-fg);
}

.user-delete:disabled,
.user-role:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Saved Plans: the "server unreachable" notice */
.saves-signin { align-self: flex-start; }
#savesScope.saves-warning {
  color: var(--danger-fg);
  font-weight: 600;
}

/* ---------- Highlighted toasts (saving) ---------- */
/* Top-center, big and colored: 'progress' while a save is running, then
   'success' or 'error'. Selectors carry `body` so they beat the touch-mode
   placement above. */
body #toast.toast-progress,
body #toast.toast-success,
body #toast.toast-error {
  top: 16px;
  bottom: auto;
  left: 50%;
  right: auto;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, -12px) scale(0.96);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35), 0 0 0 3px rgba(255, 255, 255, 0.18);
  z-index: 400;
}
body #toast.toast-progress.show,
body #toast.toast-success.show,
body #toast.toast-error.show {
  transform: translate(-50%, 0) scale(1);
}
body #toast.toast-progress { background: var(--accent-grad); }
body #toast.toast-success { background: #1e9e58; }
body #toast.toast-error { background: #c9362c; }
body #toast.toast-success.show { animation: toast-pop 0.35s ease; }

@keyframes toast-pop {
  0% { transform: translate(-50%, -12px) scale(0.9); }
  60% { transform: translate(-50%, 0) scale(1.06); }
  100% { transform: translate(-50%, 0) scale(1); }
}

.toast-spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: toast-spin 0.8s linear infinite;
}
@keyframes toast-spin { to { transform: rotate(360deg); } }

.toast-icon {
  width: 22px;
  height: 22px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  font-size: 14px;
  font-weight: 700;
}

/* While the 3D view is up the 2D plan and its chrome are hidden underneath,
   so the browser doesn't keep compositing them (see view3d.js enter3d). */
body.in-3d #canvasWrap,
body.in-3d #touchBar,
body.in-3d #hud { visibility: hidden; }

/* ---------- Terrain tool panel (tools/terrain.js) ---------- */
#terrainPanel {
  position: fixed;
  top: calc(18px + 46px * var(--ui-scale));
  right: 12px;
  width: 252px;
  z-index: 40;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  color: var(--fg);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#terrainPanel[hidden] { display: none; }
.terrain-title { font-weight: 600; font-size: 13px; }
.terrain-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.terrain-modes button,
.terrain-swatch {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 4px;
  cursor: pointer;
}
.terrain-modes button.active { background: var(--t-terrain); border-color: transparent; color: var(--on-tc); font-weight: 600; }
.terrain-materials {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.terrain-swatch {
  height: 40px;
  padding: 0;
  background-size: 64px 64px;
  position: relative;
  overflow: hidden;
}
.terrain-swatch span {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  font-size: 9px;
  line-height: 12px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  text-align: center;
}
.terrain-swatch.active { outline: 2px solid var(--t-terrain); outline-offset: 1px; }
.terrain-row {
  display: grid;
  grid-template-columns: 56px 1fr 58px;
  align-items: center;
  gap: 6px;
}
.terrain-row span { text-align: right; opacity: 0.8; }
.terrain-row input { width: 100%; min-width: 0; }
.terrain-hint { opacity: 0.7; line-height: 1.35; }
@media (max-width: 600px) {
  #terrainPanel { top: auto; bottom: 84px; right: 8px; left: 8px; width: auto; }
}
.terrain-trees {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.terrain-trees[hidden], .terrain-materials[hidden] { display: none; }
.terrain-tree {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: left;
}
.terrain-tree.active { outline: 2px solid var(--t-terrain); outline-offset: 1px; }
.terrain-tree-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
}

/* ---------- Top bar (ui/appBar.js) ---------- */
/* Two solid islands at the top corners; the strip between them stays canvas. */
.app-bar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.app-island {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 2px;
  height: calc(46px * var(--ui-scale));
  min-width: 0;
  padding: 0 5px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}

.app-logo {
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--accent-grad);
  border: none;
  border-radius: var(--r-md);
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.45);
}
.app-logo:hover { background: var(--accent-grad); filter: brightness(1.12); }
.app-logo .ico { width: 19px; height: 19px; }

.app-title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.2;
  min-width: 0;
  padding: 0 10px 0 7px;
}
.app-title h2 { margin: 0; }
.app-name {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-faint);
}
.app-plan {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--fg);
}
.menu-brand .app-plan { font-size: 12.5px; font-weight: 500; color: var(--fg-muted); }

.app-divider {
  flex: none;
  width: 1px;
  height: 22px;
  margin: 0 4px;
  background: var(--border);
}

#appBar button.icon-only {
  width: calc(36px * var(--ui-scale));
  height: calc(36px * var(--ui-scale));
  min-height: 0;
  padding: 0;
  background: transparent;
  border-color: transparent;
  border-radius: var(--r-md);
  color: var(--fg-muted);
}
#appBar button.icon-only:hover { background: var(--surface); color: var(--fg); }
#appSaveBtn:hover { color: var(--t-area) !important; }

/* ---------- Tool rail ---------- */
#toolRail {
  position: fixed;
  top: calc(20px + 46px * var(--ui-scale));
  left: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}

.rail-sep {
  flex: none;
  width: 22px;
  height: 1px;
  margin: 3px 0;
  background: var(--border);
}

#toolRail .rail-btn {
  position: relative;
  flex: none;
  width: calc(40px * var(--ui-scale));
  height: calc(40px * var(--ui-scale));
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--r-md);
  color: var(--tc);
}
.rail-btn .ico { width: 21px; height: 21px; }
#toolRail .rail-btn:hover { background: color-mix(in srgb, var(--tc) 15%, transparent); }
#toolRail .rail-btn.active {
  background: var(--tc);
  color: var(--on-tc);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--tc) 45%, transparent);
}

/* The name and hotkey, shown beside the rail on hover */
.rail-tip {
  position: absolute;
  top: 50%;
  left: calc(100% + 14px);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 10px;
  background: var(--fg);
  color: var(--bg);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-1);
  transform: translateY(-50%);
}
.rail-tip kbd {
  background: transparent;
  border-color: color-mix(in srgb, var(--bg) 40%, transparent);
  color: inherit;
  opacity: 0.75;
}
#toolRail .rail-btn:hover .rail-tip { display: flex; }

/* ---------- Which chrome shows when ---------- */
/* Touch Mode has its own command bar with the tools on it */
body.touch-mode #toolRail { display: none; }
body.touch-mode .app-island { height: calc(54px * var(--ui-scale)); }
body.touch-mode #appBar button.icon-only {
  width: calc(44px * var(--ui-scale));
  height: calc(44px * var(--ui-scale));
}
body.touch-mode #view3dBtn { height: calc(44px * var(--ui-scale)); min-height: 0; padding: 0 16px 0 12px; }
body.touch-mode #hud {
  bottom: auto;
  top: calc(20px + 54px * var(--ui-scale));
}
body.touch-mode #terrainPanel { top: calc(20px + 54px * var(--ui-scale)); }

/* View mode (Ctrl+E) is read-only: no tools, nothing to save, no menu */
body.view-mode #toolRail,
body.view-mode #appSaveBtn { display: none; }
body.view-mode #appMenuBtn { pointer-events: none; }
/* its bar sits top-centre, between the two islands */
body.view-mode #viewModeBar { top: calc(20px + 46px * var(--ui-scale)); }

/* The exported viewer has no editing at all */
body.viewer-locked #appBar,
body.viewer-locked #toolRail { display: none; }
body.viewer-locked #viewModeBar { top: 12px; }

body.in-3d #appBar,
body.in-3d #toolRail,
body.in-3d #scaleBarWidget { visibility: hidden; }

/* ---------- Narrow screens ---------- */
@media (max-width: 680px) {
  #appBar .app-title { display: none; }
  .app-island-left .app-divider { display: none; }
  #view3dBtn span { display: none; }
  #view3dBtn { padding: 0 10px; }
  .menu-grid { grid-template-columns: 1fr; }
  #view3dBar { max-width: calc(100vw - 24px); }
  #view3dBar button span { display: none; }
  #view3dBar #view3dExitBtn span { display: inline; }
  #view3d .view3d-hint { display: none; }
}
@media (max-width: 900px) {
  .menu-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .menu-grid { grid-template-columns: 1fr; }
}
