/* Jardin 3D interactif — démo Forge Labs. S'appuie sur ../_shared/demo.css. */

:root {
  --panel-w: 344px;
  --top-h: 52px;
  --sky-top: #86b8e6;
  --sky-bottom: #f3dcb4;
}

html, body { height: 100%; }
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--forest-950);
  font-size: 15px;
}

/* ---------- Bandeau ---------- */
.demo-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--top-h);
  padding: 4px var(--gutter);
  background: var(--forest-900);
  color: var(--sand-100);
  border-bottom: 1px solid var(--line-dark);
  z-index: 5;
}
.demo-top .back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
  font-weight: 600;
  font-size: .9rem;
  text-decoration: none;
  white-space: nowrap;
  color: var(--sand-100);
}
.demo-top .back:hover { color: #fff; text-decoration: underline; }
.demo-top .note {
  flex: 1 1 auto;
  margin: 0;
  text-align: center;
  font-size: .8rem;
  color: rgba(244, 239, 228, .72);
}
.demo-top .note b { color: #ffe3a3; font-weight: 600; }
.demo-top .btn { min-height: 44px; padding: .55em 1.1em; font-size: .9rem; white-space: nowrap; }

/* ---------- Mise en page ---------- */
.app {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 78%);
}
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  touch-action: none;
  outline: none;
}
#scene:focus-visible { box-shadow: inset 0 0 0 3px var(--sun-400); }

/* ---------- Surcouches de la scène ---------- */
.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(11, 31, 22, .72);
  color: var(--sand-100);
  font: 600 .86rem/1.2 var(--font-body);
  letter-spacing: .01em;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
}
.views {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(11, 31, 22, .72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.views button,
.palette-toggle {
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--sand-100);
  font: 600 .85rem/1 var(--font-body);
  cursor: pointer;
}
.views button:hover { background: rgba(255, 255, 255, .1); }
.views button[aria-pressed="true"] { background: var(--sand-100); color: var(--forest-900); }

.palette-toggle {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(11, 31, 22, .78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.palette-toggle:hover { background: rgba(11, 31, 22, .92); }
.palette-toggle svg { width: 18px; height: 18px; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(244, 239, 228, .9);
  color: var(--forest-900);
  font-size: .8rem;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .6s ease;
}
.hint.gone { opacity: 0; }

/* ---------- Palette végétale ---------- */
.palette {
  position: absolute;
  top: 66px;
  left: 12px;
  bottom: 66px;
  width: min(400px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: var(--sand-50);
  color: var(--ink);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .55);
  overflow: hidden;
  z-index: 4;
}
.palette[hidden] { display: none; }
.palette header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 8px 10px 18px;
  border-bottom: 1px solid var(--line);
}
.palette h2 { margin: 0; font-size: 1.12rem; }
.palette .close {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.palette .close:hover { background: var(--sand-100); color: var(--ink); }
.palette .scroll { overflow-y: auto; padding: 6px 18px 18px; overscroll-behavior: contain; }
.palette .intro { margin: 8px 0 10px; font-size: .84rem; color: var(--muted); }
.palette ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.palette li {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 2px 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: .84rem;
  line-height: 1.45;
}
.palette li:last-child { border-bottom: 0; }
.palette .dot { width: 14px; height: 14px; margin-top: 3px; border-radius: 50%; grid-row: span 2; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.palette .name { font-weight: 700; font-size: .95rem; }
.palette .name i { font-weight: 400; color: var(--muted); }
.palette dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 1px 8px; }
.palette dt { color: var(--muted); }
.palette dd { margin: 0; }
.palette .group { margin: 14px 0 0; font: 600 .72rem/1 var(--font-body); letter-spacing: .12em; text-transform: uppercase; color: var(--moss-500); }

.dot-erable { background: #5a8a3a; }
.dot-cerisier { background: #f0bfd0; }
.dot-amelanchier { background: #f4f1e6; }
.dot-charme { background: #6c9a45; }
.dot-cornouiller { background: #a3302b; }
.dot-noisetier { background: #8a9d4d; }
.dot-houx { background: #2f5531; }
.dot-sauge { background: #6f5bb5; }
.dot-calamagrostis { background: #c9ab72; }
.dot-iris { background: #e9c93a; }

/* ---------- Chargement et repli ---------- */
.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  background: var(--forest-900);
  color: var(--sand-100);
  z-index: 6;
  transition: opacity .7s ease, visibility .7s;
}
.loader.done { opacity: 0; visibility: hidden; }
.loader p { margin: 0; font-size: .95rem; letter-spacing: .02em; color: rgba(244, 239, 228, .8); }
.sprout { width: 64px; height: 64px; }
.sprout .stem { stroke-dasharray: 60; stroke-dashoffset: 60; animation: grow 1.4s ease-in-out infinite alternate; }
.sprout .leaf { transform-origin: 32px 40px; animation: leaf 1.4s ease-in-out infinite alternate; }
@keyframes grow { to { stroke-dashoffset: 0; } }
@keyframes leaf { from { transform: scale(.2); opacity: .2; } to { transform: scale(1); opacity: 1; } }

.fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 16px;
  padding: 24px;
  background: var(--sand-100);
  color: var(--ink);
  text-align: center;
  overflow-y: auto;
  z-index: 7;
}
.fallback[hidden] { display: none; }
.fallback svg { width: auto; height: min(52vh, 460px); max-width: 100%; aspect-ratio: 300 / 380; flex: 0 0 auto; border-radius: var(--radius); box-shadow: var(--shadow); }
.no-webgl .panel { display: none; }
.no-webgl .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.fallback h2 { margin: 0; font-size: 1.3rem; }
.fallback p { margin: 0; max-width: 34rem; color: var(--muted); font-size: .92rem; }

/* ---------- Panneau de réglages ---------- */
.panel {
  min-height: 0;
  overflow-y: auto;
  padding: 20px 20px 24px;
  background: var(--sand-50);
  color: var(--ink);
  border-left: 1px solid var(--line);
  overscroll-behavior: contain;
}
.panel h1 { font-size: 1.45rem; margin: 0 0 4px; }
.panel .lead { font-size: .88rem; margin: 0 0 16px; }
.ctrl { margin: 0 0 16px; padding: 0; border: 0; min-width: 0; }
.ctrl > legend,
.ctrl > .label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  width: 100%;
  margin: 0 0 6px;
  padding: 0;
  font: 700 .74rem/1.2 var(--font-body);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--moss-500);
}
.ctrl output { font: 700 .95rem/1 var(--font-body); letter-spacing: 0; text-transform: none; color: var(--ink); }

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--sand-100);
  border: 1px solid var(--line);
}
.seg button {
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--forest-800);
  font: 600 .88rem/1.1 var(--font-body);
  cursor: pointer;
  transition: background .2s ease, color .2s ease;
}
.seg button:hover { background: rgba(111, 143, 78, .14); }
.seg button[aria-pressed="true"] { background: var(--forest-800); color: var(--sand-100); box-shadow: 0 2px 6px -2px rgba(11, 31, 22, .5); }
.seg-ba button[aria-pressed="true"][data-ba="apres"] { background: var(--clay-500); }

/* Curseurs */
.range-wrap { position: relative; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--moss-300), var(--forest-700)); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--moss-300), var(--forest-700)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px; border-radius: 50%; background: #fff; border: 3px solid var(--clay-500); box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 3px solid var(--clay-500); box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
#hour::-webkit-slider-runnable-track { background: linear-gradient(90deg, #f0a86b, #f6dc9c 30%, #bfe0f5 50%, #f6dc9c 72%, #e98a4e); }
#hour::-moz-range-track { background: linear-gradient(90deg, #f0a86b, #f6dc9c 30%, #bfe0f5 50%, #f6dc9c 72%, #e98a4e); }
.ticks { display: flex; justify-content: space-between; margin: -6px 2px 0; font-size: .78rem; color: var(--muted); }
.ticks span { cursor: pointer; user-select: none; }
.ticks span.on { color: var(--ink); font-weight: 700; }
.sun-info { margin: 6px 0 0; font-size: .8rem; line-height: 1.45; color: var(--muted); }

.panel .foot { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--line); font-size: .8rem; color: var(--muted); }
.panel .foot .btn { width: 100%; margin-top: 10px; }

/* ---------- Tablette ---------- */
@media (max-width: 900px) {
  :root { --panel-w: 300px; }
  .demo-top .note { display: none; }
  .demo-top { justify-content: space-between; }
}

/* ---------- Téléphone ---------- */
@media (max-width: 600px) {
  :root { --top-h: 48px; }
  body { font-size: 14px; }
  .demo-top { gap: 8px; padding: 2px 10px; }
  .demo-top .back { font-size: .84rem; }
  .demo-top .btn { padding: .5em .9em; font-size: .82rem; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .panel {
    max-height: 47dvh;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    margin-top: -14px;
    position: relative;
    z-index: 3;
    box-shadow: 0 -10px 30px -16px rgba(0, 0, 0, .45);
  }
  .panel h1, .panel .lead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .ctrl { margin-bottom: 8px; }
  .ctrl > legend, .ctrl > .label { margin-bottom: 2px; font-size: .68rem; }
  .seg button { font-size: .82rem; }
  .ticks { font-size: .72rem; }
  .sun-info { font-size: .74rem; margin-top: 2px; }
  .hud { display: none; }
  .views { top: 8px; right: 8px; left: 8px; justify-content: space-between; }
  .views button { flex: 1; padding: 0 8px; font-size: .8rem; }
  .palette-toggle { left: 8px; bottom: 24px; }
  .hint { bottom: 80px; font-size: .74rem; }
  .palette { top: 64px; left: 8px; right: 8px; bottom: 22px; width: auto; }
  .panel .foot { display: none; }
}

@media (max-width: 360px) {
  .demo-top .back { font-size: .78rem; }
  .seg button { font-size: .76rem; padding: 0 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .sprout .stem { stroke-dashoffset: 0; }
  .sprout .leaf { transform: none; opacity: 1; }
}
