/* ==========================================================================
   Meta Display Glasses — Simulator
   ========================================================================== */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --app-native:   600px;
  --accent:       #0866ff;
  --accent-hover: #0756d6;
  --accent-light: #e7f3ff;
  --accent-mid:   #b3d1ff;
  --sidebar-w:    380px;
  --sidebar-bg:   #ffffff;
  --body-bg:      #f0f2f5;
  --border:       #dde1e7;
  --border-light: #eaecf0;
  --text-1:       #1c1e21;
  --text-2:       #606770;
  --text-3:       #8a8d91;
  --input-bg:     #f0f2f5;
  --radius:       8px;
}

html, body { width: 100vw; height: 100vh; overflow: hidden; }

body {
  background: var(--body-bg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', system-ui, sans-serif;
  color: var(--text-1);
  display: flex;
  font-size: 13px;
}

/* ──────────────────────────────────────────────────────────────────────────
   SIM VIEWPORT
   ────────────────────────────────────────────────────────────────────────── */
#sim-viewport {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  /* Transparent so the viewport-anchored #scene shows through; pointer-
     events go through empty areas to the scene's drag-to-pan handler. */
  background: transparent;
  pointer-events: none;
}
#sim-viewport > * { pointer-events: auto; }

/* Scene is anchored to the viewport (not to #sim-viewport) so toggling
   the sidebar never resizes/reframes the background — the sidebar just
   covers or reveals the leftmost portion of an otherwise-stable image.
   Black fallback for the "no preset loaded" instant. */
#scene {
  position: fixed;
  inset: 0;
  cursor: grab;
  z-index: -1;
  background: #000;
}

#bg-img, #bg-vid {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: none;
}

body.drag-active #sim-viewport {
  outline: 2px dashed rgba(8,102,255,0.40);
  outline-offset: -8px;
}

/* ── Waveguide HUD ──────────────────────────────────────────────
      mix-blend-mode: plus-lighter on #display-wrap is the actual
      waveguide simulation — leave it alone. The frame is otherwise
      kept visually inert (no glow / ring / sheen / scanlines) to
      stay faithful to how content actually appears on the device. ── */
#display-wrap {
  position: absolute;
  right: 48px;
  top: 48px;
  width: 360px; height: 360px;
  user-select: none;
  z-index: 200;
  mix-blend-mode: plus-lighter;
  isolation: isolate;
  /* Force this element onto its own GPU composite layer. Without it,
     Safari skips the plus-lighter blend for iframes that already have
     their own accelerated layer (canvas/WebGL apps like Pong), making
     the HUD render as an opaque overlay. */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: transform;
  transition: top 0.25s ease, bottom 0.25s ease;
}
#display-wrap.hidden { display: none; }
/* Suspend the additive waveguide blend while the placeholder is up so
   it reads clearly against any background. The blend is only meaningful
   once real HUD content is loaded. */
#display-wrap.show-placeholder { mix-blend-mode: normal; }

.wg-frame {
  position: relative;
  width: 100%; height: 100%;
  overflow: hidden;
}

#app-iframe {
  position: absolute; top: 0; left: 0;
  width: var(--app-native); height: var(--app-native);
  border: none;
  transform-origin: top left;
  /* translateZ(0) keeps the iframe on a GPU layer that participates
     in the parent's mix-blend-mode — without it Safari renders the
     iframe content as an opaque overlay for canvas/WebGL apps. */
  transform: scale(0.5) translateZ(0);
  -webkit-transform: scale(0.5) translateZ(0);
}

#wg-placeholder {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  background: rgba(5,5,15,0.55);
}
.ph-diamond {
  width: 30px; height: 30px;
  border: 1.5px solid rgba(140,200,255,0.65);
  border-radius: 3px;
  transform: rotate(45deg);
  animation: ph-diamond-pulse 2.6s ease-in-out infinite;
}
.ph-text {
  font-size: 11px; color: rgba(180,215,255,0.90);
  letter-spacing: 0.7px; text-transform: uppercase;
  font-weight: 500;
  animation: ph-text-pulse 2.6s ease-in-out infinite;
}

/* Slow, subtle attention pulse so first-time visitors notice the HUD
   and the call to action. Range is intentionally small — visible
   peripherally, not distracting once you've spotted it. */
@keyframes ph-diamond-pulse {
  0%, 100% { transform: rotate(45deg) scale(1);    opacity: 0.7; }
  50%      { transform: rotate(45deg) scale(1.12); opacity: 1;   }
}
@keyframes ph-text-pulse {
  0%, 100% { opacity: 0.75; }
  50%      { opacity: 1;    }
}

@media (prefers-reduced-motion: reduce) {
  .ph-diamond,
  .ph-text { animation: none; }
}

#load-error {
  position: absolute;
  top: 20px; left: 50%; transform: translateX(-50%);
  background: #fff0f0;
  border: 1px solid #ffcdd2;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 12px; color: #c62828;
  z-index: 400;
  display: none;
}

/* ──────────────────────────────────────────────────────────────────────────
   SIDEBAR
   ────────────────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  max-width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

/* ── Header ────────────────────────────────────────────────────── */
.side-header {
  position: relative;
  padding: 22px 20px 16px;
  border-bottom: 1px solid var(--border-light);
}

#hide-sidebar-btn {
  position: absolute;
  top: 14px;
  right: 12px;
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-3);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
#hide-sidebar-btn:hover {
  background: var(--input-bg);
  color: var(--text-1);
}
#hide-sidebar-btn:active { background: #e4e6ea; }
.side-header-eyebrow {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.side-header h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
  line-height: 1.2;
}

/* ── Nav groups ────────────────────────────────────────────────── */
.side-nav {
  flex: 1;
  padding: 8px 0;
}

.nav-group {
  padding: 16px 20px 20px;
  border-bottom: 1px solid var(--border-light);
}
.nav-group:last-child { border-bottom: none; }

.nav-group-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 14px;
}
.nav-group-label svg {
  opacity: 0.7;
  flex-shrink: 0;
}

.nav-group-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── App chips ────────────────────────────────────────────────── */
#app-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.app-chip {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.app-chip:hover {
  background: #e4e6ea;
  border-color: #c5c8ce;
  color: var(--text-1);
}
.app-chip.active {
  background: var(--accent-light);
  border-color: var(--accent-mid);
  color: var(--accent);
  font-weight: 600;
}
#app-chips:not(.expanded) .chip-extra { display: none; }
.chip-toggle {
  background: transparent;
  border: 1px dashed #b0b3b8;
  color: var(--accent);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
}
.chip-toggle:hover { background: var(--accent-light); }

/* ── URL bar ───────────────────────────────────────────────────── */
#url-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}
#url-input {
  flex: 1;
  min-width: 0;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text-1);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#url-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8,102,255,0.12);
  background: #fff;
}
#url-input::placeholder { color: var(--text-3); }

.pill-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, box-shadow 0.12s;
}
.pill-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 8px rgba(8,102,255,0.28);
}

/* ── Segmented control ─────────────────────────────────────────── */
.seg-control {
  display: flex;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}
.seg-control button {
  flex: 1;
  background: transparent;
  border: none;
  padding: 7px 10px;
  border-radius: 5px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  font-family: inherit;
}
.seg-control button:hover { color: var(--text-1); background: #e4e6ea; }
.seg-control button.active {
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

/* ── Slider / control rows ─────────────────────────────────────── */
.slider-row {
  display: grid;
  grid-template-columns: 72px 1fr 38px;
  align-items: center;
  gap: 10px;
}
.control-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  align-items: center;
  gap: 10px;
}
.slider-row label,
.control-row > label {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  font-weight: 500;
}
.slider-row > span {
  font-size: 11.5px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-weight: 600;
}

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 3px;
  background: var(--border);
  border-radius: 3px;
  outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px #fff, 0 0 0 4px rgba(8,102,255,0.25);
}

/* ── Background grid ───────────────────────────────────────────── */
#bg-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}
.bg-tile {
  position: relative;
  width: 100%; aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  border: 2px solid var(--border-light);
  background-size: cover;
  background-position: center;
  background-color: var(--input-bg);
  cursor: pointer;
  transition: border-color 0.12s, transform 0.12s, box-shadow 0.12s;
  overflow: hidden;
}
.bg-tile:hover {
  border-color: var(--accent-mid);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(0,0,0,0.10);
}
.bg-tile.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(8,102,255,0.20);
}
.bg-tile .bg-name {
  position: absolute;
  left: 5px; bottom: 4px;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.85);
  letter-spacing: 0.1px;
}
.bg-tile.is-video { background-color: #000; }
.bg-thumb-vid {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.bg-tile.is-video::after {
  content: '';
  position: absolute;
  top: 5px; right: 5px;
  width: 0; height: 0;
  border-left: 7px solid rgba(255,255,255,0.92);
  border-top: 4.5px solid transparent;
  border-bottom: 4.5px solid transparent;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6));
  pointer-events: none;
}

.bg-tile.upload {
  display: flex;
  align-items: center; justify-content: center;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  background-image: none;
  border-style: dashed;
}
.bg-tile.upload:hover { color: var(--accent); border-color: var(--accent-mid); background: var(--accent-light); }
.bg-tile.upload .upload-glyph { font-size: 15px; line-height: 1; }

/* ── Share CTA ─────────────────────────────────────────────────── */
#share-cta {
  padding: 16px 20px 24px;
  border-top: 1px solid var(--border-light);
  position: relative;
  background: var(--sidebar-bg);
}
#screenshot-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 8px;
  background: #fff;
  border: 1.5px solid var(--border);
  color: var(--text-1);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.1px;
  cursor: pointer;
  margin-bottom: 10px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
#screenshot-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent-mid);
  color: var(--accent);
}
#screenshot-btn:active { background: #d6e6ff; }
#screenshot-btn:disabled,
#record-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#record-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 8px;
  background: #fff;
  border: 1.5px solid var(--border);
  color: var(--text-1);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.1px;
  cursor: pointer;
  margin-bottom: 10px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
#record-btn:hover {
  background: #fff0f3;
  border-color: #f5b3c4;
  color: #c1284b;
}
#record-btn .rec-icon {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #e0245e;
  flex-shrink: 0;
}
#record-btn.recording {
  background: #fff;
  border-color: #f5b3c4;
  color: #c1284b;
}
#record-btn.recording:hover { background: #fff0f3; }
#record-btn.recording .rec-icon {
  width: 9px; height: 9px;
  border-radius: 2px;
  animation: rec-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 8px;
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.1px;
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s, transform 0.1s;
}
#share-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px rgba(8,102,255,0.30);
  transform: translateY(-1px);
}
#share-btn:active { transform: translateY(0); background: #064bc2; }

#last-updated {
  margin-top: 10px;
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.1px;
}

#made-by {
  margin-top: 10px;
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.1px;
}
#made-by a {
  color: var(--text-3);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.12s;
}
#made-by a:hover { color: var(--accent); }

#share-toast {
  position: absolute;
  bottom: calc(100% - 4px);
  left: 20px; right: 20px;
  text-align: center;
  background: var(--accent-light);
  border: 1.5px solid var(--accent-mid);
  color: var(--accent);
  padding: 9px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#share-toast.visible { opacity: 1; transform: translateY(0); }

/* ──────────────────────────────────────────────────────────────────────────
   FULLSCREEN SIM MODE
   ────────────────────────────────────────────────────────────────────────── */
body.fullscreen-sim #sidebar { display: none; }

#exit-fullscreen-btn {
  display: none;
  position: absolute;
  top: 18px; left: 18px;
  z-index: 500;
  width: 38px; height: 38px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.90);
  font-family: inherit;
  cursor: pointer;
  align-items: center; justify-content: center;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, background 0.15s;
}
body.fullscreen-sim #exit-fullscreen-btn { display: flex; }
body.fullscreen-sim.show-exit-btn #exit-fullscreen-btn,
body.fullscreen-sim #exit-fullscreen-btn:hover { opacity: 1; pointer-events: auto; }
#exit-fullscreen-btn:hover { background: rgba(255,255,255,0.25); color: #fff; }
