/* The shell and the embedded demo use the same layout sheet. The demo keeps
   its own canvas, controls, styles and document-level event handlers. */
.viewer {
  --edge: clamp(18px, 2.55vw, 48px);
  --menu-width: clamp(210px, 17.25vw, 306px);
  --stage-top: clamp(88px, 11.6svh, 116px);
  --gutter: clamp(16px, 2.6vw, 56px);
  min-height: 100svh;
}

.viewer-header {
  position: fixed;
  z-index: 3;
  top: clamp(16px, 2.4svh, 28px);
  left: var(--edge);
  right: var(--edge);
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.25vw, 24px);
  pointer-events: none;
}

.viewer-header > * { pointer-events: auto; }
.viewer .wordmark {
  margin-inline-end: auto;
  color: var(--ink);
  font: 400 34px/1.13 var(--font-sans);
  letter-spacing: .19em;
  transform: scaleX(1.14);
  transform-origin: left center;
}
.viewer-header .repo-link { width: 36px; height: 36px; }
.viewer .home-tools { border-radius: 11px; }
.viewer .home-tools .icon-btn { min-width: 36px; }
.viewer .home-tools .active { background: var(--ink); color: white; }

.viewer-nav {
  position: fixed;
  z-index: 2;
  top: var(--stage-top);
  left: var(--edge);
  width: var(--menu-width);
  max-height: calc(100svh - var(--stage-top) - 24px);
  overflow-y: auto;
  scrollbar-width: thin;
}
.viewer .demo-item { min-height: 42px; margin: 0; font-size: 15px; }
.viewer .demo-item[aria-current="page"] { background: var(--bg-soft); font-weight: 650; }
.viewer .menu-toggle { display: none; }
.viewer .bg-dock[hidden] { display: none; }
.viewer.zen .viewer-header, .viewer.zen .viewer-nav { visibility: hidden; }

#viewer-stage {
  position: fixed;
  inset: var(--stage-top) var(--edge) 16px calc(var(--edge) + var(--menu-width) + var(--gutter));
  pointer-events: none;
}
#viewer-stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  pointer-events: auto;
  visibility: hidden;
}
#viewer-stage iframe.ready { visibility: visible; }
@media (prefers-reduced-motion: no-preference) {
  #viewer-stage iframe.ready { animation: reveal-demo 220ms ease-out; }
  @keyframes reveal-demo { from { opacity: 0; } to { opacity: 1; } }
}

html.embedded-demo, .embedded-demo body { background: transparent; }
.embedded-demo #vita-topbar, .embedded-demo #vita-bg-canvas { display: none; }
.embedded-demo .page-wrap > h1 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.embedded-demo .page-wrap { max-width: none; margin: 0; padding: 0; }
.embedded-demo .page-wrap > [class$="-stage"] {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(255px, 22.6vw, 330px);
  gap: clamp(16px, 3.6vw, 66px);
  align-items: start;
}
.embedded-demo .canvas-col {
  height: 100svh;
  min-width: 0;
  align-items: center;
  justify-content: center;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  padding-bottom: 11px;
  gap: 10px;
}
.embedded-demo .canvas-frame {
  width: min(100%, calc(100svh - 80px));
  background: transparent;
  border: 0;
  border-radius: 0;
}
.embedded-demo .icon-bar {
  width: fit-content;
  max-width: 100%;
  justify-content: center;
  gap: 12px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, .94);
}
.embedded-demo .rail {
  min-width: 0;
  max-height: 100svh;
  overflow-y: auto;
  padding: 8px 3px 18px;
  scrollbar-width: thin;
}
.embedded-demo .settings-heading {
  margin: 0 0 4px;
  font: 650 20px/1.25 var(--font-sans);
  letter-spacing: -.025em;
}

@media (max-width: 760px) {
  .viewer { --stage-top: 110px; }
  .viewer-header { top: 14px; }
  .viewer .wordmark { font-size: 28px; }
  .viewer-nav { top: 64px; width: calc(100% - 2 * var(--edge)); overflow: visible; }
  .viewer .menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: white;
    color: var(--ink);
    font: 500 14px/1.5 var(--font-sans);
    cursor: pointer;
  }
  .viewer #menu-panel { display: none; }
  .viewer .menu-toggle[aria-expanded="true"] + #menu-panel {
    display: block;
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    width: min(100%, 320px);
    max-height: calc(100svh - 114px);
    overflow-y: auto;
    padding: 10px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 9px;
  }
  #viewer-stage { left: var(--edge); bottom: 6px; }
}

/* This breakpoint uses the width actually available to the embedded demo. */
@media (max-width: 660px) {
  .embedded-demo .page-wrap > [class$="-stage"] { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .embedded-demo .canvas-col { display: flex; height: auto; gap: 10px; padding: 0; }
  .embedded-demo .canvas-frame { width: min(100%, 62svh); }
  .embedded-demo .rail { max-height: none; overflow: visible; padding: 0 2px 24px; }
}
