/* ============================================================
   App shell: header / stage / panel
   Desktop: stage left, panel right (own scroll, footer pinned).
   Mobile: stage on top (collapsible), panel as bottom sheet.
   ============================================================ */
.app {
  --stage-h: 44dvh;
  position: relative;
  display: grid;
  height: 100vh;
  height: 100dvh;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  grid-template-rows: var(--header-h) minmax(0, 1fr);
  grid-template-areas: "header header" "stage panel";
  background: var(--bg);
}

/* ---------- Header ---------- */
.app-header {
  grid-area: header;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4);
  padding: 0 var(--s-5);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: var(--s-4); min-width: 0; }
.brand-logo { height: 30px; width: auto; }
.brand-home { display: inline-flex; border-radius: var(--r-sm); transition: opacity var(--t-fast) var(--ease); }
.brand-home:hover { opacity: .8; }
.brand-home:focus-visible { outline: none; box-shadow: var(--ring); }
.brand-divider { width: 1px; height: 24px; background: var(--line-2); }
.brand-title {
  font-family: var(--font-display); font-weight: 600; text-transform: uppercase;
  letter-spacing: var(--tracking-caps); font-size: .95rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-actions { display: flex; gap: var(--s-2); }

/* ---------- Stage ---------- */
.stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(80% 70% at 50% 45%, #1d1d21 0%, #121214 55%, #0b0b0c 100%);
  isolation: isolate;
}
.stage-viewport { position: absolute; inset: 0; }
.stage:fullscreen { background: #0b0b0c; }

.stage-top {
  position: absolute; top: var(--s-4); left: var(--s-4); right: var(--s-4);
  display: flex; justify-content: center; pointer-events: none; z-index: 3;
}
.stage-bottom {
  position: absolute; left: var(--s-4); right: var(--s-4); bottom: var(--s-4);
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-3);
  pointer-events: none; z-index: 3;
}
.stage-bottom > *, .stage-top > * { pointer-events: auto; }
.stage-tools { display: flex; gap: var(--s-2); margin-left: auto; }

.stage-hint {
  position: absolute; left: 50%; top: 68px; transform: translateX(-50%);
  z-index: 3;
}

.hotspot-popover-layer { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.hotspot-popover-layer > * { pointer-events: auto; }

.stage-grabber { display: none; }

/* ---------- Panel ---------- */
.panel {
  grid-area: panel;
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--surface-1);
  border-left: 1px solid var(--line);
  z-index: 4;
}
.panel-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  scroll-behavior: smooth;
  scrollbar-width: thin; scrollbar-color: var(--surface-4) transparent;
}
.panel-body:focus { outline: none; }
.panel-inner { padding: var(--s-5) var(--s-5) var(--s-8); }

.panel-footer {
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-1) var(--s-4);
  padding: var(--s-3) var(--s-5) calc(var(--s-3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(12px);
}
.footer-actions { display: flex; gap: var(--s-2); }
.cta-hint {
  grid-column: 1 / -1; font-size: var(--fs-xs); color: var(--text-3); min-height: 0;
}
.cta-hint:empty { display: none; }

/* ---------- Wide desktop ---------- */
@media (min-width: 1500px) { :root { --panel-w: 480px; } }

/* ---------- Mobile / tablet portrait ---------- */
@media (max-width: 900px) {
  .app {
    --stage-h: 40dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--header-h) var(--stage-h) minmax(0, 1fr);
    grid-template-areas: "header" "stage" "panel";
    transition: grid-template-rows var(--t-slow) var(--ease-out);
  }
  .app.is-stage-collapsed { --stage-h: 22dvh; }
  .app.is-stage-collapsed .stage-top,
  .app.is-stage-collapsed .stage-tools,
  .app.is-stage-collapsed .stage-hint { display: none; }
  .app-header { padding: 0 var(--s-4); }
  .brand { gap: var(--s-3); }
  .brand-logo { height: 24px; }
  .hide-sm { display: none; }

  .stage-top { top: var(--s-3); left: 0; right: 0; justify-content: flex-start; }
  .stage-bottom { left: var(--s-3); right: var(--s-3); bottom: calc(var(--s-3) + 16px); }
  .stage-hint { top: auto; bottom: 72px; width: max-content; max-width: calc(100% - 32px); }

  .panel {
    border-left: 0;
    margin-top: -16px;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-top: 1px solid var(--line-2);
    box-shadow: 0 -12px 32px rgba(0, 0, 0, .5);
  }
  .panel-inner { padding: var(--s-4) var(--s-4) var(--s-7); }
  .panel-footer { padding: 10px var(--s-4) calc(10px + env(safe-area-inset-bottom)); }
  .stepper { padding: 14px var(--s-4) 6px; border-radius: var(--r-xl) var(--r-xl) 0 0; }
  .step-btn { padding: 6px 0; }
  .step-btn .lbl { display: none; }
  .step-head { margin-bottom: var(--s-4); }
  .step-head p { font-size: var(--fs-sm); }
  .stage-hint { top: 56px; bottom: auto; }
  .stage-hint .hint-chip { font-size: var(--fs-xs); padding: 6px 6px 6px 12px; }

  .stage-grabber {
    display: grid; place-items: center;
    position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
    width: 64px; height: 28px; z-index: 5; border-radius: var(--r-pill);
  }
  .stage-grabber span {
    width: 40px; height: 4px; border-radius: 4px; background: var(--line-3);
    transition: background var(--t-fast);
  }
  .stage-grabber:hover span { background: var(--text-2); }
}

@media (max-width: 380px) {
  .brand-title { font-size: .85rem; }
}
