/* ---- Lead use case: IT incident response ----
   Base styles are the finished state (tokens in place, annotations drawn, task graded), which is
   what browsers without scroll timelines and reduced-motion readers see.

   Scroll-driven sequence, written once. Every step declares its own range as --a..--z on a
   0..100 scale; the timeline and how that scale maps onto it come from variables on .incident:
     tall desktops: the panel pins, timeline --incident (the tall track), range "contain", 1:1;
     everywhere else: timeline --doc (the figure crossing the viewport), range "cover", compressed.
   Steps: 6-30 scan | 10-59 per entity: detect, defocus, glass token, label | 26-62 counter |
          58-72 annotations draw | 66-78 task card rises | 76-92 graders tick | 92-98 stamp. */
@property --tok { syntax: "<integer>"; inherits: false; initial-value: 4; }

.incident { padding-block: var(--inset); --tl: --doc; --seg: cover; --b: 18%; --s: .5%; }
.incident__panel { padding-block: 88px; }
.incident__grid { display: grid; gap: 56px; align-items: center; }

.incident__stats { display: grid; grid-template-columns: 1fr 1fr; margin-top: 40px; border-top: 1px solid var(--panel-line); }
.incident__stats div { padding: 22px 16px 4px 0; }
.incident__stats div + div { padding-left: 20px; border-left: 1px solid var(--panel-line); }
.incident__stats dt { font-size: clamp(2.5rem, 1.6rem + 3vw, 4rem); letter-spacing: -.06em; line-height: 1; }
.incident__stats dd { margin-top: 10px; color: var(--on-panel-2); font-size: .9375rem; }
.incident__stats dd .mono { display: block; margin-top: 6px; font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; color: var(--on-panel-2); opacity: .7; }
.incident__next { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 36px; }
.incident__next .mono { margin-right: 6px; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--on-panel-2); }

.incident__figure { position: relative; margin: 0; view-timeline-name: --doc; }

/* ---- The ticket, printed on paper ---- */
.doc {
  position: relative; overflow: hidden;
  padding: 22px 20px 60px; border-radius: 18px;
  background: var(--page-2); color: var(--ink); font-size: .9375rem; line-height: 1.5;
  box-shadow: 0 40px 80px -40px rgba(0, 0, 0, .8);
}
.doc__head { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 14px; margin-bottom: 6px; border-bottom: 1px solid var(--line); font-size: .8125rem; }
.doc__meta { color: var(--ink-2); }
.doc__line { padding-top: 8px; line-height: 2.5; }
.doc__foot {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: .72rem; letter-spacing: .04em; color: var(--ink-2);
}
.doc__lock { display: inline-flex; align-items: center; gap: 6px; color: var(--signal-deep); }
.doc__n { counter-reset: tok var(--tok, 4); font-weight: 500; color: var(--ink); }
.doc__n::before { content: counter(tok); }

/* Detection scan: a soft mint bar sweeping down the page. Hidden in the finished state. */
.doc__scan {
  position: absolute; left: 0; right: 0; top: 0; height: 90px; z-index: 4; pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(124, 242, 193, .18) 70%, rgba(14, 122, 85, .85) 100%);
  opacity: 0;
}

/* Annotations: a box around the words with a label tab. */
.ann, .redact { position: relative; line-height: 1.5; }
.ann { padding: 1px 6px; border: 1px solid var(--ink); border-radius: 5px; }
.ann::before, .redact::before, .redact::after {
  content: attr(data-label); position: absolute; left: -1px; bottom: calc(100% + 1px); z-index: 3;
  padding: 1px 6px; border-radius: 4px 4px 0 0; background: var(--ink); color: var(--page);
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; line-height: 1.5; white-space: nowrap;
}
.ann--time { border-style: dashed; }
.ann--cause { border-color: var(--signal-deep); background: rgba(124, 242, 193, .3); }
.ann--cause::before { background: var(--signal-deep); }

/* Personal data: detected (amber), then defocused under a frosted glass token. */
.redact { display: inline-grid; vertical-align: baseline; padding: 1px 6px; border: 1px solid var(--line-2); border-radius: 6px; }
.redact::before { background: var(--signal-deep); }
.redact::after { content: attr(data-detected); background: #B7791F; opacity: 0; }
.redact > * { grid-area: 1 / 1; white-space: nowrap; }
.redact__raw { filter: blur(7px); opacity: .4; }
.redact__token {
  z-index: 1; align-self: center; justify-self: stretch; padding: 1px 8px; border-radius: 5px; text-align: center;
  font-size: .76em; font-weight: 500; letter-spacing: .05em; color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 255, 255, .86), rgba(255, 255, 255, .42));
  border: 1px solid #fff;
  box-shadow: inset 0 1px 0 #fff, 0 0 0 1px rgba(11, 11, 11, .07), 0 10px 22px -12px rgba(11, 11, 11, .45);
  backdrop-filter: blur(12px) saturate(1.5); -webkit-backdrop-filter: blur(12px) saturate(1.5);
}

/* ---- Becomes a graded task: a glass card overlapping the ticket ---- */
.becomes {
  position: relative; z-index: 2; margin: -44px 16px 0; padding: 18px 20px 20px;
  border: 1px solid var(--panel-line-2); border-radius: 18px;
  background: linear-gradient(180deg, rgba(20, 20, 20, .72), rgba(8, 8, 8, .82));
  backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 30px 60px -30px rgba(0, 0, 0, .9);
}
.becomes__label { display: flex; align-items: center; gap: 8px; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--signal); }
.becomes__checks { display: grid; gap: 8px; margin-top: 12px; font-size: .9375rem; }
.becomes__checks li { display: flex; align-items: center; gap: 10px; color: var(--on-panel); }
.becomes__checks i { flex: none; width: 10px; height: 10px; border-radius: 2px; border: 1px solid var(--on-panel-2); }
.becomes__checks .is-done i { background: var(--signal); border-color: var(--signal); }
.becomes__checks .is-open { color: var(--on-panel-2); }
/* Narrow screens: the stamp sits under the graders; wider screens: top right of the card. */
.becomes__stamp {
  margin-top: 14px;
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
  background: var(--signal); color: var(--signal-ink); font-size: .64rem; letter-spacing: .06em; text-transform: uppercase;
  transform: rotate(-3deg);
}

@media (min-width: 640px) {
  .becomes { margin-inline: 28px; }
  .becomes__stamp { position: absolute; right: 16px; top: 14px; margin-top: 0; }
}
@media (min-width: 1000px) {
  .incident__panel { padding-block: 128px; }
  .incident__grid { grid-template-columns: 5fr 6fr; gap: 80px; }
  .doc { padding: 28px 30px 64px; font-size: 1.0625rem; }
}

/* ---- Scroll-driven sequence ---- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* Tall desktops: pin the panel and drive everything from the track. */
    @media (min-width: 1000px) and (min-height: 820px) {
      .incident { --tl: --incident; --seg: contain; --b: 0%; --s: 1%; }
      .incident__track { height: 260vh; view-timeline-name: --incident; }
      .incident__panel {
        position: sticky; top: var(--nav-h);
        height: calc(100svh - var(--nav-h) - var(--inset)); padding-block: 0;
        display: grid; align-items: center;
      }
      .incident .h2 { font-size: clamp(2.25rem, 1.2rem + 2.6vw, 3.5rem); }
      .incident__stats { margin-top: 28px; }
      .incident__next { margin-top: 24px; }
    }

    .doc__scan, .redact, .redact::before, .redact::after, .redact__raw, .redact__token,
    .doc__n, .ann, .ann::before, .becomes, .becomes__checks .is-done i, .becomes__stamp {
      animation-timing-function: linear; animation-fill-mode: both; animation-timeline: var(--tl);
      animation-range: var(--seg) calc(var(--b) + var(--a) * var(--s)) var(--seg) calc(var(--b) + var(--z) * var(--s));
    }

    .doc__scan { --a: 6; --z: 30; animation-name: scan; }
    /* Each entity, offset by its order --o. */
    .redact, .redact::before, .redact::after, .redact__raw, .redact__token { --a: calc(10 + var(--o) * 5); --z: calc(44 + var(--o) * 5); }
    .redact::before, .redact::after, .redact__raw, .redact__token { --o: inherit; }
    .redact { animation-name: detect-box; }
    .redact::after { animation-name: detected-tab; }
    .redact::before { animation-name: entity-tab; }
    .redact__raw { animation-name: defocus; }
    .redact__token { animation-name: token-wipe; }
    .doc__n { --a: 26; --z: 62; animation-name: count-up; }

    .ann, .ann::before { --a: 58; --z: 64; }
    .ann--cause, .ann--cause::before { --a: 62; --z: 68; }
    .ann--team, .ann--team::before { --a: 66; --z: 72; }
    .ann { animation-name: ann-draw; }
    .ann--cause { animation-name: ann-draw-cause; }
    .ann::before { animation-name: tab-drop; }

    .becomes { --a: 66; --z: 78; animation-name: card-rise; }
    .becomes__checks .is-done i { --a: calc(76 + var(--n) * 4); --z: calc(78 + var(--n) * 4); animation-name: tick; }
    .becomes__stamp { --a: 92; --z: 98; animation-name: stamp; }
  }
}

@keyframes scan         { 0% { top: -90px; opacity: 0; } 10%, 85% { opacity: 1; } 100% { top: 100%; opacity: 0; } }
@keyframes detect-box   { 0% { background: transparent; border-color: var(--line-2); } 15%, 60% { background: rgba(245, 185, 74, .28); border-color: #B7791F; } 90%, 100% { background: transparent; border-color: var(--line-2); } }
@keyframes detected-tab { 0% { opacity: 0; transform: translateY(4px); } 15%, 62% { opacity: 1; transform: none; } 80%, 100% { opacity: 0; } }
@keyframes entity-tab   { 0%, 72% { opacity: 0; transform: translateY(4px); } 90%, 100% { opacity: 1; transform: none; } }
@keyframes defocus      { 0%, 55% { filter: blur(0); opacity: 1; } 88%, 100% { filter: blur(7px); opacity: .4; } }
@keyframes token-wipe   { 0%, 60% { clip-path: inset(0 100% 0 0 round 5px); opacity: 0; transform: scale(.94); } 92%, 100% { clip-path: inset(0 0 0 0 round 5px); opacity: 1; transform: none; } }
@keyframes count-up     { from { --tok: 0; } to { --tok: var(--total, 4); } }
@keyframes ann-draw     { from { border-color: transparent; } }
@keyframes ann-draw-cause { from { border-color: transparent; background: transparent; } }
@keyframes tab-drop     { from { opacity: 0; transform: translateY(6px); } }
@keyframes card-rise    { from { opacity: 0; transform: translateY(48px) scale(.97); filter: blur(10px); } }
@keyframes tick         { from { background: transparent; border-color: var(--on-panel-2); transform: scale(1); } 60% { transform: scale(1.4); } }
@keyframes stamp        { from { opacity: 0; transform: rotate(-9deg) scale(1.4); } }
