/* ==========================================================================
   BuildMog motion and the loops that bring people back (docs/14).
   Entrances, micro-interactions, the Home hero, the workbench (levels and
   badges), home health, guide check-off. Reads only src/tokens.css variables.
   ========================================================================== */

/* ---------- entrances ---------- */
@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes seg-pop { 0% { transform: scaleY(1); } 50% { transform: scaleY(1.9); } 100% { transform: scaleY(1); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
@keyframes ring-in { from { stroke-dashoffset: var(--len, 300); } to { stroke-dashoffset: var(--off, 0); } }
@keyframes glow-breathe { 0%, 100% { box-shadow: 0 8px 22px var(--glow); } 50% { box-shadow: 0 10px 34px var(--glow), 0 0 0 6px color-mix(in srgb, var(--accent) 12%, transparent); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.screen { animation: screen-in 320ms var(--ease-out) both; }
.grid > *, .stack > .garage-item, .stack > .guide-card, .stack > .card { animation: card-in 420ms var(--ease-out) both; animation-delay: calc(min(var(--i, 0), 10) * 45ms); }
.sheet-backdrop { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.tabbar a.on .ic, .tabbar a.on .orb { animation: pop 360ms var(--ease-spring); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary.pulse { animation: glow-breathe 2.6s ease-in-out infinite; }
.step-card .head, .step-card .body, .step-card .warn { animation: fade-up 260ms var(--ease-out) both; }
.segment.just-done::before { animation: seg-pop 420ms var(--ease-spring); }
.onboard .slide { animation: fade-up 320ms var(--ease-out) both; }
.onboard .slide > img { animation: float 5.2s ease-in-out infinite; } /* the slide's own picture, never the co-pilot clips in the cards */
.manual-card .thumb svg { transition: transform var(--dur-med) var(--ease-out), filter var(--dur-med); }
.manual-card:hover .thumb svg { transform: scale(1.04); filter: drop-shadow(0 6px 10px var(--glow)); }
.hw-pill.check.on .glyph { animation: pop 320ms var(--ease-spring); }
.reminder .btn-ghost:active .ic { animation: pop 320ms var(--ease-spring); }
/* the toast keeps its own centring transform; its entrance uses the translate property instead */
@keyframes toast-in { from { opacity: 0; translate: 0 12px; } to { opacity: 1; translate: 0 0; } }
.toast { animation: toast-in 360ms var(--ease-spring) both; }
/* a toast over the player sits under the top bar, clear of the controls and the paper manual */
.player ~ .toast { top: calc(72px + env(safe-area-inset-top)); bottom: auto; }
@media (prefers-reduced-motion: reduce) {
  .screen, .grid > *, .stack > *, .step-card .head, .step-card .body, .step-card .warn, .onboard .slide, .onboard .slide > img, .segment::before, .tabbar a.on .ic, .tabbar a.on .orb, .toast, .btn-primary.pulse { animation: none !important; }
}

/* ---------- the Home hero: the character and the next best thing to do ---------- */
.hero-card { position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center; padding: 18px 20px; margin: 4px 0 14px; border-radius: var(--radius-l); background: linear-gradient(135deg, var(--surface-solid) 0%, var(--accent-soft) 100%); border: 1px solid var(--border); box-shadow: var(--shadow-1); overflow: hidden; }
.hero-card::before { content: ''; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 22%, transparent), transparent); pointer-events: none; }
.hero-card > * { position: relative; }
.hero-card .eyebrow { margin-bottom: 4px; }
.hero-card h2 { margin: 0 0 4px; font: 400 26px/1.1 var(--font-display); letter-spacing: -0.02em; text-wrap: balance; }
.hero-card p { margin: 0; color: var(--text-2); font-size: 14.5px; max-width: 52ch; }
.hero-card .hero-bar { margin-top: 10px; }
.hero-card .hero-bar .progress-line { font-size: 11.5px; }
@media (max-width: 599px) {
  .hero-card { grid-template-columns: auto 1fr; padding: 16px; }
  .hero-card .btn { grid-column: 1 / -1; width: 100%; }
  .hero-card h2 { font-size: 23px; }
}

/* ---------- the workbench: builder level, badges ---------- */
.workbench { display: grid; gap: 10px; padding: 16px 18px; border-radius: var(--radius-m); background: var(--surface-solid); border: 1px solid var(--border); margin: 18px 0 0; }
.workbench .top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.workbench .level { font: 400 22px/1.1 var(--font-display); letter-spacing: -0.01em; }
.workbench .next { font: 500 12px var(--font-mono); color: var(--text-2); }
.workbench .bar { height: 8px; border-radius: 4px; background: var(--meter-track); overflow: hidden; }
.workbench .bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent-grad); width: var(--w, 0%); transition: width 700ms var(--ease-out); }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 6px; border-radius: 999px; border: 1px dashed var(--border-strong); color: var(--text-3); font: 600 12px/1.2 var(--font-ui); background: transparent; }
.badge-chip .dot { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; background: var(--meter-track); color: var(--text-3); font-size: 10px; }
.badge-chip.on { border-style: solid; border-color: transparent; background: var(--accent-soft); color: var(--text); }
.badge-chip.on .dot { background: var(--accent); color: var(--accent-ink); }
.badge-chip.new { animation: pop 460ms var(--ease-spring) 300ms both; box-shadow: 0 0 0 3px var(--accent-soft); }
/* the reward strip on Built it.: the level this build made and the badges it earned */
.done-overlay .workbench.reward { width: min(440px, 100%); margin: 2px 0 0; padding: 12px 16px; text-align: left; gap: 8px; background: color-mix(in srgb, var(--surface-solid) 86%, transparent); }
.done-overlay .workbench.reward .badges { justify-content: flex-start; }
/* the build card arrives like a print off the press: a small rise on the spring, never a fade, so the
   card is never see-through, even in a frozen frame */
@keyframes card-rise { from { transform: translateY(16px) scale(0.96); } to { transform: none; } }
.build-card { animation: card-rise 480ms var(--ease-spring) both; }
@media (prefers-reduced-motion: reduce) { .build-card { animation: none; } }

/* ---------- home health ring (garage) ---------- */
.health { display: grid; grid-template-columns: 72px 1fr; gap: 14px; align-items: center; padding: 14px 16px; border-radius: var(--radius-m); background: var(--surface-solid); border: 1px solid var(--border); }
.health svg { width: 72px; height: 72px; transform: rotate(-90deg); }
.health .track { fill: none; stroke: var(--meter-track); stroke-width: 7; }
.health .val { fill: none; stroke: var(--live); stroke-width: 7; stroke-linecap: round; stroke-dasharray: var(--len); stroke-dashoffset: var(--off); animation: ring-in 900ms var(--ease-out) both; }
.health.warn .val { stroke: var(--accent); }
.health.late .val { stroke: var(--warn); } /* late is a nudge with a button, not an alarm */
.health .num { position: absolute; }
.health .ringwrap { position: relative; display: grid; place-items: center; }
.health .ringwrap b { position: absolute; font: 700 15px var(--font-mono); }
.health h3 { margin: 0 0 2px; font: 400 20px/1.1 var(--font-display); }
.health p { margin: 0; color: var(--text-2); font-size: 13.5px; }

/* ---------- guide check-off ---------- */
.guide-steps.check { list-style: none; padding: 0; }
.guide-steps.check li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; padding: 8px 10px; border-radius: 12px; cursor: pointer; transition: background var(--dur-fast); }
.guide-steps.check li:hover { background: var(--surface-2); }
.guide-steps.check li .n { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; font: 700 11px var(--font-mono); color: var(--text-2); margin-top: 1px; }
.guide-steps.check li.on { color: var(--text-2); }
.guide-steps.check li.on .n { background: var(--live); border-color: var(--live); color: #fff; animation: pop 320ms var(--ease-spring); }
.guide-steps.check li.on span { text-decoration: line-through; text-decoration-color: var(--border-strong); }
.guide-progress { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 8px; font: 600 12px var(--font-mono); color: var(--text-2); }
.guide-progress .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--meter-track); overflow: hidden; }
.guide-progress .bar i { display: block; height: 100%; background: var(--live); width: var(--w, 0%); transition: width 300ms var(--ease-out); }
/* all steps ticked: the character's note with the one action that closes the loop */
.mog-note.done-note { flex-wrap: wrap; animation: card-in 360ms var(--ease-spring) both; }
.mog-note.done-note p { flex: 1 1 200px; }
/* the Ask button folds to a face once the page scrolls (phones) */
@media (max-width: 899px) {
  .mog-fab { transition: padding var(--dur-fast) var(--ease-out), width var(--dur-fast) var(--ease-out); }
  .mog-fab.mini { width: 52px; height: 52px; padding: 0; justify-content: center; }
  .mog-fab.mini span { display: none; }
}

/* ---------- scan: looking ---------- */
.field { position: relative; overflow: hidden; }
.field.looking::after { content: ''; position: absolute; left: 0; bottom: 0; width: 34%; height: 3px; border-radius: 3px; background: var(--accent-grad); animation: sweep 1.1s ease-in-out infinite; }
.stage-row.on .n { animation: pop 380ms var(--ease-spring); }
.stage-row.done .n { animation: pop 320ms var(--ease-spring); }

/* ---------- skeleton while a manual card has no blueprint yet ---------- */
.manual-card .thumb:empty, .manual-card .thumb > div:empty { background: linear-gradient(90deg, var(--bg-2) 25%, var(--surface-2) 50%, var(--bg-2) 75%); background-size: 200% 100%; animation: shimmer 1.6s linear infinite; }

/* ---------- the build screen (ui.js BuildScreen): the active stage breathes, a finished one pops ---------- */
@keyframes bld-breathe { 0%, 100% { box-shadow: 0 0 0 0 var(--glow); } 50% { box-shadow: 0 0 0 6px var(--accent-soft); } }
.bld-stage.done .n { animation: pop 320ms var(--ease-spring); }
.ob-home-chip.on .kicon { animation: pop 320ms var(--ease-spring); }
@media (prefers-reduced-motion: reduce) {
  .bld-stage .n, .bld-stage.on .n, .bld-stage.done .n, .stage-row .n, .stage-row.on .n, .stage-row.done .n, .ob-home-chip .kicon, .ob-home-chip.on .kicon { animation: none !important; }
  .bld-meter i, .ob-pilot, .ob-home-chip { transition: none; }
  .ob-pilot:hover { transform: none; }
}

/* The app's own Reduce motion switch (Settings) does what the OS setting does: main.js puts .bm-reduce-motion on <html>.
   Durations of 1 ms (not "none") so animationend and transitionend still fire for code that waits on them. */
html.bm-reduce-motion *, html.bm-reduce-motion *::before, html.bm-reduce-motion *::after {
  animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important;
  transition-duration: 1ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important;
}
