/*
  zainkhan.me - memoir shell
  Learning from 37signals.com:
  - one confident solid color per signal, cream ink
  - large editorial type, tight leading
  - catalog line "0.1  Title", number in a fixed column
  - every line stays visible but dull; the active one brightens
  - the essay opens inline, in the same page, one at a time
  - fixed gradient veils top and bottom
  - a single glowing controller button
*/

:root {
  --fg: #f7f3ea;
  --fg-dim: rgba(247,243,234,.62);
  --fg-faint: rgba(247,243,234,.5);
  --line: rgba(247,243,234,.16);
  --accent: #edb64c;
  --radius: 12px;
  --pad-x: clamp(1.25rem, 5vw, 4.5rem);
  --num-col: 3.4ch;
  --transition: .2s ease;
}

/* Solid theme color per state. Deep and rich, turned brighter this pass. */
body { --rgb-theme: 23, 20, 17; }
body[data-state="home"]     { --rgb-theme: 23, 20, 17; }
body[data-state="s00"]      { --rgb-theme: 92, 64, 32; }
body[data-state="s01"]      { --rgb-theme: 184, 60, 16; }
body[data-state="s02"]      { --rgb-theme: 15, 118, 110; }
body[data-state="s03"]      { --rgb-theme: 21, 122, 58; }
body[data-state="s04"]      { --rgb-theme: 67, 56, 202; }
body[data-state="s05"]      { --rgb-theme: 159, 18, 57; }
body[data-state="s06"]      { --rgb-theme: 190, 18, 60; }
body[data-state="s07"]      { --rgb-theme: 109, 40, 217; }
body[data-state="timeline"] { --rgb-theme: 51, 65, 85; }

* { margin: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 6rem; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  background-color: rgb(var(--rgb-theme));
  color: var(--fg);
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: clamp(1.2rem, .82rem + 1.15vw, 2.1rem);
  line-height: 1.4;
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background-color .5s ease;
}

/* View transitions take over when supported. */
body.vt { transition: none; }
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root), ::view-transition-new(root) {
    animation-duration: .38s;
    animation-timing-function: cubic-bezier(.2,.7,.2,1);
  }
}

/* Gradient veils: content fades under the chrome, kept short so nothing disappears. */
body::after {
  content: '';
  position: fixed; left: 0; right: 0; bottom: 0; height: 12vh;
  background: linear-gradient(0deg, rgb(var(--rgb-theme)) 0%, rgba(var(--rgb-theme), 0) 100%);
  pointer-events: none; z-index: 40;
}

::selection { background: rgba(247,243,234,.18); }
a { color: inherit; }

/* Skip link, visible only on focus. */
.skip {
  position: absolute; left: .75rem; top: -3rem; z-index: 100;
  background: var(--fg); color: rgb(var(--rgb-theme)); font-weight: 700;
  font-size: .8rem; padding: .5rem .8rem; border-radius: 8px;
  text-decoration: none; transition: top .15s ease;
}
.skip:focus { top: .75rem; }
h1, h2, h3 { color: var(--fg); font-weight: 700; line-height: 1.15; letter-spacing: -.02em; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Visible focus for every control. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }
.social a:focus-visible { outline-offset: 2px; }

/* Mobile-only pieces (hidden on desktop). */
.menu-btn { display: none; }
.brand { display: none; }
.only-mobile { display: none; }
.cat-back { display: none; }

main { flex: 1 0 auto; max-width: none; margin: 0; padding: 4.5rem var(--pad-x) 1.2rem; }

/* ---------- Fixed top bar with gradient ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; padding: 1.1rem var(--pad-x);
  background: linear-gradient(180deg, rgb(var(--rgb-theme)) 0%, rgba(var(--rgb-theme), 0) 100%);
  pointer-events: none;
}
.toplinks { display: flex; flex-wrap: wrap; gap: 1.4rem; align-items: center; pointer-events: auto; }
.toplinks a, .linklike {
  appearance: none; background: none; border: 0; padding: 0; cursor: pointer;
  color: inherit; text-decoration: none; font: inherit;
  font-weight: 700; font-size: .72em; letter-spacing: normal; opacity: .7;
  transition: opacity var(--transition), color var(--transition);
}
.toplinks a:hover, .linklike:hover { opacity: 1; color: var(--accent); }

.brandmark {
  appearance: none; background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--fg); font: inherit; font-weight: 800; font-size: 1.05rem;
  letter-spacing: -.02em; pointer-events: auto;
  display: inline-flex; align-items: center; gap: .55rem;
  transition: color .15s ease;
}
.brandmark .face {
  width: 0; height: 2rem; border-radius: 50%; object-fit: cover; display: block;
  flex: 0 0 auto; opacity: 0; margin-right: 0; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
  transition: width .22s ease, opacity .22s ease, margin-right .22s ease;
}
.brandmark:hover .face, .brandmark:focus-visible .face {
  width: 2rem; opacity: 1; margin-right: .55rem;
}
.brandmark:hover { color: var(--accent); }
.brandmark:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.brandmark .dot { color: var(--accent); }

/* ---------- Views ---------- */
.view { display: none; }
.view.is-active { display: block; animation: viewIn .4s cubic-bezier(.2,.7,.2,1); }
@keyframes viewIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Hero ---------- */
.hero { margin-bottom: 1.2rem; }
.hello {
  display: grid;
  font-size: clamp(2.4rem, min(13vw, 8.5dvh), 8rem);
  line-height: .95;
  font-weight: 800;
  letter-spacing: -.04em;
  color: var(--accent);
  min-height: 1.02em;
  margin-bottom: 1rem;
}
.hello .g {
  grid-area: 1 / 1;
  opacity: 0; transform: translateY(8px);
  transition: opacity .5s ease, transform .5s ease;
  font-family: "Noto Sans", "Noto Sans Arabic", "Noto Sans Devanagari", "Noto Sans CJK", "Noto Sans Thai", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}
.hello .g.is-on { opacity: 1; transform: none; }

.nameintro { font-size: .72em; letter-spacing: .3em; text-transform: uppercase; color: var(--fg-dim); font-weight: 700; }
.name { font-size: clamp(3.6rem, 15vw, 11rem); line-height: .9; letter-spacing: -.05em; font-weight: 800; margin: .05rem 0 0; }

/* ---------- Social: brand-colored hover chips ---------- */
.social { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem; margin: 1rem 0 1.4rem -.55rem; }
.soc {
  --brand: var(--fg); --brand-ink: rgb(var(--rgb-theme));
  display: inline-grid; place-items: center; width: 2.3rem; height: 2.3rem;
  border-radius: 50%; color: var(--fg); opacity: .6; text-decoration: none;
  transition: opacity .16s ease, transform .16s ease, background-color .16s ease;
}
.soc:hover, .soc:focus-visible { opacity: 1; transform: translateY(-3px); background-color: var(--brand); outline: none; }
.ico {
  width: 1.05rem; height: 1.05rem; display: block; background-color: currentColor;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
  transition: background-color .16s ease;
}
.soc:hover .ico, .soc:focus-visible .ico { background-color: var(--brand-ink); }
.soc-linkedin { --brand: #0A66C2; --brand-ink: #fff; }
.soc-linkedin .ico { -webkit-mask-image: url(../images/linkedin.svg); mask-image: url(../images/linkedin.svg); }
.soc-x { --brand: #ffffff; --brand-ink: #171411; }
.soc-x .ico { -webkit-mask-image: url(../images/x.svg); mask-image: url(../images/x.svg); }
.soc-youtube { --brand: #FF0000; --brand-ink: #fff; }
.soc-youtube .ico { -webkit-mask-image: url(../images/youtube.svg); mask-image: url(../images/youtube.svg); }
.soc-github { --brand: #ffffff; --brand-ink: #171411; }
.soc-github .ico { -webkit-mask-image: url(../images/github.svg); mask-image: url(../images/github.svg); }
.soc-telegram { --brand: #26A5E4; --brand-ink: #fff; }
.soc-telegram .ico { -webkit-mask-image: url(../images/telegram.svg); mask-image: url(../images/telegram.svg); }
.soc-maildotru { --brand: #005FF9; --brand-ink: #fff; }
.soc-maildotru .ico { -webkit-mask-image: url(../images/maildotru.svg); mask-image: url(../images/maildotru.svg); }
@media (hover: none) { .soc { opacity: .85; } }

.lead { font-size: 1.05em; opacity: .85; margin-bottom: 2.6rem; max-width: 42ch; }

/* ---------- Catalog: every line visible but dull, the active one bright ---------- */
.catalog { list-style: none; padding: 0; margin: 0; }
.catalog li { list-style: none; }
.cat-entry > summary { list-style: none; }
.cat-entry > summary::-webkit-details-marker { display: none; }
.cat-item {
  appearance: none; background: none; border: 0; cursor: pointer;
  width: 100%; text-align: left; color: var(--fg); font: inherit;
  display: flex; align-items: baseline; gap: 0;
  font-weight: 700; letter-spacing: -.01em;
  padding: .14em 0;
  opacity: .55;
  transition: opacity var(--transition), color var(--transition);
}
.cat-item .num { font-feature-settings: 'tnum'; flex: 0 0 var(--num-col); width: var(--num-col); }
.cat-item:hover, .cat-item:focus-visible { opacity: .85; }
.cat-entry[open] > .cat-item { opacity: 1; }
.cat-entry[open] > .cat-item .num { color: var(--accent); }
.cat-entry[open] > .cat-item:hover { opacity: 1; }

.cat-body { margin-left: var(--num-col); max-width: 50ch; padding: .2rem 0 1.5rem; animation: bodyIn .3s ease; }
.cat-body .essay p { margin: 0 0 .7em; }
.cat-body .essay a { color: inherit; text-decoration: underline; text-underline-offset: .12em; text-decoration-thickness: .06em; }
@keyframes bodyIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.tagline { margin-top: 1.6rem; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; font-size: .72em; opacity: .75; }

/* ---------- Countdown: big tabular numbers, tiny labels ---------- */
.countdown {
  display: inline-flex; align-items: flex-start; gap: 1.15rem;
  vertical-align: baseline; margin: .15rem .4rem .1rem;
}
.unit {
  display: inline-flex; flex-direction: column; align-items: flex-start;
  background: none; border-radius: 0; padding: 0; min-width: 0;
}
.unit b {
  font-variant-numeric: tabular-nums; font-feature-settings: 'tnum';
  font-size: clamp(1.6rem, 3.4vw, 2.4rem); line-height: 1; font-weight: 800;
  letter-spacing: -.03em;
}
.unit i {
  font-style: normal; font-size: clamp(.55rem, 1.1vw, .7rem);
  letter-spacing: .16em; text-transform: uppercase; opacity: .5; margin-top: .35em;
}
.countdown .sep { display: none; }
.unit:last-child b { color: var(--accent); }

/* ---------- Timeline (vertical spine) ---------- */
.signal-num { font-feature-settings: 'tnum'; font-weight: 700; font-size: .8em; color: var(--fg-dim); margin-bottom: 1rem; }
.timeline h1 { font-size: clamp(2.2rem, 1rem + 5vw, 5rem); margin: 0 0 .5rem; }
.tl { position: relative; margin: 3rem 0 0; padding: 0; }
.tl::before { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; background: var(--line); transform: translateX(-50%); }
.ev { position: relative; margin-bottom: 3rem; }
.ev .dot {
  position: absolute; left: 50%; top: .55rem; transform: translateX(-50%);
  width: 11px; height: 11px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 5px rgb(var(--rgb-theme));
}
.ev .card { width: calc(50% - 2.75rem); }
.ev:nth-child(odd) .card { margin-left: auto; }
.ev .year { font-size: 1.6em; font-weight: 800; letter-spacing: -.02em; color: var(--accent); }
.ev h2 { font-size: .95em; font-weight: 700; line-height: 1.3; margin: .3rem 0 .8rem; }
.media {
  aspect-ratio: 16 / 10; border-radius: var(--radius); overflow: hidden;
  background: rgba(247,243,234,.08); border: 1px solid var(--line);
  display: grid; place-items: center;
}
.media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media span { font-size: .6em; letter-spacing: .2em; text-transform: uppercase; color: var(--fg-faint); }

@media (max-width: 680px) {
  .tl::before { left: 5px; transform: none; }
  .ev .dot { left: 5px; transform: translateX(-50%); }
  .ev .card { width: auto; margin-left: 1.9rem !important; }
}

/* ---------- Controller (star) ---------- */
#next {
  --tx: 0px; --ty: 0px; --sc: 1;
  position: fixed;
  right: 1.1rem;
  right: calc(1.1rem + env(safe-area-inset-right, 0px));
  bottom: 1.1rem;
  bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  display: inline-grid; place-items: center;
  padding: .55rem;
  background: none; border: 0; border-radius: 0;
  color: var(--fg);
  font-size: 2rem; line-height: 1;
  cursor: grab; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.5));
  transform: translate(var(--tx), var(--ty)) scale(var(--sc));
  transition: transform .16s ease, color .16s ease;
}
#next:hover { --sc: 1.15; color: var(--accent); }
#next:active { --sc: 1; }
#next.dragging { cursor: grabbing; transition: none; filter: none; }
#next.dragging:hover { color: var(--fg); }

/* ---------- Footer: mirrors the header ---------- */
.site-footer {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; justify-content: flex-start; align-items: baseline;
  gap: 1rem 2rem; max-width: none; margin: 0;
  padding: 1.6rem var(--pad-x) 1.8rem; border-top: 1px solid var(--line);
}
.footer-links { display: flex; flex-wrap: wrap; gap: 1.4rem; align-items: center; }
.footer-links a, .footer-links .linklike {
  color: inherit; text-decoration: none; font-weight: 700; font-size: .72em;
  letter-spacing: normal; opacity: .7; transition: opacity .15s ease, color .15s ease;
}
.footer-links a:hover, .footer-links .linklike:hover { opacity: 1; color: var(--accent); }
.footer-brand { font-weight: 800; font-size: 1.05rem; letter-spacing: -.02em; }
.footer-brand .dot { color: var(--accent); }

@media (max-width: 680px) {
  .site-footer { padding-right: 4.2rem; }
}

/* ---------- Timeline photo captions ---------- */
.cap { margin-top: .6rem; font-size: .76em; color: var(--fg-dim); max-width: 46ch; }

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  body, #next, .hello .g, .cat-item { transition: none; }
  #next { animation: none; }
  .view.is-active, .cat-body { animation: none; }
  .cat-item { opacity: .6; }
}

/* ---------- Mobile ---------- */
/* ---------- Legal page ---------- */
.legal h1 { font-size: clamp(2.2rem, 1rem + 5vw, 5rem); margin: 0 0 1.4rem; }
.legal .essay p { margin: 0 0 .8em; }
.meta-note { margin-top: 1.6rem; font-size: .8em; color: var(--fg-dim); }

/* ---------- Mobile ---------- */
@media (max-width: 680px) {
  .cat-item { opacity: .55; }
  .cat-body { margin-left: 0; }
  main { padding-bottom: 9rem; }
  #next { width: 3.8rem; height: 3.8rem; font-size: 1.35rem; }

  /* Menu button */
  .menu-btn {
    display: block; position: relative; z-index: 61; pointer-events: auto;
    appearance: none; background: none; border: 0; padding: 0; cursor: pointer;
    color: inherit; font: inherit; font-weight: 700; font-size: .82em; letter-spacing: normal;
  }
  .menu-btn:hover { color: var(--accent); }

  /* The links collapse into a full-screen panel when open */
  .toplinks { display: none; }
  body.menu-open .toplinks {
    display: flex; flex-direction: column; align-items: flex-start; gap: 1.15rem;
    position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 55;
    background: rgb(var(--rgb-theme));
    padding: 6rem var(--pad-x) 2rem; overflow-y: auto; pointer-events: auto;
  }
  body.menu-open .toplinks a, body.menu-open .toplinks .linklike { font-size: 1.4rem; opacity: 1; }
  .only-mobile { display: inline; }
  body.menu-open #next { display: none; }

  .brandmark { position: relative; z-index: 61; }

  /* One idea at a time: when a section is open, hide the rest of the list */
  body.cat-open .catalog li:not(.is-open) { display: none; }
  body.cat-open .cat-back { display: inline-block; margin-bottom: 1.2rem; font-size: .9em; }

  /* Fixed, beating star (no dragging on mobile) */
  #next { animation: starBeat 1.7s ease-in-out infinite; cursor: pointer; }
}

@keyframes starBeat {
  0%, 60%, 100% { transform: translate(0, 0) scale(1); }
  80% { transform: translate(0, 0) scale(1.22); }
}
