/* ==========================================================================
   Mohammed Lahrouri — site styles
   Tokens first; change colours/sizes here.
   ========================================================================== */

:root {
  --bg: #FFFFFF;
  --text: #111214;
  --muted: #52575D;          /* secondary text, 7:1 on white; stays AA over the animated background */
  --accent: #2C4C7A;         /* focus ring */
  --rule: rgba(17, 18, 20, 0.12);
  --grid: rgba(17, 18, 20, 0.045);
  --surface: #F5F5F5;
  --button: #8A8D91;
  --read-text: #26292D;

  /* typographic cover tones */
  --tone-stone: #ECEAE6;
  --tone-sea:   #DDE7EE;
  --tone-sage:  #E2E9E0;
  --tone-sand:  #F0E7D8;
  --tone-slate: #E1E5EB;
  --cover-ink:  #1F2328;
  --cover-sub:  #4F555C;

  --serif: Georgia, "Gelasio", Cambria, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --column: 624px;
  --gutter: 20px;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0B0B0C;
  --text: #F2F2F2;
  --muted: #B4B7BB;
  --accent: #A8BFE0;
  --rule: rgba(242, 242, 242, 0.14);
  --grid: rgba(242, 242, 242, 0.04);
  --surface: #17181A;
  --button: #3A3C40;
  --read-text: #DCDCDA;

  --tone-stone: #1E1D1B;
  --tone-sea:   #16212A;
  --tone-sage:  #18211A;
  --tone-sand:  #262017;
  --tone-slate: #1A1E25;
  --cover-ink:  #ECECEA;
  --cover-sub:  #A9ADB2;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  /* subtle graph paper across the whole page */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 56px 56px;
  background-position: center -1px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
body.reading { background-image: none; }

/* animated background (assets/bg.js) replaces the CSS grid when it runs */
.bg-canvas {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
.has-bg-canvas body { background-image: none; }

.page {
  max-width: calc(var(--column) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 5rem var(--gutter) 3rem;
}

/* one quiet fade on load */
.ready .page { animation: arrive 420ms ease-out both; }
@keyframes arrive { from { opacity: 0; } to { opacity: 1; } }

/* ---------- links & focus ------------------------------------------------ */
a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: text-decoration-color 150ms ease, color 150ms ease;
}
a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- hero --------------------------------------------------------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
}

.avatar {
  width: 64px; height: 64px;
  border-radius: 10px;
  overflow: hidden;
  flex: none;
  display: grid; place-items: center;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--rule);
  font-family: var(--serif);
  font-size: 1.35rem;
  color: var(--muted);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.toggles { display: flex; gap: 0.25rem; margin-right: -0.6rem; }

.toggle {
  min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 0.6rem;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  font: 400 0.875rem/1 var(--sans);
  cursor: pointer;
}
.toggle:hover { color: var(--text); }

.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

.name {
  margin: 0 0 0.9rem;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.5rem, 8.5vw, 3.75rem);
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 0 0 1.5rem;
  font-size: 1.125rem;
  line-height: 1.6;
}

/* ---------- social row --------------------------------------------------- */
.social {
  display: flex;
  flex-wrap: wrap;
  column-gap: 1.1rem;
  color: var(--muted);
  font-size: 0.875rem;
}
.social a, .social .soon, .linklike {
  display: inline-flex; align-items: center;
  min-height: 44px;
}
.social a { color: var(--muted); text-decoration: none; }
.social a:hover { color: var(--text); }
.soon { color: var(--muted); }
.soon small { font-size: 0.85em; margin-left: 0.3em; }

.linklike {
  padding: 0;
  background: none; border: 0;
  font: inherit; color: var(--muted);
  cursor: pointer;
}
.linklike:hover { color: var(--text); }
.linklike.is-copied { color: var(--text); }

/* ---------- sections ----------------------------------------------------- */
main section { margin-top: 4rem; }

h2 {
  margin: 0 0 1rem;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 1.25rem;
  line-height: 1.4;
}

p { margin: 0 0 1rem; }
ul { margin: 0; padding: 0; list-style: none; }

/* ---------- writing cards ------------------------------------------------ */
.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1.5rem;
  row-gap: 2.25rem;
}
.card-link { display: block; text-decoration: none; color: inherit; }

.cover {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  margin-bottom: 0.85rem;
}
.cover-photo { box-shadow: inset 0 0 0 1px var(--rule); }
.cover img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform 300ms ease;
}

/* typographic cover: honest, no stock imagery */
.cover-type {
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 1rem 1.1rem 1.05rem;
  color: var(--cover-ink);
  box-shadow: inset 0 0 0 1px var(--rule);
}
.cover-venue {
  font-size: 0.75rem;
  color: var(--cover-sub);
  line-height: 1.3;
}
.cover-word {
  margin-top: auto;
  font-family: var(--serif);
  font-size: clamp(1.4rem, 3.4vw, 1.75rem);
  line-height: 1.12;
  letter-spacing: -0.01em;
  transform-origin: left bottom;
  transition: transform 300ms ease;
}
/* decorative chart on a typographic cover */
.cover-type { --chart-accent: #2F6FD0; }
[data-theme="dark"] .cover-type { --chart-accent: #8DB8FF; }
.cover-art {
  position: absolute;
  left: 0; right: 0; top: 2.6rem; bottom: 3.4rem;
  width: 100%; height: calc(100% - 6rem);
  overflow: visible;
}
.cover-venue, .cover-word { position: relative; }
.chart-grid line { stroke: var(--cover-ink); stroke-opacity: .09; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-line { fill: none; stroke-linecap: round; vector-effect: non-scaling-stroke;
  stroke-dasharray: 1; stroke-dashoffset: 1; }
.chart-line-a { stroke: var(--chart-accent); stroke-width: 2; }
.chart-line-b { stroke: var(--cover-ink); stroke-opacity: .35; stroke-width: 1.5; }
.chart-area { opacity: 0; }
.cover-art.is-drawn .chart-line { animation: chart-draw 1.6s cubic-bezier(.3,.7,.2,1) forwards; }
.cover-art.is-drawn .chart-line-b { animation-delay: .25s; }
.cover-art.is-drawn .chart-area { animation: chart-fade 1s ease-out .9s forwards; }
@keyframes chart-draw { to { stroke-dashoffset: 0; } }
@keyframes chart-fade { to { opacity: 1; } }

.tone-stone { background: var(--tone-stone); }
.tone-sea   { background: var(--tone-sea); }
.tone-sage  { background: var(--tone-sage); }
.tone-sand  { background: var(--tone-sand); }
.tone-slate { background: var(--tone-slate); }

.is-planned .cover-type {
  background: var(--bg);
  box-shadow: none;
  border: 1px dashed var(--rule);
  color: var(--muted);
}

.card-link:hover .cover img { transform: scale(1.03); }
.card-link:hover .cover-word { transform: scale(1.03); }

.card-title {
  margin: 0 0 0.2rem;
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.45;
  text-wrap: pretty;
}
.card-link:hover .card-title { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.22em; }
.card-summary {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.55;
}
.card-meta { margin: 0; color: var(--muted); font-size: 0.8125rem; line-height: 1.5; }
.is-planned .card-meta { font-style: italic; }

/* ---------- resources ---------------------------------------------------- */
.empty { color: var(--muted); }
.resources li { margin-bottom: 1rem; }
.note { display: block; color: var(--muted); font-size: 0.9375rem; }

/* ---------- subscribe ---------------------------------------------------- */
.subscribe h2 { font-size: 1.125rem; margin-bottom: 0.4rem; }
.subscribe p { color: var(--muted); font-size: 0.9375rem; margin-bottom: 0.9rem; }
.subscribe-form { display: flex; gap: 0.5rem; }
.subscribe-form input,
.subscribe-form button {
  min-height: 44px;
  font: inherit; font-size: 0.875rem;
  border-radius: 8px;
}
.subscribe-form input {
  flex: 1 1 auto; min-width: 0;
  padding: 0 0.85rem;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--muted);
}
.subscribe-form button {
  flex: none;
  padding: 0 1rem;
  border: 0;
  background: var(--button);
  color: #fff;
}
.subscribe-form [disabled] { cursor: not-allowed; }

/* ---------- footer ------------------------------------------------------- */
.footer {
  margin-top: 4rem;
  color: var(--muted);
  font-size: 0.8125rem;
}
.footer p { margin: 0; }
.footer .credits { margin-top: 0.35rem; font-size: 0.75rem; }

/* ---------- article reading page ---------------------------------------- */
.page-reading { max-width: calc(42rem + 2 * var(--gutter)); padding-top: 2rem; }

.article-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 2.5rem;
}
.toggles-reading { margin-right: -0.6rem; }
.home-link {
  display: inline-flex; align-items: center; gap: 0.45rem; min-height: 44px;
  font-size: 0.9375rem;
  text-decoration: none;
  color: var(--muted);
}
.home-link:hover { color: var(--text); }
.home-link .icon { width: 15px; height: 15px; }

.article h1 {
  margin: 0 0 0.6rem;
  font-family: var(--sans);
  font-weight: 600;
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  line-height: 1.2;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.article-meta { color: var(--muted); font-size: 0.9375rem; margin-bottom: 2.25rem; }
.lede {
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.7;
  color: var(--muted);
  margin-bottom: 2rem;
}
.prose {
  font-family: var(--serif);
  font-size: 1.1875rem;      /* 19px */
  line-height: 1.75;
  color: var(--read-text);
  max-width: 36rem;          /* ~65 characters */
  hyphens: auto;
}
.prose p { margin: 0 0 1.4em; }
.prose b, .prose strong { font-weight: 700; color: var(--text); }
.prose .draft { color: var(--muted); font-style: italic; }
.prose .closing { margin-top: 2.5em; }
.footer-reading { border-top: 1px solid var(--rule); padding-top: 1.25rem; }

/* ---------- utilities ---------------------------------------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- responsive --------------------------------------------------- */
@media (min-width: 640px) {
  .name { white-space: nowrap; }      /* the name stays on one line */
}

@media (max-width: 479.98px) {
  :root { --gutter: 18px; }
  .page { padding-top: 2rem; }
  .tagline { font-size: 1.0625rem; }
  .cards { grid-template-columns: 1fr; row-gap: 2rem; }
  .prose, .lede { font-size: 1.125rem; }
}

@media (min-width: 480px) and (max-width: 1024px) {
  :root { --gutter: 32px; --column: 660px; }
  .page { padding-top: 4rem; }
}

/* ---------- reduced motion ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .chart-line { stroke-dashoffset: 0; }
  .chart-area { opacity: 1; }
  .card-link:hover .cover img,
  .card-link:hover .cover-word { transform: none; }
}
