/* =========================================================================
   Crumb Trail, a Daily Bread parable walk
   Vanilla CSS. No ads. Soft glow for kindness, gentle redirect for a miss.
   Harvest-adjacent warm palette, tuned to the Snack Quests storefront loaf.
   ========================================================================= */

:root {
  --cream: #fff6eb;
  --paper: #fff1dc;
  --peach: #ffd4b8;
  --cookie: #c4783a;
  --cookie-dark: #8b4e1f;
  --jam: #d64545;
  --gold: #f4b942;
  --bread: #e8a838;
  --mint: #7bc47f;
  --sky: #7eb8d4;
  --ink: #3b2a1a;
  --ink-soft: #5c4633;
  --white: #fffcf7;
  --dur: 260ms;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overscroll-behavior: none;
  background: var(--cream);
}

body {
  font-family: "Nunito", "Segoe UI", sans-serif;
  color: var(--ink);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; }
.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;
}

/* Keep tappable controls at least 44 CSS pixels on every viewport. */
button,
a.sq-studio {
  min-width: 44px;
  min-height: 44px;
}

/* ------------------------------- Opening -------------------------------- */
#sq-open {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #1a120c;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#sq-open.is-off { display: none !important; }
#sq-open .sq-stage {
  position: relative;
  width: min(100%, 920px);
  max-height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#sq-open .sq-art {
  display: block;
  width: min(100%, 100dvh);
  height: auto;
  max-height: calc(100dvh - 96px);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  object-position: center;
  margin: 0 auto;
  border-radius: 8px;
  background: #4aa3d6;
}
#sq-open .sq-continue {
  position: absolute;
  right: 4%;
  bottom: 5%;
  left: auto;
  transform: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-width: 44px;
  min-height: 44px;
}
#sq-open .sq-continue img {
  display: block;
  width: 72px;
  height: auto;
  filter: drop-shadow(0 4px 6px rgba(59, 42, 26, 0.45));
}
#sq-open .sq-continue:active img { transform: scale(0.94); }
#sq-open .sq-continue:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  border-radius: 50%;
}
#sq-open .sq-howto {
  display: none;
  width: min(100%, 560px);
  max-height: 92dvh;
  overflow: auto;
  box-sizing: border-box;
  padding: 8px;
}
#sq-open.is-howto .sq-stage { display: none; }
#sq-open.is-howto .sq-howto { display: block; }
#sq-open .sq-levels {
  display: none;
  width: min(100%, 560px);
  max-height: 92dvh;
  overflow: auto;
  box-sizing: border-box;
  padding: 8px;
}
#sq-open.is-levels .sq-stage,
#sq-open.is-levels .sq-howto { display: none; }
#sq-open.is-levels .sq-levels { display: block; }
#sq-open .sq-levels-card {
  background: var(--paper);
  background-clip: padding-box;
  color: #3b2a1a;
  border-style: solid;
  border-width: 30px;
  border-image: url(../assets/ui/card-frame.png) 150 / 30px stretch;
  padding: 12px 14px 18px;
  text-align: center;
  box-sizing: border-box;
}
#sq-open .sq-levels-card h2 {
  margin: 0 0 14px;
  font-family: "Fredoka", Georgia, serif;
  font-size: clamp(22px, 5vw, 30px);
  line-height: 1.2;
}
.level-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.level-btn {
  display: flex;
  flex-direction: column;
  width: 100%;
  box-sizing: border-box;
  border-style: solid;
  border-width: 14px;
  border-image: url(../assets/ui/badge-frame.png) 90 / 14px stretch;
  background: var(--white);
  background-clip: padding-box;
  padding: 0;
  overflow: hidden;
  text-align: left;
  cursor: pointer;
  min-width: 44px;
  min-height: 56px;
}
.level-btn-heading {
  display: block;
  padding: 10px 12px 8px;
  box-sizing: border-box;
}
.level-btn strong {
  display: block;
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  font-size: 18px;
  color: var(--ink);
}
.level-btn-heading span {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.level-btn-bg {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  object-position: center 65%;
}
.level-btn-bg--richfool { object-position: center 78%; }
.level-btn-bg--prodigal { object-position: center 60%; }
.level-btn-bg--virgins { object-position: center 70%; }
.level-btn:active { transform: translateY(2px); }
#sq-open .sq-howto-card {
  background: var(--paper);
  background-clip: padding-box;
  color: #3b2a1a;
  border-style: solid;
  border-width: 30px;
  border-image: url(../assets/ui/card-frame.png) 150 / 30px stretch;
  padding: 12px 14px 18px;
  text-align: center;
  box-sizing: border-box;
}
#sq-open .sq-howto-scroll {
  display: block;
  width: 72px;
  height: auto;
  margin: 0 auto 8px;
  filter: drop-shadow(0 3px 3px rgba(59, 42, 26, 0.3));
}
#sq-open .sq-howto-card h2 {
  margin: 0 0 12px;
  font-family: "Fredoka", Georgia, serif;
  font-size: clamp(22px, 5vw, 30px);
  line-height: 1.2;
}
#sq-open .sq-howto-card p {
  margin: 0 0 10px;
  font-size: clamp(15px, 3.6vw, 18px);
  line-height: 1.45;
  text-align: left;
}
#sq-open .sq-play {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  margin: 14px auto 0;
  display: block;
}
#sq-open .sq-play img {
  display: block;
  width: 84px;
  height: auto;
  filter: drop-shadow(0 4px 6px rgba(59, 42, 26, 0.4));
  transition: transform 120ms ease;
}
#sq-open .sq-play:active img { transform: scale(0.94); }
#sq-open .sq-studio {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: #fff6eb;
  background: rgba(26, 18, 12, 0.78);
  border: 2px solid #e8a838;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px 8px 8px;
  font-family: "Fredoka", Georgia, serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
#sq-open .sq-studio svg {
  display: block;
  width: 22px;
  height: 22px;
  flex: none;
}

/* ------------------------------- App shell ------------------------------- */
#app {
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
  gap: 10px;
  background:
    radial-gradient(circle at 12% 8%, #ffe4c4 0, transparent 28%),
    radial-gradient(circle at 90% 0%, #ffd6d0 0, transparent 24%),
    linear-gradient(180deg, var(--cream), #ffe8c8 40%, #fff6eb 100%);
}
#app.is-glowing {
  background:
    radial-gradient(circle at 50% 40%, rgba(244, 185, 66, 0.45) 0, transparent 55%),
    linear-gradient(180deg, #fff4c8, #ffe08a 40%, #fff6eb 100%);
}

.hud {
  width: min(94vw, 520px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.track-tag {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cookie-dark);
  background: transparent;
  border: 0;
  border-style: solid;
  border-width: 10px 16px;
  border-image: url(../assets/ui/badge-frame.png) 90 / 10px 16px stretch;
  margin: 0;
}

.heart-meter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--cookie-dark);
}
.crook-icon {
  height: 24px;
  width: auto;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(59, 42, 26, 0.35));
}
.heart-meter__hearts {
  display: flex;
  gap: 2px;
}
.heart-icon {
  width: 20px;
  height: auto;
  display: block;
  opacity: 0.32;
  filter: grayscale(0.6);
  transition: opacity 400ms ease, filter 400ms ease, transform 400ms ease;
}
.heart-icon.is-filled {
  opacity: 1;
  filter: none;
  transform: scale(1.08);
}
.heart-meter.is-lit .heart-icon.is-filled {
  filter: drop-shadow(0 0 6px rgba(244, 185, 66, 0.9));
}

.stage-info {
  text-align: center;
  box-sizing: border-box;
  width: 100%;
  min-height: 80px;
  padding: 20px 16% 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: url(../assets/ui/banner-frame.png) center / 100% 100% no-repeat;
}
.stage-info__title {
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  font-size: clamp(18px, 4.6vw, 24px);
  font-weight: 700;
  color: var(--ink);
}
.stage-info__subtitle {
  font-size: clamp(11px, 3vw, 13px);
  color: var(--ink-soft);
  margin-top: 2px;
  line-height: 1.3;
}
.hud-divider {
  display: block;
  width: min(80vw, 420px);
  height: auto;
  margin: -2px auto 0;
  opacity: 0.85;
}

.stage-dots {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
}
.stage-dots li {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--paper);
}
.stage-dots li.is-done { background: var(--gold); }
.stage-dots li.is-now {
  background: var(--mint);
  transform: scale(1.2);
}

.stage-wrap {
  width: min(94vw, 520px);
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* ------------------------------- Trail path ------------------------------ */
.trail-scene {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  max-height: min(68dvh, 560px);
  box-sizing: border-box;
  border-style: solid;
  border-width: 22px;
  border-image: url(../assets/ui/card-frame.png) 150 / 22px stretch;
  border-radius: 20px;
  overflow: hidden;
  background: #7eb8d4;
  background-clip: padding-box;
  box-shadow: 0 8px 0 rgba(59, 42, 26, 0.12);
}
.trail-scene svg.backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.trail-scene img.backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 62%;
  display: block;
}
.trail-scene img.backdrop.scene-richfool { object-position: center 75%; }
.trail-scene img.backdrop.scene-prodigal { object-position: center 60%; }
.trail-scene img.backdrop.scene-virgins { object-position: center 68%; }
.crumb {
  position: absolute;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: url(../assets/crumb.png) center / 78% no-repeat;
  transform: translate(-50%, -50%);
  cursor: pointer;
  z-index: 2;
  filter: drop-shadow(0 2px 2px rgba(59, 42, 26, 0.4));
}
.crumb.is-decoy {
  background-image: url(../assets/crumb-moldy.png);
  filter: drop-shadow(0 2px 2px rgba(59, 42, 26, 0.4));
  opacity: 0.92;
}
.crumb.is-done {
  filter: none;
  opacity: 0.32;
  pointer-events: none;
}
.crumb.is-glow {
  z-index: 3;
  animation: soft-glow 1.5s ease-in-out infinite;
}
.crumb.is-shake { animation: gentle-shake 480ms ease; }
.crumb:active { filter: brightness(0.9); }

@keyframes soft-glow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 246, 235, 0.4), 0 0 12px 4px rgba(244, 185, 66, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(255, 246, 235, 0.55), 0 0 22px 8px rgba(244, 185, 66, 0.8); }
}
@keyframes gentle-shake {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(calc(-50% - 7px), -50%); }
  75% { transform: translate(calc(-50% + 7px), -50%); }
}

.loaf {
  position: absolute;
  width: 58px;
  height: 58px;
  transform: translate(-50%, -78%);
  z-index: 4;
  pointer-events: none;
  transition: left 420ms ease, top 420ms ease;
  filter: drop-shadow(0 4px 0 rgba(59, 42, 26, 0.18));
}
.loaf svg { width: 100%; height: 100%; display: block; }

/* ----------------------------- Pattern match ----------------------------- */
.match-board {
  width: 100%;
  box-sizing: border-box;
  background: var(--white);
  background-clip: padding-box;
  border-style: solid;
  border-width: 24px;
  border-image: url(../assets/ui/card-frame.png) 150 / 24px stretch;
  border-radius: 20px;
  padding: 12px 12px 16px;
  box-shadow: 0 8px 0 rgba(59, 42, 26, 0.12);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}
.match-preview {
  display: flex;
  gap: 10px;
  min-height: 64px;
  align-items: center;
  justify-content: center;
}
.match-chip {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--cookie-dark);
  background: var(--paper);
  display: grid;
  place-items: center;
}
.match-chip img { width: 78%; height: 78%; display: block; object-fit: contain; }
.match-chip.is-empty { background: #f3e6d8; }
.match-pads {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: min(100%, 280px);
}
.match-pad {
  aspect-ratio: 1;
  box-sizing: border-box;
  border-style: solid;
  border-width: 12px;
  border-image: url(../assets/ui/badge-frame.png) 90 / 12px stretch;
  background: var(--paper);
  background-clip: padding-box;
  cursor: pointer;
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 72px;
}
.match-pad img { width: 56%; height: 56%; display: block; object-fit: contain; }
.match-pad.is-glow {
  background: #fff4c4;
  animation: soft-glow 900ms ease;
}
.match-pad.is-shake { animation: pad-shake 480ms ease; }
.match-pad:active { transform: scale(0.96); }
.match-pad:disabled { cursor: default; }
@keyframes pad-shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.match-status {
  font-size: 14px;
  font-weight: 700;
  color: var(--cookie-dark);
  min-height: 1.3em;
}

/* -------------------------------- Overlays ------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(59, 42, 26, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
}
.overlay[hidden] { display: none; }
.overlay--glow { background: rgba(232, 168, 56, 0.28); }
.overlay__card {
  width: min(92vw, 420px);
  box-sizing: border-box;
  background: var(--white);
  background-clip: padding-box;
  border-style: solid;
  border-width: 30px;
  border-image: url(../assets/ui/card-frame.png) 150 / 30px stretch;
  border-radius: 20px;
  padding: 10px 10px 16px;
  box-shadow: 0 10px 0 rgba(59, 42, 26, 0.18);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 86vh;
  overflow-y: auto;
  touch-action: pan-y;
}
.overlay__card--glow {
  background: linear-gradient(180deg, #fffaf2, #ffe9a8);
  background-clip: padding-box;
  box-shadow: 0 0 28px rgba(244, 185, 66, 0.55), 0 10px 0 rgba(59, 42, 26, 0.12);
}
.overlay__eyebrow {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cookie);
}
.overlay__title {
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  font-size: 24px;
  font-weight: 700;
}
.overlay__body {
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-soft);
}
.overlay__verse {
  font-size: 16px;
  font-style: italic;
  line-height: 1.5;
  background: #ffe9a8;
  border-radius: 12px;
  padding: 12px 14px;
}
.overlay__ref {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cookie-dark);
}

.fork-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.fork-btn {
  box-sizing: border-box;
  border-style: solid;
  border-width: 14px;
  border-image: url(../assets/ui/badge-frame.png) 90 / 14px stretch;
  border-radius: 16px;
  background: var(--paper);
  background-clip: padding-box;
  padding: 6px 8px;
  text-align: left;
  cursor: pointer;
  min-width: 44px;
  min-height: 56px;
}
.fork-btn strong {
  display: block;
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  font-size: 18px;
}
.fork-btn span {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
}
/* Colored by role, not by the literal word - which word is the redirect
   varies by story (it's "Wait" for the Samaritan, "Store it all" for the
   Rich Fool), so buildForkStage() assigns these classes itself instead of
   matching a specific label here. */
.fork-btn--glow-a { background: #e7f6ea; }
.fork-btn--glow-b { background: #fff4c4; }
.fork-btn--redirect { background: #f3e6d8; }
.fork-btn:active { transform: translateY(2px); }

.btn {
  box-sizing: border-box;
  border-style: solid;
  border-width: 16px 22px;
  border-image: url(../assets/ui/badge-frame.png) 90 / 16px 22px stretch;
  border-radius: 999px;
  padding: 4px 6px;
  font-weight: 800;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}
#chooseStoryBtn {
  background: var(--paper);
  background-clip: padding-box;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}
.btn--primary {
  background: var(--gold);
  background-clip: padding-box;
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(59, 42, 26, 0.28);
}
.btn--primary:active { box-shadow: none; transform: translateY(4px); }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(90vw, 420px);
  background: var(--white);
  color: var(--ink);
  border: 3px solid var(--cookie);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  z-index: 50;
  box-shadow: 0 6px 0 rgba(59, 42, 26, 0.12);
}
.toast[hidden] { display: none; }

@media (max-width: 380px) {
  .loaf { width: 50px; height: 50px; }
  .overlay__title { font-size: 21px; }
}
