/*
 * plnnd logo animations: split wordmark, loading screen, scroll-tracking header logo.
 * Framework-free. Pair with plnnd-logo.js (or loader-snippet.html for the loader on its own).
 *
 * How it works: the wordmark is drawn twice on top of itself. The back layer ("history",
 * espresso) is clipped to the left of the cut, the front layer ("plan", tangerine) to the
 * right of it. --plnnd-cut is the cut position in % of the logo width; moving it moves the split.
 *   -1.5  = all tangerine   60.8 = brand rest position   101.5 = all espresso
 *
 * DO NOT let a CSS minifier merge the two scroll rules marked below (see README, "Pitfalls").
 */

/* Registering the property is what lets the browser animate the cut smoothly.
   Without it the cut jumps from start to end instead of sliding. */
@property --plnnd-cut { syntax: "<number>"; inherits: true; initial-value: 60.8; }

/* Colours. Light mode values from the brand kit. */
:root {
  --plnnd-hist: #2A1A12;        /* espresso: left of the cut */
  --plnnd-plan: #D9540F;        /* deep tangerine: right of the cut */
  --plnnd-loader-bg: #FAF6F2;   /* warm white: loading screen background */
  --plnnd-gap: 0.59;            /* half the brand gap at the cut, % of logo width */
}
/* Dark mode, three ways in: system setting, data-theme="dark", or class "dark" on <html>.
   If the app uses a different switch, set the same three colours under that switch instead. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not(.light) {
    --plnnd-hist: #FAF6F2; --plnnd-plan: #FF6A1F; --plnnd-loader-bg: #2A1A12;
  }
}
:root[data-theme="dark"], :root.dark {
  --plnnd-hist: #FAF6F2; --plnnd-plan: #FF6A1F; --plnnd-loader-bg: #2A1A12;
}

/* ---------- The split wordmark ---------- */
.plnnd-wm {
  position: relative; display: inline-block; vertical-align: middle; line-height: 0;
  aspect-ratio: 261.525 / 69.825;
  height: 34px; /* default; the logo must never be narrower than 120px */
}
.plnnd-wm svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.plnnd-wm__hist { color: var(--plnnd-hist); clip-path: inset(0 calc((100 - var(--plnnd-cut) + var(--plnnd-gap)) * 1%) 0 0); }
.plnnd-wm__plan { color: var(--plnnd-plan); clip-path: inset(0 0 0 calc((var(--plnnd-cut) + var(--plnnd-gap)) * 1%)); }

/* ---------- Loading screen ---------- */
.plnnd-loader {
  position: fixed; inset: 0; z-index: 2147483000; display: grid; place-items: center;
  background: var(--plnnd-loader-bg);
  transition: opacity .4s ease, visibility .4s;
}
/* The loader's sweep starts with the cut left of the logo (was an inline style in index.html; the security policy
   allows no inline styles). The app moves the cut through the style API, which the policy allows. */
.plnnd-loader .plnnd-wm { --plnnd-cut: -1.5; }
.plnnd-loader.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.plnnd-loader .plnnd-wm { height: auto; width: min(64vw, 320px); }
/* One sweep left to right takes 1.6 s, then it sweeps back, and so on until hidden. */
.plnnd-loader:not(.is-hidden) .plnnd-wm { animation: plnnd-sweep 1.6s cubic-bezier(.65, 0, .35, 1) infinite alternate; }
@keyframes plnnd-sweep { from { --plnnd-cut: -1.5; } to { --plnnd-cut: 101.5; } }
@media (prefers-reduced-motion: reduce) {
  .plnnd-loader:not(.is-hidden) .plnnd-wm { animation: none; --plnnd-cut: 60.8; }
}

/* ---------- Scroll-tracking header logo ----------
   Page-scroll mode: the browser drives the cut from the page's scroll position, no script work.
   plnnd-logo.js adds .plnnd-wm--page-scroll only when the browser supports this; otherwise
   (and for scrolling panels inside the app) the script sets --plnnd-cut itself. */
@keyframes plnnd-track { from { --plnnd-cut: -1.5; } to { --plnnd-cut: 101.5; } }
@supports (animation-timeline: scroll()) {
  .plnnd-wm.plnnd-wm--page-scroll { animation: plnnd-track linear both; }
  /* KEEP SEPARATE: a separate, more specific rule, so a minifier can't fold the timeline into the
     animation shorthand above. Browsers reject a timeline inside the shorthand and the logo freezes. */
  html .plnnd-wm.plnnd-wm--page-scroll { animation-timeline: scroll(root block); }
}

/* ---------- PLNND app additions ----------
   Linked from index.html as a plain file (not imported through the app build), so the build's CSS
   minifier never touches the rules above. */

/* Start-up screen: one plain line under the logo says what is happening */
.plnnd-loader__inner { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 0 16px; text-align: center; }
.plnnd-loader__step {
  margin: 0; min-height: 1.45em; max-width: 40ch;
  font: 500 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--plnnd-hist); opacity: .72;
}
.plnnd-loader__retry {
  display: none; margin-top: -6px; padding: 7px 16px; border: 0; border-radius: 8px; cursor: pointer;
  font: 600 13px/1 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--plnnd-plan); color: #FFFFFF;
}
.plnnd-loader.has-problem .plnnd-loader__retry { display: inline-block; }
/* Something needs the user: the logo stops in the brand position.
   !important because the logo's starting position is set inline on the element. */
.plnnd-loader.has-problem .plnnd-wm { animation: none; --plnnd-cut: 60.8 !important; }

/* Small sweeping logo for waits inside the app (saving, chart, chat). Never narrower than 120 px. */
.plnnd-wm.plnnd-wm--working { height: 32px; animation: plnnd-sweep 1.6s cubic-bezier(.65, 0, .35, 1) infinite alternate; }
/* Reduced motion: the logo stands still in the brand position (also for the start-up screen, whose
   rule above loses to the inline starting position without !important) */
@media (prefers-reduced-motion: reduce) {
  .plnnd-wm.plnnd-wm--working { animation: none; }
  .plnnd-loader .plnnd-wm, .plnnd-wm.plnnd-wm--working { --plnnd-cut: 60.8 !important; }
}
