:root {
  --cream: #FBF3E2;
  --cream-2: #F5E9D0;
  --ink: #4A3221;
  --ink-soft: #6b4d34;
  --green: #7DA654;
  --shadow: rgba(74, 50, 33, 0.18);

  --c-bechamel: #4FA8D8;
  --c-veloute: #E8A659;
  --c-espagnole: #B4432A;
  --c-tomato: #E63946;
  --c-hollandaise: #F5C518;

  --font-hand: "Patrick Hand", sans-serif;
  --font-title: "Permanent Marker", cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  font-family: var(--font-hand);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------- Canvas / viewport ----------
   The canvas is a flex sibling BELOW the hero band, not an absolutely
   positioned full-screen layer underneath it — so its own box (and the
   SVG's default overflow:hidden) physically excludes the heading's screen
   area. No amount of panning/zooming/dragging the tree can put content
   under the heading, because the canvas literally doesn't extend there. */

#viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  touch-action: none;
  cursor: grab;
  background:
    radial-gradient(ellipse at 50% 30%, #fffaf0 0%, var(--cream) 55%, var(--cream-2) 100%);
}

#viewport.grabbing { cursor: grabbing; }

#world-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#world {
  will-change: transform;
}

.node-hit {
  cursor: pointer;
}

.sauce-label {
  font-family: var(--font-title);
  fill: var(--ink);
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--cream);
  stroke-width: 6px;
  stroke-linejoin: round;
  pointer-events: none;
  user-select: none;
}

.derivative-label {
  font-family: var(--font-hand);
  font-weight: 700;
  fill: var(--ink);
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--cream);
  stroke-width: 5px;
  stroke-linejoin: round;
  pointer-events: none;
  user-select: none;
  transition: opacity 0.15s linear;
}

/* ---------- Top bar ---------- */

#topbar {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 20;
  pointer-events: none;
}

#topbar > * { pointer-events: auto; }

#mute-btn { margin-left: auto; }
#mute-btn[aria-pressed="true"] { background: var(--c-hollandaise); }

.crayon-btn {
  font-family: var(--font-hand);
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px 18px 16px 20px / 18px 16px 20px 16px;
  padding: 8px 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  user-select: none;
}

.crayon-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--shadow);
}

.crayon-btn.round {
  padding: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 22px;
  justify-content: center;
}

.home-icon { font-size: 18px; }

#breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  background: rgba(255,255,255,0.75);
  border: 2px dashed var(--ink-soft);
  border-radius: 14px;
  padding: 6px 12px;
  max-width: 60vw;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}
#breadcrumb::-webkit-scrollbar { display: none; }

#breadcrumb .crumb {
  cursor: pointer;
  color: var(--ink-soft);
  text-decoration: underline dashed;
}
#breadcrumb .crumb.current {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  cursor: default;
}
#breadcrumb .sep { opacity: 0.5; }

/* ---------- Hero heading ----------
   A permanent flex band above the canvas (see #app/#viewport) — not an
   overlay — so it always stays on screen and the tree can never scroll
   underneath it at any zoom level. */

#hero {
  position: relative;
  flex: 0 0 auto;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  padding: max(64px, calc(env(safe-area-inset-top) + 58px)) 16px 10px;
  background: var(--cream);
}

#hero-title {
  margin: 0;
  text-align: center;
  font-family: var(--font-title);
  font-weight: normal;
  line-height: 1.16;
  font-size: clamp(18px, 3.6vw, 38px);
  color: var(--ink);
  text-wrap: balance;
  max-width: 16ch;
}

.hero-word {
  display: inline-block;
  opacity: 0;
  transform: translateY(-26px) rotate(-7deg);
  animation: hero-word-in 0.6s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
  paint-order: stroke;
  -webkit-text-stroke: 7px var(--cream);
  text-shadow: 0 0 7px var(--cream), 0 0 7px var(--cream);
}
.hero-word + .hero-word { margin-left: 0.28em; }
.hero-word:nth-child(1) { animation-delay: 0.1s; }
.hero-word:nth-child(2) { animation-delay: 0.22s; }
.hero-word:nth-child(3) { animation-delay: 0.34s; }
.hero-word:nth-child(4) { animation-delay: 0.46s; }
.hero-word:nth-child(5) { animation-delay: 0.58s; }
.hero-word:nth-child(6) { animation-delay: 0.7s; }

.hero-word-accent { color: var(--c-tomato); }

@keyframes hero-word-in {
  60% { opacity: 1; transform: translateY(3px) rotate(1.5deg); }
  100% { opacity: 1; transform: translateY(0) rotate(0deg); }
}

#hero-underline {
  width: min(240px, 55vw);
  height: 14px;
  margin-top: 1px;
  overflow: visible;
}
#hero-underline path {
  fill: none;
  stroke: var(--c-tomato);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 480;
  stroke-dashoffset: 480;
  animation: hero-underline-draw 0.9s ease-out 0.95s forwards;
}
@keyframes hero-underline-draw {
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .hero-word, #hero-underline path { animation: none; opacity: 1; stroke-dashoffset: 0; }
}

@media (max-width: 560px) {
  #hero { padding-top: max(56px, calc(env(safe-area-inset-top) + 48px)); }
}

/* ---------- Falling leaves (ambient) ---------- */

#falling-leaves {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 6;
}

.falling-leaf {
  position: absolute;
  top: -8vh;
  left: var(--x, 50%);
  width: var(--size, 22px);
  height: var(--size, 22px);
  animation: leaf-fall var(--dur, 13s) linear var(--delay, 0s) infinite;
  opacity: 0;
  will-change: transform, opacity;
}

@keyframes leaf-fall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  6% { opacity: 0.9; }
  25% { transform: translate(calc(var(--drift, 40px) * 0.35), 26vh) rotate(calc(var(--spin, 300deg) * 0.3)); }
  50% { transform: translate(calc(var(--drift, 40px) * -0.25), 52vh) rotate(calc(var(--spin, 300deg) * 0.55)); }
  75% { transform: translate(calc(var(--drift, 40px) * 0.5), 78vh) rotate(calc(var(--spin, 300deg) * 0.8)); }
  94% { opacity: 0.85; }
  100% { transform: translate(var(--drift, 40px), 108vh) rotate(var(--spin, 300deg)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .falling-leaf { animation: none; display: none; }
}

/* ---------- Zoom controls ---------- */

#zoom-controls {
  position: absolute;
  right: 14px;
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
}

/* ---------- Hint bubble ---------- */

.hint-bubble {
  position: absolute;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 14px;
  box-shadow: 2px 2px 0 var(--shadow);
  z-index: 15;
  transition: opacity 0.6s ease;
  pointer-events: none;
  white-space: nowrap;
}
.hint-bubble.faded { opacity: 0; }

/* ---------- Cards (info / recipe) ---------- */

.card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(1);
  width: min(420px, 90vw);
  max-height: min(78vh, 640px);
  overflow-y: auto;
  background: #fffdf7;
  border: 3px solid var(--ink);
  border-radius: 22px 26px 22px 28px / 26px 22px 30px 22px;
  box-shadow: 6px 6px 0 var(--shadow);
  padding: 22px 22px 26px;
  z-index: 30;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.card.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -46%) scale(0.94);
}

.card-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #fff;
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
}

.card h2 {
  font-family: var(--font-title);
  font-size: 26px;
  margin: 0 4px 4px;
  line-height: 1.2;
}

.card .built-from {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0 4px 14px;
  font-style: italic;
}

.card .tagline {
  font-size: 15px;
  color: var(--ink-soft);
  margin: 0 4px 14px;
}

.card h3 {
  font-family: var(--font-hand);
  font-size: 18px;
  margin: 16px 4px 6px;
  border-bottom: 2px dashed currentColor;
  display: inline-block;
  padding-bottom: 2px;
}

.card ul, .card ol {
  margin: 6px 0 0;
  padding-left: 22px;
}

.card li { margin-bottom: 6px; line-height: 1.35; font-size: 15.5px; }

.sauce-pill {
  display: inline-block;
  font-family: var(--font-title);
  font-size: 12px;
  color: #fff;
  padding: 3px 10px;
  border-radius: 12px;
  margin-bottom: 10px;
}

/* ---------- Chef ---------- */

.chef-group, .sign-group { cursor: pointer; }
.chef-group:focus, .sign-group:focus { outline: none; }
.chef-group:focus-visible, .sign-group:focus-visible { outline: 3px dashed var(--ink); outline-offset: 10px; }

@keyframes chef-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-5px) rotate(-1deg); }
}
@keyframes chef-bob-walking {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-9px) rotate(1.5deg); }
}

.chef-body-anim {
  animation: chef-bob 2.6s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center bottom;
}
.chef-walking .chef-body-anim {
  animation: chef-bob-walking 0.5s ease-in-out infinite;
}

.chef-facing {
  transition: transform 0.15s ease;
}
.chef-facing-left .chef-facing {
  transform: scaleX(-1);
}

.chef-shadow {
  transition: transform 0.5s ease;
  transform-box: fill-box;
  transform-origin: center;
}
.chef-walking .chef-shadow {
  animation: chef-shadow-pulse 0.5s ease-in-out infinite;
}
@keyframes chef-shadow-pulse {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0.82); }
}

/* legs swing opposite each other while walking */
.chef-leg-l, .chef-leg-r { transition: transform 0.2s ease; }
.chef-walking .chef-leg-l {
  animation: chef-leg-swing 0.5s ease-in-out infinite;
}
.chef-walking .chef-leg-r {
  animation: chef-leg-swing 0.5s ease-in-out infinite reverse;
}
@keyframes chef-leg-swing {
  0%, 100% { transform: rotate(-22deg); }
  50% { transform: rotate(22deg); }
}

/* the free arm swings gently while walking; the "catch" arm is reserved
   for the fruit-catch / tap-to-wave reactions */
.chef-arm-l { transition: transform 0.2s ease; }
.chef-walking .chef-arm-l {
  animation: chef-arm-swing 0.5s ease-in-out infinite reverse;
}
@keyframes chef-arm-swing {
  0%, 100% { transform: rotate(14deg); }
  50% { transform: rotate(-14deg); }
}

.chef-arm-r { transition: transform 0.2s ease; }

@keyframes chef-wave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-32deg); }
  50% { transform: rotate(-10deg); }
  75% { transform: rotate(-26deg); }
}
@keyframes chef-catch {
  0% { transform: rotate(0deg); }
  40% { transform: rotate(-95deg); }
  70% { transform: rotate(-70deg); }
  100% { transform: rotate(0deg); }
}
.chef-catching .chef-body-anim {
  animation: chef-catch-hop 0.5s ease-out;
}
@keyframes chef-catch-hop {
  0% { transform: translateY(0); }
  35% { transform: translateY(-14px); }
  100% { transform: translateY(0); }
}

/* ---------- Instagram signpost ---------- */

.sign-sway {
  animation: sign-idle-sway 4.5s ease-in-out infinite;
}
@keyframes sign-idle-sway {
  0%, 100% { transform: rotate(-1.2deg); }
  50% { transform: rotate(1.2deg); }
}
@keyframes sign-wiggle {
  0%, 100% { transform: rotate(-1.2deg); }
  30% { transform: rotate(9deg); }
  60% { transform: rotate(-6deg); }
  100% { transform: rotate(-1.2deg); }
}

/* ---------- Falling fruit ---------- */

.falling-fruit {
  animation: fruit-fall linear forwards;
  pointer-events: none;
}
@keyframes fruit-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  8% { opacity: 1; }
  100% { transform: translateY(var(--fall-dist)) rotate(140deg); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chef-body-anim, .chef-walker, .chef-leg-l, .chef-leg-r, .chef-arm-l,
  .sign-sway, .falling-fruit {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Misc ---------- */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-width: 520px) {
  .home-label { display: none; }
  .crayon-btn { padding: 8px 12px; }
  #breadcrumb { max-width: 46vw; font-size: 14px; }
  .card { padding: 18px 16px 22px; }
  .card h2 { font-size: 22px; }
}
