/* Writing: post list and magazine-style post pages.
   Loaded after css/style.css; uses its tokens (--ink, --paper, --gutter, --ease-out, …). */

.page-writing {
  --measure: 680px;          /* body text column: ~36–40 Korean characters a line */
  --wide: 1080px;            /* wide images, cover, pager */
  --body-ink: #2b2b28;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --accent-bar: linear-gradient(180deg, var(--peach), var(--orange) 35%, var(--magenta) 65%, var(--purple));
}

.page-writing main {
  padding-bottom: clamp(96px, 12vw, 180px);
}

/* Shared column grid: full bleed | wide | content | wide | full bleed */
.post-head,
.post-cover,
.post-body,
.post-foot,
.post-pager {
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--gutter), 1fr)
    [wide-start] minmax(0, calc((var(--wide) - var(--measure)) / 2))
    [content-start] min(var(--measure), 100% - 2 * var(--gutter))
    [content-end] minmax(0, calc((var(--wide) - var(--measure)) / 2))
    [wide-end] minmax(var(--gutter), 1fr) [full-end];
}

.post-head > *,
.post-body > *,
.post-foot > * {
  grid-column: content;
}

/* ---------- Reading progress (scroll-driven, CSS only) ---------- */

.read-progress {
  display: none;
}

@supports (animation-timeline: scroll()) {
  .read-progress {
    display: block;
    position: fixed;
    inset: 0 0 auto;
    z-index: 20;
    height: 2px;
    background: linear-gradient(90deg, var(--peach), var(--orange), var(--magenta), var(--purple));
    transform-origin: 0 50%;
    animation: read-progress linear both;
    animation-timeline: scroll(root block);
  }

  @keyframes read-progress {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
  }
}

/* ---------- Post head ---------- */

.post-head {
  padding-top: clamp(48px, 8vw, 128px);
}

.post-head__eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.post-head__eyebrow a {
  text-decoration: none;
}

.post-head__eyebrow a::before {
  content: "←";
  display: inline-block;
  margin-right: 6px;
  transition: transform 0.5s var(--ease-out);
}

.post-head__eyebrow a:hover::before,
.post-head__eyebrow a:focus-visible::before {
  transform: translateX(-3px);
}

.post-head__title {
  grid-column: wide;
  margin-top: 20px;
  max-width: 18em;
  font-size: clamp(32px, 5vw, 64px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.post-head__eyebrow,
.post-head__dek,
.post-head__meta {
  grid-column: wide;
}

.post-head__dek {
  margin-top: 24px;
  max-width: 34em;
  font-size: clamp(18px, 1.6vw, 21px);
  font-weight: 500;
  line-height: 1.6;
  letter-spacing: -0.015em;
  color: #4a4a46;
}

.post-head__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--ink);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Cover ---------- */

.post-cover {
  margin-top: clamp(40px, 5vw, 64px);
  overflow: clip; /* the edge-to-edge cover's entry scale must not widen the page on phones */
}

.post-cover__img {
  grid-column: wide;
  width: 100%;
  height: auto;
  max-height: 82vh;
  object-fit: cover;
  border-radius: 4px;
  background: var(--paper-tint);
}

.js .post-cover__img {
  animation: post-cover-in 1.4s var(--ease-out) both;
}

@keyframes post-cover-in {
  from { opacity: 0; transform: scale(1.015); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 599px) {
  /* On phones the cover runs edge to edge, like the start of a magazine spread. */
  .post-cover__img {
    grid-column: full;
    border-radius: 0;
  }
}

/* ---------- Body ---------- */

.post-body {
  margin-top: clamp(48px, 6vw, 80px);
  font-size: 18px;
  line-height: 1.85;
  letter-spacing: -0.008em;
  color: var(--body-ink);
  word-break: keep-all;
  overflow-wrap: break-word;
}

@media (max-width: 599px) {
  .post-body {
    font-size: 17px;
    line-height: 1.8;
  }
}

.post-body > * + * {
  margin-top: 1.25em;
}

/* Grid items do not collapse margins, so set-off blocks only space themselves
   from above, and the block after them takes the same space. */
.post-body > :is(blockquote, .post-code, .post-figure) {
  margin-bottom: 0;
}

.post-body > :is(blockquote, .post-code) + * {
  margin-top: 2em;
}

.post-body > .post-figure + * {
  margin-top: 2.6em;
}

.post-body > .post-break + * {
  margin-top: 0;
}

.post-body h2,
.post-body h3,
.post-body h4 {
  color: var(--ink);
  font-weight: 600;
  letter-spacing: -0.03em;
  text-wrap: balance;
  scroll-margin-top: 24px;
}

.post-body h2 {
  margin-top: 2.6em;
  font-size: clamp(24px, 2.4vw, 30px);
  line-height: 1.35;
}

.post-body h3 {
  margin-top: 2.2em;
  font-size: clamp(20px, 1.8vw, 22px);
  line-height: 1.4;
}

.post-body h4 {
  margin-top: 2em;
  font-size: 18px;
}

.post-body h2 + *,
.post-body h3 + *,
.post-body h4 + * {
  margin-top: 0.75em;
}

.post-body a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: rgba(20, 20, 20, 0.35);
  text-underline-offset: 0.22em;
  transition: text-decoration-color 0.3s var(--ease-out);
}

.post-body a:hover,
.post-body a:focus-visible {
  text-decoration-color: currentColor;
}

.post-body strong {
  font-weight: 650;
  color: var(--ink);
}

.post-body ul,
.post-body ol {
  padding-left: 1.3em;
}

.post-body ul {
  list-style: disc;
}

.post-body ol {
  list-style: decimal;
}

.post-body li + li,
.post-body li > ul,
.post-body li > ol {
  margin-top: 0.4em;
}

.post-body li > ul {
  list-style: circle;
}

.post-body li::marker {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Quote: a thin bar in the site's gradient, larger set text */
.post-body blockquote {
  position: relative;
  margin-block: 2em;
  padding-left: 24px;
  font-size: clamp(19px, 1.7vw, 21px);
  font-weight: 500;
  line-height: 1.7;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.post-body blockquote::before {
  content: "";
  position: absolute;
  inset: 0.35em auto 0.35em 0;
  width: 2px;
  border-radius: 2px;
  background: var(--accent-bar);
}

.post-body blockquote > * + * {
  margin-top: 0.8em;
}

/* Code */
.post-body code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.12em 0.38em;
  border-radius: 4px;
  background: rgba(20, 20, 20, 0.06);
  word-break: break-word;
}

.post-code {
  position: relative;
  margin-block: 2em;
}

.post-code pre {
  overflow-x: auto;
  padding: 22px 24px;
  border-radius: 6px;
  background: #1c1b1a;
  color: #ecebe6;
  font-size: 14px;
  line-height: 1.7;
  letter-spacing: 0;
  -webkit-overflow-scrolling: touch;
}

.post-code pre code {
  padding: 0;
  background: none;
  font-size: inherit;
  word-break: normal;
  white-space: pre;
}

.post-code__lang {
  position: absolute;
  top: 8px;
  right: 12px;
  font-family: var(--mono);
  font-size: 11px;
  color: rgba(236, 235, 230, 0.45);
  text-transform: lowercase;
}

.post-break {
  height: auto;
  margin-block: 3.2em;
  border: 0;
  text-align: center;
  color: var(--muted);
}

.post-break::before {
  content: "· · ·";
  letter-spacing: 0.6em;
}

/* ---------- Figures ---------- */

.post-body > .post-figure {
  margin-top: 2.6em;
}

.post-figure img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  background: var(--paper-tint);
}

.post-figure figcaption {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.005em;
  color: var(--muted);
}

.post-figure--wide {
  grid-column: wide;
}

.post-figure--full {
  grid-column: full;
}

.post-figure--full img {
  border-radius: 0;
}

.post-figure--full figcaption {
  width: min(var(--measure), 100% - 2 * var(--gutter));
  margin-inline: auto;
}

/* A row of images (several image lines in one paragraph) */
.post-figure__row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 24px);
  align-items: start;
}

.post-figure--cols-3 .post-figure__row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.post-figure--full .post-figure__row {
  padding-inline: var(--gutter);
}

@media (max-width: 599px) {
  .post-figure--wide {
    grid-column: full;
  }

  .post-figure--wide img {
    border-radius: 0;
  }

  .post-figure--wide figcaption {
    padding-inline: var(--gutter);
  }

  .post-figure--cols-3 .post-figure__row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------- Post foot & pager ---------- */

.post-foot {
  margin-top: clamp(64px, 8vw, 104px);
  row-gap: 32px;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.post-tags li {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.post-foot__back {
  justify-self: start;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
}

.post-foot__back:hover,
.post-foot__back:focus-visible {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.post-pager {
  margin-top: clamp(56px, 7vw, 96px);
}

.post-pager__link {
  grid-column: wide;
  display: grid;
  gap: 6px;
  padding-block: 24px;
  border-top: 1px solid var(--line);
  text-decoration: none;
}

.post-pager__link:last-child {
  border-bottom: 1px solid var(--line);
}

.post-pager__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.post-pager__title {
  font-size: clamp(18px, 1.8vw, 22px);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.025em;
  transition: transform 0.6s var(--ease-out);
}

.post-pager__link:hover .post-pager__title,
.post-pager__link:focus-visible .post-pager__title {
  transform: translateX(6px);
}

.post-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--orange);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.5;
}

/* ---------- List page ---------- */

.writing-hero {
  padding: clamp(48px, 8vw, 120px) var(--gutter) clamp(40px, 5vw, 72px);
}

.writing-hero__eyebrow {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.writing-hero__title {
  margin-top: 16px;
  font-size: clamp(44px, 8vw, 140px);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.045em;
}

.writing-hero__lead {
  margin-top: 24px;
  max-width: 30em;
  font-size: clamp(18px, 1.8vw, 26px);
  font-weight: 500;
  letter-spacing: -0.02em;
}

.writing-list {
  padding: 0 var(--gutter);
}

.writing-list a {
  display: block;
  text-decoration: none;
}

.writing-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Media frame shared by the lead story and cards */
.writing-lead__media,
.writing-card__media {
  overflow: hidden;
  border-radius: 4px;
  background: var(--paper-tint);
}

.writing-lead__img,
.writing-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 1.2s var(--ease-out);
}

.writing-lead__img--blank,
.writing-card__img--blank {
  background:
    radial-gradient(100% 70% at 80% 110%, rgba(249, 186, 140, 0.8) 0%, transparent 60%),
    radial-gradient(80% 60% at 10% 120%, rgba(125, 87, 171, 0.55) 0%, transparent 55%),
    linear-gradient(180deg, #e0e0dd 0%, #ece4da 100%);
}

.writing-lead__link:hover .writing-lead__img,
.writing-lead__link:focus-visible .writing-lead__img,
.writing-card__link:hover .writing-card__img,
.writing-card__link:focus-visible .writing-card__img {
  transform: scale(1.025);
}

/* Lead story: the newest post, large */
.writing-lead {
  padding-top: 24px;
  border-top: 1px solid var(--ink);
}

.writing-lead__link {
  display: grid !important;
  gap: 24px;
}

.writing-lead__media {
  aspect-ratio: 16 / 9;
}

.writing-lead__title {
  margin-top: 12px;
  font-size: clamp(26px, 3.4vw, 48px);
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.writing-lead__summary {
  margin-top: 16px;
  max-width: 32em;
  font-size: clamp(16px, 1.3vw, 18px);
  line-height: 1.7;
  color: #4a4a46;
}

@media (min-width: 900px) {
  .writing-lead__link {
    grid-template-columns: 7fr 5fr;
    align-items: end;
    gap: clamp(32px, 4vw, 64px);
  }
}

/* Remaining posts */
.writing-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(48px, 5vw, 72px) 24px;
  margin-top: clamp(64px, 8vw, 112px);
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

@media (min-width: 700px) {
  .writing-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1100px) {
  .writing-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.writing-card__media {
  aspect-ratio: 3 / 2;
  margin-bottom: 16px;
}

.writing-card__title {
  margin-top: 8px;
  font-size: clamp(19px, 1.6vw, 22px);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.025em;
}

.writing-card__summary {
  margin-top: 8px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.writing-empty {
  padding: 48px 0;
  border-top: 1px solid var(--ink);
  color: var(--muted);
}

/* ---------- Header: current section ---------- */

.site-nav a[aria-current="page"] {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* ---------- Motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  .js .post-cover__img,
  .read-progress {
    animation: none;
  }

  .read-progress {
    display: none;
  }

  .writing-lead__img,
  .writing-card__img,
  .post-pager__title,
  .post-head__eyebrow a::before {
    transition: none;
  }
}

.post-body > :first-child {
  margin-top: 0;
}
