/* Layout : scène 3D plein cadre à gauche, panneau de commandes à droite (sous la scène sur téléphone) */
:root {
  --bg: #e6eaed;
  --panel: #f6f8f9;
  --ink: #1b2229;
  --muted: #5b6772;
  --line: #cbd3d9;
  --accent: #d9531a;
  --accent-ink: #ffffff;
  --card: #fbfcfc;
  --wall: #d3d9de;
  --floor: #ffffff;
  --ceil: #e3e8eb;
  --edge: #2a3038;
  --font-display: 'Barlow Semi Condensed', 'Arial Narrow', system-ui, sans-serif;
  --font-body: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161b;
    --panel: #181e24;
    --ink: #e5eaee;
    --muted: #93a0ab;
    --line: #2b343d;
    --accent: #ff7a3d;
    --accent-ink: #1a0f08;
    --card: #1e252c;
    --wall: #232b33;
    --floor: #6f7378;
    --ceil: #2a333c;
    --edge: #0c1014;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11161b;
  --panel: #181e24;
  --ink: #e5eaee;
  --muted: #93a0ab;
  --line: #2b343d;
  --accent: #ff7a3d;
  --accent-ink: #1a0f08;
  --card: #1e252c;
  --wall: #232b33;
  --floor: #6f7378;
  --ceil: #2a333c;
  --edge: #0c1014;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.4;
}
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  height: 100%;
}
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}
#view { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#view:active { cursor: grabbing; }

.hint {
  position: absolute;
  left: 16px;
  top: 14px;
  right: 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}
.card {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: min(320px, calc(100% - 32px));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  pointer-events: none;
}
.card .ref {
  display: inline-block;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 1px 7px;
  border-radius: 3px;
  margin-right: 8px;
}
.card .name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
}
.card ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.card li { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.card .idle { margin: 0; color: var(--muted); font-size: 13px; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  transition: opacity 0.25s ease;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: loading-spin 0.8s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .loading-spinner { animation: none; }
}
@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

.panel {
  min-width: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 18px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.panel h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  line-height: 1.05;
  letter-spacing: 0.01em;
  text-wrap: balance;
}
.panel .sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.panel .size {
  margin: 10px 0 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
}
.group { display: grid; gap: 6px; }
.group > h2 {
  margin: 0 0 2px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  cursor: pointer;
}
.row input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: none; }
.row .lbl { flex: 1; min-width: 0; }
.row .code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
button {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button[aria-pressed="true"].chip {
  background: var(--ink);
  color: var(--panel);
  border-color: var(--ink);
}
button.chip { font-family: var(--font-mono); font-size: 12px; padding: 4px 10px; }
button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 500;
}
button.primary[aria-pressed="true"] { filter: brightness(0.92); }
.views { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.views button { padding: 6px 4px; text-align: center; }
.slider { display: grid; gap: 4px; }
.slider label { display: flex; justify-content: space-between; }
.stop { margin: 2px 0 0; font-size: 12px; line-height: 1.4; color: var(--accent); }
.slider output { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--line);
}
.sw[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.paintname { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.note { margin: 0; color: var(--muted); font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mobile-bar {
  display: none;
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  z-index: 5;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.settings-toggle, .door-toggle {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  border-radius: 20px;
  padding: 9px 18px;
  flex: none;
}
.settings-toggle {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
}
.door-toggle {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
}
.door-toggle[aria-pressed="true"] { filter: brightness(0.92); }
.mobile-explode {
  flex: 1 0 100%;
  order: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.mobile-explode label { display: flex; justify-content: space-between; }
.mobile-explode input[type="range"] { display: block; margin-top: 4px; }

@media (max-width: 860px) {
  html, body { height: auto; }
  .app { grid-template-columns: minmax(0, 1fr); height: auto; }
  .stage { height: 100dvh; }
  .app.panel-open .stage { height: min(60vh, 480px); }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; padding-inline: 16px; display: none; }
  .card { width: calc(100% - 32px); }
  .hint { display: none; }
  .mobile-bar { display: flex; }
  .app.panel-open .panel { display: flex; }
}
