/* Jack and the Beanstalk: storybook styling.
   Only transform and opacity are ever animated. */

:root {
  --parchment: #F2E6C8;
  --parchment-deep: #E6D3A3;
  --paper: #FBF4E1;
  --ink: #2B2316;
  --ink-soft: #5B4F38;
  --bean: #2D5B35;
  --bean-deep: #1D3F26;
  --leaf: #5C8A3E;
  --gold: #D9A21B;
  --gold-deep: #A9780C;
  --sky: #A8D0E6;
  --sky-deep: #5C94B4;
  --berry: #9B3B2A;
  --spring: cubic-bezier(.34, 1.56, .64, 1);

  /* depth: base -> elevated -> floating (layered, colour-tinted, low opacity) */
  --shadow-elevated:
    0 1px 1px rgba(77, 52, 12, .06),
    0 6px 14px -6px rgba(77, 52, 12, .14),
    0 28px 44px -26px rgba(45, 91, 53, .34);
  --shadow-floating:
    0 2px 2px rgba(29, 63, 38, .08),
    0 12px 22px -8px rgba(29, 63, 38, .22),
    0 34px 56px -24px rgba(77, 52, 12, .38);
  --shadow-press:
    0 1px 1px rgba(29, 63, 38, .14),
    0 3px 6px -3px rgba(29, 63, 38, .24);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.7;
  color: var(--ink);
  background-color: var(--parchment);
  background-image:
    radial-gradient(ellipse 70% 38% at 88% -4%, rgba(168, 208, 230, .75), transparent 70%),
    radial-gradient(ellipse 40% 26% at 12% 6%, rgba(217, 162, 27, .26), transparent 70%),
    radial-gradient(ellipse 60% 40% at 0% 100%, rgba(92, 138, 62, .30), transparent 70%),
    radial-gradient(ellipse 50% 36% at 100% 78%, rgba(168, 208, 230, .34), transparent 70%);
  background-attachment: fixed;
}

/* paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.35  0 0 0 0 0.26  0 0 0 0 0.12  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

header, main, footer { position: relative; z-index: 1; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -64px; z-index: 50;
  padding: 10px 16px; border-radius: 10px;
  background: var(--bean-deep); color: var(--paper); font-weight: 600;
}
.skip-link:focus-visible { top: 12px; outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- hero ---------- */
.hero {
  position: relative;
  padding: 44px 0 36px;
  overflow: hidden;
}
@media (min-width: 640px) { .hero { padding: 72px 0 52px; } }

.hero-stalk {
  position: absolute; z-index: 0; pointer-events: none;
  right: -18px; top: 0; height: 420px; width: auto;
  opacity: .28;
}
@media (min-width: 768px) {
  .hero-stalk { right: 6%; height: 108%; opacity: .95; }
}
.hero-stalk .leaf { transform-box: fill-box; transform-origin: 0% 50%; animation: sway 6s ease-in-out infinite alternate; }
.hero-stalk .l2, .hero-stalk .l4, .hero-stalk .l6 { transform-origin: 100% 50%; }
.hero-stalk .l2 { animation-delay: -1.2s; }
.hero-stalk .l3 { animation-delay: -2.4s; }
.hero-stalk .l4 { animation-delay: -3.1s; }
.hero-stalk .l5 { animation-delay: -4.2s; }
.hero-stalk .l6 { animation-delay: -5s; }
.hero-stalk .cloud { transform-box: fill-box; animation: drift 9s ease-in-out infinite alternate; }

@keyframes sway { from { transform: rotate(-4deg); } to { transform: rotate(5deg); } }
@keyframes drift { from { transform: translateX(-6px); } to { transform: translateX(8px); } }

.eyebrow {
  margin: 0 0 14px;
  font-size: .8rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--gold-deep);
}

.hero-title {
  margin: 0;
  max-width: 11ch;
  font-size: clamp(2.9rem, 10.5vw, 6rem);
  line-height: .98;
  font-weight: 650;
  letter-spacing: -0.03em;
  color: var(--bean-deep);
  font-variation-settings: "opsz" 144;
  text-wrap: balance;
}
.hero-title em {
  font-style: italic; font-weight: 500; color: var(--bean);
  display: inline-block;
  background: linear-gradient(transparent 68%, rgba(217, 162, 27, .42) 68% 90%, transparent 90%);
}

.hero-lede {
  margin: 22px 0 0; max-width: 34rem;
  font-size: 1.1rem; color: var(--ink-soft);
}

/* ---------- step vine ---------- */
.steps {
  list-style: none; margin: 34px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  max-width: 34rem;
  position: relative;
}
.step { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.step::before { /* the vine between beans */
  content: ""; position: absolute; top: 13px; left: 30px; right: -4px; height: 3px;
  border-radius: 3px; background: rgba(45, 91, 53, .25);
}
.step:last-child::before { display: none; }
.step[data-state="done"]::before { background: var(--bean); }

.bean {
  position: relative; z-index: 1;
  width: 30px; height: 30px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--paper);
  border: 2.5px solid rgba(45, 91, 53, .35);
  box-shadow: 0 2px 4px -1px rgba(77, 52, 12, .2);
  transition: transform .5s var(--spring);
  transform: scale(.82);
}
.step[data-state="current"] .bean { transform: scale(1); border-color: var(--bean); background: var(--gold); }
.step[data-state="done"] .bean { transform: scale(1); border-color: var(--bean); background: var(--bean); }
.step[data-state="done"] .bean::after {
  content: ""; position: absolute; left: 8px; top: 5px; width: 6px; height: 11px;
  border: solid var(--paper); border-width: 0 2.5px 2.5px 0; transform: rotate(40deg);
}
.step[data-state="current"] .bean { animation: bob 2.4s var(--spring) infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-3px) scale(1.06); } }

.step-label { font-size: .86rem; font-weight: 600; color: var(--ink-soft); line-height: 1.3; }
.step[data-state="current"] .step-label, .step[data-state="done"] .step-label { color: var(--bean-deep); }

/* ---------- panels ---------- */
.panel {
  position: relative;
  padding: 22px 18px 26px;
  border-radius: 24px;
  background:
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(168, 208, 230, .22), transparent 70%),
    radial-gradient(ellipse 50% 40% at 0% 100%, rgba(217, 162, 27, .12), transparent 70%),
    var(--paper);
  border: 1px solid rgba(169, 120, 12, .22);
  box-shadow: var(--shadow-elevated);
}
@media (min-width: 640px) { .panel { padding: 34px 36px 38px; } }

.panel-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 24px; }
.chapter {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: Fraunces, Georgia, serif; font-weight: 700; font-size: 1.15rem;
  color: var(--paper); background: var(--bean);
  box-shadow: 0 0 0 4px rgba(217, 162, 27, .35), var(--shadow-press);
}
.panel-title { margin: 0; font-size: clamp(1.6rem, 4.6vw, 2.15rem); line-height: 1.1; letter-spacing: -0.03em; font-weight: 650; color: var(--bean-deep); }
.panel-sub { margin: 6px 0 0; color: var(--ink-soft); max-width: 40rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 22px;
  border-radius: 999px; border: 1.5px solid transparent;
  font: inherit; font-weight: 600; line-height: 1.2; text-align: center;
  cursor: pointer; text-decoration: none; -webkit-tap-highlight-color: transparent;
  transition: transform .35s var(--spring), opacity .2s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(.97); }
.btn:focus-visible { outline: 3px solid var(--sky-deep); outline-offset: 3px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary { background: var(--bean); color: var(--paper); box-shadow: 0 1px 1px rgba(29, 63, 38, .25), 0 8px 16px -6px rgba(29, 63, 38, .5), 0 18px 28px -16px rgba(45, 91, 53, .5); }
.btn-primary:hover:not([disabled]) { background: var(--bean-deep); box-shadow: var(--shadow-floating); }
.btn-gold { background: var(--gold); color: var(--ink); box-shadow: 0 1px 1px rgba(110, 76, 6, .25), 0 8px 16px -6px rgba(169, 120, 12, .55), 0 18px 28px -16px rgba(169, 120, 12, .5); }
.btn-gold:hover:not([disabled]) { background: #E4B02E; }
.btn-ghost { background: rgba(251, 244, 225, .6); color: var(--bean-deep); border-color: rgba(45, 91, 53, .4); }
.btn-ghost:hover:not([disabled]) { background: #fff8e6; border-color: var(--bean); }
.btn-wide { width: 100%; font-size: 1.05rem; min-height: 52px; }
@media (min-width: 640px) { .btn-wide { width: auto; min-width: 240px; } }
.btn-small { min-height: 36px; padding: 6px 14px; font-size: .9rem; }

.camera-btn { display: none; }
@media (pointer: coarse) { .camera-btn { display: inline-flex; } }

/* ---------- dropzone ---------- */
.dropzone {
  position: relative; display: grid; place-items: center;
  aspect-ratio: 4 / 3; width: 100%; max-height: 420px;
  border-radius: 18px; overflow: hidden; cursor: pointer;
  background:
    radial-gradient(circle at 50% 0%, rgba(168, 208, 230, .35), transparent 65%),
    repeating-linear-gradient(135deg, rgba(217, 162, 27, .08) 0 12px, transparent 12px 24px),
    var(--parchment);
  border: 2.5px dashed rgba(45, 91, 53, .45);
  color: var(--bean);
  transition: transform .4s var(--spring), opacity .2s ease;
}
.dropzone:hover { transform: translateY(-2px); border-color: var(--bean); }
.dropzone:active { transform: scale(.99); }
.dropzone:has(input:focus-visible) { outline: 3px solid var(--sky-deep); outline-offset: 4px; }
.dropzone.is-over { transform: scale(1.015); border-color: var(--gold-deep); border-style: solid; }
.dropzone.has-photo { border-style: solid; border-color: rgba(169, 120, 12, .4); }

.drop-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 16px; }
.drop-title { font-size: 1.35rem; font-weight: 600; letter-spacing: -0.02em; color: var(--bean-deep); margin-top: 6px; }
.drop-hint { color: var(--ink-soft); font-size: .95rem; }
.photo-preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.tips { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.tips li { position: relative; padding-left: 28px; color: var(--ink-soft); }
.tips li::before { content: ""; position: absolute; left: 4px; top: .6em; width: 12px; height: 8px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: var(--gold); box-shadow: 0 0 0 2px rgba(169, 120, 12, .25); }
.privacy {
  display: flex; gap: 10px; align-items: flex-start; margin: 0;
  padding: 12px 14px; border-radius: 14px;
  background: rgba(168, 208, 230, .3); color: var(--bean-deep); font-size: .92rem; line-height: 1.55;
}
.privacy svg { flex: none; margin-top: 2px; }

/* ---------- settings controls ---------- */
.field { border: 0; margin: 0; padding: 0; min-width: 0; }
.field-label { padding: 0; margin-bottom: 10px; font-weight: 700; font-size: .82rem; letter-spacing: .1em; text-transform: uppercase; color: var(--gold-deep); }
.field-hint { margin: 10px 0 0; font-size: .9rem; color: var(--ink-soft); }

.opt-grid { display: grid; gap: 8px; }
.opt-grid-cards { grid-template-columns: 1fr 1fr; }
.opt-grid-seg { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); }
.opt { position: relative; display: block; cursor: pointer; }
.opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.opt-face {
  display: flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
  min-height: 48px; padding: 10px 12px; border-radius: 14px;
  background: var(--parchment); border: 1.5px solid rgba(45, 91, 53, .25);
  font-weight: 600; font-size: .95rem; line-height: 1.3; color: var(--ink);
  box-shadow: 0 1px 1px rgba(77, 52, 12, .06);
  transition: transform .35s var(--spring), opacity .2s ease;
}
.opt-grid-cards .opt-face { min-height: 62px; }
.opt-grid-cards .opt:first-child { grid-column: 1 / -1; }
.opt:hover .opt-face { transform: translateY(-2px); border-color: var(--bean); }
.opt:active .opt-face { transform: scale(.97); }
.opt input:checked + .opt-face {
  background: var(--bean); color: var(--paper); border-color: var(--bean-deep);
  box-shadow: 0 1px 1px rgba(29, 63, 38, .25), 0 8px 16px -8px rgba(29, 63, 38, .55);
}
.opt input:checked + .opt-face::after {
  content: ""; flex: none; width: 10px; height: 14px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: var(--gold);
}
.opt input:focus-visible + .opt-face { outline: 3px solid var(--sky-deep); outline-offset: 2px; }
.opt input:disabled + .opt-face { opacity: .55; cursor: not-allowed; transform: none; }
.dot { flex: none; width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(43, 35, 22, .25); }

/* ---------- stages / plates ---------- */
.stage {
  position: relative; display: grid; place-items: center;
  aspect-ratio: 1 / 1; width: 100%;
  border-radius: 20px; overflow: hidden;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(168, 208, 230, .45), transparent 70%),
    radial-gradient(ellipse 70% 50% at 50% 100%, rgba(92, 138, 62, .25), transparent 70%),
    var(--parchment);
  border: 1.5px dashed rgba(45, 91, 53, .3);
}
.stage.is-scene { aspect-ratio: auto; min-height: 0; display: block; background: transparent; border: 0; overflow: visible; }
.stage:has(.plate:not([hidden])) { border-style: solid; border-color: transparent; background: transparent; overflow: visible; aspect-ratio: auto; display: block; }

.stage-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px; text-align: center; color: var(--ink-soft); }
.stage-empty p { margin: 0; font-size: 1.1rem; }

.plate { margin: 0; animation: rise .6s var(--spring) both; }
/* the decorative mat sits around the picture so the art itself stays unaltered */
.plate-frame {
  padding: 12px;
  border-radius: 18px;
  background:
    linear-gradient(160deg, rgba(217, 162, 27, .85), rgba(169, 120, 12, .9) 40%, rgba(45, 91, 53, .9) 100%);
  box-shadow: var(--shadow-floating);
}
.plate-frame img { display: block; width: 100%; height: auto; border-radius: 8px; background: var(--parchment); }
.plate figcaption {
  margin-top: 14px; padding: 0 4px;
  font-family: Fraunces, Georgia, serif; font-style: italic; font-size: 1.02rem; line-height: 1.65; color: var(--ink);
}
.plate figcaption.small { font-size: .92rem; color: var(--ink-soft); font-family: "DM Sans", system-ui, sans-serif; font-style: normal; }

@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- loader ---------- */
.loader-block { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 18px; text-align: center; }
.loader-title { margin: 6px 0 0; font-size: 1.4rem; font-weight: 600; letter-spacing: -0.02em; color: var(--bean-deep); animation: pulse 1.8s ease-in-out infinite; }
.loader-note { margin: 4px 0 0; max-width: 24rem; font-size: .92rem; color: var(--ink-soft); line-height: 1.6; }
.sprout svg { overflow: visible; }
.sprout-stem { transform-box: fill-box; transform-origin: 50% 100%; animation: grow 2.6s var(--spring) infinite; }
.sprout-leaf { transform-box: fill-box; }
.sprout-leaf.a { transform-origin: 100% 100%; animation: unfurl 2.6s var(--spring) infinite; }
.sprout-leaf.b { transform-origin: 0% 100%; animation: unfurl 2.6s var(--spring) .15s infinite; }
.sprout-bean { transform-box: fill-box; transform-origin: 50% 50%; animation: wiggle 2.6s ease-in-out infinite; }
@keyframes grow { 0% { transform: scaleY(.15); opacity: 0; } 35% { opacity: 1; } 70%, 100% { transform: scaleY(1); opacity: 1; } }
@keyframes unfurl { 0%, 35% { transform: scale(0); } 80%, 100% { transform: scale(1); } }
@keyframes wiggle { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(5deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* ---------- scene cards ---------- */
.scene-card {
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px; border-radius: 20px;
  background: var(--parchment);
  border: 1px solid rgba(169, 120, 12, .25);
  box-shadow: var(--shadow-elevated);
}
.scene-title { margin: 0; font-size: 1.45rem; line-height: 1.15; letter-spacing: -0.03em; font-weight: 650; color: var(--bean-deep); }
.scene-body { min-height: 0; }
.spec-label { margin: 0 0 6px; font-size: .78rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--gold-deep); }
.spec {
  margin: 0; padding: 14px 16px; border-radius: 14px;
  background: var(--paper); border-left: 4px solid var(--gold);
  font-family: Fraunces, Georgia, serif; font-style: italic; font-size: 1rem; line-height: 1.65; color: var(--ink);
}
.scene-body .loader-block { padding: 28px 8px; }
.scene-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- errors ---------- */
.inline-error {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin: 12px 0 0; padding: 10px 14px; border-radius: 12px;
  background: rgba(155, 59, 42, .1); border: 1.5px solid rgba(155, 59, 42, .45);
  color: #7a2a1c; font-size: .95rem; line-height: 1.5; font-weight: 500;
}
.inline-error[hidden] { display: none; }
.inline-error [data-part="msg"] { flex: 1 1 14rem; }

.foot { text-align: center; padding: 0 16px 40px; color: var(--ink-soft); font-size: .88rem; }
.foot p { margin: 0 auto; max-width: 36rem; }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
