/* CEAR SHOWCASE — styles
   Illustrated / drawn aesthetic on warm paper, in the Gourd TCM brand palette
   (gourdtcm.com): jade green, gold, ink, parchment creams. Lora + Lato.
   Mobile is a first-class surface, not a fallback. */

:root {
  /* Brand palette */
  --paper:   #f4ecd8;   /* main parchment */
  --paper-2: #fbf5e6;   /* lighter card cream */
  --paper-3: #ece0c6;   /* deeper cream — borders / hover */
  --ink:     #2c2f2d;   /* primary text (dark charcoal-green) */
  --jade:    #3f6f63;   /* brand green — secondary text, primary interactive */
  --jade-deep:#274a41;
  --gold:    #d2a93b;   /* brand gold — highlights, active, glow */
  --ink-dim: #5c675f;   /* muted body */
  --ink-faint:#8c8a78;  /* captions */

  /* Semantic */
  --bg: var(--paper);
  --accent: var(--jade);
  --accent-2: var(--gold);
  --line: rgba(63, 111, 99, 0.22);
  --panel-bg: rgba(251, 245, 230, 0.92);
  --gold-glow: rgba(210, 169, 59, 0.40);
  --radius: 14px;
  --shadow: 0 16px 40px rgba(44, 47, 45, 0.18);
  --serif: "Lora", Georgia, "Times New Roman", serif;
  --sans: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  /* Soft light glow behind the ear; never darker than the base paper, so there
     is no vignette that reads as left/right borders. */
  background:
    radial-gradient(130% 105% at 50% 28%, #fdf8ec 0%, var(--paper) 72%);
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- Loader ---------- */
.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 18px;
  justify-items: center;
  background: var(--paper);
  z-index: 50;
  transition: opacity 0.6s var(--ease);
}
.loader.is-hidden { opacity: 0; pointer-events: none; }
.loader__ring {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 3px solid rgba(63, 111, 99, 0.18);
  border-top-color: var(--jade);
  animation: spin 0.9s linear infinite;
}
.loader__text { color: var(--jade); font-size: 14px; letter-spacing: 0.02em; font-family: var(--serif); font-style: italic; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Top bar ---------- */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 18px 14px;
  z-index: 20;
  pointer-events: none;
}
.brand {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: 0.30em;
  font-size: 22px;
  color: var(--jade-deep);
  pointer-events: auto;
}
.topbar__actions { display: flex; align-items: center; gap: 10px; pointer-events: none; }
/* Buttons carry serif weight to balance the CEAR wordmark opposite them. */
.topbar__link {
  pointer-events: auto;
  background: rgba(251, 245, 230, 0.85);
  border: 1px solid var(--line);
  color: var(--jade-deep);
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 16px;
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.topbar__link:hover { color: var(--ink); border-color: var(--gold); background: var(--paper-2); }
.topbar__link--primary {
  background: var(--jade);
  color: var(--paper-2);
  border-color: var(--jade);
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(63, 111, 99, 0.3);
}
.topbar__link--primary:hover { background: var(--jade-deep); border-color: var(--jade-deep); color: var(--paper-2); }

/* ---------- Narrative ---------- */
.narrative {
  position: absolute;
  z-index: 25;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 48px));
  max-height: 78vh;
  overflow-y: auto;
  padding: 30px 28px 26px;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-top: 3px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}
.narrative.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.98);
}
.narrative__close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--ink-faint);
  font-size: 26px; line-height: 1; cursor: pointer;
}
.narrative__close:hover { color: var(--ink); }
.narrative__body p {
  margin: 0 0 14px;
  font-size: 15.5px;
  line-height: 1.64;
  color: var(--ink-dim);
}
.narrative__body p:first-child {
  font-family: var(--serif);
  font-size: 20px;
  color: var(--ink);
  line-height: 1.45;
}
.narrative__body strong { color: var(--jade); font-weight: 600; }
.narrative__cta { margin-top: 8px; width: 100%; }

/* ---------- Category bar ---------- */
.categorybar {
  position: absolute;
  z-index: 20;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  max-width: calc(100vw - 24px);
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--ease);
}
.categorybar.is-visible { opacity: 1; pointer-events: auto; }
.categorybar__lead { flex: none; color: var(--ink-faint); font-size: 13px; padding-left: 4px; white-space: nowrap; font-style: italic; font-family: var(--serif); }
.categorybar__chips {
  display: flex;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;                 /* let this flex child shrink so it can scroll */
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;          /* allow horizontal swipe (canvas sets none) */
  scroll-snap-type: x proximity;
}
.categorybar__chips::-webkit-scrollbar { display: none; }
.chip { scroll-snap-align: start; }
.chip {
  white-space: nowrap;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.35);
  color: var(--jade);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-family: var(--sans);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.chip:hover { color: var(--ink); border-color: var(--gold); }
.chip.is-active {
  color: var(--ink);
  background: var(--gold);
  border-color: var(--gold);
  font-weight: 700;
  box-shadow: 0 0 18px var(--gold-glow);
}

/* ---------- Payoff line ---------- */
.payoff {
  position: absolute;
  z-index: 18;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  bottom: calc(90px + env(safe-area-inset-bottom));
  width: min(560px, calc(100vw - 40px));
  padding: 14px 44px 14px 20px;
  background: rgba(251, 245, 230, 0.95);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.58;
  color: var(--ink);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;   /* let drags pass through to rotate the ear */
  transition: opacity 0.45s var(--ease), transform 0.45s var(--ease);
}
.payoff.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.payoff__text { margin: 0; }
.payoff__close {
  position: absolute;
  top: 6px; right: 8px;
  width: 30px; height: 30px;
  display: grid; place-content: center;
  background: none; border: none;
  color: var(--ink-faint);
  font-size: 24px; line-height: 1; cursor: pointer;
  pointer-events: auto;   /* but the close button itself is clickable */
}
.payoff__close:hover { color: var(--ink); }

/* ---------- Point panel ---------- */
.panel {
  position: absolute;
  z-index: 30;
  bottom: 0; left: 0; right: 0;
  max-height: 44vh;
  overflow-y: auto;
  /* Centre the content in a readable column with symmetric side gutters. */
  padding: 22px max(28px, calc((100vw - 1060px) / 2)) 24px;
  background: var(--paper-2);
  border-top: 3px solid var(--jade);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px);
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
}
.panel.is-visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
.panel__close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--ink-faint);
  font-size: 26px; line-height: 1; cursor: pointer;
}
.panel__close:hover { color: var(--ink); }
.panel__eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--jade);
  font-weight: 700;
  margin-bottom: 6px;
}
.panel__title { margin: 0 0 16px; font-family: var(--serif); font-weight: 600; font-size: 26px; color: var(--ink); letter-spacing: -0.01em; }
/* Bottom sheet is wide: lay the three facts out in a row so it stays shallow. */
.panel__facts { margin: 0; display: grid; gap: 16px 28px; grid-template-columns: repeat(3, 1fr); align-items: start; }
.fact dt {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 4px;
}
.fact dd { margin: 0; font-size: 15px; line-height: 1.55; color: var(--ink); }
.panel__note {
  margin: 20px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-faint);
  line-height: 1.5;
  font-style: italic;
}

/* ---------- Buttons (narrative CTA, modal) ---------- */
.btn {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.15s var(--ease), box-shadow 0.2s, background 0.2s;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--jade);
  color: var(--paper-2);
  box-shadow: 0 6px 20px rgba(63, 111, 99, 0.35);
}
.btn--primary:hover { background: var(--jade-deep); box-shadow: 0 8px 26px rgba(63, 111, 99, 0.42); }
.btn--ghost {
  background: rgba(251, 245, 230, 0.8);
  border-color: var(--line);
  color: var(--jade);
  backdrop-filter: blur(6px);
}
.btn--ghost:hover { color: var(--ink); border-color: var(--gold); }

/* ---------- Hint ---------- */
.hint {
  position: absolute;
  z-index: 15;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top));
  transform: translateX(-50%) translateY(-8px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(210, 169, 59, 0.16);
  border: 1px solid rgba(210, 169, 59, 0.5);
  color: #93701c;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
}
.hint.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Picture-in-picture window (small view frame; tap to swap) ---------- */
.pip-frame {
  position: fixed;
  z-index: 16;
  margin: 0; padding: 0;
  background: transparent;
  border: 2px solid rgba(63, 111, 99, 0.55);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(44, 47, 45, 0.3);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease), border-color 0.2s;
}
.pip-frame.is-visible { opacity: 1; pointer-events: auto; }
.pip-frame:hover { border-color: var(--gold); }
.pip-frame__swap {
  position: absolute;
  top: 6px; right: 6px;
  width: 24px; height: 24px;
  display: grid; place-content: center;
  border-radius: 50%;
  background: rgba(251, 245, 230, 0.92);
  color: var(--jade);
  font-size: 14px; font-weight: 700;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.22);
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-content: center;
  padding: 20px;
  background: rgba(44, 47, 45, 0.4);
  backdrop-filter: blur(4px);
}
.modal[hidden] { display: none; }
.modal__card {
  position: relative;
  width: min(400px, 100%);
  padding: 32px 28px 24px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-top: 3px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal__close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--ink-faint);
  font-size: 26px; line-height: 1; cursor: pointer;
}
.modal__title { margin: 0 0 10px; font-family: var(--serif); font-weight: 600; font-size: 23px; color: var(--ink); }
.modal__body { margin: 0 0 20px; color: var(--ink-dim); line-height: 1.55; font-size: 15px; }
.modal__form { display: grid; gap: 14px; }
.modal__form label { display: grid; gap: 6px; font-size: 13px; color: var(--jade); }
.modal__form input {
  font-family: var(--sans);
  font-size: 15px;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
.modal__form input:focus { outline: none; border-color: var(--gold); }
.modal__form .btn { margin-top: 4px; }
.modal__fine { margin: 14px 0 0; font-size: 12px; color: var(--ink-faint); text-align: center; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .narrative {
    top: auto;
    bottom: calc(90px + env(safe-area-inset-bottom));
    left: 12px; right: 12px;
    width: auto;
    transform: none;
    max-height: 56vh;
    padding: 22px 20px 20px;
  }
  .narrative.is-hidden { transform: translateY(16px); }
  .narrative__body p:first-child { font-size: 17px; }
  .narrative__body p { font-size: 14.5px; }

  .panel {
    max-height: 64vh;
    padding: 22px 20px calc(24px + env(safe-area-inset-bottom));
  }
  /* Stack the facts vertically again on a narrow screen. */
  .panel__facts { grid-template-columns: 1fr; gap: 16px; }

  .payoff {
    bottom: calc(90px + env(safe-area-inset-bottom));
    font-size: 13.5px;
    padding: 13px 40px 13px 16px;
  }
  .categorybar {
    left: 12px; right: 12px;
    transform: none;
    max-width: none;
    border-radius: 16px;
    /* Fade the right edge so it's clear the chip row scrolls. */
    -webkit-mask-image: linear-gradient(90deg, #000 90%, transparent 100%);
    mask-image: linear-gradient(90deg, #000 90%, transparent 100%);
  }
  .categorybar.is-visible { pointer-events: auto; }
  .categorybar__lead { display: none; }   /* reclaim space for chips */
  .chip { padding: 9px 14px; font-size: 13.5px; }
  .btn { padding: 11px 18px; font-size: 13.5px; }
  .brand { font-size: 19px; letter-spacing: 0.22em; }
  .topbar__link { font-size: 14px; padding: 8px 14px; }
  .topbar { padding-left: 14px; padding-right: 14px; }
}

/* Very narrow phones: keep CEAR + both top buttons on one line. */
@media (max-width: 380px) {
  .brand { font-size: 17px; letter-spacing: 0.12em; }
  .topbar__link { font-size: 12.5px; padding: 7px 12px; }
  .topbar__actions { gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.08s !important; }
}
