/* =============================================================
   AEIR CO2 Skin Rejuvenation — Microsite
   Visual spec: .context/microsite-skin-rejuvenation/03-visual-design.md
   ============================================================= */

/* Self-hosted Instrument Sans (variable, weights 400-700) */
@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: block;
  src: url("fonts/instrument-sans-variable.woff2") format("woff2-variations"),
       url("fonts/instrument-sans-variable.woff2") format("woff2");
}

/* ============================================================
   Tokens (from visual spec §8)
   ============================================================ */
:root {
  --color-ink:               #282828;
  --color-ink-muted:         #5A6171;
  --color-surface:           #F9F9F9;
  --color-white:             #FFFFFF;
  --color-hairline:          #E6E6E6;

  --color-accent:            #007AFF;
  --color-accent-text:       #0065D6;

  --color-success:           #2E7D5B;
  --color-error:             #B43A2F;

  --color-qr-dark:           #000000;
  --color-qr-light:          #FFFFFF;

  --color-handle-pill:       #FFFFFF;
  --color-handle-halo:       rgba(40, 40, 40, 0.45);
  --color-handle-press-bg:   rgba(40, 40, 40, 0.04);

  --color-face-divider-core: rgba(255, 255, 255, 0.72);
  --color-face-divider-edge: rgba(40, 40, 40, 0.35);

  --font-family-sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --type-headline-weight:            600;
  --type-headline-size:              28px;
  --type-headline-line-height:       1.15;
  --type-headline-tracking:          -0.01em;

  --type-subhead-weight:             400;
  --type-subhead-size:               16px;
  --type-subhead-line-height:        1.35;

  --type-case-label-active-weight:   600;
  --type-case-label-inactive-weight: 500;
  --type-case-label-size:            15px;
  --type-case-label-line-height:     1.2;

  --type-duration-landscape-size:    13px;
  --type-duration-portrait-size:     12px;
  --type-duration-weight:            400;

  --type-orientation-label-size:        11px;
  --type-orientation-label-weight:      600;
  --type-orientation-label-line-height: 1.0;
  --type-orientation-label-tracking:    0.12em;

  --type-protocol-row1-size:         16px;
  --type-protocol-row1-weight:       500;
  --type-protocol-row1-line-height:  1.35;

  --type-protocol-mech-size:         15px;
  --type-protocol-mech-weight:       400;
  --type-protocol-mech-line-height:  1.45;

  --type-more-toggle-size:           13px;
  --type-more-toggle-weight:         500;
  --type-more-toggle-tracking:       0.02em;

  --type-qr-label-size:              12px;
  --type-qr-label-weight:            500;
  --type-qr-label-tracking:          0.04em;

  --space-xs:  4px;
  --space-s:   8px;
  --space-m:   16px;
  --space-l:   24px;
  --space-xl:  32px;
  --space-2xl: 48px;

  --safe-edge-landscape-h: var(--space-xl);
  --safe-edge-landscape-v: var(--space-l);
  --safe-edge-portrait-h:  var(--space-l);
  --safe-edge-portrait-v:  var(--space-l);

  --radius-sm:   2px;
  --radius-md:   4px;
  --radius-lg:   8px;
  --radius-xl:   12px;
  --radius-pill: 9999px;

  --elev-0:    none;
  --elev-1:    0 1px 2px rgba(40, 40, 40, 0.06), 0 1px 3px rgba(40, 40, 40, 0.08);
  --elev-2:    0 4px 12px rgba(40, 40, 40, 0.10), 0 2px 4px rgba(40, 40, 40, 0.06);
  --elev-halo: 0 0 0 1px rgba(40, 40, 40, 0.45);

  --handle-pill-width:           4px;
  --handle-puck-diameter:        44px;
  --handle-puck-diameter-drag:   48.4px;
  --handle-hit-width:            44px;

  --qr-tile-size:                130px;
  --qr-tile-padding:             12px;
  --qr-graphic-size:             106px;

  --hero-strip-height-landscape: 100px;
  --hero-strip-height-portrait:  120px;
  --case-nav-height-landscape:   64px;
  --case-nav-height-portrait:    72px;

  --stage-aspect-landscape:      16 / 10;
  --stage-aspect-portrait:       3 / 4;

  --logo-height-landscape:       28px;
  --logo-height-portrait:        32px;

  --motion-duration-fast:       80ms;
  --motion-duration-normal:     120ms;
  --motion-duration-slow:       180ms;
  --motion-duration-crossfade:  240ms;
  --motion-duration-hint:       1600ms;
  --motion-duration-pulse:      3500ms;

  --motion-ease-out:            cubic-bezier(0.2, 0.8, 0.2, 1);
  --motion-ease-in:             cubic-bezier(0.4, 0, 1, 1);
  --motion-ease-in-out:         cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   Reset / base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--color-surface);
  color: var(--color-ink);
  font-family: var(--font-family-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

img { display: block; max-width: 100%; height: auto; -webkit-user-drag: none; }
sub { font-size: 0.72em; vertical-align: -0.18em; }

/* ============================================================
   App shell — flex column, viewport-filling, no scroll
   ============================================================ */
.app {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  background: var(--color-surface);
  overflow: hidden;
}

/* ============================================================
   Hero strip
   ============================================================ */
.hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  height: var(--hero-strip-height-landscape);
  padding: 0 var(--safe-edge-landscape-h);
  gap: var(--space-l);
  background: var(--color-surface);
}

.hero__brand { display: flex; align-items: center; }
.hero__logo {
  height: var(--logo-height-landscape);
  width: auto;
  pointer-events: auto;
}

.hero__text { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.hero__headline {
  margin: 0;
  font-weight: var(--type-headline-weight);
  font-size: var(--type-headline-size);
  line-height: var(--type-headline-line-height);
  letter-spacing: var(--type-headline-tracking);
  color: var(--color-ink);
}
.hero__subhead {
  margin: 2px 0 0;
  font-weight: var(--type-subhead-weight);
  font-size: var(--type-subhead-size);
  line-height: var(--type-subhead-line-height);
  color: var(--color-ink-muted);
}

.hero__qr {
  display: flex;
  align-items: center;
  gap: var(--space-m);
  justify-self: end;
}

.qr__label {
  font-size: var(--type-qr-label-size);
  font-weight: var(--type-qr-label-weight);
  letter-spacing: var(--type-qr-label-tracking);
  color: var(--color-ink);
  white-space: nowrap;
}

.qr__tile {
  display: block;
  width: var(--qr-tile-size);
  height: var(--qr-tile-size);
  padding: var(--qr-tile-padding);
  background: var(--color-qr-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--elev-1);
  text-decoration: none;
  flex-shrink: 0;
}

.qr__img {
  width: var(--qr-graphic-size);
  height: var(--qr-graphic-size);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ============================================================
   Case nav (segmented control)
   ============================================================ */
.case-nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: var(--case-nav-height-landscape);
  margin: 0 var(--safe-edge-landscape-h);
  background: var(--color-surface);
  border-top: 1px solid var(--color-hairline);
  border-bottom: 1px solid var(--color-hairline);
  position: relative;
}

.case-nav__segment {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--space-s);
  padding: var(--space-m) var(--space-l);
  color: var(--color-ink-muted);
  font-weight: var(--type-case-label-inactive-weight);
  transform-origin: center;
  transition: transform var(--motion-duration-fast) var(--motion-ease-out),
              background-color var(--motion-duration-slow) var(--motion-ease-out),
              box-shadow var(--motion-duration-slow) var(--motion-ease-out),
              color var(--motion-duration-slow) var(--motion-ease-out);
  border-radius: var(--radius-md);
  background: transparent;
  will-change: transform, background-color;
}

.case-nav__segment:not(:last-child)::after {
  content: "";
  position: absolute;
  right: 0;
  top: 20%;
  bottom: 20%;
  width: 1px;
  background: var(--color-hairline);
}

.case-nav__segment.is-active::after,
.case-nav__segment.is-active + .case-nav__segment::after {
  /* Suppress divider next to active */
}
.case-nav__segment.is-active::after { background: transparent; }

.case-nav__segment.is-active {
  background: var(--color-white);
  color: var(--color-ink);
  font-weight: var(--type-case-label-active-weight);
  box-shadow: var(--elev-1);
  z-index: 1;
}
.case-nav__segment.is-active + .case-nav__segment::after { /* keep default */ }

.case-nav__segment.is-pressed {
  transform: scale(0.98);
  background: var(--color-handle-press-bg);
}
.case-nav__segment.is-active.is-pressed {
  background: var(--color-white);
  transform: scale(0.98);
}

.case-nav__label {
  font-size: var(--type-case-label-size);
  line-height: var(--type-case-label-line-height);
}
.case-nav__duration {
  font-size: var(--type-duration-landscape-size);
  font-weight: var(--type-duration-weight);
  line-height: 1.2;
  color: var(--color-ink-muted);
  position: relative;
  padding-left: var(--space-s);
}
.case-nav__duration::before {
  content: "·";
  position: absolute;
  left: 0;
  color: var(--color-ink-muted);
}

/* ============================================================
   Slider stage
   ============================================================ */
.stage {
  position: relative;
  display: grid;
  place-items: center;
  padding: var(--safe-edge-landscape-v) var(--safe-edge-landscape-h);
  min-height: 0;
  overflow: hidden;
  container-type: size;
}

.stage__label {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--type-orientation-label-size);
  font-weight: var(--type-orientation-label-weight);
  line-height: var(--type-orientation-label-line-height);
  letter-spacing: var(--type-orientation-label-tracking);
  text-transform: uppercase;
  color: var(--color-ink-muted);
  pointer-events: none;
}
.stage__label--before { left: calc(var(--safe-edge-landscape-h) * 0.25); }
.stage__label--after  { right: calc(var(--safe-edge-landscape-h) * 0.25); }

.stage__frame {
  position: relative;
  aspect-ratio: var(--stage-aspect-landscape);
  /* Fit within stage in both axes by sizing to the lesser of 100cqw and 100cqh * aspect */
  width: min(100cqw, 100cqh * (16 / 10));
  height: auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.app[data-orientation="portrait"] .stage__frame {
  aspect-ratio: var(--stage-aspect-portrait);
  width: min(100cqw, 100cqh * (3 / 4));
}

/* Panels (one per case) */
.panel {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-duration-crossfade) var(--motion-ease-out);
}
.panel.is-active {
  opacity: 1;
  pointer-events: auto;
}
.panel[hidden] { display: block; }  /* override default hidden so crossfade works; JS toggles .is-active */

.panel__img {
  position: absolute;
  inset: 0;
  display: block;
}
.panel__img img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: var(--color-surface);
  pointer-events: none;
}

.panel__after-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  /* clip-path drives the reveal; no layout, no repaint of the image */
  clip-path: inset(0 0 0 var(--split, 50%));
  will-change: clip-path;
}
.panel__after-clip .panel__img { inset: 0; }

/* Handle: pill + puck, positioned absolutely */
.panel__handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--split, 50%);
  width: var(--handle-hit-width);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: left;
  z-index: 3;
}

.panel__pill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: var(--handle-pill-width);
  background: var(--color-handle-pill);
  opacity: 0.80;
  box-shadow: var(--elev-halo);
  transition: opacity var(--motion-duration-normal) var(--motion-ease-out);
  pointer-events: none;
}

.panel__puck {
  position: relative;
  width: var(--handle-puck-diameter);
  height: var(--handle-puck-diameter);
  border-radius: var(--radius-pill);
  background: var(--color-handle-pill);
  box-shadow: var(--elev-halo), var(--elev-1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--motion-duration-normal) var(--motion-ease-out),
              box-shadow var(--motion-duration-normal) var(--motion-ease-out),
              opacity var(--motion-duration-normal) var(--motion-ease-out);
  will-change: transform;
  pointer-events: none;
}

.panel__glyph {
  font-size: 14px;
  line-height: 1;
  color: var(--color-ink);
  letter-spacing: 1px;
  font-weight: 600;
}

.panel.is-dragging .panel__pill { opacity: 1; }
.panel.is-dragging .panel__puck {
  transform: scale(1.10);
  box-shadow: var(--elev-halo), var(--elev-2);
}

/* Face-case divider (visual spec §5.2) */
.panel__divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--split, 50%);
  transform: translateX(-50%);
  width: 3px;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(
      to right,
      var(--color-face-divider-edge) 0 1px,
      var(--color-face-divider-core) 1px 2px,
      var(--color-face-divider-edge) 2px 3px
    );
  opacity: 1;
  transition: opacity var(--motion-duration-normal) var(--motion-ease-out);
  will-change: left, opacity;
}
.panel.is-edge-left  .panel__divider,
.panel.is-edge-right .panel__divider { opacity: 0; }

/* Edge state — swap glyph via content */
.panel.is-edge-left  .panel__glyph::before { content: "›"; }
.panel.is-edge-right .panel__glyph::before { content: "‹"; }
.panel.is-edge-left  .panel__glyph,
.panel.is-edge-right .panel__glyph { font-size: 0; }
.panel.is-edge-left  .panel__glyph::before,
.panel.is-edge-right .panel__glyph::before { font-size: 18px; font-weight: 600; }

/* Ghost-drag animation (first load only) */
.panel.is-hinting .panel__puck {
  animation: ghost-puck var(--motion-duration-hint) var(--motion-ease-in-out) 1;
}
@keyframes ghost-puck {
  0%    { opacity: 0.7;  transform: scale(1); }
  12%   { opacity: 1.0;  transform: scale(1.08); }
  44%   { opacity: 1.0;  transform: scale(1); }
  56%   { opacity: 1.0;  transform: scale(1); }
  87%   { opacity: 1.0;  transform: scale(1); }
  100%  { opacity: 0.8;  transform: scale(1); }
}

/* Idle pulse (post-reset) */
.panel.is-pulsing .panel__puck {
  animation: pulse-puck var(--motion-duration-pulse) var(--motion-ease-in-out) infinite;
}
@keyframes pulse-puck {
  0%, 100% { opacity: 0.80; }
  50%      { opacity: 1.00; }
}

/* ============================================================
   Protocol panel
   ============================================================ */
.protocol {
  background: var(--color-white);
  border-top: 1px solid var(--color-hairline);
  padding: var(--space-m) var(--space-l);
}

.protocol__row1 {
  font-size: var(--type-protocol-row1-size);
  font-weight: var(--type-protocol-row1-weight);
  line-height: var(--type-protocol-row1-line-height);
  color: var(--color-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.protocol__row2 {
  display: flex;
  align-items: baseline;
  gap: var(--space-s);
  margin-top: var(--space-xs);
  min-width: 0;
}

.protocol__mech {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--type-protocol-mech-size);
  font-weight: var(--type-protocol-mech-weight);
  line-height: var(--type-protocol-mech-line-height);
  color: var(--color-ink-muted);
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr;
  max-height: 3em;
  transition: max-height var(--motion-duration-crossfade) var(--motion-ease-out);
}
.protocol__mech-text {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}
.protocol.is-expanded .protocol__mech {
  max-height: 8em;
}
.protocol.is-expanded .protocol__mech-text {
  -webkit-line-clamp: unset;
  display: block;
  overflow: visible;
  text-overflow: clip;
}

.protocol__toggle {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-size: var(--type-more-toggle-size);
  font-weight: var(--type-more-toggle-weight);
  letter-spacing: var(--type-more-toggle-tracking);
  color: var(--color-accent-text);
  white-space: nowrap;
}
.protocol__toggle::before {
  /* 44x44 hit target expansion */
  content: "";
  position: absolute;
  inset: -14px -12px;
}
.protocol__toggle-chevron {
  display: inline-block;
  transform: rotate(0);
  transition: transform var(--motion-duration-crossfade) var(--motion-ease-out);
}
.protocol.is-expanded .protocol__toggle-label::after {
  content: "";
}
.protocol.is-expanded .protocol__toggle-chevron {
  transform: rotate(180deg);
}

/* ============================================================
   Portrait orientation
   ============================================================ */
.app[data-orientation="portrait"] {
  grid-template-rows: auto auto 1fr auto;
}

.app[data-orientation="portrait"] .hero {
  grid-template-columns: auto 1fr;
  grid-template-rows: auto;
  height: var(--hero-strip-height-portrait);
  padding: 0 var(--safe-edge-portrait-h);
  gap: var(--space-m);
}
.app[data-orientation="portrait"] .hero__logo {
  height: var(--logo-height-portrait);
}
.app[data-orientation="portrait"] .hero .hero__qr {
  display: none; /* hero-embedded QR hidden in portrait; cloned floating QR takes its place */
}
.app[data-orientation="portrait"] .hero__text {
  flex-direction: column;
}

.app[data-orientation="portrait"] .case-nav {
  height: var(--case-nav-height-portrait);
  margin: 0 var(--safe-edge-portrait-h);
}
.app[data-orientation="portrait"] .case-nav__segment {
  flex-direction: column;
  gap: 2px;
  padding: var(--space-m) var(--space-s);
}
.app[data-orientation="portrait"] .case-nav__duration {
  font-size: var(--type-duration-portrait-size);
  padding-left: 0;
}
.app[data-orientation="portrait"] .case-nav__duration::before {
  content: none;
}

.app[data-orientation="portrait"] .stage {
  padding: var(--safe-edge-portrait-v) var(--safe-edge-portrait-h);
  padding-bottom: calc(var(--safe-edge-portrait-v) + 22px); /* room for labels below */
}
.app[data-orientation="portrait"] .stage__frame {
  aspect-ratio: var(--stage-aspect-portrait);
}
.app[data-orientation="portrait"] .stage__label {
  top: auto;
  bottom: var(--safe-edge-portrait-v);
  transform: none;
}
.app[data-orientation="portrait"] .stage__label--before {
  left: var(--safe-edge-portrait-h);
}
.app[data-orientation="portrait"] .stage__label--after {
  right: var(--safe-edge-portrait-h);
  left: auto;
}

.app[data-orientation="portrait"] .protocol {
  padding: var(--space-m) var(--space-l);
  /* reserve right-side space for the floating QR + label above */
  padding-right: calc(var(--qr-tile-size) + var(--space-l) + var(--safe-edge-portrait-h));
  padding-bottom: var(--space-m);
  position: relative;
  min-height: calc(var(--qr-tile-size) + var(--type-qr-label-size) * 2 + var(--space-s) + var(--space-m));
}

/* Portrait QR — floating bottom-right corner over protocol panel */
.hero__qr.hero__qr--portrait {
  display: flex;
  position: fixed;
  right: var(--safe-edge-portrait-h);
  bottom: var(--safe-edge-portrait-v);
  flex-direction: column;
  align-items: center;
  gap: var(--space-s);
  z-index: 5;
}
.hero__qr.hero__qr--portrait .qr__label {
  order: -1;
}

/* ============================================================
   Reduced motion — kill decorative animation but keep the drag
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .panel.is-dragging .panel__puck { transform: none; }
}
