/* ═══════════════════════════════════════════════════════════════════════════
   /chapters — Mode Selector Overlay + Switch-Experience Toggle
   Full-screen cinematic gateway between Basic and Cinematic modes.
═══════════════════════════════════════════════════════════════════════════ */

/* Hide page while selector is deciding — selector itself stays visible */
html.cx-pending body > *:not(.cx-selector):not(.cx-switch) { opacity: 0 !important; visibility: hidden; }

/* ── Overlay ─────────────────────────────────────────────────────────────── */
.cx-selector {
  position: fixed; inset: 0;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--ink-deep, #0a0908);
  color: var(--limestone, #e8e2d6);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity .6s var(--ease-out, cubic-bezier(0.16,1,0.3,1));
}
.cx-selector.is-open { opacity: 1; pointer-events: auto; }

/* Animated background gradient mesh */
.cx-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 22% 28%, rgba(176,141,87,0.18) 0%, transparent 55%),
    radial-gradient(ellipse at 78% 72%, rgba(45,74,62,0.22)  0%, transparent 58%),
    radial-gradient(ellipse at 50% 50%, rgba(196,167,108,0.06) 0%, transparent 70%),
    linear-gradient(135deg, #0a0908 0%, #15110d 100%);
  animation: cxBgDrift 18s ease-in-out infinite alternate;
  z-index: 0;
}
@keyframes cxBgDrift {
  0%   { transform: scale(1)    rotate(0deg); filter: hue-rotate(0deg); }
  100% { transform: scale(1.12) rotate(1deg); filter: hue-rotate(-5deg); }
}

/* Vignette */
.cx-bg::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(10,9,8,0.85) 100%);
  pointer-events: none;
}

/* Grain overlay */
.cx-bg-grain {
  position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
  opacity: 0.4;
  z-index: 1;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.cx-head {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: clamp(24px, 4vw, 48px) 20px clamp(32px, 5vh, 64px);
  max-width: 600px;
}
.cx-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-sc, 'Cormorant SC', serif);
  font-size: 10px;
  letter-spacing: 0.48em;
  text-transform: uppercase;
  color: var(--bronze-pale, #c4a76c);
  margin-bottom: 24px;
}
.cx-eyebrow::before, .cx-eyebrow::after {
  content: ''; width: 24px; height: 1px;
  background: rgba(196,167,108,0.5);
}
.cx-title {
  font-family: var(--font-display, 'Cormorant Garamond', serif);
  font-weight: 300;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1.08;
  letter-spacing: -0.015em;
  color: var(--warm-white, #f6f2ec);
  margin-bottom: 16px;
}
.cx-title em { font-style: italic; color: var(--bronze-pale, #c4a76c); }
.cx-sub {
  font-family: var(--font-body, 'EB Garamond', serif);
  font-size: clamp(15px, 1.3vw, 17px);
  line-height: 1.7;
  color: rgba(232,226,214,0.64);
  max-width: 460px;
  margin: 0 auto;
}

/* ── Options row ─────────────────────────────────────────────────────────── */
.cx-options {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(16px, 2vw, 28px);
  width: min(92vw, 960px);
  padding: 0 clamp(16px, 3vw, 32px);
}

/* Card */
.cx-opt {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  aspect-ratio: 4 / 5;
  padding: clamp(24px, 3vw, 40px);
  background: rgba(15, 12, 9, 0.6);
  border: 1px solid rgba(200, 190, 172, 0.08);
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  color: inherit;
  transition:
    transform 0.6s var(--ease-out, cubic-bezier(0.16,1,0.3,1)),
    border-color 0.4s ease,
    background 0.5s ease;
  backdrop-filter: blur(8px) saturate(1.2);
  -webkit-backdrop-filter: blur(8px) saturate(1.2);
}

/* Preview layer — canvas/gradient/image */
.cx-opt-preview {
  position: absolute;
  inset: 0;
  opacity: 0.3;
  transform: scale(1.05);
  transition: opacity 0.6s ease, transform 1.2s var(--ease-out, cubic-bezier(0.16,1,0.3,1));
  pointer-events: none;
  z-index: 0;
}
.cx-opt-preview::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(10,9,8,0.2) 0%, rgba(10,9,8,0.92) 100%);
}

/* Basic preview — structured grid pattern */
.cx-opt-basic .cx-opt-preview {
  background:
    linear-gradient(135deg, #2d4a3e 0%, #1a1612 100%);
}
.cx-opt-basic .cx-opt-preview::before {
  content: '';
  position: absolute; inset: 20%;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(196,167,108,0.18) 0 2px,
      transparent 2px 32px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(196,167,108,0.12) 0 1px,
      transparent 1px 48px
    );
  transition: opacity 0.6s ease;
}

/* Cinematic preview — flowing bronze mesh */
.cx-opt-cinematic .cx-opt-preview {
  background:
    radial-gradient(circle at 30% 30%, rgba(176,141,87,0.45) 0%, transparent 45%),
    radial-gradient(circle at 70% 70%, rgba(45,74,62,0.55) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(196,167,108,0.22) 0%, transparent 60%),
    linear-gradient(160deg, #1a1612 0%, #050403 100%);
}
.cx-opt-cinematic .cx-opt-preview::before {
  content: '';
  position: absolute; inset: 0;
  background: conic-gradient(from 0deg at 50% 50%,
    rgba(196,167,108,0.08) 0deg,
    transparent 90deg,
    rgba(196,167,108,0.14) 180deg,
    transparent 270deg,
    rgba(196,167,108,0.08) 360deg
  );
  animation: cxCinSpin 22s linear infinite;
}
@keyframes cxCinSpin {
  to { transform: rotate(360deg); }
}

/* Content */
.cx-opt-content {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; gap: 14px;
}
.cx-opt-num {
  font-family: var(--font-display, serif); font-style: italic;
  font-size: 13px;
  color: rgba(196,167,108,0.55);
  letter-spacing: 0.16em;
}
.cx-opt-label {
  font-family: var(--font-sc, serif);
  font-size: 9px;
  letter-spacing: 0.48em;
  text-transform: uppercase;
  color: var(--bronze-pale, #c4a76c);
}
.cx-opt-title {
  font-family: var(--font-display, serif);
  font-weight: 300;
  font-size: clamp(1.75rem, 3.4vw, 2.75rem);
  line-height: 1.05;
  color: var(--warm-white, #f6f2ec);
  letter-spacing: -0.01em;
  margin-top: 4px;
}
.cx-opt-title em { font-style: italic; color: var(--bronze-pale, #c4a76c); }
.cx-opt-desc {
  font-family: var(--font-body, serif);
  font-size: 14px;
  line-height: 1.6;
  color: rgba(232,226,214,0.58);
  max-width: 30ch;
}

/* CTA */
.cx-opt-cta {
  position: relative; z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-sc, serif);
  font-size: 10px;
  letter-spacing: 0.44em;
  text-transform: uppercase;
  color: var(--limestone, #e8e2d6);
  padding-top: 20px;
  border-top: 1px solid rgba(200,190,172,0.1);
  transition: gap 0.5s var(--ease-out, cubic-bezier(0.16,1,0.3,1)),
              color 0.4s ease,
              border-color 0.4s ease;
}
.cx-opt-cta svg {
  width: 14px; height: 14px;
  transition: transform 0.5s var(--ease-out, cubic-bezier(0.16,1,0.3,1));
}

/* Hover state */
.cx-opt:hover {
  transform: scale(1.02) translateY(-4px);
  border-color: rgba(196,167,108,0.35);
  background: rgba(22, 17, 12, 0.75);
}
.cx-opt:hover .cx-opt-preview {
  opacity: 0.58;
  transform: scale(1);
}
.cx-opt:hover .cx-opt-cta {
  color: var(--bronze-pale, #c4a76c);
  gap: 22px;
  border-color: rgba(196,167,108,0.4);
}
.cx-opt:hover .cx-opt-cta svg {
  transform: translateX(6px);
}

/* Dim sibling when hovering */
.cx-options:has(.cx-opt:hover) .cx-opt:not(:hover) {
  opacity: 0.45;
  filter: blur(1.5px);
  transform: scale(0.98);
}

/* Active/pressed */
.cx-opt:active { transform: scale(1.005) translateY(-2px); }

/* Loading state (when picked) */
.cx-selector.is-loading .cx-opt:not(.is-picked) { opacity: 0.12; filter: blur(4px); }
.cx-selector.is-loading .cx-opt.is-picked       { transform: scale(1.06); border-color: var(--bronze-pale, #c4a76c); }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.cx-foot {
  position: relative;
  z-index: 2;
  padding: clamp(24px, 4vh, 48px) 20px clamp(20px, 3vh, 32px);
  text-align: center;
}
.cx-foot-hint {
  font-family: var(--font-sc, serif);
  font-size: 9px;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  color: rgba(232,226,214,0.28);
}
.cx-skip {
  display: inline-block;
  margin-top: 14px;
  font-family: var(--font-display, serif);
  font-style: italic;
  font-size: 13px;
  color: rgba(232,226,214,0.48);
  background: none;
  border: none;
  border-bottom: 1px dotted rgba(232,226,214,0.24);
  padding: 2px 6px;
  cursor: pointer;
  transition: color 0.3s ease, border-color 0.3s ease;
}
.cx-skip:hover { color: var(--bronze-pale, #c4a76c); border-color: var(--bronze-pale, #c4a76c); }

/* ── Reveal animation ────────────────────────────────────────────────────── */
.cx-selector .cx-head,
.cx-selector .cx-opt,
.cx-selector .cx-foot { opacity: 0; transform: translateY(16px); transition: opacity .8s .1s var(--ease-out, ease), transform .8s .1s var(--ease-out, ease); }
.cx-selector.is-open .cx-head { opacity: 1; transform: none; transition-delay: .2s; }
.cx-selector.is-open .cx-opt:nth-child(1) { opacity: 1; transform: none; transition-delay: .4s; }
.cx-selector.is-open .cx-opt:nth-child(2) { opacity: 1; transform: none; transition-delay: .55s; }
.cx-selector.is-open .cx-foot { opacity: 1; transform: none; transition-delay: .75s; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .cx-options { grid-template-columns: 1fr; width: min(92vw, 400px); }
  .cx-opt { aspect-ratio: 5 / 4; }
  .cx-options:has(.cx-opt:hover) .cx-opt:not(:hover) { opacity: 0.7; filter: none; }
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .cx-bg { animation: none; }
  .cx-opt-cinematic .cx-opt-preview::before { animation: none; }
  .cx-selector, .cx-selector *, .cx-opt, .cx-opt-preview { transition-duration: 0.2s !important; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SWITCH EXPERIENCE — floating toggle pill (shown in both modes)
═══════════════════════════════════════════════════════════════════════════ */
.cx-switch {
  position: fixed;
  bottom: clamp(20px, 3vh, 32px);
  right: clamp(20px, 3vw, 32px);
  z-index: 9800;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px 11px 14px;
  background: rgba(10, 9, 8, 0.72);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(196, 167, 108, 0.2);
  border-radius: 999px;
  color: var(--limestone, #e8e2d6);
  font-family: var(--font-sc, serif);
  font-size: 9px;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity 0.6s var(--ease-out, ease),
    transform 0.6s var(--ease-out, ease),
    background 0.3s ease,
    border-color 0.3s ease,
    gap 0.3s var(--ease-out, ease);
}
.cx-switch.is-visible { opacity: 1; transform: none; }
.cx-switch:hover {
  background: rgba(22, 17, 12, 0.85);
  border-color: var(--bronze-pale, #c4a76c);
  color: var(--bronze-pale, #c4a76c);
  gap: 16px;
}
.cx-switch-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--bronze-pale, #c4a76c);
  box-shadow: 0 0 8px var(--bronze-pale, #c4a76c);
  flex-shrink: 0;
  animation: cxPulse 2.6s ease-in-out infinite;
}
@keyframes cxPulse {
  0%, 100% { opacity: 0.55; }
  50%       { opacity: 1; }
}
.cx-switch-icon {
  display: inline-block;
  transition: transform 0.4s var(--ease-out, ease);
}
.cx-switch:hover .cx-switch-icon { transform: rotate(180deg); }

@media (max-width: 520px) {
  .cx-switch { font-size: 8px; padding: 9px 14px 9px 10px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SWITCH — v2 wrapper/button/menu form (used by simplified mode-selector.js)
   The wrapper (.cx-switch) becomes a positioning host; the styled pill is
   .cx-switch-btn. The menu (.cx-switch-menu) opens above it.
   (These rules override the older .cx-switch pill rules above via ordering.)
═══════════════════════════════════════════════════════════════════════════ */
.cx-switch {
  /* Keep the fixed positioning from earlier rule; reset the pill look. */
  padding: 0 !important;
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 0 !important;
  border-radius: 0 !important;
  opacity: 1 !important;
  transform: none !important;
  display: block;
  color: inherit;
  gap: 0 !important;
}
.cx-switch:hover {
  background: transparent !important;
  border-color: transparent !important;
  color: inherit !important;
  gap: 0 !important;
}

.cx-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px 11px 14px;
  background: rgba(10, 9, 8, 0.78);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(196, 167, 108, 0.22);
  border-radius: 999px;
  color: var(--limestone, #e8e2d6);
  font-family: var(--font-sc, serif);
  font-size: 9px;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease, gap 0.3s var(--ease-out, ease);
}
.cx-switch-btn:hover,
.cx-switch.is-open .cx-switch-btn {
  background: rgba(22, 17, 12, 0.9);
  border-color: var(--bronze-pale, #c4a76c);
  color: var(--bronze-pale, #c4a76c);
  gap: 14px;
}
.cx-switch-caret {
  display: inline-flex;
  align-items: center;
  transition: transform 0.3s var(--ease-out, ease);
}
.cx-switch.is-open .cx-switch-caret { transform: rotate(180deg); }

.cx-switch-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  min-width: 260px;
  padding: 8px;
  background: rgba(10, 9, 8, 0.94);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid rgba(196, 167, 108, 0.2);
  border-radius: 10px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s var(--ease-out, ease);
}
.cx-switch.is-open .cx-switch-menu {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.cx-switch-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  border-radius: 6px;
  color: var(--limestone, #e8e2d6);
  transition: background 0.25s ease, color 0.25s ease;
  cursor: pointer;
}
.cx-switch-item + .cx-switch-item { margin-top: 2px; }
.cx-switch-item:hover {
  background: rgba(196, 167, 108, 0.1);
  color: var(--bronze-pale, #c4a76c);
}
.cx-switch-item-label {
  font-family: var(--font-display, serif);
  font-size: 15px;
  letter-spacing: 0.005em;
}
.cx-switch-item-hint {
  font-family: var(--font-sc, serif);
  font-size: 8.5px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(232, 226, 214, 0.42);
}
