/* ── FOLDABLE SHOWCASE (iPhone Duo) ──────── */

.duo-showcase {
  --duo-height: min(400px, calc((100vw - 48px) * 900 / 1280));
  --duo-open-width: calc(var(--duo-height) * 1280 / 900);
  --duo-closed-width: calc(var(--duo-height) * 879 / 1280);
  --duo-width: var(--duo-open-width);
  --spring-easing: linear(
    0, 0.009, 0.035 2.1%, 0.141 4.4%, 0.723 12.9%, 0.938 16.7%,
    1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%,
    1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%,
    0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1
  );

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  container: duo-showcase / inline-size;
}

.duo-showcase:has(.duo-input-closed:checked) {
  --duo-width: var(--duo-closed-width);
}

.duo-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--duo-height);
}

.duo-device-frame {
  width: var(--duo-width);
  height: var(--duo-height);
  border-radius: clamp(20px, calc(var(--duo-height) * 0.082), 34px);
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(255, 255, 255, 0.08);
  background: var(--phone-bg);
  cursor: pointer;
  line-height: 0;
  /* Fallback for older browsers before overriding with physics-based linear() easing */
  transition: width 0.65s cubic-bezier(0.22, 1, 0.36, 1), transform 0.2s ease;
  transition-timing-function: var(--spring-easing);
}

.duo-device-frame:hover {
  transform: translateY(-2px);
}

@supports not (animation-timing-function: linear(0, 1)) {
  .duo-device-frame {
    transition-duration: 0.45s;
    transition-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
  }
}

.duo-img {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  max-width: none;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 0;
  transition: opacity 0.32s ease;
}

.duo-img-open {
  width: var(--duo-open-width);
  z-index: 2;
}

.duo-img-open.is-base-view {
  opacity: 1;
  z-index: 1;
}

.duo-img-open.is-active-view {
  opacity: 1;
}

.duo-img-closed {
  width: var(--duo-closed-width);
  z-index: 3;
}

.duo-showcase:has(.duo-input-closed:checked) .duo-img-closed.is-active-view {
  opacity: 1;
}

.duo-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 12px;
}

.duo-toggle {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 4px;
  border-radius: 100px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Many views don't fit on one row on a phone: stack the Open/Closed toggle and
   the view toggle into one column of the same width, each laid out two across
   on the same equal-width grid, so every button is the same size. An odd last
   view sits centered on its own row. (Four tracks, each button spanning two,
   so that centered button keeps the same width.) */
@container duo-showcase (max-width: 600px) {
  .duo-controls-many {
    display: inline-grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .duo-controls-many .duo-toggle {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-radius: 24px;
  }

  .duo-controls-many .duo-toggle-option {
    grid-column: span 2;
    justify-content: center;
  }

  .duo-controls-many .duo-toggle-option:last-of-type:nth-of-type(odd) {
    grid-column: 2 / span 2;
  }
}

.duo-toggle-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 16px;
  border-radius: 100px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.duo-toggle-option:hover {
  color: var(--text);
}

.duo-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.duo-toggle-option:has(.duo-input:checked) {
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.duo-toggle-option:has(.duo-input:focus-visible) {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.duo-caption {
  font-size: 0.875rem;
  color: var(--text-muted);
  min-height: 1.5em;
}

.duo-caption-item {
  display: none;
}

.duo-showcase:not(:has(.duo-input-closed:checked)) .duo-caption-open.is-active-view,
.duo-showcase:has(.duo-input-closed:checked) .duo-caption-closed.is-active-view {
  display: inline;
}

@supports not selector(:has(*)) {
  .duo-showcase.is-closed {
    --duo-width: var(--duo-closed-width);
  }

  .duo-showcase.is-closed .duo-img-closed.is-active-view {
    opacity: 1;
  }

  .duo-toggle-option.is-selected {
    background: var(--bg);
    color: var(--text);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }

  .duo-showcase:not(.is-closed) .duo-caption-open.is-active-view,
  .duo-showcase.is-closed .duo-caption-closed.is-active-view {
    display: inline;
  }
}

@media (prefers-reduced-motion: reduce) {
  .duo-device-frame,
  .duo-img,
  .duo-toggle-option {
    transition: none !important;
  }
}
