/*
  Layout and components, following the QR quiz (03-web/css) so the two read as
  one product. Colours and fonts come from theme.css.
  Type scale (px): 12 / 14 / 16 / 18 / 21 / 24 / 36 / 48 / 60, as the quiz.
*/

:root {
  --gutter: 24px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; overscroll-behavior: none; }

h1, h2, h3, h4, p, ul, ol { margin: 0; }
button, input { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--color-accent); /* coral shows on white and on navy */
  outline-offset: 3px;
}

[tabindex='-1']:focus { outline: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- type */

.display {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  font-size: 36px;
  line-height: 1.1;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.lede {
  font-size: 18px;
  line-height: 1.55;
  color: var(--color-ink-soft);
  max-width: 34em;
}

.fine-print {
  font-size: 12px;
  line-height: 1.55;
  color: var(--color-ink-soft);
  max-width: 44ch;
}

/* The brand name as text (no logo until its usage rights are confirmed), as the quiz. */
.wordmark {
  font: 600 18px / 1 var(--font-text);
  letter-spacing: 0.02em;
}

/* ---------------------------------------------------------------- controls (as the quiz) */

.button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 0 28px;
  border: 1px solid transparent;
  border-radius: var(--radius-button);
  font: 600 18px / 1 var(--font-text);
  letter-spacing: 0.01em;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.2s, opacity 0.2s, transform 0.15s var(--ease-out);
}

.button:active:not(:disabled) { transform: scale(0.985); }
.button:disabled { cursor: default; opacity: 0.45; }

.button-primary { background: var(--color-brand); color: var(--color-on-brand); }
.button-primary:active:not(:disabled) { background: var(--color-brand-deep); }

.button-quiet {
  background: transparent;
  border-color: var(--color-ink);
  color: var(--color-ink);
}

.link {
  appearance: none;
  background: none;
  border: 0;
  padding: 10px 0;
  color: var(--color-ink);
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  cursor: pointer;
  text-align: left;
}

/* ---------------------------------------------------------------- screens */

.app { position: fixed; inset: 0; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  padding:
    max(20px, env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

.screen.is-active { display: flex; flex-direction: column; }

.screen.is-entering { animation: screen-in 420ms var(--ease-out) both; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.brandbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  min-height: 40px;
  flex: none;
}

.brandbar__title { font-size: 14px; opacity: 0.8; }

/* ---------------------------------------------------------------- 1. start */

.intro__art { flex: 1 1 auto; min-height: 180px; position: relative; }
.intro__art canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.intro__text {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 20px;
  padding-bottom: 8px;
}

.intro__title { font: var(--display-weight) clamp(2.25rem, 10vw, 3rem) / 1.06 var(--font-display); letter-spacing: -0.02em; max-width: 9.5em; text-wrap: balance; }

.intro__actions { display: flex; flex-direction: column; gap: 12px; }

.consent { font-size: 14px; color: var(--color-ink); max-width: 36em; }

.intro__fineprint { flex: none; padding-top: 8px; }

/* ---------------------------------------------------------------- 2. camera */

.camera { padding: 0; background: var(--color-paper); }

.stage { position: absolute; inset: 0; overflow: hidden; }

.stage video,
.stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror, so moving left moves left */
}

/* A test photo is shown unmirrored: it isn't a mirror. Placed by main.js. */
.stage img { object-fit: contain; transform: none; background: var(--color-backdrop); }
.stage img.is-placed { inset: auto; object-fit: fill; background: none; }

.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.veil { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.veil__fill { fill: var(--color-veil); }

.rim {
  fill: none;
  stroke: var(--color-guide);
  stroke-width: 1.5;
  transition: stroke 300ms ease, stroke-width 300ms ease;
}

/* The scan's progress runs round the oval in coral, like the quiz's progress bar. */
.rim--progress {
  stroke: var(--color-accent);
  stroke-width: 3;
  stroke-linecap: round;
  transition: none;
}

.camera.is-ready .rim:not(.rim--progress) { stroke: var(--color-brand); stroke-width: 2; }

.brandbar--over {
  position: absolute;
  top: 0; left: 0; right: 0;
  align-items: center;
  padding:
    max(14px, env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    0
    max(var(--gutter), env(safe-area-inset-left));
}

.guide {
  position: absolute;
  left: 0; right: 0;
  top: var(--guide-top, 70%);
  padding: 0 var(--gutter) max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center; /* centred under the centred oval */
  gap: 14px;
}

.guide__hint {
  font: var(--display-weight) 28px / 1.15 var(--font-display);
  letter-spacing: -0.01em;
  min-height: 1.15em;
  text-wrap: balance;
}

.guide__note { font-size: 14px; color: var(--color-ink-soft); }

.checks {
  list-style: none;
  padding: 0;
  display: flex;
  gap: 22px;
  font-size: 14px;
  color: var(--color-ink-soft);
}

.checks li { display: flex; align-items: center; gap: 8px; }

.checks li::before {
  content: '';
  width: 12px; height: 12px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--color-ink-soft);
  transition: background-color 200ms ease, box-shadow 200ms ease;
}

.checks li.is-ok { color: var(--color-ink); }
.checks li.is-ok::before { background: var(--color-brand); box-shadow: inset 0 0 0 1.5px var(--color-brand); }

#read-anyway { width: auto; }

.camera.is-scanning .checks,
.camera.is-scanning .guide__note,
.camera.is-scanning #read-anyway { visibility: hidden; }

/* ---------------------------------------------------------------- notice */

.notice__body {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 20px;
  max-width: 34em;
}

/* ---------------------------------------------------------------- 3. questions (as the quiz) */

.question { padding: 0; }

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
  min-height: calc(env(safe-area-inset-top) + 56px);
  padding: env(safe-area-inset-top) var(--gutter) 0 10px;
}

.quiz-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding: 0 14px 0 6px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.quiz-back:active { background: var(--color-backdrop); }

.quiz-count { font-size: 14px; color: var(--color-ink-soft); font-variant-numeric: tabular-nums; }

.quiz-progress { flex: none; height: 2px; background: var(--color-line); }

.quiz-bar {
  display: block;
  height: 100%;
  background: var(--color-accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 0.7s var(--ease-out);
}

.question__body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-top: 36px;
}

.question-text {
  margin: 0 var(--gutter) 32px;
  font: var(--display-weight) clamp(1.875rem, 8.4vw, 2.25rem) / 1.12 var(--font-display);
  letter-spacing: -0.015em;
  text-wrap: balance;
  outline: none;
}

.options { list-style: none; padding: 0; border-top: 1px solid var(--color-line); }
.options li { border-bottom: 1px solid var(--color-line); }

.option {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.option-face {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 16px var(--gutter);
  transition: background-color 0.15s;
}

.option:active > .option-face { background: var(--color-backdrop); }

.option-label { font-size: 18px; line-height: 1.35; }

.option-mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1.5px solid var(--color-ink-soft);
  border-radius: 50%;
}

.options--multi .option-mark { border-radius: 6px; }
.option-mark svg { opacity: 0; }

/* The navy layer spreads out from the point tapped (--x, --y set in views.js). */
.option-fill {
  position: absolute;
  inset: 0;
  background: var(--color-brand);
  color: var(--color-on-brand);
  clip-path: circle(0 at var(--x, 50%) var(--y, 50%));
  transition: clip-path 0.45s var(--ease-out);
  pointer-events: none;
}

.option[aria-pressed='true'] .option-fill { clip-path: circle(150% at var(--x, 50%) var(--y, 50%)); }
.option-fill .option-face { background: none; }

.option-fill .option-mark {
  background: var(--color-on-brand);
  border-color: var(--color-on-brand);
  color: var(--color-brand);
}

.option-fill .option-mark svg { opacity: 1; }

.option[aria-disabled='true'] .option-label { color: var(--color-ink-soft); }

.question-actions { margin-top: auto; padding: 16px var(--gutter) 8px; }
.question-hint { margin-bottom: 12px; font-size: 14px; color: var(--color-brand); }
.question-hint:empty { display: none; }

/* ---------------------------------------------------------------- 4. result (as the quiz) */

.result { padding: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.result.is-active { display: block; } /* scrolls as one column */

.result-hero {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding:
    max(20px, env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    36px
    max(var(--gutter), env(safe-area-inset-left));
  background: var(--color-brand);
  color: var(--color-on-brand);
}

.reading__art {
  position: relative;
  width: min(100%, 380px);
  aspect-ratio: 4 / 5;
  margin: 0 auto;
}

.reading__art canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.reading__headline {
  font: var(--display-weight) clamp(1.875rem, 8.4vw, 2.25rem) / 1.12 var(--font-display);
  letter-spacing: -0.015em;
  text-wrap: balance;
  outline: none;
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 20px;
  margin: 20px 0 0;
  font-size: 14px;
}

.facts dt { opacity: 0.75; }
.facts dd { margin: 0; }

.profile { list-style: none; padding: 0; margin-top: 28px; }

.profile li {
  padding: 14px 0 16px;
  border-top: 1px solid rgb(255 255 255 / 0.22);
}

.profile h3 {
  font: var(--display-weight) clamp(1.75rem, 8vw, 2.25rem) / 1.06 var(--font-display);
  letter-spacing: -0.02em;
}

.profile p { margin-top: 6px; max-width: 36ch; opacity: 0.86; }

.result-main {
  padding:
    44px
    max(var(--gutter), env(safe-area-inset-right))
    max(40px, env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

.result-heading { font: var(--display-weight) 36px / 1.1 var(--font-display); letter-spacing: -0.015em; }
.result-note { margin-top: 10px; color: var(--color-ink-soft); max-width: 40ch; }
.result-extras { margin-top: 72px; }

.product-list { list-style: none; display: grid; gap: 56px; margin-top: 28px; padding: 0; }

.product-figure {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 0.9;
  margin: 0 calc(var(--gutter) * -1);
  background: var(--color-backdrop);
  border-radius: var(--radius-panel);
  overflow: hidden;
}

.product-figure img {
  width: 82%;
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  mix-blend-mode: multiply; /* white photo backgrounds disappear into the backdrop */
}

.product-step {
  position: absolute;
  top: 18px;
  left: var(--gutter);
  font: 600 14px / 1 var(--font-text);
  color: var(--color-brand);
}

.product-body { padding-top: 24px; }
.product-name { font: var(--display-weight) 36px / 1.08 var(--font-display); letter-spacing: -0.015em; }
.product-line { margin-top: 6px; font-size: 14px; color: var(--color-ink-soft); }
.product-summary { margin-top: 16px; font-size: 18px; max-width: 38ch; }

.product-detail { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--color-line); }
.product-detail h4 { margin-bottom: 6px; font: 600 14px / 1.3 var(--font-text); }

.product-detail p,
.product-reasons { color: var(--color-ink-soft); line-height: 1.55; max-width: 44ch; }

.product-reasons { padding-left: 1.1em; }
.product-reasons li + li { margin-top: 4px; }
.product-reasons li::marker { color: var(--color-accent); }

/* A required warning line (format v1.1; every sunscreen), styled as in the quiz */
.product-warning {
  margin-top: 20px;
  padding: 12px 14px;
  background: var(--color-backdrop);
  border-left: 3px solid var(--color-accent);
  font-size: 14px;
  line-height: 1.5;
  max-width: 44ch;
}

/* Text the brand kit marks as MISSING, shown only with ?review=1 */
.is-missing { display: inline-block; padding: 6px 10px; border: 1.5px dashed var(--color-accent); color: var(--color-ink); font-weight: 600; }

.result-actions {
  display: grid;
  gap: 12px;
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--color-line);
}

/* The reveal: the reading draws itself on canvas; the words follow once. */
.result.is-entering .result-hero { animation: panel-in 900ms cubic-bezier(0.65, 0, 0.35, 1) both; }
.result.is-entering .reading__headline { animation: reveal 700ms var(--ease-out) 900ms both; }
.result.is-entering .facts { animation: reveal 700ms var(--ease-out) 1000ms both; }
.result.is-entering .profile { animation: reveal 700ms var(--ease-out) 1120ms both; }
.result.is-entering .result-main { animation: reveal 700ms var(--ease-out) 1300ms both; }

@keyframes panel-in {
  from { clip-path: inset(100% 0 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- debug */

.debug-panel {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 16px));
  max-height: 45vh;
  overflow: auto;
  padding: 8px 10px;
  background: rgba(6, 31, 42, 0.86);
  color: #e8eef1;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  border-radius: 8px;
  white-space: pre;
  pointer-events: none; /* never in the way of a tap */
}

/* Only on the camera screen; the result screen has its own block of numbers. */
body:not([data-screen='screen-camera']) .debug-panel { display: none; }

.debug-data {
  margin: 32px 0 0;
  padding: 12px;
  background: var(--color-backdrop);
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

/* ---------------------------------------------------------------- larger screens */

@media (min-width: 768px) {
  :root { --gutter: 48px; }
  .button { width: auto; min-width: 240px; }
  .intro__actions, .notice__body { align-items: flex-start; }
  .intro__text { align-items: flex-start; }
  .intro__title { font-size: 60px; }
  .lede { font-size: 21px; }
  .guide__hint { font-size: 36px; }
  .question__body { width: 100%; max-width: 720px; margin: 0 auto; padding-top: 72px; }
  .quiz-header, .quiz-progress { width: 100%; max-width: 720px; margin: 0 auto; }
  .question-text { font-size: 48px; line-height: 1.06; margin-bottom: 48px; }
  .question-actions { margin-top: 32px; padding-bottom: 48px; }
  .reading__headline { font-size: 48px; line-height: 1.06; }
  .product-figure { margin: 0; }
  .product-step { left: 20px; }
  .result-actions .button { justify-self: start; }
}

/* Landscape tablets and laptops: side by side, as the quiz. */
@media (min-width: 1000px) and (min-aspect-ratio: 1/1) {
  .intro {
    display: none;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    column-gap: 48px;
  }
  .intro.is-active { display: grid; }
  .intro .brandbar { grid-column: 1 / -1; }
  .intro__art { grid-column: 2; grid-row: 2; }
  .intro__text { grid-column: 1; grid-row: 2; align-self: center; }
  .intro__fineprint { grid-column: 1 / -1; }

  .result.is-active { display: grid; grid-template-columns: minmax(400px, 0.9fr) 1fr; align-items: start; }
  .result-hero { position: sticky; top: 0; min-height: 100vh; padding: 40px 56px 56px; }
  .result-main { max-width: 640px; padding: 72px 64px 64px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }
}
