@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;700&family=Inter:wght@400&family=Bodoni+Moda:wght@400;700&display=swap');

/* ---------- design tokens ---------- */
:root {
  --black: #000000;
  --dark-gray: #424141;
  --mid-gray: rgba(66, 66, 66, 0.54); /* #424242 at 54% */
  --white: #ffffff;
  --off-white: #fdfdfd;
  --mirror-gold: #e8bf93;

  --font-title: 'Source Sans Pro', sans-serif;
  --font-serif: 'Bodoni Moda', 'Bodoni 72', Georgia, serif;
  --font-ui: 'Inter', sans-serif;

  --radius-input: 8px;
  --radius-pill: 30px;
  --radius-checkbox: 4px;

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--white);
  color: var(--black);
  font-family: var(--font-serif);
  -webkit-font-smoothing: antialiased;
  /* touch: taps register immediately with no double-tap zoom (pinch still
     works), no grey tap flash, no rubber-band bounce, no text inflation */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

a, button, input, textarea, label { touch-action: manipulation; }

body {
  display: flex;
  justify-content: center;
  background: #ececec; /* visible only as letterbox on wider viewports */
  min-height: 100vh;
}

.screen {
  width: 100%;
  max-width: 390px;
  min-height: 844px;
  background: var(--white);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

img, svg { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; background: none; border: none; padding: 0; }
a { color: inherit; text-decoration: none; }

/* ---------- Screen 1: Home (node 52:7) ---------- */
/* The Figma frame is exactly 390x844 — the same as `.screen`'s own box —
   so every element below is positioned with the frame's literal pixel
   coordinates, no scaling math needed. */

.home {
  justify-content: flex-start;
}

.home-hero {
  position: relative;
  width: 390px;
  height: 424px; /* node 52:8 */
  flex: 0 0 auto;
}

.home-text {
  width: 390px;
  padding: 8px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  z-index: 10;
}

/* node 56:40: a 132px text box, then the envelope starting at x≈162.9 —
   right after the text, not pushed to the far edge */
.home-nav {
  display: flex;
  align-items: center;
  gap: 30.9px;
  height: 21px;
}

.home-nav span {
  flex: none;
  width: 132px;
  white-space: nowrap;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: 0.75px;
  color: var(--dark-gray);
}

/* Figma applies a vertical flip + 180deg rotation to this icon (net effect:
   a horizontal mirror of the raw asset) — replicated here so the envelope's
   angled flap matches the design instead of running backwards. */
.home-nav svg { flex: none; width: 18.88px; height: 13px; transform: scaleX(-1); }

/* node 52:12: Source Sans Bold 40px, 4px tracking, title case */
.home-title {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 40px;
  line-height: 115%;
  letter-spacing: 4px;
  color: var(--black);
  width: 342px;
  max-width: 100%;
  margin: 0;
}

.home-body {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 15px;
  line-height: 140%;
  letter-spacing: 0.75px;
  color: var(--dark-gray);
  margin: 0;
}

/* mirrors: nodes 56:289 (man), 56:349 (curly hair), 56:257 (straight hair).
   The source SVGs draw their circle inset within a padded square canvas
   (the visible circle is ~57% of the file's own width/height, matching
   Figma's own asset), so the border ring is a separate pseudo-element
   inset to land exactly on the drawn circle's edge, not on the padded
   image box. */
.home-mirror-wrap {
  position: absolute;
  display: block;
}

.home-mirror-wrap::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 1px solid var(--black);
  pointer-events: none;
}

/* the drawn circle isn't centered identically in every file — mirror-char-06
   and -07 share one (slightly off-center) circle position, distinct from
   mirror-char-05's — so each needs its own measured inset (via direct pixel
   scan of the rendered art) rather than one shared percentage. */
.home-mirror-1::after,
.home-mirror-2::after { inset: 21.35% 20.66% 21.70% 22.40%; }
.home-mirror-3::after { inset: 21.35% 21.53% 21.53% 21.35%; }

.home-mirror {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.home-mirror-1 { left: 71px; top: 393px; width: 402px; height: 402px; z-index: 1; }
.home-mirror-2 { left: -77px; top: 223px; width: 360px; height: 360px; z-index: 2; }
.home-mirror-3 { left: 156px; top: 182px; width: 273px; height: 273px; z-index: 3; }

/* on arrival the mirrors fall in from above and land exactly on their Figma
   spots: they accelerate down, hit, and settle with two shrinking bounces */
@keyframes mirror-drop {
  0%   { transform: translateY(-110vh); animation-timing-function: cubic-bezier(.5, 0, 1, .5); }
  60%  { transform: translateY(0);      animation-timing-function: cubic-bezier(0, .5, .5, 1); }
  74%  { transform: translateY(-22px);  animation-timing-function: cubic-bezier(.5, 0, 1, .5); }
  86%  { transform: translateY(0);      animation-timing-function: cubic-bezier(0, .5, .5, 1); }
  93%  { transform: translateY(-6px);   animation-timing-function: cubic-bezier(.5, 0, 1, .5); }
  100% { transform: translateY(0); }
}

.home-mirror-wrap { animation: mirror-drop 1.1s both; }
.home-mirror-3 { animation-delay: .1s; }
.home-mirror-2 { animation-delay: .3s; }
.home-mirror-1 { animation-delay: .5s; }

@media (prefers-reduced-motion: reduce) {
  .home-mirror-wrap,
  .flow-door-layer { animation: none; }
}

/* mirror blinks: each portrait's eye dots were pulled out of its SVG into an
   open-eye layer, alongside a closed-eye layer drawn at Figma's size (nodes
   74:566/74:567 — 2x1 and 3x1px at the 402px mirror). Both layers share the
   portrait's 576-unit canvas, so the smaller mirrors scale proportionally.
   A blink hard-swaps the two, so the dot is replaced by the line rather than
   the line sitting on top of it. */
.mirror-eyes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.mirror-eyes-closed { opacity: 0; }

/* one shared 6s cycle; each mirror's blink window is fixed at a different
   point in it (evenly 2s apart) so the three can never blink together */
.home-mirror-1 .mirror-eyes-open   { animation: mirror-open-1 6s linear infinite; }
.home-mirror-1 .mirror-eyes-closed { animation: mirror-closed-1 6s linear infinite; }
.home-mirror-2 .mirror-eyes-open   { animation: mirror-open-2 6s linear infinite; }
.home-mirror-2 .mirror-eyes-closed { animation: mirror-closed-2 6s linear infinite; }
.home-mirror-3 .mirror-eyes-open   { animation: mirror-open-3 6s linear infinite; }
.home-mirror-3 .mirror-eyes-closed { animation: mirror-closed-3 6s linear infinite; }

@keyframes mirror-open-1   { 0%, 9% { opacity: 1; } 9.01%, 13% { opacity: 0; } 13.01%, 100% { opacity: 1; } }
@keyframes mirror-closed-1 { 0%, 9% { opacity: 0; } 9.01%, 13% { opacity: 1; } 13.01%, 100% { opacity: 0; } }
@keyframes mirror-open-2   { 0%, 42% { opacity: 1; } 42.01%, 46% { opacity: 0; } 46.01%, 100% { opacity: 1; } }
@keyframes mirror-closed-2 { 0%, 42% { opacity: 0; } 42.01%, 46% { opacity: 1; } 46.01%, 100% { opacity: 0; } }
@keyframes mirror-open-3   { 0%, 75% { opacity: 1; } 75.01%, 79% { opacity: 0; } 79.01%, 100% { opacity: 1; } }
@keyframes mirror-closed-3 { 0%, 75% { opacity: 0; } 75.01%, 79% { opacity: 1; } 79.01%, 100% { opacity: 0; } }

/* main character (node 56:41). On the home frame Figma places this node as a
   horizontally flipped frame at x=249, i.e. rendered across x -11..249 — so
   the layers (cut from the node's own unflipped art) sit inside a mirrored
   wrapper. The wrapper is separate from the rig because the rig's fade-in
   animation owns `transform`. */
.home-character-rig {
  position: absolute;
  left: -11px;
  top: 620px;
  width: 260px;
  height: 227px;
  z-index: 10;
  animation: home-wave-in .9s ease-out .15s both;
}

@keyframes home-wave-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.home-char-flip {
  position: absolute;
  inset: 0;
  transform: scaleX(-1);
}

/* the art is 261.007x226.859; Figma offsets it ~1.2px left inside the frame */
.home-char-layer {
  position: absolute;
  left: -1.2px;
  top: 0;
  width: 261px;
  height: 227px;
  display: block;
}

.home-char-base { z-index: 1; } /* torso/sleeve/hair/face — never animates */

/* hand: only the hand itself rotates, pivoting at the wrist where it overlaps
   the sleeve (≈52,145 in the art's own coordinates), so the joint stays
   covered. Rest (0deg) is exactly Figma's pose; negative angles swing it away
   from the face. One unchanging shape under a pure rotation — no stutter. */
.home-char-hand {
  z-index: 2;
  transform-origin: 52px 145px;
  animation: home-hand-swing 1.8s ease-in-out infinite;
  animation-delay: 1s;
}

@keyframes home-hand-swing {
  0%, 100% { transform: rotate(0deg); }
  50%      { transform: rotate(-16deg); }
}

/* eyes: swap on their own separate, slower loop — a blink, decoupled from
   the hand entirely */
.home-char-eyes { z-index: 3; }

.home-char-eyes-open {
  animation: home-eyes-open 4.8s linear infinite;
  animation-delay: 1.6s;
}

.home-char-eyes-closed {
  opacity: 0;
  animation: home-eyes-closed 4.8s linear infinite;
  animation-delay: 1.6s;
}

@keyframes home-eyes-open {
  0%, 89%      { opacity: 1; }
  89.01%, 94%  { opacity: 0; }
  94.01%, 100% { opacity: 1; }
}

@keyframes home-eyes-closed {
  0%, 89%      { opacity: 0; }
  89.01%, 94%  { opacity: 1; }
  94.01%, 100% { opacity: 0; }
}

.home-cta {
  position: absolute;
  left: 214px;
  top: 776px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--black);
  border-radius: var(--radius-pill);
  background: var(--white);
  transition: transform .15s ease;
  box-sizing: border-box;
}

.home-cta:active { transform: scale(0.97); }

.home-cta span {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 14px;
  line-height: 1.3;
  color: var(--black);
  width: 86px;
}

.home-cta svg { width: 29px; flex: 0 0 auto; }

/* ---------- shared chrome: safety banner + nav bar (screens 2-4) ---------- */

.safety-banner {
  background: var(--off-white);
  border-bottom: 1px solid var(--black);
  padding: 8px 16px;
}

.safety-banner p {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 11px;
  line-height: 130%;
  color: var(--dark-gray);
  text-align: center;
}

.nav-bar {
  border-bottom: 1px solid var(--black);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  line-height: 17px; /* Figma's 41px bar: 17px text + 24px padding */
}

.nav-bar .nav-archive,
.nav-bar .nav-label {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 14px;
  color: var(--dark-gray);
}

.nav-bar .nav-archive.active,
.nav-bar .nav-label.active {
  font-weight: 700;
  letter-spacing: 0.56px;
  color: var(--black);
}

.top-section { flex: 0 0 auto; }

.footer {
  flex: 0 0 auto;
  margin-top: auto;
  text-align: center;
  padding: 16px;
  border-top: 1px solid var(--black);
}

.footer p {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 12px;
  color: var(--mid-gray);
}

/* ---------- Archive / My Mirror: the mirror wall (52:66, 61:469, 63:29, 63:95) ---------- */
/* Mirrors drop in with Matter.js and can be hung on the five hooks taken
   from the Figma archive layout. JS positions each mirror; CSS only draws. */

.wall {
  position: relative;
  flex: 0 0 auto;
  height: 672px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.archive-hint {
  position: absolute;
  top: 24px;
  left: 24px;
  right: 24px;
  margin: 0;
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--mid-gray);
  text-align: center;
  pointer-events: none;
}

.archive-empty {
  position: absolute;
  top: 45%;
  left: 24px;
  right: 24px;
  margin: 0;
  font-family: var(--font-serif);
  font-size: 13px;
  color: var(--mid-gray);
  text-align: center;
}

.wall-mirror {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  border-radius: 50%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  will-change: transform;
}

.wall-mirror.is-hung { z-index: 1; }

.wall-mirror.is-dragging { cursor: grabbing; z-index: 5; }
.wall-mirror:focus-visible { outline: 2px solid var(--black); outline-offset: 3px; }

/* mirror-closed.svg draws its circle at 57% of its square canvas, centred;
   blow the art up so that circle exactly fills its (round) box */
.mirror-art {
  position: absolute;
  left: -37.73%;
  top: -37.73%;
  width: 175.45%;
  height: 175.45%;
  max-width: none;
  pointer-events: none;
}

/* free hooks show faintly only while a mirror is being dragged */
.hook-ghost {
  position: absolute;
  border-radius: 50%;
  border: 1px dashed rgba(66, 66, 66, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, border-color .2s ease, background-color .2s ease;
}

.wall.dragging .hook-ghost.free { opacity: 1; }
.hook-ghost.target { border-color: var(--black); background: rgba(0, 0, 0, 0.04); }

/* the enlarged / opened mirror sits in a 390px frame centred on the wall */
.wall-viewer {
  position: absolute;
  top: 0;
  left: 50%;
  width: 390px;
  height: 100%;
  margin-left: -195px;
  z-index: 30;
  pointer-events: none;
}

.viewer-scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: none;
}

.viewer-scrim.visible { display: block; }

/* ---------- the door mirror (create flow + archive viewer) ---------- */
/* Laid out on its open surface circle. The lid is hinged at its left edge;
   swung -102.6deg it shows as the brown sliver in Figma's open art, with the
   grey rim (the lid's thickness) peeking out beside it. */

/* perspective is anchored at the hinge and kept shallow so the swing still
   reads as 3D but the open lid lands close to Figma's flat, orthographic art */
.door {
  position: absolute;
  transform-origin: 0 0;
  perspective: 3000px;
  perspective-origin: 0 50%;
  pointer-events: auto;
}

.door[hidden] { display: none; }

.door-surface {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #c69c6d;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 66:132: Bodoni Bold 22px carved into the glass — gold letters with a tight
   shadow line inside their top edges (the #mirror-engrave filter,
   js/mirror.js), lines 26px apart */
.door-answer {
  margin: 0;
  width: 80%;
  max-height: 62%; /* the widest band of the circle an 80%-wide box fits in */
  overflow: hidden;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 22px;
  line-height: 1.18;
  color: var(--mirror-gold);
  filter: url(#mirror-engrave);
  text-align: center;
  word-break: break-word;
}

.door-hinge {
  position: absolute;
  left: -3.57%;
  top: 43.1%;
  width: 5.16%;
  height: 13.8%;
  background: linear-gradient(90deg, #b6b6b6, #d0d0d0 4%, #e3e3e3 9%, #f0f0f0 14%, #f7f7f7 21%, #fafafa 35%, #b6b6b6);
  opacity: 0;
  transition: opacity .3s ease;
}

.door.is-open .door-hinge { opacity: 1; }

.door-lid {
  position: absolute;
  inset: 0;
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  transition: transform var(--swing, 1100ms) cubic-bezier(.45, .05, .3, 1);
}

.door.is-open .door-lid { transform: rotateY(-102.6deg); }

.door-rim,
.door-back,
.door-front {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.door-rim { background: #ccc; }

.door-front {
  overflow: hidden;
  transform: translateZ(0.5px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.door-back {
  background: #a67c52;
  transform: translateZ(calc(var(--thick, 4px) * -1)) rotateY(180deg);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* 61:469: the major, Bodoni Bold 22px black, across the middle of the glass */
.door-major {
  position: absolute;
  inset: 0;
  padding: 0 9.8%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  color: var(--black);
  text-align: center;
  word-break: break-word;
  opacity: 0;
  transition: opacity .25s ease .15s;
  pointer-events: none;
}

.door-major-text { margin: 0; font-weight: 700; font-size: 22px; }

/* 69:432: "-Name" in Bodoni Book 14px under the major */
.door-name { margin: 0; font-weight: 400; font-size: 14px; line-height: 1.2; }
.door-name[hidden] { display: none; }

.door.show-major .door-major { opacity: 1; }

/* the knob (the grey dot at 85% across the glass); the hit area is larger
   than the drawn dot so it's easy to tap */
.door-knob {
  position: absolute;
  left: 85%;
  top: 50%;
  width: 18%;
  height: 18%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  cursor: pointer;
}

.door-knob:focus-visible { outline: 2px solid var(--black); outline-offset: -4px; }
.door.is-open .door-knob { pointer-events: none; }

/* ---------- Create: three questions (52:126 → 69:337 → 69:217) ---------- */

/* the mirror stage is 451 / 416 / 419px tall across the three Figma steps */
.flow-stage {
  position: relative;
  flex: 0 0 auto;
  height: 451px;
  overflow: hidden; /* the arriving mirror falls in from under the nav bar */
  transition: height .5s ease;
}

.create-flow[data-step="2"] .flow-stage { height: 416px; }
.create-flow[data-step="3"] .flow-stage { height: 419px; }

.flow-door-layer {
  position: absolute;
  top: 0;
  left: 50%;
  width: 390px;
  height: 100%;
  margin-left: -195px;
  animation: mirror-drop 1.1s .15s both;
}

.create-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 0 0 auto;
}

/* line heights below pin each box to Figma's measured height (Bodoni 72's
   "normal" leading); the Bodoni Moda web font would otherwise run taller */
.create-heading {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 22px;
  line-height: 26px;
  text-align: center;
  margin: 0;
}

.flow-step:not([hidden]) { animation: flow-step-in .35s ease; }

@keyframes flow-step-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.field { display: flex; flex-direction: column; gap: 8px; }
.field[hidden] { display: none; }

.field label {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 14px;
  line-height: 17px;
  color: var(--black);
}

/* Figma strokes sit inside the box, so 11px padding + 1px border = its 12px */
.field input[type="text"] {
  border: 1px solid var(--black);
  border-radius: var(--radius-input);
  background: var(--off-white);
  padding: 11px;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 14px;
  line-height: 18px;
  color: var(--black);
  outline: none;
}

.field input[type="text"]::placeholder { color: var(--mid-gray); }

.field .textarea-wrap {
  border: 1px solid var(--dark-gray);
  border-radius: var(--radius-input);
  background: var(--off-white);
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field input[type="text"]:focus-visible,
.field .textarea-wrap:focus-within { outline: 2px solid var(--black); outline-offset: 1px; }

/* one line tall like the Figma field; grows as the answer does */
.field textarea {
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  width: 100%;
  height: 17px;
  max-height: 120px;
  overflow-y: hidden;
  padding: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 14px;
  line-height: 17px;
  color: var(--black);
}

.field textarea::placeholder { color: var(--mid-gray); }

.textarea-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.textarea-toolbar .icons { display: flex; gap: 8px; }
.textarea-toolbar img { width: 20px; height: 20px; opacity: 0.6; }
.textarea-toolbar button img { width: 18px; height: 20px; opacity: 0.75; }

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input { position: absolute; opacity: 0; width: 0; height: 0; }

.checkbox-box {
  width: 20px;
  height: 20px;
  border: 1px solid var(--black);
  border-radius: var(--radius-checkbox);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
}

.checkbox-box img { width: 14px; height: 14px; opacity: 0; transition: opacity .15s ease; }
.checkbox-row input:checked + .checkbox-box { background: var(--black); }
.checkbox-row input:checked + .checkbox-box img { opacity: 1; filter: invert(1); }
.checkbox-row input:focus-visible + .checkbox-box { outline: 2px solid var(--black); outline-offset: 2px; }

.checkbox-row span {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 14px;
  line-height: 17px;
  color: var(--dark-gray);
}

/* bottom bar (52:173 / 69:367): Back + Write/Finish */
.flow-actions {
  margin-top: auto;
  display: flex;
  gap: 12px;
  padding: 16px 20px 24px;
  border-top: 1px solid var(--black);
}

.btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 11px;
  border-radius: var(--radius-input);
  border: 1px solid var(--black);
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 15px;
  line-height: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, opacity .15s ease;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn:disabled:active { transform: none; }
.btn-back { background: var(--off-white); color: var(--mid-gray); }
.btn-write { background: var(--black); color: var(--white); }
