/* preview.css — layout shell for the GO FAST overlay preview section.
   Owns ONLY the stage, background and overlay positioning. The overlays
   themselves are styled entirely by the real overlays.css (untouched). */

.gf-preview {
  position: relative;
  width: 100%;
  margin: 0 auto;
  container-type: inline-size;
}

/* The composited stage: background image + overlays on top. 16:9 racing scene. */
.gf-preview-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
  /* Placeholder background until the real image is supplied. Dark cockpit-ish
     gradient so overlay contrast reads correctly during build. */
  background:
    radial-gradient(120% 90% at 50% 18%, #2a2f38 0%, #161a20 42%, #0b0d11 100%),
    #0b0d11;
  background-size: cover;
  background-position: center;
}

/* Optimised cockpit background: WebP (~48 KB) with a PNG fallback for the
   rare engine without image-set/WebP support. background-size:cover scales it. */
.gf-preview-stage.has-image {
  /* WebP only (~48 KB) — supported by every modern browser. The PNG fallback was
     dropped to slim the bundle; re-add an image-set() fallback if a legacy engine
     ever needs it. */
  background-image: url("../../../overlays/img/cockpit.png");
}

/* Each overlay is absolutely placed on the stage. Position values are
   expressed as percentages of the stage so they scale responsively.
   left/top set the anchor; transform keeps within bounds where needed. */
.gf-ovl {
  position: absolute;
  /* The real .overlay-panel inside controls its own size (overlays.css). */
}

/* Overlays are authored at a fixed 2560x1440 "design" size (a real sim
   screen) and the whole layer is uniformly scaled to fit the actual stage
   width — so native-px overlays render at a sensible fraction of the
   container and shrink proportionally on smaller/mobile stages without
   clipping. --gf-stage-scale = stageWidth / 2560 is set by preview-boot.js
   on load + resize (ResizeObserver). */
.gf-preview-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 2560px;            /* design width = a real sim "screen" */
  height: 1440px;           /* 16:9 design height */
  transform-origin: top left;
  transform: scale(var(--gf-stage-scale, 1));
  pointer-events: none;
}

/* Hidden overlay (toggled off). */
.gf-ovl[hidden] { display: none !important; }

/* Loading skeleton — covers the stage until boot completes + the bg decodes,
   then fades out. Shimmer blocks roughly mark where the main overlays land. */
.gf-skeleton {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: #0b0d11;
  transition: opacity .5s ease;
}
.gf-preview-stage.gf-ready .gf-skeleton { opacity: 0; pointer-events: none; }
.gf-skel-block {
  position: absolute;
  border-radius: 10px;
  background: linear-gradient(100deg, rgba(255,255,255,.035) 30%, rgba(255,255,255,.09) 50%, rgba(255,255,255,.035) 70%);
  background-size: 200% 100%;
  animation: gf-skel-shimmer 1.4s ease-in-out infinite;
}
@keyframes gf-skel-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* No hover affordance in the preview — overlays aren't draggable here, so
   cancel overlays.css's "Hold left-click to unlock" hover veil (same trick
   the app uses for its static preview pane, scoped to our stage). */
.gf-preview-stage .overlay-panel:not(.edit-mode):not([data-no-hit-clip]):hover::after { content: none; }

/* Build-time label on the placeholder bg. */
.gf-preview-stage[data-placeholder]::after {
  content: "background placeholder";
  position: absolute;
  left: 12px;
  bottom: 10px;
  font: 600 11px/1 system-ui, sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.28);
  pointer-events: none;
}

/* ===================== Configure Overlays UI ===================== */
/* Liquid-glass button — same recipe + dark tune as the drawer (plain blur
   pair = fallback for engines without SVG-referenced backdrop filters).
   Hover = green outline (--c-primary-200 #27E88D), no glow. */
.gf-config-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: url(#liquid-distortion) blur(14px) saturate(140%);
  backdrop-filter: url(#liquid-distortion) blur(14px) saturate(140%);
  border: 1px solid rgba(255,255,255,.05);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.15), 0 8px 24px rgba(0,0,0,.4);
  isolation: isolate;
  color: #fff;
  font-family: 'Satoshi', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: border-color .15s;
}
.gf-config-btn:hover { border-color: #27E88D; }
.gf-config-btn svg { color: #27E88D; }
/* Shrink the button on narrow embeds so it doesn't dominate the small stage. */
@container (max-width: 680px) {
  .gf-config-btn { top: 10px; right: 10px; padding: 4px 8px; font-size: 10px; gap: 5px; border-radius: 7px; }
  .gf-config-btn svg { width: 12px; height: 12px; }
}

.gf-drawer-scrim {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: rgba(0,0,0,.4);
}
.gf-drawer-scrim[hidden] { display: none; }

/* Liquid-glass drawer — the app's .liquid-glass recipe (newui.css) on the
   dark "reading surface" tune (.modal-neura.liquid-glass: denser tint +
   heavier blur + calmer saturation so toggle labels stay readable over the
   bright cockpit). The url(#liquid-distortion) is the SVG turbulence/
   displacement filter inlined in index.html. The plain blur pair above it is
   the fallback: engines that reject SVG-referenced backdrop filters
   (Firefox/Safari) drop the url() declaration and keep the frosted blur. */
.gf-drawer {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(340px, 88%);
  height: 100%;
  background: rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: url(#liquid-distortion) blur(14px) saturate(140%);
  backdrop-filter: url(#liquid-distortion) blur(14px) saturate(140%);
  color: #fff;
  border-left: 1px solid rgba(255,255,255,.05);
  border-radius: 12px 0 0 12px; /* left corners only — right edge sits flush with the stage */
  box-shadow: inset 0 1px 1px rgba(255,255,255,.15), -16px 0 44px rgba(0,0,0,.5);
  isolation: isolate;
  display: flex;
  flex-direction: column;
  transform: translateX(101%);
  /* .16s = snappy open. will-change keeps the slide on the compositor — the
     liquid-glass backdrop-filter re-samples every frame during the slide,
     which stuttered at the old .28s without the hint. */
  transition: transform .16s cubic-bezier(.4,0,.2,1);
  will-change: transform;
  font-family: 'Satoshi', system-ui, sans-serif;
  font-weight: 400;
}
.gf-drawer.is-open { transform: translateX(0); }

/* Firefox fallback: Gecko PARSES the url(#liquid-distortion) backdrop-filter
   as valid (so it wins the cascade over the plain declaration above) but
   cannot RENDER SVG-referenced backdrop filters — net result: no blur at all.
   Re-assert the plain frosted blur in a Gecko-only block; @supports
   (-moz-appearance:none) matches Firefox only (false in Chromium/WebKit). */
@supports (-moz-appearance: none) {
  .gf-drawer,
  .gf-config-btn {
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
  }
}

.gf-drawer-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 14px;
  flex: 0 0 auto;
}
.gf-drawer-title { font-family: 'Satoshi', system-ui, sans-serif; font-size: 17px; font-weight: 700; letter-spacing: .01em; }
.gf-drawer-count { font-family: 'Satoshi', system-ui, sans-serif; margin-left: auto; font-size: 12px; font-weight: 500; color: rgba(255,255,255,.6); font-variant-numeric: tabular-nums; }
.gf-drawer-close {
  background: none; border: none; color: rgba(255,255,255,.6);
  font-size: 24px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.gf-drawer-close:hover { color: #fff; }

.gf-drawer-list { flex: 1 1 auto; overflow-y: auto; padding: 2px 20px 24px; }

.gf-toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid rgba(255,255,255,.12);
  cursor: pointer;
}
.gf-toggle-row:first-child { border-top: none; }
.gf-toggle-label { font-family: 'Satoshi', system-ui, sans-serif; flex: 1; font-size: 14.5px; font-weight: 500; color: #fff; }

/* Brief nudge when a toggle is refused at the max-visible cap. */
@keyframes gf-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
.gf-toggle-row.gf-shake { animation: gf-shake .32s ease; }

.gf-switch { position: relative; width: 42px; height: 24px; flex: 0 0 auto; }
.gf-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.gf-switch input:disabled { cursor: not-allowed; }
.gf-switch-knob {
  position: absolute; inset: 0; border-radius: 999px;
  background: #3a3f47; transition: background .18s; pointer-events: none;
}
.gf-switch-knob::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .18s;
}
.gf-switch input:checked + .gf-switch-knob { background: #27E88D; }
.gf-switch input:checked + .gf-switch-knob::after { transform: translateX(18px); }

/* ===================== Mobile: tap-to-expand ===================== */
/* On phone-width embeds the 16:9 stage is tiny, so it acts as a thumbnail with a
   dark veil + pulsing prompt; tapping it opens a large landscape view (fullscreen.js). */
.gf-fs-veil {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: none;                 /* revealed only on narrow embeds (container query) */
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  background: rgba(6, 8, 11, .58);
  -webkit-backdrop-filter: blur(1.5px);
  backdrop-filter: blur(1.5px);
  color: #fff;
  cursor: pointer;
  font-family: 'Satoshi', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.gf-fs-veil span {
  font-size: clamp(15px, 5cqw, 26px);
  font-weight: 700;
  letter-spacing: .01em;
  text-shadow: 0 2px 16px rgba(0, 0, 0, .65);
  animation: gf-fs-pulse 2.2s ease-in-out infinite;
}
@keyframes gf-fs-pulse {
  0%, 100% { opacity: .6;  transform: scale(.99); }
  50%      { opacity: 1;   transform: scale(1.02); }
}
@media (prefers-reduced-motion: reduce) {
  .gf-fs-veil span { animation: none; opacity: .9; }
}

.gf-fs-close {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 10000;
  display: none;                 /* revealed only while expanded */
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: rgba(16, 18, 23, .8);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, .22);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Show the tap-to-fullscreen veil whenever the preview is rendered phone-narrow. */
@container (max-width: 600px) {
  .gf-fs-veil { display: flex; }
}

/* Expanded state: cover the viewport; fullscreen.js sizes/rotates the stage. */
.gf-preview.gf-fs-open {
  position: fixed;
  inset: 0;
  z-index: 9998;
  max-width: none !important;
  width: 100vw;
  height: 100vh;        /* fallback */
  height: 100dvh;       /* excludes mobile browser chrome (iOS/Android) */
  margin: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.gf-preview.gf-fs-open .gf-fs-veil  { display: none; }
.gf-preview.gf-fs-open .gf-fs-close { display: inline-flex; }
.gf-preview.gf-fs-open .gf-preview-stage { border-radius: 0; }
