/* Single Studio shell — show/hide tool views without full page reload */

body.studio-shell-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.studio-tool-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.studio-tool-view[hidden] {
  display: none !important;
}

.studio-tool-view > .splitter-layout,
.studio-tool-view > .composer-layout {
  flex: 1 1 auto;
  min-height: 0;
}

.studio-ctrl-group[hidden] {
  display: none !important;
}

.studio-ctrl-group {
  display: contents;
}

.studio-library-mount:empty {
  display: none;
}

/*
 * Shared Library panel lives inside #composeLibraryMount (reparented between tools).
 * Layout CSS uses `> .sprites-panel` for the grid/drawer slot — so the mount must
 * take that slot and pass height down, or #spritePalette never gets a scrollport.
 */
.composer-layout > #composeLibraryMount.studio-library-mount:not(:empty) {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.composer-layout > #composeLibraryMount > #studioLibraryPanel,
.composer-layout > #composeLibraryMount > .sprites-panel {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 0;
  box-shadow: none;
}

.composer-layout > #composeLibraryMount #spritePalette {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 1101px) {
  .composer-layout.layout-desktop > #composeLibraryMount.studio-library-mount:not(:empty) {
    grid-area: sprites;
    border-right: 1px solid var(--border);
  }

  .composer-layout.layout-desktop > #composeLibraryMount > .sprites-panel > .studio-drawer-close,
  .composer-layout.layout-desktop > #composeLibraryMount > .sprites-panel > .drawer-close {
    display: none !important;
  }
}

/* When the shared library lives under Extract advanced, keep column chrome */
#extractLibraryColumn .studio-library-mount:not(:empty) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

#extractLibraryColumn #studioLibraryPanel {
  flex: 1 1 auto;
  min-height: 0;
  border: none;
  box-shadow: none;
}

/* Preview view fills the shell like the standalone page */
#studioViewPreview:not([hidden]) {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#studioViewPreview .preview-chooser,
#studioViewPreview #preview {
  flex: 1 1 auto;
  min-height: 0;
}

/* ── Tool-switch loading — opaque cover (no messy UI bleeding through) ───── */
.studio-switch-loading {
  position: fixed;
  inset: 0;
  /* Above tool chrome; below cookie (1100) and auth (1000) gates so sign-in stays usable */
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* Solid theme background — never translucent over mid-switch layout */
  background: var(--navy, #121820);
  opacity: 1;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.studio-switch-loading.is-visible {
  pointer-events: auto;
}

.studio-switch-loading.is-leaving {
  opacity: 0;
  pointer-events: none;
}

.studio-switch-loading[hidden] {
  display: none !important;
}

.studio-switch-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  max-width: 280px;
}

.studio-switch-loading-brand {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--cream, #f0ebe3);
  line-height: 1.1;
}

.studio-switch-loading-brand span {
  display: block;
  margin-top: 2px;
  font-family: "Source Sans 3", system-ui, sans-serif;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent, #c4a574);
}

.studio-switch-loading .tile-loader {
  --tile-size: 36px;
  --dot: 3px;
  --gap: 1.5px;
  width: var(--tile-size);
  height: var(--tile-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: var(--gap);
}

.studio-switch-loading .tile-loader span {
  width: var(--dot);
  height: var(--dot);
  margin: auto;
  border-radius: 1px;
  background: var(--accent, #c4a574);
  opacity: 0.12;
  animation: tile-lay 1.6s ease-in-out infinite;
}

.studio-switch-loading-msg {
  margin: 0;
  font-family: "Source Sans 3", system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted, rgba(240, 235, 227, 0.62));
  line-height: 1.35;
}

@keyframes tile-lay {
  0%, 100% {
    opacity: 0.12;
    transform: scale(0.55);
  }
  35%, 55% {
    opacity: 1;
    transform: scale(1);
  }
  75% {
    opacity: 0.35;
    transform: scale(0.85);
  }
}

@media (prefers-reduced-motion: reduce) {
  .studio-switch-loading .tile-loader span {
    animation: none;
    opacity: 0.55;
  }
}

/* Freeze interaction + hide layout thrash under the cover (switch + F5 boot) */
body.studio-shell-switching,
body.studio-shell-booting {
  cursor: progress;
}

body.studio-shell-switching .studio-stepper,
body.studio-shell-switching .studio-tool-menu-btn,
body.studio-shell-switching .app-header .controls,
body.studio-shell-switching .studio-tool-view,
body.studio-shell-booting .studio-stepper,
body.studio-shell-booting .studio-tool-menu-btn,
body.studio-shell-booting .app-header .controls,
body.studio-shell-booting .studio-tool-view {
  pointer-events: none !important;
}

/* Theme toggle must stay clickable during boot / under the loading cover */
body.studio-shell-switching .app-header .controls .theme-toggle,
body.studio-shell-switching .app-header .controls [data-theme-toggle],
body.studio-shell-booting .app-header .controls .theme-toggle,
body.studio-shell-booting .app-header .controls [data-theme-toggle] {
  pointer-events: auto !important;
}

/* Soften underlying chrome so any 1-frame leak is calm, not a drawer collage */
body.studio-shell-switching .studio-tool-view,
body.studio-shell-booting .studio-tool-view {
  filter: none;
  opacity: 0;
}
