/* Огонёк (js/streak.js). Pixel flame like the mascot: crisp rects, colours from tokens
   (--fl-* in tokens.css), the tips flicker through three frames in steps — no smooth
   tweening, it would blur the pixels. Stage colours grow with the streak. */

.fl { display: block; width: 100%; height: 100%; overflow: visible; }

/* Flicker: each frame shows a third of the cycle. */
.fl__f { opacity: 0; animation: fl-flick 0.54s step-end infinite; }
.fl__f--1 { animation-delay: 0s; }
.fl__f--2 { animation-delay: -0.36s; }
.fl__f--3 { animation-delay: -0.18s; }
@keyframes fl-flick {
  0% { opacity: 1; }
  33.333% { opacity: 0; }
}

[data-stage] { --fl-o: var(--fl-outer); --fl-m: var(--fl-mid); --fl-c: var(--fl-mid); }
[data-stage="2"] { --fl-c: var(--fl-core); }
[data-stage="3"] { --fl-o: var(--fl-mid); --fl-m: var(--fl-core); --fl-c: var(--fl-hot); }
[data-stage="4"] { --fl-o: var(--fl-v-outer); --fl-m: var(--fl-v-mid); --fl-c: var(--fl-v-core); }
[data-stage="5"] { --fl-o: var(--fl-v-outer); --fl-m: var(--fl-v-mid); --fl-c: var(--fl-v-core); }
[data-stage="5"] .fl { filter: drop-shadow(0 0 3px var(--fl-v-mid)); }

/* Not today yet (or the server hasn't answered): grey and still. */
.is-off { --fl-o: var(--fl-off); --fl-m: var(--fl-off); --fl-c: var(--fl-off); }
.is-off .fl__f { animation: none; }
.is-off .fl__f--1 { opacity: 1; }

/* ---------- Header button ---------- */
.streak {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 var(--s-3) 0 var(--s-2);
  border: 0;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-14);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.streak:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.streak__flame { width: 20px; height: 24px; }
.streak__n {
  display: inline-block;
  height: 1.2em;
  line-height: 1.2em;
  overflow: hidden;
  min-width: 1ch;
}
@media (pointer: coarse) { .streak { height: 44px; } }
/* Phone: the flame lives on home only. Other headers already hold the theme switch and the avatar,
   a third control pushed them past the screen edge (Агент, Пропущенное at 360px). */
@media (max-width: 480px) {
  body:not([data-view="dashboard"]) .streak { display: none; }
}
/* Phone header is tight: the number stays, the padding goes. */
@media (max-width: 420px) {
  .streak { padding: 0 var(--s-2) 0 6px; gap: 4px; }
  .streak__flame { width: 16px; height: 20px; }
}

/* ---------- First visit of the day ---------- */
.streak.is-bump .streak__flame { animation: fl-jump 0.6s steps(6) both; }
@keyframes fl-jump {
  0% { transform: translateY(0) scale(1); }
  35% { transform: translateY(-6px) scale(1.3); }
  70% { transform: translateY(1px) scale(0.95); }
  100% { transform: translateY(0) scale(1); }
}
.streak__roll { display: flex; flex-direction: column; animation: fl-roll 0.5s 0.25s var(--ease-out) both; }
.streak__roll > span { height: 1.2em; }
@keyframes fl-roll { to { transform: translateY(-50%); } }

.streak__sparks { position: absolute; left: 18px; top: 8px; pointer-events: none; }
.streak__sparks i {
  position: absolute;
  width: 3px;
  height: 3px;
  background: var(--fl-c);
  opacity: 0;
  animation: fl-spark 0.8s var(--d) steps(5) both;
}
.streak__sparks i:nth-child(odd) { background: var(--fl-m); }
@keyframes fl-spark {
  0% { opacity: 1; transform: translate(0, 0); }
  100% { opacity: 0; transform: translate(var(--dx), -22px); }
}

/* ---------- Popover ---------- */
.streak-pop { width: min(300px, calc(100vw - 2 * var(--gutter))); padding: var(--s-4); }
.streak-pop__head { display: flex; align-items: center; gap: var(--s-4); }
.streak-pop__flame { width: 50px; height: 60px; flex: none; }
.streak-pop__n {
  font-family: var(--font-headline);
  font-size: 40px;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.streak-pop__cap { color: var(--text-2); font-size: var(--fs-14); }
.streak-pop__week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin: var(--s-4) 0 var(--s-3);
  padding: 0;
  list-style: none;
}
.streak-pop__day { display: grid; justify-items: center; gap: 4px; }
.streak-pop__dot {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
}
.streak-pop__day.is-today .streak-pop__dot { box-shadow: inset 0 0 0 2px var(--accent); }
.fl--mini { width: 14px; height: 17px; }
.fl--mini .fl__f { animation: none; }
.fl--mini .fl__f--1 { opacity: 1; }
.streak-pop__wd { color: var(--text-3); font-size: var(--fs-12); }
.streak-pop__day.is-today .streak-pop__wd { color: var(--text); font-weight: 600; }
.streak-pop__next { font-weight: 600; }
.streak-pop__best, .streak-pop__rule { margin-top: 4px; color: var(--text-3); font-size: var(--fs-12); }

@media (prefers-reduced-motion: reduce) {
  .fl__f { animation: none; }
  .fl__f--1 { opacity: 1; }
}


/* Outside home the header flame stands still: where people read, nothing flickers at the edge of the eye. */
body:not([data-view="dashboard"]) .streak .fl__f { animation: none; }
body:not([data-view="dashboard"]) .streak .fl__f--1 { opacity: 1; }

/* ---------- Milestone scene (7 / 30 / 100 / 365) ---------- */
.fl-burst {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--s-2);
  padding: var(--gutter);
  text-align: center;
  background: color-mix(in srgb, var(--bg) 97%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.25s var(--ease-out);
  cursor: pointer;
  outline: none;
  touch-action: none;
}
.fl-burst.is-in { opacity: 1; }
.fl-burst.is-gone { opacity: 0; }

.fl-burst__stage {
  position: relative;
  width: min(40vw, 168px);
  aspect-ratio: 10 / 12;
  margin-bottom: var(--s-4);
}
/* Soft light behind the fire once it levels up. */
.fl-burst__stage::before {
  content: '';
  position: absolute;
  inset: -45%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--fl-m) 38%, transparent), transparent);
  opacity: 0;
  transition: opacity 0.5s var(--ease-out);
}
.fl-burst.is-up .fl-burst__stage::before { opacity: 1; }
.fl-burst__flame { position: relative; display: block; width: 100%; height: 100%; }
.fl-burst.is-up .fl-burst__flame .fl { animation: fl-flash 0.6s steps(6) both; }
@keyframes fl-flash {
  0% { filter: brightness(2.6); transform: scale(1.28); }
  45% { filter: brightness(1.4); transform: scale(0.94); }
  100% { filter: none; transform: none; }
}

.fl-burst__sparks { position: absolute; left: 50%; top: 55%; }
.fl-burst__sparks i {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px;
  background: var(--fl-c);
  opacity: 0;
}
.fl-burst__sparks i:nth-child(3n) { background: var(--fl-m); }
.fl-burst__sparks i:nth-child(3n + 1) { background: var(--fl-o); }
.fl-burst.is-up .fl-burst__sparks i { animation: fl-burst 0.9s var(--d) steps(7) both; }
@keyframes fl-burst {
  0% { opacity: 1; transform: translate(0, 0); }
  100% { opacity: 0; transform: translate(var(--x), var(--y)); }
}

.fl-burst__n {
  height: 1em;
  overflow: hidden;
  font-family: var(--font-headline);
  font-size: clamp(72px, 24vw, 132px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.fl-burst__roll { display: flex; flex-direction: column; }
.fl-burst__roll > span { height: 1em; }
.fl-burst.is-up .fl-burst__roll { animation: fl-roll 0.55s var(--ease-out) both; }
.fl-burst__cap { color: var(--text-2); font-size: var(--fs-16, 16px); }
.fl-burst__title {
  max-width: 22ch;
  margin-top: var(--s-3);
  font-weight: 700;
  font-size: clamp(18px, 5vw, 22px);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s 0.35s var(--ease-out), transform 0.4s 0.35s var(--ease-out);
}
.fl-burst.is-up .fl-burst__title { opacity: 1; transform: none; }
.fl-burst.is-out .fl-burst__n,
.fl-burst.is-out .fl-burst__cap,
.fl-burst.is-out .fl-burst__title { opacity: 0; transition: opacity 0.2s; }

@media (prefers-reduced-motion: reduce) {
  .fl-burst.is-up .fl-burst__flame .fl,
  .fl-burst.is-up .fl-burst__sparks i,
  .fl-burst.is-up .fl-burst__roll { animation: none; }
  .fl-burst__roll { transform: translateY(-50%); }
  .fl-burst__title { transition: none; transform: none; }
}
