@font-face {
  font-family: "Louize Display";
  src: url("fonts/LouizeDisplay-Regular.otf") format("opentype");
  font-display: swap;
}
@font-face {
  font-family: "Brown";
  src: url("fonts/Brown-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Brown";
  src: url("fonts/Brown-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --floral: #FFFAEE;
  --peach: #FFDDC8;
  --peach-glow: #FFC7A5;
  --salmon: #FF7B67;
  --salmon-strong: #E5614D;
  --sienna: #76413A;
  --pine: #02574F;
  --aqua: #A4D6CC;
  --display: "Louize Display", "Iowan Old Style", Georgia, serif;
  --body: "Brown", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--floral);
  color: var(--sienna);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Step 1: picker ---------- */
.picker {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
}
.picker__inner { width: 100%; max-width: 720px; min-width: 0; display: grid; gap: 12px; }
.picker__step {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--salmon-strong);
}
.picker__title {
  margin: 0 0 16px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(34px, 6vw, 52px);
  line-height: 1.05;
  text-wrap: balance;
}
.picker__form { display: grid; gap: 28px; }

.field { display: grid; gap: 8px; max-width: 320px; }
.field label, .characters legend { font-weight: 700; font-size: 15px; }
.field input {
  font: inherit;
  font-size: 18px;
  color: var(--sienna);
  padding: 12px 14px;
  border: 1.5px solid #D2B5A7;
  border-radius: 10px;
  background: #fff;
}
.field input:focus-visible { outline: 3px solid var(--aqua); outline-offset: 1px; border-color: var(--pine); }

.characters { border: 0; padding: 0; margin: 0; display: grid; gap: 12px; min-width: 0; }
.characters legend { padding: 0; margin-bottom: 12px; }
.characters__list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.character-card { position: relative; display: block; cursor: pointer; }
.character-card input { position: absolute; opacity: 0; inset: 0; }
.character-card__frame {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 16px 8px 14px;
  border-radius: 18px;
  background: var(--peach);
  border: 2px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.character-card img { width: 100%; max-width: 150px; aspect-ratio: 665 / 891; object-fit: contain; }
.character-card__label { font-size: 15px; }
.character-card:hover .character-card__frame { transform: translateY(-3px); }
.character-card input:checked + .character-card__frame {
  border-color: var(--salmon-strong);
  background: #FFE8DB;
}
.character-card input:focus-visible + .character-card__frame { outline: 3px solid var(--aqua); outline-offset: 2px; }

.button {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  border-radius: 999px;
  padding: 14px 28px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s ease, background 0.15s ease;
}
.button:focus-visible { outline: 3px solid var(--aqua); outline-offset: 2px; }
.button--primary { background: var(--salmon-strong); color: var(--floral); justify-self: start; }
.button--primary:hover { transform: translateY(-1px); background: #D9543F; }
.button--ghost {
  background: rgba(255, 250, 238, 0.88);
  color: var(--sienna);
  border-color: rgba(118, 65, 58, 0.25);
  padding: 10px 18px;
  font-size: 14px;
}
.button--ghost:hover { background: var(--floral); }


/* ---------- Step 2: scene ---------- */
.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--floral);
}
.stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 2752px;
  height: 1536px;
  transform-origin: 0 0;
  overflow: hidden;
  contain: layout paint;
}
.scene__controls {
  position: absolute;
  right: 16px;
  top: calc(16px + env(safe-area-inset-top, 0px));
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* every layer is a zero-size box sitting on its anchor point;
   transforms on it rotate/scale around that point */
.layer, .pose, .breath { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.layer img { position: absolute; left: 0; top: 0; max-width: none; user-select: none; -webkit-user-drag: none; }
.show-layers .layer img { outline: 3px dashed rgba(229, 97, 77, 0.8); }

.shadow { position: absolute; border-radius: 50%; pointer-events: none; }

.fx { position: absolute; inset: 0; pointer-events: none; }
.glow {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 227, 176, 0.95) 0%, rgba(255, 199, 165, 0.45) 40%, rgba(255, 199, 165, 0) 70%);
  pointer-events: none;
}
.sparkle {
  position: absolute;
  left: 0; top: 0;
  clip-path: polygon(50% 0%, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0% 50%, 39% 39%);
}
.firefly { position: absolute; left: 0; top: 0; }
.firefly__dot {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, #FFF6DF 0%, #FFE9C7 30%, rgba(255, 233, 199, 0.35) 55%, rgba(255, 233, 199, 0) 72%);
}
.leaf { position: absolute; left: 0; top: 0; }

.dusk {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(64, 76, 140, 0.55) 0%, rgba(118, 65, 58, 0.35) 70%, rgba(62, 60, 58, 0.45) 100%);
  mix-blend-mode: multiply;
  opacity: 0;
}
.story-text {
  position: absolute;
  margin: 0;
  font-family: var(--display);
  line-height: 1.25;
  text-wrap: pretty;
}
.story-text .word { display: inline-block; white-space: pre; }
.cover { position: absolute; inset: 0; background: var(--floral); pointer-events: none; }

/* ---------- phone held upright ---------- */
.story-panel { display: none; }
.scene.is-portrait .story-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: 0;
  right: 0;
  top: var(--scene-h, 60vh);
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  padding: 16px 20px;
}
.scene.is-portrait .story-text {
  position: static;
  margin: 0 auto;
  max-width: 34ch;
  font-size: clamp(22px, 6.2vw, 30px);
  text-align: center;
}
.scene.is-portrait .scene__controls {
  top: auto;
  left: 16px;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  justify-content: center;
}
