/* Surkora motion.
   One orchestrated moment (the morning brief arriving), then motion only where a person acts:
   a tile opens, a tab is chosen, a sheet is pulled, a number settles. Reduced motion is honoured at the end. */

:root {
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-io: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-glide: cubic-bezier(0.25, 1.18, 0.4, 1);
  --nav-x: 14px;
  --sub-x: 18px;
  --lift: 10px;
}

/* ---------- The brief arrives ---------- */

/* The field horizon is drawn as live SVG so its bands can be laid down one after another. */
.brief.has-field { background-image: none; }
.brief-field {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 46px;
  pointer-events: none;
}
.bf-gold { fill: var(--gold); }
.bf-green { fill: var(--leaf); }
.bf-mint { fill: var(--mint); }
html:not([data-loaded]) .brief-field path { clip-path: inset(0 100% 0 0); }

@keyframes band-wipe {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(var(--rise, 10px)); filter: blur(var(--blur, 0)); }
}
@keyframes fade-in {
  from { opacity: 0; }
}
@keyframes mark-pop {
  from { opacity: 0; transform: scale(0.3); }
}

html.intro .brief-field path { animation: band-wipe 1000ms var(--ease-out) both; }
html.intro .brief-field .bf-green { animation-delay: 110ms; }
html.intro .brief-field .bf-mint { animation-delay: 220ms; }
html.intro #briefDate { --rise: 8px; animation: rise-in 560ms var(--ease-out) 80ms both; }
html.intro #briefHead { --rise: 16px; --blur: 6px; animation: rise-in 760ms var(--ease-out) 160ms both; }
html.intro #briefCounts { --rise: 8px; animation: rise-in 560ms var(--ease-out) 320ms both; }
html.intro #briefList .vrow-head .mark { animation: mark-pop 480ms var(--ease-pop) calc(560ms + var(--n, 0) * 55ms) both; }
html.intro #briefList .vrow-answer { animation: fade-in 420ms ease-out calc(600ms + var(--n, 0) * 55ms) both; }

/* The parcel's own outline is traced, then filled. pathLength="1" makes the dash maths size-free. */
@keyframes trace {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}
@keyframes fill-in {
  from { fill-opacity: 0; }
}
.brief-shape.is-drawing path {
  stroke-dasharray: 1;
  animation: trace 1200ms var(--ease-io) both, fill-in 520ms ease-out 980ms both;
}
html.intro .brief-shape.is-drawing path { animation-delay: 260ms, 1240ms; }

/* ---------- Tiles open in place ---------- */

.vrow { transition: border-color 0.15s, transform 0.2s var(--ease-out); }
.vrow:has(> .vrow-head:not([aria-expanded="true"]):active) { transform: scale(0.985); }

::view-transition-group(*) { animation-duration: 380ms; animation-timing-function: var(--ease-out); }
::view-transition-old(*),
::view-transition-new(*) { animation-duration: 240ms; }
::view-transition-image-pair(.vrow) { overflow: clip; border-radius: var(--leaf-r-sm); }
/* The tile being opened stays above the neighbours it pushes aside. Each tile's new state is
   revealed by its moving frame instead of cross-fading, so no ghost text shows through. */
::view-transition-group(.lead) { z-index: 1; }
::view-transition-old(.vrow),
::view-transition-new(.vrow) { mix-blend-mode: normal; }
::view-transition-new(.vrow) { animation: none; }
::view-transition-old(.vrow) { animation-duration: 140ms; }
::view-transition-old(.vrow),
::view-transition-new(.vrow) {
  top: 0;
  left: 0;
  width: auto;
  height: auto;
}
::view-transition-group(vt-tabbar),
::view-transition-group(vt-appbar) { animation: none; }
::view-transition-old(vt-tabbar),
::view-transition-old(vt-appbar) { display: none; }
::view-transition-new(vt-tabbar),
::view-transition-new(vt-appbar) { animation: none; }

/* Chevrons turn with the content instead of snapping. motion.js animates the heights both ways. */
.vrow-head > .ic { transition: transform 0.42s var(--ease-glide); }
.vrow.is-closing .vrow-head > .ic { transform: none; }
.fold > summary::after { transition: transform 0.42s var(--ease-glide), margin-top 0.42s var(--ease-glide); }
.fold.is-closing > summary { border-bottom-width: 0; }
.fold.is-closing > summary::after { margin-top: -3px; transform: rotate(45deg); }

/* ---------- Content arrives in order ---------- */

/* Each child of a host steps in a beat after the one before. --k is the beat, capped at 8. */
@property --k {
  syntax: "<integer>";
  inherits: false;
  initial-value: 0;
}
:nth-child(2) { --k: 1; }
:nth-child(3) { --k: 2; }
:nth-child(4) { --k: 3; }
:nth-child(5) { --k: 4; }
:nth-child(6) { --k: 5; }
:nth-child(7) { --k: 6; }
:nth-child(8) { --k: 7; }
:nth-child(n + 9) { --k: 8; }
@keyframes step-in {
  from { opacity: 0; translate: 0 var(--lift); }
}
html[data-nav] .view.active > :not(.subtabs, .subview, #briefList),
html[data-nav] .view.active > .subview.active > *,
.subview.is-sliding > *,
.sheet.open .sheet-body > *,
.vrow-body.is-opening > *,
.is-entering > * { animation: step-in 460ms var(--ease-out) calc(60ms + var(--k) * 45ms) backwards; }
html[data-nav] #view-hoy.active > #briefList > .vrow { animation: step-in 460ms var(--ease-out) calc(90ms + var(--n, 0) * 40ms) backwards; }

/* A part that was hidden eases into place where it appears. */
@keyframes reveal {
  from { opacity: 0; translate: 0 -6px; scale: 0.985; }
}
.is-revealing { animation: reveal 420ms var(--ease-out); }
@keyframes arrive {
  from { opacity: 0; translate: 0 12px; scale: 0.97; }
}
.is-new { transform-origin: 0 100%; animation: arrive 520ms var(--ease-out); }

/* ---------- Moving between views ---------- */

.views { overflow-x: clip; }
html[data-nav="back"] { --nav-x: -14px; }
@keyframes view-in {
  from { opacity: 0; transform: translateX(var(--nav-x)); }
}
html[data-nav] .view.active { animation: view-in 320ms var(--ease-out) backwards; }
html[data-subnav="back"] { --sub-x: -18px; }
@keyframes sub-in {
  from { opacity: 0; translate: var(--sub-x) 0; }
}
.subview.is-sliding { animation: sub-in 380ms var(--ease-out) backwards; }
@media (max-width: 899px) {
  html[data-nav][data-view="mapa"] .map-pane { animation: fade-in 260ms ease-out backwards; }
}

/* One ink that glides to the chosen tab: a mint pill on phones, an underline on desktop. */
.tab-ink {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--ink-w, 0);
  height: var(--ink-h, 0);
  border-radius: 999px;
  background: var(--mint-tint);
  opacity: 0;
  pointer-events: none;
  transform: translate(var(--ink-x, 0), var(--ink-y, 0));
}
.tabbar.ink-ready .tab-ink {
  opacity: 1;
  transition: transform 520ms var(--ease-glide), width 420ms var(--ease-out), opacity 200ms;
}
.tabbar.has-ink .tab.active .ic { background: none; }
.tab .ic { transition: background 0.2s, transform 0.18s var(--ease-out); }
.tab:active .ic { transform: scale(0.9); }
@media (min-width: 900px) {
  .tabbar { position: relative; }
  .tab-ink { border-radius: 3px 3px 0 0; background: var(--emerald); }
  .tabbar.has-ink .tab::after { display: none; }
  .tab:active .ic { transform: none; }
}

/* The same idea inside a view: sub tabs and segmented choices share one sliding selection. */
.seg-buttons,
.segmented { position: relative; }
.subtabs button,
.seg-buttons button,
.segmented label { position: relative; z-index: 1; }
.subtabs button,
.seg-buttons button { transition: color 0.2s, transform 0.18s var(--ease-out); }
.glide-ink {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  box-sizing: border-box;
  width: var(--gw, 0);
  height: var(--gh, 0);
  opacity: 0;
  pointer-events: none;
  transform: translate(var(--gx, 0), var(--gy, 0));
}
.has-glide > .glide-ink { opacity: 1; }
.glide-ready > .glide-ink {
  transition: transform 460ms var(--ease-glide), width 380ms var(--ease-out), height 380ms var(--ease-out), opacity 200ms;
}
.subtabs > .glide-ink { border: 1px solid #bfe0cb; border-radius: 999px; background: var(--mint-tint); }
.seg-buttons > .glide-ink { border-radius: 10px; background: var(--surface); box-shadow: 0 1px 2px rgba(16, 35, 26, 0.14); }
.segmented > .glide-ink { border-radius: 11px; background: var(--surface); box-shadow: 0 1px 2px rgba(16, 35, 26, 0.14); }
.subtabs.has-glide button.active { border-color: transparent; background: none; }
.seg-buttons.has-glide button.active,
.segmented.has-glide input:checked + span { background: none; box-shadow: none; }
.subtabs button:active,
.seg-buttons button:active,
.segmented label:active { transform: scale(0.96); }

/* A switch knob stretches while pressed, then springs across. */
.toggle i::after { transition: transform 0.38s var(--ease-glide), width 0.2s var(--ease-out); }
.toggle:active i::after { width: 27px; }
.toggle.active:active i::after { transform: translateX(13px); }

/* ---------- Things answer a press ---------- */

.btn { transition: background 0.15s, border-color 0.15s, transform 0.18s var(--ease-out); }
.chip-btn { transition: border-color 0.15s, background 0.15s, transform 0.18s var(--ease-out); }
.icon-btn { transition: background 0.15s, color 0.15s, transform 0.18s var(--ease-out); }
.fab { transition: border-color 0.15s, color 0.15s, transform 0.18s var(--ease-out); }
.btn:not(:disabled):active,
.chip-btn:not(:disabled):active,
.icon-btn:not(:disabled):active,
.fab:active { transform: scale(0.96); }

/* ---------- Sheets ---------- */

@keyframes scrim-in { from { opacity: 0; } }
@keyframes scrim-out { to { opacity: 0; } }
.scrim:not(.hidden) { animation: scrim-in 300ms ease-out; }
.scrim.leaving { pointer-events: none; animation: scrim-out 240ms ease-in forwards; }

@media (max-width: 899px) {
  .sheet { transition: transform 280ms var(--ease-io); }
  .sheet.open { transition: transform 460ms var(--ease-sheet); }
  .sheet-grip,
  .sheet-head { touch-action: none; }
  .sheet.dragging { transition: none; }
}
@media (min-width: 900px) {
  .sheet {
    transform: translate(-50%, -47%) scale(0.97);
    transition: transform 220ms var(--ease-io), opacity 180ms ease-in;
  }
  .sheet.open {
    transform: translate(-50%, -50%);
    transition: transform 420ms var(--ease-out), opacity 220ms ease-out;
  }
}

/* ---------- Small confirmations ---------- */

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 14px) scale(0.96); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translate(-50%, 8px) scale(0.98); }
}
.toast:not(.hidden) { animation: toast-in 380ms var(--ease-out); }
.toast.leaving { animation: toast-out 200ms ease-in forwards; }

@keyframes pill-in {
  from { opacity: 0; transform: translate(-50%, -6px); }
}
.loading:not(.hidden) .loading-pill { animation: pill-in 300ms var(--ease-out) 120ms backwards; }

@keyframes badge-pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.18); }
}
.tab-badge.pop { animation: badge-pop 460ms var(--ease-out); }

@keyframes ping {
  from { opacity: 0.55; transform: scale(1); }
  to { opacity: 0; transform: scale(2.8); }
}
.net-dot { position: relative; transition: background 0.3s, box-shadow 0.3s, border-radius 0.3s, transform 0.4s var(--ease-pop); }
.net-dot::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: inherit;
  content: "";
  opacity: 0;
}
.net-dot.ping::after { animation: ping 900ms var(--ease-out); }

/* ---------- Numbers settle into place ---------- */

@property --p {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}
@keyframes ring-fill {
  from { --p: 0; }
}
.score-ring { position: relative; border: 0; --ring: var(--line-strong); }
.score-ring.low { --ring: var(--leaf); }
.score-ring.medium { --ring: var(--gold); }
.score-ring.high { --ring: var(--risk); }
.score-ring::before {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--ring) calc(var(--p) * 1%), var(--line) 0);
  content: "";
  --p: var(--score, 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7.5px), #000 calc(100% - 7px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 7.5px), #000 calc(100% - 7px));
  transition: --p 900ms var(--ease-out);
  animation: ring-fill 1200ms var(--ease-out) 150ms both;
}

.chart-line {
  stroke-dasharray: 1;
  animation: trace 1100ms var(--ease-io) 240ms both;
}
.chart-bar {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: bar-grow 640ms var(--ease-out) calc(var(--i, 0) * 40ms) both;
}
@keyframes bar-grow {
  from { transform: scaleY(0); }
}
.chart-dot {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: mark-pop 420ms var(--ease-pop) calc(520ms + var(--i, 0) * 70ms) both;
}

/* ---------- Reduced motion: everything lands at once ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { animation-delay: 0s !important; transition-delay: 0s !important; }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
  /* Whatever still moves only fades: no travel, no stagger. Folds open natively, so their content fades in. */
  :root,
  html[data-nav],
  html[data-subnav] { --nav-x: 0px; --sub-x: 0px; --lift: 0px; }
  details[open] > :not(summary) { animation: fade-in 200ms ease-out; }
  .vrow:has(> .vrow-head:active),
  .tab:active .ic,
  .btn:active,
  .chip-btn:active,
  .icon-btn:active,
  .fab:active,
  .subtabs button:active,
  .seg-buttons button:active,
  .segmented label:active { transform: none; }
  .toggle:active i::after { width: 22px; }
  .toggle.active:active i::after { transform: translateX(18px); }
}
@media print {
  .brief-field path { clip-path: none !important; }
  .chart-line { stroke-dasharray: none; }
}
