<script lang="ts">
  // @ts-nocheck
  // v0.2 Phase 6 — thin composition. The three split-out shells own
  // their respective responsibilities; this file just decides whether
  // to render the chrome (main window) or pass children straight
  // through (secondary windows like /float, /viewer, /preview, which
  // also have their own +layout@.svelte to break out of this layout).
  import "../app.css";
  import { page as sveltePage } from "$app/stores";
  import AppRuntime from "$lib/shell/AppRuntime.svelte";
  import AppChrome from "$lib/shell/AppChrome.svelte";
  import AppOverlays from "$lib/shell/AppOverlays.svelte";

  let { children } = $props();

  // Defensive: secondary windows use +layout@.svelte to escape this
  // root layout, but if any /float, /viewer, /preview load ever
  // reaches here we still drop the chrome.
  let isSecondaryWindow = $derived(
    $sveltePage.url.pathname.startsWith("/float") ||
    $sveltePage.url.pathname.startsWith("/viewer") ||
    $sveltePage.url.pathname.startsWith("/preview")
  );

  // v0.3 Tactile Quietware activation.
  //
  // Phase 5g (round-15): quietware is now ON by default on the
  // feat/v0.3-tactile-quietware branch so every normal Tauri build
  // shows the new design without needing the VITE_LUMOTIA_QUIETWARE
  // env var. The v0.2 fallback is still reachable by explicitly
  // clearing the attribute via dev tools, or by setting
  // VITE_LUMOTIA_QUIETWARE=0 at build time to force the off state.
  //
  // Combine with data-theme="light" and data-contrast="high" (wired
  // elsewhere) for the light and high-contrast modes.
  $effect(() => {
    if (typeof document === "undefined") return;
    if (import.meta.env.VITE_LUMOTIA_QUIETWARE === "0") {
      // Explicit opt-out → restore v0.2 surface.
      if (document.documentElement.dataset.design === "quietware") {
        delete document.documentElement.dataset.design;
      }
    } else {
      document.documentElement.dataset.design = "quietware";
    }
  });
</script>

<AppRuntime />

{#if isSecondaryWindow}
  {@render children()}
{:else}
  <AppChrome>
    {@render children()}
  </AppChrome>
{/if}

<AppOverlays />
