/* Features page: nine strange habits for a machine.
   Static first: every glyph is a finished drawing. Motion is added only when the
   visitor has not asked for less of it, and only once the card has been seen. */

.features main { overflow-x: clip; }

/* ---- hero ---- */
.habits-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
  align-items: center;
  gap: clamp(2rem, 6vw, 6rem);
  padding-block: clamp(2.6rem, 5.2vw, 5.6rem);
}
.habits-hero h1 { font-size: clamp(2.6rem, 4.1vw, 3.6rem); line-height: 1.04; }
.habits-hero .lead { max-width: 33rem; }

.habits-stage {
  --track: 4rem;
  --rider-w: min(46%, 15rem);
  container-type: inline-size;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  aspect-ratio: 1000 / 640;
  border-radius: 1rem;
  background: var(--ganache);
}
.habits-stage .drawing-grid { z-index: -2; }
.stage-contours {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1;
  fill: none; stroke: #c7bba438; stroke-width: 1.35; stroke-linecap: round;
  pointer-events: none;
}
.habits-track {
  position: absolute; inset-inline: 7%; bottom: var(--track); height: 1px;
  background: #b5c2a1;
}
.habits-track::before, .habits-track::after {
  content: ""; position: absolute; top: 50%; width: .5rem; height: .5rem;
  border: 1px solid #c0d5ae; transform: translateY(-50%);
}
.habits-track::before { left: -1px; border-radius: 50%; background: var(--ganache); }
.habits-track::after { right: -1px; background: #b2cfa9; }
.habits-rider {
  position: absolute; inset-inline-start: 0; bottom: var(--track);
  inline-size: var(--rider-w); block-size: auto;
  transform: translateX(calc(60cqw - 50%));          /* parked at 60% of the track */
}

/* ---- ticker ---- */
.habits-ticker {
  overflow: hidden;
  border-block: 1px solid var(--rule);
  padding-block: .8rem;
  color: var(--body);
  font: 500 .82rem/1.5 var(--mono);
  letter-spacing: .02em;
  white-space: nowrap;
}
.ticker-track { display: flex; inline-size: max-content; }
.ticker-run { flex: none; white-space: pre; }

/* ---- the nine stops ---- */
.habits {
  list-style: none;
  margin-block: clamp(2.4rem, 5vw, 4.5rem) clamp(2.6rem, 5vw, 4.75rem);
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}
@media (min-width: 600px) { .habits { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .habits { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.15rem; } }

.habit {
  position: relative;
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
  padding: clamp(1.15rem, 2vw, 1.7rem);
  border: 1px solid var(--rule);
  border-radius: .8rem;
  background: var(--sheet);
}
.habit-no {
  display: flex; align-items: center; gap: .5rem;
  color: var(--body); font: 550 .78rem/1.4 var(--mono); letter-spacing: .05em;
}
.habit-no::before {
  content: ""; order: -2; flex: none; width: .4rem; height: .4rem;
  border: 1px solid currentColor; border-radius: 50%; background: var(--sheet);
}
.habit-no::after { content: ""; order: -1; flex: none; width: .9rem; height: 1px; background: var(--control-edge); }
.habit:last-child .habit-no::before { border-radius: 0; background: currentColor; }

.habit-tag {
  position: absolute; top: 1rem; right: 1rem;
  padding: .12rem .45rem;
  border: 1px solid var(--rule); border-radius: .3rem;
  color: var(--body); font: 550 .68rem/1.4 var(--mono); letter-spacing: .06em; text-transform: uppercase;
}

.glyph {
  display: block;
  inline-size: 7.5rem; block-size: 7.5rem;
  margin: 1rem 0 .9rem;
  color: var(--ink);
  fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  overflow: visible;
}
.glyph * { transform-box: fill-box; transform-origin: 50% 50%; }
.glyph .dot { fill: currentColor; stroke: none; }
.glyph .dot-g { fill: var(--green); stroke: none; }
.glyph .acc { stroke: var(--green); }
.glyph .soft { opacity: .35; }
.glyph .paper { fill: var(--sheet); }

.habit h2 {
  font-size: clamp(1.4rem, 1.7vw, 1.65rem);
  line-height: 1.15;
  letter-spacing: -.04em;
}
.habit p { margin: .65rem 0 0; color: var(--body); font-size: .96rem; line-height: 1.6; }

/* ---- closing ---- */
.habits-end {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 1.4rem 3rem;
  padding-block: clamp(2.2rem, 4.5vw, 4.2rem);
  border-top: 1px solid var(--rule);
}
.habits-end-line {
  margin: 0; max-inline-size: 24ch;
  font: 535 clamp(1.55rem, 2.9vw, 2.6rem)/1.12 var(--type); letter-spacing: -.045em;
}
.habits-end .actions { margin-top: 0; }

/* ---- glyph geometry for the finished drawings ---- */
/* 01 knock */
.g-knock .k-door { transform-box: view-box; transform-origin: 60px 40px; }
.g-knock .k-dot { transform: translate(48px, 60px); }
/* 03 backwards */
.g-back .sp-line { stroke-dasharray: 1 1; stroke-dashoffset: 0; }
.g-back .sp-dot { transform: translate(22.8px, 87px); }
/* 02 ink */
.g-ink .ink-draw { stroke-dasharray: 1 1; stroke-dashoffset: 0; }
/* 04 memory */
.g-mem .m-g { transform-box: view-box; transform-origin: 60px 60px; }
.g-mem .m-a { transform: rotate(240deg); }
.g-mem .m-b { transform: rotate(120deg); }
.g-mem .m-a-in { transform: translateY(18px); }
.g-mem .m-a-g { opacity: 1; }
.g-mem .m-c-in { opacity: .35; transform: translateY(-8px); }
/* 05 books */
.g-books .bk { transform-origin: 50% 50%; }
/* 06 map */
.g-map .e { stroke-dasharray: 1 1; stroke-dashoffset: 0; }
.g-map .halo { opacity: 0; transform-origin: 50% 50%; }
.g-map .n-last { transform-origin: 50% 50%; }
/* 07 box */
.g-box .b-x { transform: translateX(34px); }
.g-box .b-y { transform: translateY(20px); }
/* 08 spend */
.g-spend .sp-hatch { transform: none; }
/* 09 pocket */
.g-pocket .p-orbit { transform-box: view-box; transform-origin: 60px 60px; }
.g-pocket .p-phone { transform-origin: 50% 50%; }
.g-pocket .p-link { stroke-dasharray: 3 3; }

/* ---- phones ---- */
@media (max-width: 800px) {
  .habits-hero { grid-template-columns: minmax(0, 1fr); gap: 1.8rem; padding-block: 2.15rem; }
  .habits-hero h1 { font-size: clamp(1.9rem, 8.2vw, 3.6rem); }
  .habits-stage { --track: 1.6rem; --rider-w: 6.6rem; aspect-ratio: auto; block-size: 9rem; }
}

/* ---- motion: only when it has not been declined ---- */
@media (prefers-reduced-motion: no-preference) {
  /* cards: hidden before entry only when features.js is running */
  .fx .habit { opacity: 0; transform: translateY(12px); transition: opacity .6s ease, transform .6s ease; transition-delay: var(--stagger, 0s); }
  .fx .habit.is-seen { opacity: 1; transform: none; }
  @media (min-width: 1000px) {
    .habit:nth-child(3n+2) { --stagger: .08s; }
    .habit:nth-child(3n) { --stagger: .16s; }
  }
  @media (min-width: 600px) and (max-width: 999.98px) {
    .habit:nth-child(2n) { --stagger: .08s; }
  }

  .habits-rider { animation: ride 9s linear infinite, bob .9s ease-in-out infinite alternate; }
  @keyframes ride { from { transform: translateX(-100%); } to { transform: translateX(100cqw); } }
  @keyframes bob { from { translate: 0 0; } to { translate: 0 -2px; } }

  .ticker-track { animation: ticker 52s linear infinite; }
  @keyframes ticker { to { transform: translateX(-50%); } }

  /* 01 knock (5 s) */
  .is-seen .g-knock .k-dot { animation: k-dot 5s ease-in-out infinite; }
  .is-seen .g-knock .k-door { animation: k-door 5s ease-in-out infinite; }
  @keyframes k-dot {
    0% { transform: translate(12px, 60px); opacity: 0; }
    6% { transform: translate(12px, 60px); opacity: 1; }
    36%, 60% { transform: translate(48px, 60px); opacity: 1; }
    78% { transform: translate(108px, 60px); opacity: 1; }
    88% { transform: translate(108px, 60px); opacity: 0; }
    100% { transform: translate(12px, 60px); opacity: 0; }
  }
  @keyframes k-door {
    0%, 44% { transform: rotate(0); }
    58%, 76% { transform: rotate(-90deg); }
    88%, 100% { transform: rotate(0); }
  }

  /* 02 ink (6 s) */
  .is-seen .g-ink .ink-draw { animation: ink-draw 6s ease-in-out infinite backwards; animation-delay: calc(var(--i) * .45s); }
  .is-seen .g-ink .ink-shift { animation: ink-shift 6s ease-in-out infinite; }
  .is-seen .g-ink .ink-run { animation: ink-run 6s ease-in-out infinite; }
  @keyframes ink-draw {
    0% { stroke-dashoffset: 1; opacity: 1; }
    9% { stroke-dashoffset: 0; }
    88% { stroke-dashoffset: 0; opacity: 1; }
    100% { stroke-dashoffset: 0; opacity: 0; }
  }
  @keyframes ink-shift { 0%, 66% { transform: translateX(0); } 70% { transform: translateX(2px); } 76%, 100% { transform: translateX(0); } }
  @keyframes ink-run {
    0% { transform: translateX(0); opacity: 1; }
    80% { transform: translateX(90px); opacity: 1; }
    90%, 100% { transform: translateX(90px); opacity: 0; }
  }

  /* 03 backwards (3 s each way) */
  .is-seen .g-back .sp-line { animation: sp-draw 3s linear infinite alternate; }
  .is-seen .g-back .sp-dot { animation: sp-dot 3s linear infinite alternate; }
  @keyframes sp-draw { 0%, 8% { stroke-dashoffset: 1; } 92%, 100% { stroke-dashoffset: 0; } }
  @keyframes sp-dot{0%{transform:translate(60.0px,58.0px)}8.00%{transform:translate(60.0px,58.0px)}11.50%{transform:translate(68.5px,59.8px)}15.00%{transform:translate(67.7px,69.9px)}18.50%{transform:translate(59.1px,75.6px)}22.00%{transform:translate(48.7px,74.3px)}25.50%{transform:translate(40.9px,67.3px)}29.00%{transform:translate(37.7px,57.3px)}32.50%{transform:translate(39.4px,46.9px)}36.00%{transform:translate(45.4px,38.3px)}39.50%{transform:translate(54.4px,32.8px)}43.00%{transform:translate(64.8px,31.0px)}46.50%{transform:translate(75.2px,33.1px)}50.00%{transform:translate(84.2px,38.6px)}53.50%{transform:translate(90.9px,46.8px)}57.00%{transform:translate(94.8px,56.6px)}60.50%{transform:translate(95.5px,67.2px)}64.00%{transform:translate(93.1px,77.5px)}67.50%{transform:translate(87.8px,86.7px)}71.00%{transform:translate(80.3px,94.1px)}74.50%{transform:translate(71.1px,99.3px)}78.00%{transform:translate(60.8px,101.9px)}81.50%{transform:translate(50.2px,101.8px)}85.00%{transform:translate(40.0px,99.2px)}88.50%{transform:translate(30.7px,94.1px)}92.00%{transform:translate(22.8px,87.0px)}100%{transform:translate(22.8px,87.0px)}}

  /* 04 memory (8 s) */
  .is-seen .g-mem .m-a { animation: m-a 8s ease-in-out infinite; }
  .is-seen .g-mem .m-a-in { animation: m-a-in 8s ease-in-out infinite; }
  .is-seen .g-mem .m-a-g { animation: m-a-g 8s ease-in-out infinite; }
  .is-seen .g-mem .m-b { animation: m-b 8s linear infinite; }
  .is-seen .g-mem .m-c { animation: m-c 8s linear infinite; }
  .is-seen .g-mem .m-c-in { animation: m-c-in 8s ease-in-out infinite; }
  @keyframes m-a { 0% { transform: rotate(0); } 55%, 92% { transform: rotate(240deg); } 100% { transform: rotate(360deg); } }
  @keyframes m-a-in { 0%, 40% { transform: translateY(0); } 55%, 92% { transform: translateY(18px); } 100% { transform: translateY(0); } }
  @keyframes m-a-g { 0%, 40% { opacity: 0; } 55%, 92% { opacity: 1; } 100% { opacity: 0; } }
  @keyframes m-b { from { transform: rotate(120deg); } to { transform: rotate(480deg); } }
  @keyframes m-c { from { transform: rotate(240deg); } to { transform: rotate(600deg); } }
  @keyframes m-c-in {
    0% { opacity: 0; transform: translateY(0); }
    8%, 40% { opacity: 1; transform: translateY(0); }
    80%, 100% { opacity: 0; transform: translateY(-14px); }
  }

  /* 05 books (5 s) */
  .is-seen .g-books .bk-1 { animation: bk-1 5s ease-in-out infinite; }
  .is-seen .g-books .bk-2 { animation: bk-2 5s ease-in-out infinite; }
  .is-seen .g-books .bk-3 { animation: bk-3 5s ease-in-out infinite; }
  .is-seen .g-books .bk-dot { animation: bk-dot 5s ease-in-out infinite; }
  @keyframes bk-1 { 0%, 18% { transform: translateY(0) scaleX(1); } 42%, 58% { transform: translateY(16px) scaleX(.08); } 82%, 100% { transform: translateY(0) scaleX(1); } }
  @keyframes bk-2 { 0%, 18% { transform: scaleX(1); } 42%, 58% { transform: scaleX(.08); } 82%, 100% { transform: scaleX(1); } }
  @keyframes bk-3 { 0%, 18% { transform: translateY(0) scaleX(1); } 42%, 58% { transform: translateY(-16px) scaleX(.08); } 82%, 100% { transform: translateY(0) scaleX(1); } }
  @keyframes bk-dot { 0%, 18% { transform: scale(1); } 42%, 58% { transform: scale(2.2); } 82%, 100% { transform: scale(1); } }

  /* 06 map (6 s) */
  .is-seen .g-map .e { animation: map-draw 6s ease-in-out infinite backwards; animation-delay: calc(var(--i) * .5s); }
  .is-seen .g-map .n-last { animation: map-pulse 6s ease-in-out infinite; animation-delay: 3.1s; }
  .is-seen .g-map .halo { animation: map-halo 6s ease-out infinite; animation-delay: 3.1s; }
  @keyframes map-draw {
    0% { stroke-dashoffset: 1; opacity: 1; }
    10% { stroke-dashoffset: 0; }
    90% { stroke-dashoffset: 0; opacity: 1; }
    100% { stroke-dashoffset: 0; opacity: 0; }
  }
  @keyframes map-pulse { 0%, 100% { transform: scale(1); } 7% { transform: scale(1.6); } 16% { transform: scale(1); } }
  @keyframes map-halo { 0% { transform: scale(1); opacity: .7; } 18%, 100% { transform: scale(3.4); opacity: 0; } }

  /* 07 box (x 2.3 s, y 1.7 s: the path never closes on itself quickly) */
  .is-seen .g-box .b-x { animation: b-x 2.3s linear infinite alternate; }
  .is-seen .g-box .b-y { animation: b-y 1.7s linear infinite alternate; }
  @keyframes b-x { from { transform: translateX(0); } to { transform: translateX(64px); } }
  @keyframes b-y { from { transform: translateY(0); } to { transform: translateY(64px); } }

  /* 08 spend (5 s) */
  .is-seen .g-spend .sp-hatch { animation: spend 5s ease-in-out infinite; }
  @keyframes spend {
    0% { transform: translateX(-66px); opacity: 1; }
    50%, 86% { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(0); opacity: 0; }
  }

  /* 09 pocket (14 s orbit, 3 s link) */
  .is-seen .g-pocket .p-orbit { animation: spin 14s linear infinite; }
  .is-seen .g-pocket .p-phone { animation: spin-back 14s linear infinite; }
  .is-seen .g-pocket .p-link { animation: p-march 3s linear infinite, p-pulse 3s ease-in-out infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
  @keyframes spin-back { to { transform: rotate(-360deg); } }
  @keyframes p-march { to { stroke-dashoffset: -12; } }
  @keyframes p-pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
}

/* ---- reduced motion: nothing moves ---- */
@media (prefers-reduced-motion: reduce) {
  .habits-ticker { white-space: normal; }
  .ticker-run { white-space: normal; }
  .ticker-run + .ticker-run, .ticker-tail { display: none; }
  .ticker-track { inline-size: auto; }
}
