/*
 * Cinema Machina Experience System
 * Small shared primitives for product-led pages: glass surfaces, a depth
 * carousel, disclosures and a sticky mobile action. Native CSS only.
 *
 * Adapted patterns (re-implemented, no source copied verbatim):
 * - Depth layout maths: React Bits "DepthCarousel" (MIT + Commons Clause,
 *   use as part of a website permitted). Rewritten without GSAP or React.
 * - Carousel keyboard/ARIA roles: shadcn/ui Carousel (MIT).
 * - Inset specular glass edge: Kokonut UI "liquid-glass-card" (MIT).
 */

:root {
  --cm-glass-tint: rgba(24, 20, 14, 0.62);
  --cm-glass-solid: #17130e;
  --cm-glass-line: rgba(226, 193, 155, 0.2);
  --cm-glass-spec: rgba(255, 238, 214, 0.1);
  --cm-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- CMGlassPanel ---------- */
.cm-glass {
  position: relative;
  isolation: isolate;
  border: 1px solid var(--cm-glass-line);
  background: var(--cm-glass-solid);
  box-shadow:
    inset 0 1px 0 var(--cm-glass-spec),
    inset 0 -1px 0 rgba(0, 0, 0, 0.35),
    0 24px 60px -24px rgba(0, 0, 0, 0.7);
}
.cm-glass::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(
    160deg,
    rgba(255, 236, 205, 0.07) 0%,
    rgba(255, 236, 205, 0) 38%,
    rgba(201, 169, 110, 0.05) 100%
  );
  pointer-events: none;
}
@supports (
  (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))
) {
  .cm-glass {
    background: var(--cm-glass-tint);
    -webkit-backdrop-filter: blur(16px) saturate(1.25);
    backdrop-filter: blur(16px) saturate(1.25);
  }
}
@media (max-width: 720px) {
  @supports (
    (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))
  ) {
    .cm-glass {
      -webkit-backdrop-filter: blur(8px) saturate(1.15);
      backdrop-filter: blur(8px) saturate(1.15);
    }
  }
}
@media (prefers-reduced-transparency: reduce) {
  .cm-glass {
    background: var(--cm-glass-solid);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

/* ---------- CMScrollCollapse (disclosure) ---------- */
.cm-details summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  color: #d9ccb5;
  font-size: 0.86rem;
  letter-spacing: 0.02em;
}
.cm-details summary::-webkit-details-marker {
  display: none;
}
.cm-details summary::after {
  content: '';
  width: 0.45rem;
  height: 0.45rem;
  margin-left: auto;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.35s var(--cm-ease);
}
.cm-details[open] summary::after {
  transform: rotate(225deg) translateY(-2px);
}
.cm-details summary:hover {
  color: #f1e3c7;
}
.cm-details > :not(summary) {
  color: #b3a998;
  font-size: 0.86rem;
  line-height: 1.7;
}
.cm-details[open] > :not(summary) {
  animation: cm-fade 0.45s var(--cm-ease) both;
}
.cm-details--row {
  border-bottom: 1px solid rgba(201, 169, 110, 0.16);
}
.cm-details--row summary {
  min-height: 64px;
  font: 400 clamp(1.25rem, 2vw, 1.6rem) / 1.2 var(--font-display);
  letter-spacing: -0.01em;
  color: #eee5d3;
}
.cm-details--row > p {
  max-width: 62ch;
  padding-bottom: 1.4rem;
}
@keyframes cm-fade {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- CMDepthCarousel ---------- */
.cm-depth {
  position: relative;
  margin-top: clamp(2rem, 4vw, 3.2rem);
}
.cm-depth__tabs {
  display: flex;
  width: max-content;
  max-width: calc(100% - 2rem);
  margin: 0 auto;
  padding: 0.3rem;
  border-radius: 999px;
  gap: 0.2rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.cm-depth__tabs button {
  min-height: 40px;
  padding: 0 1.1rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #b0a593;
  font: 500 0.78rem/1 var(--font-body);
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.35s var(--cm-ease),
    color 0.35s var(--cm-ease);
}
.cm-depth__tabs button[aria-selected='true'] {
  background: rgba(226, 193, 155, 0.16);
  color: #f3e2c2;
  box-shadow: inset 0 0 0 1px rgba(226, 193, 155, 0.28);
}
.cm-depth__track {
  display: grid;
  margin: clamp(1.6rem, 3vw, 2.6rem) 0 0;
  padding: 0;
  list-style: none;
  perspective: 1800px;
  perspective-origin: 50% 40%;
}
.cm-depth__item {
  grid-area: 1 / 1;
  justify-self: center;
  width: min(1040px, 74vw, calc(58svh * 1.6));
  transform-style: preserve-3d;
  transition:
    transform 0.8s var(--cm-ease),
    opacity 0.6s var(--cm-ease);
  will-change: transform;
}
.cm-depth__media {
  position: relative;
  margin: 0;
  aspect-ratio: 16 / 10;
  border: 1px solid rgba(201, 169, 110, 0.3);
  border-radius: 14px;
  overflow: hidden;
  background: #1e1e1e;
  box-shadow:
    0 60px 120px -40px rgba(0, 0, 0, 0.85),
    0 0 0 1px rgba(0, 0, 0, 0.5);
}
.cm-depth__media::after {
  content: '';
  position: absolute;
  inset: 0;
  background: #0b0a08;
  opacity: var(--cm-dim, 0);
  pointer-events: none;
  transition: opacity 0.6s var(--cm-ease);
}
.cm-depth__media picture {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: auto !important;
}
.cm-depth__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.cm-depth__copy {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 0.3rem clamp(1.5rem, 4vw, 3.5rem);
  align-items: start;
  margin-top: 1.6rem;
  transition: opacity 0.5s var(--cm-ease);
}
.cm-depth__label {
  grid-column: 1 / -1;
  color: var(--forge-bronze, #c9a96e);
  font-size: 0.66rem;
  letter-spacing: 0.19em;
  text-transform: uppercase;
}
.cm-depth__copy h3 {
  font: 400 clamp(2rem, 3.2vw, 3.2rem) / 1 var(--font-display);
  letter-spacing: -0.03em;
  color: #f2e9d8;
}
.cm-depth__copy > p:not(.cm-depth__label) {
  color: #c2b8a7;
  font-size: 1rem;
  line-height: 1.65;
}
.cm-depth__copy .cm-details {
  grid-column: 2;
}
.cm-depth[data-ready] .cm-depth__item:not([data-active]) .cm-depth__copy {
  opacity: 0;
}
.cm-depth[data-ready] .cm-depth__item:not([data-active]) {
  cursor: pointer;
}
.cm-depth__nav {
  display: flex;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 1.6rem;
}
.cm-depth__arrow {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(226, 193, 155, 0.3);
  border-radius: 50%;
  background: linear-gradient(
    155deg,
    rgba(226, 193, 155, 0.15),
    rgba(22, 18, 12, 0.8)
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 238, 214, 0.18),
    0 12px 30px -15px #000;
  color: #e2c19b;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.3s var(--cm-ease);
}
@supports (
  (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))
) {
  .cm-depth__arrow {
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
}
@media (prefers-reduced-transparency: reduce) {
  .cm-depth__arrow {
    background: var(--cm-glass-solid);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
.cm-depth__arrow:hover {
  border-color: #e2c19b;
}
.cm-depth__arrow:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Mobile: no pseudo-3D. One readable item, native scroll snap. */
@media (max-width: 720px) {
  .cm-depth__track {
    display: flex;
    gap: 0.9rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 1rem;
    padding: 0 1rem 0.6rem;
    perspective: none;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }
  .cm-depth__track::-webkit-scrollbar {
    display: none;
  }
  .cm-depth__item {
    flex: 0 0 86%;
    width: auto;
    scroll-snap-align: start;
    transform: none !important;
    opacity: 1 !important;
  }
  .cm-depth__media {
    aspect-ratio: auto;
  }
  .cm-depth__media picture,
  .cm-depth__media img {
    height: auto;
  }
  .cm-depth__media::after {
    display: none;
  }
  .cm-depth__copy {
    display: block;
    opacity: 1 !important;
  }
  .cm-depth__copy h3 {
    margin-top: 0.4rem;
    font-size: 1.9rem;
  }
  .cm-depth__copy > p:not(.cm-depth__label) {
    margin-top: 0.5rem;
    font-size: 0.95rem;
  }
  .cm-depth__copy .cm-details {
    margin-top: 0.4rem;
  }
  .cm-depth__nav {
    display: none;
  }
}

/* ---------- CMStickyCTA (mobile only) ---------- */
.cm-sticky-cta {
  position: fixed;
  z-index: 40;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.55rem 0.55rem 0.55rem 1rem;
  border-radius: 14px;
  color: #d9ccb5;
  font-size: 0.78rem;
  transform: translateY(140%);
  transition: transform 0.5s var(--cm-ease);
}
.cm-sticky-cta[data-shown] {
  transform: none;
}
.cm-sticky-cta .forge-button {
  min-height: 44px;
}
@media (min-width: 721px) {
  .cm-sticky-cta {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cm-depth__item,
  .cm-depth__copy,
  .cm-depth__media::after,
  .cm-sticky-cta,
  .cm-details summary::after {
    transition: none !important;
  }
  .cm-details[open] > :not(summary) {
    animation: none;
  }
}
