/* Sourdough Planner — motion primitives */
/* Tasteful, mobile-safe animations. Everything is suppressed when the user
   has requested reduced motion, and nothing here blocks interaction. */

:root {
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-xs: 120ms;
  --dur-sm: 200ms;
  --dur-md: 320ms;
  --dur-lg: 480ms;
}

/* ---- Keyframes --------------------------------------------------------- */

@keyframes sd-fade-up {
  from { opacity: 0; transform: translate3d(0, 14px, 0); }
  to   { opacity: 1; transform: translate3d(0, 0, 0); }
}

@keyframes sd-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes sd-scale-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes sd-grow-in {
  from { transform: scaleY(0); opacity: 0; }
  to   { transform: scaleY(1); opacity: 1; }
}

@keyframes sd-tip-in {
  from { opacity: 0; transform: translate3d(-50%, 4px, 0) scale(0.96); }
  to   { opacity: 1; transform: translate3d(-50%, 0, 0) scale(1); }
}

/* ---- Panel entry (staggered) ------------------------------------------ */

.sd-panel {
  animation: sd-fade-up var(--dur-md) var(--ease-out-quart) both;
  animation-delay: calc(var(--sd-panel-delay, 0) * 60ms);
}

.sd-feed-planner { --sd-panel-delay: 0; }
.sd-app > .sd-panel:nth-of-type(2) { --sd-panel-delay: 1; }
.sd-app > .sd-panel:nth-of-type(3) { --sd-panel-delay: 2; }
.sd-app > .sd-panel:nth-of-type(4) { --sd-panel-delay: 3; }
.sd-app > .sd-panel:nth-of-type(5) { --sd-panel-delay: 4; }
.sd-app > .sd-panel:nth-of-type(6) { --sd-panel-delay: 5; }

/* ---- Result/insight cards --------------------------------------------- */

.sd-result-card,
.sd-insight-card {
  animation: sd-fade-up var(--dur-sm) var(--ease-out-quart) both;
}

/* ---- Method/step cards (staggered) ------------------------------------ */

.sd-step-card {
  animation: sd-fade-up var(--dur-md) var(--ease-out-quart) both;
  animation-delay: calc(var(--step-index, 0) * 40ms);
}

/* ---- Timeline proportional blocks (staggered) ------------------------- */

.sd-phase-block {
  animation: sd-fade-up var(--dur-md) var(--ease-out-quart) both;
  animation-delay: calc(var(--phase-index, 0) * 30ms);
}

.sd-phase-rail {
  transform-origin: top;
  animation: sd-grow-in var(--dur-lg) var(--ease-out-quart) both;
  animation-delay: calc(var(--phase-index, 0) * 30ms + 120ms);
}

/* ---- Button / toggle feedback ----------------------------------------- */

.btn,
.sd-secondary-btn,
.sd-mode-switch button,
.sd-unit-switch button,
.sd-tab-btn,
.theme-toggle,
[data-export-action],
#addInclusionBtn {
  transition:
    background-color var(--dur-xs) var(--ease-out-quart),
    color var(--dur-xs) var(--ease-out-quart),
    border-color var(--dur-xs) var(--ease-out-quart),
    box-shadow var(--dur-xs) var(--ease-out-quart),
    transform var(--dur-xs) var(--ease-out-quart);
}

.btn:active,
.sd-secondary-btn:active,
[data-export-action]:active,
.sd-mode-switch button:active,
.sd-unit-switch button:active,
.sd-tab-btn:active,
.theme-toggle:active {
  transform: scale(0.97);
}

/* Inputs: soft focus ring instead of the browser default. */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  transition: box-shadow var(--dur-sm) var(--ease-out-quart), border-color var(--dur-sm) var(--ease-out-quart);
}

/* ---- Tab cross-fade --------------------------------------------------- */

.sd-tab-content {
  animation: sd-fade-in var(--dur-sm) var(--ease-out-quart);
}

/* ---- App-shell view transitions --------------------------------------- */
/* Each Plan/Feed/Timeline/Method/Diary view fades + slides up gently when
   it becomes the active view. */

.ll-view:not([hidden]) {
  animation: sd-fade-up 240ms var(--ease-out-quart) both;
}

/* ---- Hero KPI value: subtle "rise" when the number changes ------------ */

.ll-hero-value {
  transition: color 200ms var(--ease-out-quart);
  display: inline-block;
}

.ll-hero-value.is-changing {
  animation: ll-rise-pop 360ms var(--ease-out-back);
}

@keyframes ll-rise-pop {
  0%   { transform: translateY(2px) scale(0.96); }
  55%  { transform: translateY(-1px) scale(1.06); }
  100% { transform: translateY(0)    scale(1); }
}

/* ---- Live-timer step: pulse on transition ----------------------------- */
/* When the step index changes the live card glows for a beat so the user's
   eye is drawn to the new step. */

.ll-live-card {
  transition: box-shadow 320ms var(--ease-out-quart);
}

.ll-live-card.is-step-changed {
  animation: ll-live-pulse 1100ms var(--ease-out-quart);
}

@keyframes ll-live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(184, 112, 63, 0.0); }
  20%  { box-shadow: 0 0 0 6px rgba(184, 112, 63, 0.28); }
  100% { box-shadow: 0 0 0 0 rgba(184, 112, 63, 0.0); }
}

/* ---- Goal chip selection bounce --------------------------------------- */

.ll-goal-chip {
  transition: background-color 150ms var(--ease-out-quart),
              color 150ms var(--ease-out-quart),
              border-color 150ms var(--ease-out-quart),
              transform 220ms var(--ease-out-back);
}

.ll-goal-chip.is-active {
  animation: ll-chip-pop 360ms var(--ease-out-back);
}

@keyframes ll-chip-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ---- Kitchen timer urgent: amber pulse near zero ---------------------- */
/* JS toggles `.is-urgent` on the timer row when remaining < 60s. */

.ll-ktimer.is-urgent {
  animation: ll-ktimer-urgent 1.3s ease-in-out infinite;
}

@keyframes ll-ktimer-urgent {
  0%, 100% { background-color: transparent; }
  50%      { background-color: rgba(216, 110, 50, 0.16); }
}

/* ---- Tab-bar active-tab tick ------------------------------------------ */

.ll-tab[aria-pressed="true"] .ll-tab-icon,
.ll-tab[aria-pressed="true"] svg {
  animation: ll-tab-bounce 360ms var(--ease-out-back);
}

@keyframes ll-tab-bounce {
  0%   { transform: scale(0.92); }
  60%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ---- Rising-loaf animation in live timer (bulk/proof phases) ---------- */

.ll-live-loaf {
  display: flex;
  justify-content: center;
  margin: 0.5rem 0 0.25rem;
}

.ll-live-loaf svg {
  width: 96px;
  height: 72px;
}

.ll-live-loaf-dough {
  transform-origin: 40px 56px;
  animation: ll-dough-rise 4.6s ease-in-out infinite;
}

@keyframes ll-dough-rise {
  0%, 100% { transform: scaleY(0.78); }
  50%      { transform: scaleY(1); }
}

/* ---- Empty-state illustration ---------------------------------------- */

.ll-empty-art {
  width: 200px;
  height: auto;
  max-width: 75%;
  margin: 0 auto 0.75rem;
  display: block;
  /* Gentle entrance — lifts in like the loaf is settling on the board. */
  animation: ll-empty-settle 700ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes ll-empty-settle {
  0%   { opacity: 0; transform: translateY(10px) scale(0.94); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* All animations respect reduced-motion. */
@media (prefers-reduced-motion: reduce) {
  .ll-view,
  .ll-hero-value.is-changing,
  .ll-live-card.is-step-changed,
  .ll-goal-chip.is-active,
  .ll-ktimer.is-urgent,
  .ll-tab[aria-pressed="true"] .ll-tab-icon,
  .ll-tab[aria-pressed="true"] svg,
  .ll-live-loaf-dough,
  .ll-empty-art {
    animation: none !important;
  }
}

/* ---- Glossary tooltip -------------------------------------------------- */

.sd-term-tip {
  animation: sd-tip-in var(--dur-sm) var(--ease-out-back) both;
}

/* ---- Reduced motion ---------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* A5 native-feel: hover styling only on devices that can truly hover.
   On touch, WebView :hover 'sticks' after a tap - every hover rule was
   moved here mechanically (bodies unchanged) so taps stay clean. */
@media (hover: hover) {
.btn:hover, .sd-secondary-btn:hover, [data-export-action]:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
}
