/* Public /themes — left theme rail + live iframe stage */

html:has(body.page-themes),
body.page-themes {
  height: 100%;
  overflow: hidden;
}

body.page-themes {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  /* No marketing header — reclaim the body padding reserved for #marketing-header. */
  padding-top: 0;
  background: #f4f4f5;
  color: var(--myst-ink, #14101c);
}

.themes-page {
  --themes-rail-w: min(20rem, 34vw);
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  background: #f4f4f5;
}

.themes-rail {
  display: flex;
  flex-direction: column;
  width: var(--themes-rail-w);
  flex-shrink: 0;
  min-height: 0;
  border-right: 1px solid rgb(var(--myst-chrome-rgb, 34 34 34) / 0.1);
  background: #fff;
}

.themes-rail__head {
  flex-shrink: 0;
  padding: 1.25rem 1.15rem 0.85rem;
  border-bottom: 1px solid rgb(var(--myst-chrome-rgb, 34 34 34) / 0.08);
}

.themes-rail__title-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.themes-rail__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0.35rem;
  background: transparent;
  color: var(--myst-muted, #5c5569);
  text-decoration: none;
  cursor: pointer;
}

.themes-rail__back svg {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.themes-rail__back:hover {
  color: var(--myst-ink, #14101c);
  background: rgb(var(--myst-chrome-rgb, 34 34 34) / 0.06);
}

.themes-rail__title {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--myst-font-display, "Open Sauce One", system-ui, sans-serif);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--myst-ink, #14101c);
  text-wrap: balance;
}

.themes-rail__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.themes-rail__empty {
  margin: 0.75rem 0.25rem;
  font-family: var(--myst-font-sans, "Open Sauce One", system-ui, sans-serif);
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--myst-muted, #5c5569);
}

.themes-rail__item {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr);
  gap: 0.75rem;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 0.55rem;
  border: 1px solid transparent;
  border-radius: 0.65rem;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.themes-rail__item:hover {
  background: rgb(var(--myst-chrome-rgb, 34 34 34) / 0.04);
}

.themes-rail__item.is-active {
  background: #fff;
  border-color: rgb(var(--myst-chrome-rgb, 34 34 34) / 0.16);
  box-shadow: 0 1px 0 rgb(var(--myst-chrome-rgb, 34 34 34) / 0.04);
}

.themes-rail__thumb {
  display: block;
  width: 4.5rem;
  height: 3rem;
  overflow: hidden;
  border-radius: 0.4rem;
  background: #ececef;
}

.themes-rail__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.themes-rail__meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.themes-rail__name {
  font-family: var(--myst-font-sans, "Open Sauce One", system-ui, sans-serif);
  font-size: 0.9375rem;
  font-weight: 650;
  line-height: 1.2;
  color: var(--myst-ink, #14101c);
}

.themes-rail__tag {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--myst-muted, #5c5569);
}

.themes-rail__desc {
  display: none;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--myst-muted, #5c5569);
}

@media (min-width: 1100px) {
  .themes-rail__desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

.themes-stage {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: #ececef;
}

.themes-stage__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  background: #fff;
  border-bottom: 1px solid rgb(var(--myst-chrome-rgb, 34 34 34) / 0.08);
}

.themes-stage__identity {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.themes-stage__list-back {
  display: none;
  align-items: center;
  gap: 0.15rem;
  margin: 0;
  padding: 0.2rem 0.35rem 0.2rem 0.15rem;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: var(--myst-muted, #5c5569);
  font-family: var(--myst-font-sans, "Open Sauce One", system-ui, sans-serif);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.themes-stage__list-back svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
  flex-shrink: 0;
}

.themes-stage__list-back:hover {
  color: var(--myst-ink, #14101c);
  background: rgb(var(--myst-chrome-rgb, 34 34 34) / 0.06);
}

.themes-stage__name {
  margin: 0;
  font-family: var(--myst-font-sans, "Open Sauce One", system-ui, sans-serif);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--myst-ink, #14101c);
}

.themes-stage__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.themes-stage__devices {
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  height: 2.25rem;
  padding: 0.2rem;
  border-radius: 0.55rem;
  background: rgb(var(--myst-chrome-rgb, 34 34 34) / 0.06);
}

.themes-stage__device {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  gap: 0.35rem;
  margin: 0;
  height: 100%;
  padding: 0 0.65rem;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: var(--myst-muted, #5c5569);
  font-family: var(--myst-font-sans, "Open Sauce One", system-ui, sans-serif);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.themes-stage__device svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

.themes-stage__device.is-on {
  background: #fff;
  color: var(--myst-ink, #14101c);
  box-shadow: 0 1px 2px rgb(var(--myst-chrome-rgb, 34 34 34) / 0.08);
}

.themes-stage__open {
  display: inline-flex;
  align-items: center;
  height: 2.25rem;
  padding: 0 0.85rem;
  border-radius: 0.55rem;
  border: 1px solid rgb(var(--myst-chrome-rgb, 34 34 34) / 0.14);
  background: #fff;
  color: var(--myst-ink, #14101c);
  font-family: var(--myst-font-sans, "Open Sauce One", system-ui, sans-serif);
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
}

.themes-stage__open:hover {
  background: rgb(var(--myst-chrome-rgb, 34 34 34) / 0.04);
}

/* Self-contained CTA — themes page no longer loads marketing-v4.css. */
.themes-stage__actions .themes-stage__cta.v3-btn,
.themes-stage__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: 2.25rem;
  min-height: 2.25rem;
  padding: 0 0.85rem;
  border: 0;
  border-radius: 0.55rem;
  background: var(--myst-primary, #7c3aed);
  color: #fff;
  font-family: var(--myst-font-sans, "Open Sauce One", system-ui, sans-serif);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
}

.themes-stage__cta:hover {
  background: var(--myst-primary-press, #6d28d9);
}

.themes-stage__viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0.85rem;
}

.themes-stage__frame {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: 0.65rem;
  background: #fff;
  border: 1px solid rgb(var(--myst-chrome-rgb, 34 34 34) / 0.1);
  box-shadow: 0 12px 40px -28px rgb(var(--myst-chrome-rgb, 34 34 34) / 0.45);
  transition: width 0.25s ease, max-width 0.25s ease;
}

.themes-stage__viewport[data-device="mobile"] .themes-stage__frame {
  width: min(100%, 24.5rem);
  margin-inline: auto;
}

.themes-stage__iframe {
  /* Render larger, then scale down for a slightly sharper preview (≈1.2× DPI). */
  --themes-iframe-dpi: 1.2;
  display: block;
  width: calc(100% * var(--themes-iframe-dpi));
  height: calc(100% * var(--themes-iframe-dpi));
  border: 0;
  background: #fff;
  transform: scale(calc(1 / var(--themes-iframe-dpi)));
  transform-origin: 0 0;
}

.themes-stage__loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  align-items: flex-start;
  justify-content: stretch;
  background: rgb(255 255 255 / 0.72);
  pointer-events: none;
}

.themes-stage__loading.is-on,
.themes-stage__loading:not([hidden]) {
  display: flex;
}

.themes-stage__loading[hidden] {
  display: none !important;
}

.themes-stage__loading-bar {
  display: block;
  width: 100%;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--myst-primary, #7c3aed),
    transparent
  );
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: themes-loading-slide 1.1s ease-in-out infinite;
}

@keyframes themes-loading-slide {
  0% {
    background-position: -40% 0;
  }
  100% {
    background-position: 140% 0;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mobile: list first, then full-screen preview on theme tap */
@media (max-width: 899px) {
  .themes-page {
    flex-direction: column;
  }

  .themes-page[data-mobile-view="list"] .themes-stage {
    display: none;
  }

  .themes-page[data-mobile-view="preview"] .themes-rail {
    display: none;
  }

  .themes-rail {
    width: 100%;
    border-right: 0;
    flex: 1 1 auto;
    min-height: 0;
  }

  .themes-rail__head {
    padding: 0.85rem 1rem 0.55rem;
  }

  .themes-rail__title {
    font-size: 1.05rem;
  }

  .themes-rail__scroll {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0.55rem 0.85rem 1rem;
    gap: 0.55rem;
  }

  .themes-rail__item {
    width: 100%;
    grid-template-columns: 5.5rem minmax(0, 1fr);
    padding: 0.55rem;
    border: 1px solid rgb(var(--myst-chrome-rgb, 34 34 34) / 0.08);
    background: #fff;
  }

  .themes-rail__item.is-active {
    border-color: rgb(var(--myst-chrome-rgb, 34 34 34) / 0.22);
    background: #fafafa;
  }

  .themes-rail__thumb {
    width: 5.5rem;
    height: 4.25rem;
  }

  .themes-rail__desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .themes-stage {
    flex: 1 1 auto;
    min-height: 0;
  }

  .themes-stage__list-back {
    display: inline-flex;
  }

  .themes-stage__bar {
    flex-wrap: nowrap;
    gap: 0.45rem;
    padding: 0.55rem 0.75rem;
  }

  .themes-stage__identity {
    flex: 1 1 auto;
    min-width: 0;
  }

  .themes-stage__name {
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .themes-stage__actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 0.4rem;
  }

  .themes-stage__devices {
    display: none;
  }

  .themes-stage__open,
  .themes-stage__actions .themes-stage__cta.v3-btn,
  .themes-stage__cta {
    height: 2rem;
    min-height: 2rem;
    padding: 0 0.7rem;
    font-size: 0.75rem;
  }

  .themes-stage__viewport {
    padding: 0.55rem 0.65rem 0.85rem;
  }

  .themes-stage__viewport[data-device="mobile"] .themes-stage__frame,
  .themes-stage__viewport .themes-stage__frame {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .themes-stage__loading-bar {
    animation: none;
    background: var(--myst-primary, #7c3aed);
  }

  .themes-stage__frame {
    transition: none;
  }
}
