/* Motion: buttons, panels and charts. Loaded after style.css; the extension stylesheets load later still and use the same
   tokens. Durations and curves come only from the variables on :root in style.css (--dur-*, --ease-*, --tr-ui).
   Only opacity, translate, scale, colour and shadow move: the individual `translate` and `scale` properties are used,
   not `transform`, so they never collide with the transforms the layout and the drag code already set. */

/* ---------- buttons, chips, tabs, rows: hover, press, selected <-> normal ---------- */
:where(button, summary, [role="tab"], .sr-item, .finder-item, .adv-tr, .lens-btn, .icon-btn) {
  transition: var(--tr-ui);
}
:where(button, summary, [role="tab"]) { --press: .965; }
/* Wide rows and tiles shrink less: 3.5% of a full-width row is a visible jump. */
:where(.yr-row, .city-row, .adv-bar, .adv-srow, .adv-sw, .adv-mult, .adv-card, .lg-row, .ml-row, .sp-item, #pedia-nav button, .lp-tile, .cv-site, .cv-open, .finder-x) { --press: .985; }
:where(button, summary, [role="tab"], .sr-item, .finder-item):active:not(:disabled) {
  scale: var(--press, .965);
  transition: var(--tr-press);
}
/* A tighter shadow while pressed; the selected state wins over the plain one by specificity. */
:is(button, summary, .sr-item, .finder-item):active:not(:disabled) { box-shadow: 0 1px 3px -1px rgb(10 10 10 / .35); }
:is(.btn, .lens-btn, .lp-tile, .yr-tabs button, .yr-modes button, #pedia-nav button, .adv-tabs button)[aria-pressed="true"]:active,
:is(.btn, .lens-btn, .lp-tile, .yr-tabs button, .yr-modes button, #pedia-nav button, .adv-tabs button)[aria-expanded="true"]:active,
:is(.btn, .lens-btn, .lp-tile, .yr-tabs button, .yr-modes button, #pedia-nav button, .adv-tabs button)[aria-selected="true"]:active,
:is(.lens-btn, .lp-tile, #pedia-nav button).active:active { box-shadow: 0 2px 5px -3px rgb(10 10 10 / .4); }
.yield { transition: var(--tr-ui); }
.yield::before { transition: background-color var(--dur-fast) var(--ease-out); }
.lens-more .caret { display: inline-block; transition: rotate var(--dur-mid) var(--ease-out); }
.lens-more[aria-expanded="true"] .caret { transform: none; rotate: 180deg; }
#search-input { transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
#search-input:focus-visible { box-shadow: 0 0 0 2px var(--focus-halo), 0 0 0 4px var(--focus); outline: none; }
.lg-row, .adv-bar, .adv-srow, .adv-sw, .city-row, .yr-row { transition: var(--tr-ui); }

/* ---------- panels and windows: enter and leave ---------- */
/* Every panel is shown and hidden with the [hidden] attribute (style.css: display none !important, except for these panels, whose display none is the plain rule below). Leaving works
   because `display` is a discrete transition (allow-discrete): the element stays displayed while it fades out, then
   goes to display none. Entering uses @starting-style. A browser without those two simply shows and hides at once.
   The hidden state is also pointer-events none, so a leaving panel never catches a click. */
:is(#city-panel, #lens-picker, #legend, #search-results, #share-pop, #yield-report, #toast, .lens-strip, .map-layers-pop, .app-dock, .modal, .cv-maplegend) {
  --ex: 0px; --ey: 8px; --es: .98;
  transition: opacity var(--dur-mid) var(--ease-out), translate var(--dur-mid) var(--ease-out), scale var(--dur-mid) var(--ease-out),
    display var(--dur-mid) allow-discrete;
}
#city-panel, .app-dock-right { --ex: 18px; --ey: 0px; --es: 1; transform-origin: 100% 50%; }
.app-dock-left { --ex: -18px; --ey: 0px; --es: 1; transform-origin: 0 50%; }
#lens-picker, #legend, .map-layers-pop { transform-origin: 50% 100%; }
#search-results, #share-pop, #yield-report { --ey: -6px; transform-origin: 50% 0; }
#toast, .lens-strip { --ey: -10px; --es: .96; }
.modal { --ey: 0px; --es: 1; }
:is(#city-panel, #lens-picker, #legend, #search-results, #share-pop, #yield-report, #toast, .lens-strip, .map-layers-pop, .app-dock, .modal, .cv-maplegend)[hidden] {
  display: none; opacity: 0; translate: var(--ex) var(--ey); scale: var(--es); pointer-events: none;
}
@starting-style {
  :is(#city-panel, #lens-picker, #legend, #search-results, #share-pop, #yield-report, #toast, .lens-strip, .map-layers-pop, .app-dock, .modal, .cv-maplegend) {
    opacity: 0; translate: var(--ex) var(--ey); scale: var(--es);
  }
}
/* The card of a window follows the scrim: a little scale and lift. */
.modal-card, .help-card { transition: opacity var(--dur-mid) var(--ease-out), translate var(--dur-mid) var(--ease-out), scale var(--dur-mid) var(--ease-out); }
.modal[hidden] :is(.modal-card, .help-card) { opacity: 0; translate: 0 10px; scale: .97; }
@starting-style { .modal :is(.modal-card, .help-card) { opacity: 0; translate: 0 10px; scale: .97; } }

/* Find your powiat is added and removed by app/finder.js: it enters with an animation and leaves with .leaving. */
@keyframes board-in { from { opacity: 0; translate: 0 -10px; scale: .97; } }
@keyframes board-out { to { opacity: 0; translate: 0 -10px; scale: .97; } }
.finder-back { animation: fade-in var(--dur-mid) var(--ease-out) both; }
.finder { animation: board-in var(--dur-mid) var(--ease-out) both; }
.finder-back.leaving { animation: fade-out var(--dur-mid) var(--ease-in-out) both; pointer-events: none; }
.finder-back.leaving .finder { animation: board-out var(--dur-mid) var(--ease-in-out) both; }
.cc-back { animation: fade-in var(--dur-mid) var(--ease-out) both; }
.cc-box { animation: board-in var(--dur-mid) var(--ease-out) both; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* Phone bottom sheets: they rise from below, and the swipe-down snap-back animates the real transform. */
@media (max-width: 700px) {
  #city-panel, .app-dock-left, .app-dock-right { --ex: 0px; --ey: 28px; --es: 1; transform-origin: 50% 100%; }
  #city-panel, .app-dock {
    transition: opacity var(--dur-mid) var(--ease-out), translate var(--dur-mid) var(--ease-out), scale var(--dur-mid) var(--ease-out),
      display var(--dur-mid) allow-discrete, transform var(--dur-mid) var(--ease-out);
  }
  #city-panel.dragging-sheet, .app-dock.cv-dragging { transition: none; }
}

/* ---------- charts grow once per opening ---------- */
/* ui/motion.js growOnce() sets .grow on the panel for a second and a half after it opens (or the lens or advisor
   changes). Elements that appear in that window animate once; later re-renders (a hover, a filter) do not. */
@keyframes grow-x { from { scale: 0 1; } }
@keyframes grow-y { from { scale: 1 0; } }
@keyframes reveal-x { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes pop-in { from { opacity: 0; scale: .9; translate: 0 6px; } }

/* The step of a staggered row: 0 for the first, up to 5 for the sixth and later. */
.grow :is(.ind, .yr-bar, .yr-row, .cv-ind, .adv-bar, .adv-srow, .adv-sw, .lg-row, .yield-tile, .cv-yield, .adv-tile, .cv-cr, .adv-mult) { --k: 0; }
.grow :is(.ind, .yr-bar, .yr-row, .cv-ind, .adv-bar, .adv-srow, .adv-sw, .lg-row, .yield-tile, .cv-yield, .adv-tile, .cv-cr, .adv-mult):nth-child(2) { --k: 1; }
.grow :is(.ind, .yr-bar, .yr-row, .cv-ind, .adv-bar, .adv-srow, .adv-sw, .lg-row, .yield-tile, .cv-yield, .adv-tile, .cv-cr, .adv-mult):nth-child(3) { --k: 2; }
.grow :is(.ind, .yr-bar, .yr-row, .cv-ind, .adv-bar, .adv-srow, .adv-sw, .lg-row, .yield-tile, .cv-yield, .adv-tile, .cv-cr, .adv-mult):nth-child(4) { --k: 3; }
.grow :is(.ind, .yr-bar, .yr-row, .cv-ind, .adv-bar, .adv-srow, .adv-sw, .lg-row, .yield-tile, .cv-yield, .adv-tile, .cv-cr, .adv-mult):nth-child(5) { --k: 4; }
.grow :is(.ind, .yr-bar, .yr-row, .cv-ind, .adv-bar, .adv-srow, .adv-sw, .lg-row, .yield-tile, .cv-yield, .adv-tile, .cv-cr, .adv-mult):nth-child(n+6) { --k: 5; }

/* bars: scale from the left edge (diverging negatives from the right) */
.grow :is(.yr-track i, .ind .bar i, .cv-bar > i, .adv-bar .tr i, .cv-meter > i, .adv-tr .tbar, .adv-minibar i) {
  transform-origin: 0 50%;
  animation: grow-x var(--dur-slow) var(--ease-out) both;
  animation-delay: calc(var(--k, 0) * var(--stagger));
}
.grow .adv-bars.div .tr i.neg, .grow .adv-tr .tbar { transform-origin: 100% 50%; }
/* tiles and swatches: a small rise */
.grow :is(.yield-tile, .cv-yield, .adv-tile, .lg-row .kx, .adv-sw i) {
  animation: pop-in var(--dur-mid) var(--ease-out) both;
  animation-delay: calc(var(--k, 0) * var(--stagger));
}
/* the lens histogram canvas and the chart pictures (SVG, canvas): the bars rise, the lines are wiped in */
.grow .lg-hist { transform-origin: 50% 100%; animation: grow-y var(--dur-slow) var(--ease-out) both; }
.grow .adv-hist .bar { transform-box: fill-box; transform-origin: 50% 100%; animation: grow-y var(--dur-slow) var(--ease-out) both; }
.grow :is(.cv-spark, .adv-scatter canvas, .adv-share-bar, .adv-srow .st, .adv-cols-chart svg) { animation: reveal-x var(--dur-slow) var(--ease-out) both; }
.grow .adv-donut svg { transform-origin: 50% 50%; animation: pop-in var(--dur-slow) var(--ease-out) both; }

/* ---------- reduced motion: everything is instant ---------- */
@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-mid: 0ms; --dur-slow: 0ms; --stagger: 0ms; }
  *, ::before, ::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
