/* Scene M6 "Fourteen Days" (#two-weeks, W8). Ink world, one sticky 100svh stage.
   Layout, desktop: copy left, the numeral (drawn by the stage canvas) right, the day strip across the bottom, the boundary
   under it. Phone: the numeral on top, an opaque sheet under it holding the copy, the strip and the boundary.
   Default (no JS, reduced motion, fx-fail) is the composed, fully lit state: every tick lit, the last one vermilion, the
   DOM numeral shown. The cinematic rules below only dim what the scene's own scrub then lights. */

#two-weeks { --weeks-top: 88px; --weeks-bottom: calc(var(--seam) + 18px); --tick-w: 3px; --art-h: 36svh; }

.weeks { display: grid; gap: 1.6rem; }
.weeks__sheet { display: contents; }
.weeks__copy { display: grid; gap: .9rem; align-content: start; align-self: center; max-width: 36rem; }
.weeks__copy .label { margin-bottom: .2rem; }
.weeks__copy h2 { font-size: clamp(1.9rem, min(3.7vw, 6.2svh), 3.6rem); }
.weeks__sub { font-family: var(--font-mono); font-size: var(--t-data); letter-spacing: .1em; text-transform: uppercase; color: var(--mut); line-height: 1.5; }
.weeks__body { display: grid; gap: .65rem; max-width: 34rem; font-size: clamp(1rem, min(1.1vw, 2.3svh), 1.15rem); line-height: 1.45; color: var(--fg); }

/* ---- the numeral and its unit (the dots are on the canvas; this is the typographic twin) ---- */
.weeks__art { display: grid; align-content: end; justify-items: end; gap: .9rem; min-height: 22rem; }
.weeks__num { margin: 0; display: flex; align-items: flex-end; justify-content: flex-end; gap: .35em; font-family: var(--font-display); line-height: .8; }
.weeks__num .num { font-size: clamp(9rem, 24vw, 22rem); line-height: .8; }
.num__glyph { display: block; height: .8em; width: auto; overflow: visible; }
.weeks__num .weeks__unit { font-size: var(--t-h3); font-weight: 600; letter-spacing: -.02em; padding-bottom: .1em; }
.weeks__free { margin: 0; justify-self: end; padding: .25em .8em; border: 0; background: var(--signal); font-family: var(--font-mono); font-size: var(--t-data); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink); }

/* ---- the day strip ---- */
.ruler { position: relative; margin-top: .4rem; }
.ruler__ticks { position: relative; display: grid; grid-template-columns: repeat(14, 1fr); align-items: end; height: 3.4rem; border-bottom: 1px solid var(--line); color: var(--fg); }
.tick { display: flex; align-items: flex-end; height: 1.5rem; }
.tick::before { content: ''; display: block; width: var(--tick-w); height: 100%; margin-inline: auto; background: currentColor; transform-origin: 50% 100%; }
.tick--mark { height: 2.5rem; }
.tick--origin { position: absolute; left: 0; bottom: 0; height: 2.5rem; width: var(--tick-w); }
.tick--origin::before { margin: 0; }
.tick--last { position: relative; height: 3rem; color: var(--signal); }
/* day 14 is the seal (svg/seal.mjs, via the generated img): the proof, stamped */
.tick--last::before { width: 28px; height: 28px; margin-bottom: 1px; background: url('../../img/seal-signal.svg') center / contain no-repeat; }

/* the strip does not end at day 14: a dashed line carries on, with an arrowhead */
.ruler__more { display: flex; align-items: center; justify-content: flex-end; gap: .6rem; margin: .5rem 0 0; color: var(--mut); }
.ruler__go { font-family: var(--font-mono); font-size: var(--t-data); letter-spacing: .12em; text-transform: uppercase; line-height: 1.3; }
.ruler__dash { position: relative; flex: none; width: 40px; border-bottom: 2px dashed var(--fg); opacity: .6; }
.ruler__dash::after { content: ''; position: absolute; right: -1px; bottom: -5px; width: 8px; height: 8px; border: solid var(--fg); border-width: 2px 2px 0 0; transform: rotate(45deg); transform-origin: 100% 0; }

.ruler__marks { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-top: .75rem; }
.mark { display: grid; gap: .22rem; align-content: start; min-width: 0; color: var(--fg); }
.mark__when { font-family: var(--font-mono); font-size: var(--t-data); letter-spacing: .12em; text-transform: uppercase; color: var(--mut); }
.mark__title { position: relative; justify-self: start; padding: .16em 0 .14em; border: 0; border-bottom: 3px solid transparent; font-family: var(--font-display); font-size: clamp(.9rem, 1.25vw, 1.15rem); font-weight: 700; letter-spacing: -.01em; line-height: 1.15; transform-origin: 0 50%; }
.mark__sub { font-size: .9375rem; line-height: 1.35; color: var(--mut); max-width: 24ch; }
.mark[data-kind="person"] .mark__title { border-bottom-color: var(--signal); }
.mark[data-kind="machine"] .mark__title { border-bottom-color: var(--fg); }
.mark:last-child { text-align: left; }

.weeks__then { margin: .7rem 0 0; font-size: clamp(.9rem, min(1vw, 2svh), 1.05rem); color: var(--fg); }
.weeks__then a { color: var(--fg); font-weight: 600; text-decoration: underline; text-decoration-color: var(--signal); text-underline-offset: .22em; margin-left: .4em; }

/* ---- the still (no JS, reduced motion, fx-fail) ----
   The DOM already holds the whole picture: the typographic "2 weeks" and the lit day strip. The composed frame used to be a second
   copy of both (a stippled 2 and another strip), so beside them a visitor saw two numerals and two rulers in a 1.7 vh section.
   It is now the ink field with its dust, a backdrop behind the section (numeral.mjs `composed`), and carries neither. */
html:not(.js) #two-weeks .stage, html.static #two-weeks .stage, html.fx-fail #two-weeks .stage { position: relative; }
html:not(.js) #two-weeks .composed, html.static #two-weeks .composed, html.fx-fail #two-weeks .composed {
  position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; margin: 0; object-fit: cover; pointer-events: none;
}

/* ---- desktop grid (every mode); the cinematic pin fixes the height ---- */
@media (min-width: 901px) {
  .weeks { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); grid-template-rows: auto auto auto; column-gap: 3vw; }
  .weeks__copy { grid-area: 1 / 1; }
  .weeks__art { grid-area: 1 / 2; }
  .ruler { grid-area: 2 / 1 / 3 / 3; display: grid; grid-template-columns: minmax(0, 1fr) 9rem; }
  .ruler__ticks { grid-column: 1; grid-row: 1; }
  .ruler__marks { grid-column: 1; grid-row: 2; }
  .ruler__more { grid-column: 2; grid-row: 1; position: relative; display: block; height: 3.4rem; margin: 0; }
  .ruler__dash { position: absolute; left: 0; right: 0; bottom: 0; width: auto; border-bottom-width: 2px; }
  .ruler__go { position: absolute; left: .9rem; bottom: .7rem; max-width: 7.6rem; }
  .weeks__then { grid-area: 3 / 1 / 4 / 3; }
  .ruler__marks { display: block; position: relative; height: 6.6rem; }
  .mark { position: absolute; top: 0; left: calc(var(--at) * 100%); transform: translateX(-50%); width: 17rem; }
  .mark[data-marker="0"] { left: 0; transform: none; }
  .mark[data-marker="1"] { left: 25%; transform: none; }
  .mark[data-marker="2"] { left: 60.7%; }
  .mark[data-marker="3"] { left: 100%; transform: translateX(-100%); justify-items: end; text-align: right; }
  .mark[data-marker="3"] .mark__title { margin-left: 0; transform-origin: 100% 50%; }
  .mark[data-marker="3"] .mark__sub { margin-left: auto; }
}

/* ---- cinematic: the pinned stage ---- */
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks { height: 100%; padding: var(--weeks-top) 0 var(--weeks-bottom); }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks__art { min-height: 0; }
@media (min-width: 901px) {
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks { grid-template-rows: minmax(0, 1fr) auto auto; }
}

/* the canvas the scene creates: behind the copy, over the poster */
.weeks__fx { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; pointer-events: none; }

/* pre-states: only under the cinematic path, only on what the scrub resolves every frame */
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .tick:not(.is-lit)::before { opacity: .5; transform: scaleY(.55); }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .tick.is-lit::before { animation: tick-pop .34s cubic-bezier(.2, 0, .1, 1) both; }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .tick--last:not(.is-lit) { color: var(--fg); }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .tick--last:not(.is-lit)::before { transform: scale(.55); }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .tick--last.is-lit::before { animation: seal-pop .5s cubic-bezier(.2, 0, .1, 1) both; }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .tick--last.is-lit::after { content: ''; position: absolute; left: 50%; bottom: 1px; width: 28px; height: 28px; margin-left: -14px; border: 1.5px solid var(--signal); border-radius: 50%; pointer-events: none; animation: seal-ping 3.6s ease-out .5s infinite; }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .ruler__more { opacity: .45; transition: opacity .5s; }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .ruler__more.is-lit { opacity: 1; }
@keyframes seal-pop { 0% { transform: scale(.55); } 55% { transform: scale(1.22); } 100% { transform: scale(1); } }
@keyframes seal-ping { 0% { transform: scale(1); opacity: .8; } 70%, 100% { transform: scale(2.4); opacity: 0; } }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .mark:not(.is-reached) { opacity: .86; }   /* AA: the muted lines are 62% of the bone at full opacity, so any dimmer fails 4.5:1 */
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .mark:not(.is-reached) .mark__title { border-bottom-color: transparent; }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .mark.is-stamp .mark__title { animation: stamp-in .22s cubic-bezier(.7, 0, .2, 1) both; }
@keyframes tick-pop { 0% { transform: scaleY(.55); } 55% { transform: scaleY(1.22); } 100% { transform: scaleY(1); } }
@keyframes stamp-in { 0% { transform: translateY(6px); opacity: 0; } 100% { transform: scale(1) rotate(0); opacity: 1; } }

/* machine text on the last marker: a ghost line always readable, a bright overlay that types over it */
.mark__title .mark__typed { position: absolute; left: 0; top: .16em; white-space: nowrap; color: var(--fg); pointer-events: none; }
.mark__title .mark__typed.has-caret::after { content: ''; display: inline-block; width: 2px; height: 1em; margin-left: 2px; vertical-align: -.12em; background: var(--signal); animation: caret-blink 1s steps(1) infinite; }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .mark[data-marker="3"] .mark__title { color: var(--on-ink-dim); }
html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .mark[data-marker="3"].is-reached .mark__title { color: transparent; }
html:not(.js) .mark__typed, html.static .mark__typed { display: none; }

/* the canvas draws the numeral: take the typographic 2 out of the flow (the unit stays, and now stacks directly above the
   free stamp instead of sitting at the baseline of an invisible 17 rem glyph, where a short stage pushed it over the stamp), and hide the poster */
#two-weeks[data-live] .weeks__num .num { display: none; }
#two-weeks[data-live] .composed { opacity: 0; visibility: hidden; }
#two-weeks[data-live] .weeks__num { min-height: 1px; }

/* ---- phone: the numeral band on top, an opaque sheet under it (the sheet carries the copy, the strip and the boundary) ---- */
@media (max-width: 900px) {
  #two-weeks { --weeks-top: 0px; --weeks-bottom: 0px; }
  .weeks { gap: 0; }
  .weeks__art { order: -1; min-height: 16rem; padding-top: 5rem; }
  .weeks__num .num { font-size: 11rem; }
  .weeks__num .weeks__unit { font-size: 1.1rem; }
  .weeks__sheet { display: grid; gap: .55rem; padding: .8rem 0 .8rem; }
  .weeks__copy { gap: .3rem; max-width: none; align-self: auto; }
  .weeks__copy .label { margin-bottom: 0; }
  .weeks__copy h2 { font-size: clamp(1.4rem, 6.6vw, 1.8rem); }
  .weeks__sub { font-size: .6875rem; line-height: 1.4; }
  .weeks__body { font-size: 1rem; line-height: 1.3; gap: .3rem; }
  .ruler__ticks { height: 2.3rem; }
  .tick { height: 1.1rem; }
  .tick--mark, .tick--origin { height: 1.6rem; }
  .tick--last { height: 2rem; }
  .tick--last::before { width: 24px; height: 24px; }
  .ruler__more { margin-top: .3rem; gap: .5rem; }
  .ruler__go { font-size: .6875rem; }
  .ruler__marks { gap: .35rem .8rem; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: .4rem; }
  .mark { gap: .12rem; }
  .mark__when { font-size: .6875rem; }
  .mark__title { font-size: .9375rem; }
  .mark__sub { font-size: .75rem; line-height: 1.28; max-width: none; }
  .weeks__then { font-size: .875rem; line-height: 1.32; }

  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks { display: block; }
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks__body p + p { display: none; }   /* pinned phone sheet is height-bound; the delivery-system line shows in every other mode */
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks__art { position: absolute; top: 0; right: var(--gutter); height: var(--art-h); min-height: 0; padding: 0 0 .7rem; z-index: 3; align-content: end; }
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks__art .num { display: none; }
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks__sheet {
    position: absolute; left: calc(var(--gutter) * -1); right: calc(var(--gutter) * -1); bottom: 0; padding: 1rem var(--gutter) calc(var(--seam) + .4rem);
    background: var(--ink-2); border-top: 1px solid var(--line); clip-path: polygon(0 0, calc(100% - 22px) 0, 100% 22px, 100% 100%, 0 100%);
  }
}

/* Pinned phone stage on a short screen (740 to 829 px tall): four marker sublines would lift the sheet over the numeral, so
   they are clipped there and only there, and the sheet tightens so its top stays under the numeral band. Every other mode and size shows them (no JS, reduced motion, fx-fail, flowing,
   taller phones, tablets). Deviation recorded in the PR; tests/e2e/checks/scene-twoweeks.mjs pins both sides. */
@media (min-width: 381px) and (max-width: 900px) and (min-height: 740px) and (max-height: 829px) {
  .weeks__sheet { gap: .5rem; padding-top: .75rem; }
  .weeks__body { gap: .25rem; }
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .mark__sub { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* A viewport too short for the pinned layout reads as a flowing section instead (the numeral is then the typographic twin). At 16 px body
   type the phone sheet needs about 550 px on a 390 px screen and 600 on a 360 px one, so phones under 740 px tall, and 380 px wide ones
   under 940, flow rather than let the sheet climb over the numeral. */
@media (min-width: 901px) and (max-height: 660px), (max-width: 900px) and (max-height: 739px), (max-width: 380px) and (max-height: 939px) {
  html.js:not(.fx-fail):not(.static) #two-weeks .track { height: auto; }
  html.js:not(.fx-fail):not(.static) #two-weeks .track > .stage { position: static; height: auto; overflow: visible; padding-block: var(--pad-block); }
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks { height: auto; display: grid; padding: 0; }
  #two-weeks .weeks__fx { display: none; }
  #two-weeks[data-live] .weeks__num .num { display: block; visibility: visible; }
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks__art { position: static; height: auto; padding: 0; }
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks__art .num { display: block; }
  html.js:not(.fx-fail):not(.static) #two-weeks:not([data-fx-fail]) .weeks__sheet { position: static; padding: 0; background: none; border: 0; clip-path: none; margin: 0; display: grid; }
}
