/* ============================================================================
   EGIS · BEME World — scene layer + token unification with the landing story.
   The funnel UI keeps its glass-card language; it now sits inside the SAME
   void-black / starfield / solar-amber world as index3.html, so crossing from
   the landing page reads as "changing rooms," not "leaving the nice page."
   ========================================================================== */

/* ── Token unification: BEME's gold aligns to the story's solar amber ── */
.beme-body {
  --gold: #F59E0B;
  --solar: #F59E0B;
  --brand-500: #0E9E53;
  --glow-gold: 0 0 24px rgba(245, 158, 11, 0.35);
  background: #050A12; /* void base — the layer paints the gradients */
}

/* ── Fixed world layer, behind all funnel UI ── */
.bw-layer {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  --dawn: 0;
}
/* lift the funnel content above the (z-index:0, pointer-events:none) world;
   .beme-top/.modal-bg/.toast-host are already positioned + z-indexed in beme.css */
.stage { position: relative; z-index: 2; }

.bw-void {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 50% 30%, color-mix(in srgb, var(--brand-500) calc(var(--dawn, 0) * 10%), transparent), transparent),
    radial-gradient(ellipse 60% 45% at 50% 78%, color-mix(in srgb, var(--solar) calc(var(--dawn, 0) * 38%), transparent), transparent),
    linear-gradient(180deg, #050A12 0%, #0B1220 45%, #04140C 100%);
  transition: background .1s linear;
}
.bw-sun {
  position: absolute; left: 50%; top: 60%; width: 240px; height: 240px; margin: -120px 0 0 -120px;
  border-radius: 50%; mix-blend-mode: screen; filter: blur(1.5px);
  background: radial-gradient(circle, #FFF3D6 0%, var(--solar) 34%, rgba(245,158,11,0.30) 58%, transparent 72%);
  opacity: var(--sun-op, 0);
  transform: translate3d(0, var(--sun-y, 90px), 0) scale(var(--sun-s, 0.62));
}

.bw-canvas { position: absolute; inset: 0; }

.bw-world-outer { position: absolute; inset: 0; perspective: 1400px; perspective-origin: 50% 42%; }
.bw-world {
  position: absolute; left: 50%; top: 46%; transform-style: preserve-3d;
  transform: translate(-50%, -50%) scale(var(--world-s, 1)) translateY(var(--world-y, 0px)) rotateY(var(--drift-y, 0deg)) rotateX(var(--drift-x, 0deg));
}

/* ── Cells — the visitor's appliances, made physical ── */
.bw-cells { position: relative; transform-style: preserve-3d; }
.bw-cell {
  position: absolute; top: 0; left: 0; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 3px; transform-style: preserve-3d;
  background: linear-gradient(135deg, #0F1E2C 0%, #1B3654 36%, #2A2F5C 54%, #14202E 78%, #0D1A26 100%);
  box-shadow: inset 0 0 0 1px rgba(140,190,255,0.14), 0 6px 18px rgba(0,0,0,0.5);
  will-change: transform, opacity; opacity: 0;
}
.bw-cells::after {
  content: ''; position: absolute; inset: -2px;
  background:
    repeating-linear-gradient(90deg, rgba(205,228,255,0.20) 0 1px, transparent 1px 51px),
    repeating-linear-gradient(0deg,  rgba(205,228,255,0.20) 0 1px, transparent 1px 51px);
  opacity: var(--grid-op, 0); transition: opacity .25s linear;
}
.bw-cells::before {
  content: ''; position: absolute; inset: -2px; z-index: 2; border-radius: 3px;
  background: linear-gradient(122deg, transparent 38%, rgba(255,255,255,0.16) 49%, transparent 60%);
  opacity: var(--sheen-op, 0); mix-blend-mode: screen; pointer-events: none;
}

/* ── Array — fans out to the visitor's REAL computed panel count ── */
.bw-array {
  position: absolute; top: 0; left: 0; transform-style: preserve-3d;
  transform: translate3d(0, var(--arr-y, 0px), var(--arr-z, 0px)) rotateX(var(--panel-tilt, 0deg)) scale(var(--arr-s, 1));
}
.bw-clone {
  position: absolute; top: 0; left: 0; width: 168px; height: 228px; margin: -114px 0 0 -84px;
  border-radius: 4px; border: 2px solid #9AA6B2;
  background:
    repeating-linear-gradient(90deg, rgba(205,228,255,0.20) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(0deg,  rgba(205,228,255,0.20) 0 1px, transparent 1px 28.5px),
    linear-gradient(135deg, #0F1E2C 0%, #1B3654 36%, #2A2F5C 54%, #14202E 78%, #0D1A26 100%);
  transform-style: preserve-3d; opacity: var(--clone-op, 0);
  transform: translate3d(var(--cx, 0px), var(--cy, 0px), var(--cz, 0px)) scale(var(--cs, 0.3));
  box-shadow: 0 8px 22px rgba(0,0,0,0.5);
}
.bw-count {
  position: absolute; left: 50%; top: 24%; transform: translateX(-50%);
  font-family: var(--f-mono, monospace); font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--solar); text-shadow: 0 0 14px rgba(245,158,11,0.5); opacity: 0; transition: opacity .3s;
}

/* ── House — flat-geometric, grounded object the array lands on ── */
.bw-house {
  position: absolute; top: 0; left: 0; transform-style: preserve-3d;
  opacity: var(--house-op, 0); transform: translate3d(0, var(--house-y, 140px), -60px) rotateX(52deg) scale(1.2);
}
.bw-roof {
  position: absolute; left: -170px; top: -238px; width: 340px; height: 96px;
  clip-path: polygon(0 100%, 50% 0, 100% 100%);
  background: linear-gradient(180deg, color-mix(in srgb, var(--solar) calc(var(--dawn, 0) * 30%), #3A4A58) 0%, #232F3A 100%);
  box-shadow: 0 -6px 30px color-mix(in srgb, var(--solar) calc(var(--power, 0) * 70%), transparent);
  filter: drop-shadow(0 -2px 0 rgba(255,255,255,0.06));
}
.bw-wall {
  position: absolute; left: -128px; top: -146px; width: 256px; height: 150px; border-radius: 2px 2px 0 0;
  background:
    linear-gradient(100deg, color-mix(in srgb, var(--solar) calc(var(--dawn, 0) * 22%), transparent) 0%, transparent 40%),
    linear-gradient(180deg, #223142 0%, #1A2530 100%);
}
.bw-door { position: absolute; left: -18px; top: -40px; width: 36px; height: 40px; border-radius: 3px 3px 0 0; background: #0F1620; }
.bw-window { position: absolute; width: 40px; height: 34px; border-radius: 3px; background: #10161F; transition: background .3s ease, box-shadow .3s ease; }
.bw-window.w1 { left: -92px; top: -118px; }
.bw-window.w2 { left: 52px;  top: -118px; }
.bw-window.w3 { left: -20px; top: -70px; width: 30px; height: 26px; }

/* ── Components that dock in chapter 4 — battery stack + inverter ── */
.bw-batt {
  position: absolute; left: -196px; top: -104px; width: 34px; display: flex; flex-direction: column-reverse; gap: 3px;
  opacity: var(--dock, 0); transform: translateX(calc((1 - var(--dock, 0)) * -30px));
  filter: drop-shadow(0 0 calc(var(--glow, 0) * 14px) rgba(140,198,62,0.7));
}
.bw-batt-seg { height: 12px; border-radius: 3px; background: #16281B; border: 1px solid rgba(140,198,62,0.25); transition: background .3s, border-color .3s; }
.bw-batt-seg[data-on="1"] { background: linear-gradient(180deg, #2E5B25, #1E3D1A); border-color: rgba(140,198,62,0.7); }
.bw-inv {
  position: absolute; left: 156px; top: -104px; width: 30px; height: 38px; border-radius: 4px;
  display: grid; place-items: center; font-family: var(--f-mono, monospace); font-size: 14px; color: var(--solar);
  background: #1A2530; border: 1px solid rgba(245,158,11,0.35);
  opacity: calc(var(--dock, 0) * 0.4); transform: translateX(calc((1 - var(--dock, 0)) * 30px));
}
.bw-inv[data-on="1"] { opacity: var(--dock, 0); box-shadow: 0 0 14px rgba(245,158,11,0.35); }

/* ── Wind turbine — appears beside the house when the visitor adds wind ── */
.bw-turbine { position: absolute; left: 218px; top: -196px; width: 8px; opacity: 0; transition: opacity .4s; }
.bw-t-pole { position: absolute; left: 2px; top: 0; width: 4px; height: 120px; border-radius: 2px; background: linear-gradient(180deg, #9AA6B2, #4A5866); }
.bw-t-rotor { position: absolute; left: 4px; top: 0; width: 0; height: 0; animation: bwSpin 1.8s linear infinite; }
.bw-t-rotor i { position: absolute; left: -2px; top: -46px; width: 4px; height: 46px; border-radius: 3px; background: linear-gradient(180deg, #E7ECF1, #9AA6B2); transform-origin: 50% 100%; }
.bw-t-rotor i:nth-child(2) { transform: rotate(120deg); }
.bw-t-rotor i:nth-child(3) { transform: rotate(240deg); }
@keyframes bwSpin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .bw-t-rotor { animation: none; } }

/* ── Grade + grain (same finish as the landing story) ── */
.bw-grade {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 65% 55% at 32% 22%, rgba(255,201,138,0.10), transparent 62%),
    linear-gradient(180deg, rgba(0,0,0,0.16) 0%, transparent 22%, transparent 78%, rgba(0,0,0,0.22) 100%);
  mix-blend-mode: soft-light;
}
.bw-grain {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  background: #000; opacity: 0.05; mix-blend-mode: overlay;
  filter: url(#bwGrain);
}

/* ── Chapter rail — the funnel's spine, same grammar as the landing rail ── */
.bw-rail {
  position: fixed; left: clamp(14px, 2.5vw, 34px); top: 50%; z-index: 60;
  transform: translateY(-50%); display: flex; flex-direction: column; gap: 30px;
}
.bw-rail-track { position: absolute; left: 3.5px; top: 5px; bottom: 5px; width: 2px; background: rgba(255,255,255,0.14); border-radius: 2px; }
.bw-rail-fill { position: absolute; left: 0; top: 0; width: 100%; height: 0%; background: linear-gradient(180deg, var(--solar), var(--brand-500)); border-radius: 2px; }
.bw-dot {
  position: relative; display: flex; align-items: center; gap: 12px; background: none; border: none; padding: 4px 4px 4px 0;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.bw-dot .dot { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid rgba(255,255,255,0.32); background: transparent; transition: all .25s ease; flex-shrink: 0; }
.bw-dot.reached .dot { background: rgba(255,255,255,0.6); border-color: rgba(255,255,255,0.6); }
.bw-dot.active .dot { width: 12px; height: 12px; background: var(--solar); border-color: var(--solar); box-shadow: 0 0 14px 3px rgba(245,158,11,0.55); }
.bw-dot .label {
  font-family: var(--f-mono, monospace); font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: #fff; opacity: 0; transform: translateX(-6px); transition: all .25s ease; white-space: nowrap;
}
.bw-dot.active .label { opacity: 1; transform: translateX(0); }
.bw-dot:hover .label { opacity: .7; transform: translateX(0); }
.bw-dot:focus-visible { outline: 2px solid var(--solar); outline-offset: 4px; border-radius: 4px; }
@media (max-width: 860px) { .bw-rail { display: none; } }

/* ── Arrival veil — the dissolve-through-the-sun crossing from the landing ── */
.bw-veil {
  position: fixed; inset: 0; z-index: 10000; pointer-events: none;
  background:
    radial-gradient(circle at 50% 55%, #FFF3D6 0%, var(--solar, #F59E0B) 22%, rgba(245,158,11,0.55) 40%, #050A12 78%);
  opacity: 1; transition: opacity 1.2s ease;
}
.bw-veil.lift { opacity: 0; }

/* ── Funnel chapters — full-height scroll sections ── */
.chapter { min-height: 100vh; padding: 9vh 0 10vh; box-sizing: border-box; }
.chapter:first-of-type { padding-top: 4vh; }
.chapter-continue { text-align: center; margin-top: 44px; }
.chapter-continue .hintline { display: block; margin-top: 10px; font-family: var(--f-mono, monospace); font-size: .62rem; letter-spacing: .18em; text-transform: uppercase; color: var(--faint, #8a93a0); }

/* personalized arrival line under chapter 1's headline */
.arrive-line {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: .95rem; color: var(--solar); font-style: italic;
}
.arrive-line::before { content: ''; width: 18px; height: 2px; border-radius: 2px; background: linear-gradient(90deg, var(--solar), transparent); }

/* save indicator becomes honest — flashes on every real save() */
.beme-top .save { transition: color .25s ease, text-shadow .25s ease; }
.beme-top .save.flash { color: var(--solar); text-shadow: 0 0 12px rgba(245,158,11,0.6); }

/* ── Dimensional buttons — depth, not flatness. A primary button is a lit
   object: gradient body, inner top-highlight, tight + ambient shadows, and a
   real pressed state. Ghost buttons become glass. ── */
.beme-body .btn {
  background: linear-gradient(180deg, #FFC24A 0%, var(--solar) 45%, #D97F06 100%);
  color: #1A1204; font-weight: 700; border: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -2px 0 rgba(0, 0, 0, 0.18),
    0 2px 6px rgba(0, 0, 0, 0.45),
    0 10px 26px rgba(245, 158, 11, 0.28);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.beme-body .btn:hover {
  transform: translateY(-2px); filter: brightness(1.06);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -2px 0 rgba(0, 0, 0, 0.18),
    0 4px 10px rgba(0, 0, 0, 0.5),
    0 16px 34px rgba(245, 158, 11, 0.4);
}
.beme-body .btn:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 2px 6px rgba(0, 0, 0, 0.3),
    0 1px 3px rgba(0, 0, 0, 0.4);
}
.beme-body .btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.16); color: #E7ECF1;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease, color .2s ease;
}
.beme-body .btn-ghost:hover {
  transform: translateY(-1px); border-color: rgba(245, 158, 11, 0.6); color: var(--solar);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 4px 14px rgba(0, 0, 0, 0.4), 0 0 18px rgba(245, 158, 11, 0.2);
}
.beme-body .btn-ghost:active { transform: translateY(1px); }

/* ── The Genesis Report print document ──
   On screen it never shows; in print it is the ONLY thing that shows —
   browser print-to-PDF produces a clean branded report, not a page screenshot. */
.print-doc { display: none; }
@media print {
  body.beme-body > *:not(.print-doc) { display: none !important; }
  .beme-body { background: #fff !important; }
  .print-doc {
    display: block; color: #111; font-family: Georgia, 'Times New Roman', serif;
    max-width: 640pt; margin: 0 auto;
  }
  .pd-cover { text-align: center; padding: 60pt 0 40pt; page-break-after: always; }
  .pd-cover img { width: 64pt; height: 64pt; object-fit: contain; margin-bottom: 12pt; }
  .pd-brand { font-size: 10pt; letter-spacing: 0.3em; color: #B45309; font-weight: 700; margin-bottom: 18pt; }
  .pd-cover h1 { font-size: 30pt; margin: 0 0 8pt; color: #111; }
  .pd-sub { color: #555; font-size: 11pt; margin-bottom: 36pt; }
  .pd-heads { display: flex; justify-content: center; gap: 28pt; flex-wrap: wrap; }
  .pd-heads div { text-align: center; }
  .pd-heads b { display: block; font-size: 16pt; color: #0A7B3E; }
  .pd-heads span { font-size: 9pt; color: #666; text-transform: uppercase; letter-spacing: 0.1em; }
  .pd-sec { page-break-inside: avoid; padding: 14pt 0; border-bottom: 0.5pt solid #ddd; }
  .pd-sec h2 { font-size: 14pt; color: #0A7B3E; margin: 0 0 6pt; }
  .pd-sec p { font-size: 11pt; line-height: 1.65; margin: 0; white-space: pre-wrap; }
  .pd-foot {
    margin-top: 24pt; font-size: 8.5pt; color: #777; text-align: center; line-height: 1.5;
    display: flex; flex-direction: column; align-items: center; gap: 6pt;
    border-top: 0.5pt solid #ddd; padding-top: 10pt;
  }
  .pd-footmark { width: 22pt; height: auto; opacity: .85; }
}

@media (prefers-reduced-motion: reduce) {
  .bw-veil { display: none; }
}
