/*
 * A — the darkroom (#anatomy): one sentence set at poster scale and fully parsed. Night in both
 * schemes, with its column lines showing. This is the no-JS / reduced-motion final frame:
 * every bracket, tag, role and the dimmed modifiers at once (Task 13 stages them on scroll).
 * The sentence scales with the column, so it breaks the same way at every width of a layout;
 * from 768px it is set in sense lines where the data breaks it (ANATOMY.breaks: the subject and
 * its clause, the verb and object, then the not-A / but-B pair one above the other).
 */

#anatomy {
  --fg: var(--room-fg);
  --fg-mute: var(--room-mute);
  --rule: var(--room-hair);
  --focus: var(--room-fg);
  --room-soft: #C9C9C4;
  --room-text: #DADAD5;
  background: repeating-linear-gradient(90deg, var(--room-guide) 0 1px, transparent 1px var(--col)) var(--m) 0 /
      calc(100% - 2 * var(--m) + 1px) 100% no-repeat,
    var(--room-bg);
  color: var(--room-fg);
  overflow-x: clip;
}

#anatomy .section__lead {
  color: var(--room-soft);
}

/* ---------------------------------------------------------------- legend */

.anatomy-legend {
  display: grid;
  grid-template-columns: subgrid;
  align-items: center;
  margin-top: 2.5rem;
  border-block: 1px solid var(--room-hair);
}

.anatomy-legend__title {
  grid-column: 1 / -1;
  padding: 10px var(--pad) 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.2;
  color: var(--room-mute);
}

.anatomy-legend dl {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.anatomy-legend dl > div {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  padding: 10px var(--pad);
}

.anatomy-legend dt {
  min-width: 1.4em;
  font-family: var(--font-en);
  font-weight: 800;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--signal);
}

.anatomy-legend dd {
  font-size: 0.75rem;
  color: var(--room-mute);
}

/* ---------------------------------------------------------------- the sentence */

.anatomy {
  display: grid;
  grid-template-columns: subgrid;
}

.anatomy > * {
  grid-column: 1 / -1;
  min-width: 0;
}

.anatomy-sentence {
  --fs: calc(var(--col) * 0.49);
  --gap: 52px;
  --leader: max(14px, calc(var(--col) * 0.22));
  margin-top: 4.5rem;
  padding: 0 var(--pad);
  font-family: var(--font-en);
  font-weight: 500;
  font-stretch: 96%;
  font-size: var(--fs);
  line-height: calc(1.1em + max(1.6em, var(--gap)));
  letter-spacing: -0.022em;
  color: var(--recede);
  counter-reset: tag;
}

/* The core (S, V, O and the full stop) stays white; everything that modifies it recedes. */
.anatomy-sentence [data-core] {
  color: var(--room-fg);
}

.anatomy-sentence .note {
  color: var(--room-fg);
  font-size: 12px;
}

/* Clause and phrase tags are numbered in reading order, 01–05. */
.anatomy-sentence :is(.span--clause, .span--phrase) > .note::before {
  counter-increment: tag;
  content: counter(tag, decimal-leading-zero);
  margin-right: 8px;
  color: var(--signal);
}

/* Phones: long tags wrap upward within a narrow measure, so a tag near the right edge stays on
   screen; the role note (O: to부정사) waits for wider screens. */
@media (max-width: 767px) {
  .anatomy-sentence .note {
    width: max-content;
    max-width: 9em;
    white-space: normal;
    font-size: 11px;
  }

  .anatomy-sentence .span--role > .note {
    display: none;
  }

  /* A tag the data marks (noteHang: 'left') opens near the right edge on phones, so it hangs to
     the left of its leader instead. */
  .anatomy-sentence [data-note-hang="left"] > .note {
    padding: 0 6px var(--leader) 0;
    border-left: 0;
    border-right: 1px solid var(--signal);
    text-align: right;
    transform: translateX(-100%);
  }
}

@media (min-width: 768px) {
  .anatomy-sentence {
    --fs: calc(var(--col) * 0.58);
    --gap: 84px;
    margin-top: 7.5rem;
  }

  /* Sense lines where the data puts them (ANATOMY.breaks): the renderer marks the outermost
     element ending at each break, so the line ends after any closing bracket. */
  .anatomy-sentence [data-break]::after {
    content: "\A";
    white-space: pre;
  }

  /* The role's name beside its letter, and the role note (O: to부정사) under them. */
  .anatomy-sentence .role-label::after {
    margin-left: 8px;
    font-family: var(--font-mono);
    font-weight: 400;
    font-stretch: 100%;
    font-size: 12px;
    color: var(--room-mute);
  }

  .anatomy-sentence [data-role="S"] > .role-label::after {
    content: "주어";
  }

  .anatomy-sentence [data-role="V"] > .role-label::after {
    content: "동사";
  }

  .anatomy-sentence [data-role="O"] > .role-label::after {
    content: "목적어";
  }

  .anatomy-sentence [data-role="C"] > .role-label::after {
    content: "보어";
  }

  .anatomy-sentence .span--role > .note {
    top: 100%;
    bottom: auto;
    margin-top: calc(var(--fs) * 0.55 + 8px);
    padding: 0;
    border-left: 0;
    color: var(--room-mute);
  }
}

/* ---------------------------------------------------------------- captions, translation, motto */

/* The six steps of the scroll sequence, set as one numbered rail in the final frame. */
.anatomy-captions {
  display: grid;
  grid-template-columns: subgrid;
  margin-top: 3.5rem;
  counter-reset: step;
}

.anatomy-captions li {
  grid-column: span 3;
  padding: 10px var(--pad) 18px;
  border-top: 1px solid var(--room-hair);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: -0.01em;
  counter-increment: step;
}

.anatomy-captions li::before {
  content: counter(step, decimal-leading-zero);
  display: block;
  margin-bottom: 1.25rem;
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 11px;
  line-height: 1;
  color: var(--room-mute);
}

.anatomy-translation {
  margin-top: 3.5rem;
  padding: 0 var(--pad);
  font-size: 1.3125rem;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: -0.03em;
  color: var(--room-text);
}

.anatomy-motto {
  --dot-w: 0.193em;
  --dot-h: 0.187em;
  --dot-x: -0.2em;
  margin-top: 5.5rem;
  padding: 0 0 3.5rem calc(var(--pad) - 0.03em);
  font-family: var(--font-en);
  font-weight: 800;
  font-stretch: 100%;
  font-size: calc(var(--col) * 1.13);
  line-height: 0.9;
  letter-spacing: -0.055em;
}

@media (min-width: 768px) {
  .anatomy-legend dl {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .anatomy-legend dl > div {
    padding: 12px var(--pad);
  }

  .anatomy-captions {
    margin-top: 5rem;
  }

  .anatomy-captions li {
    grid-column: span 2;
  }

  .anatomy-translation {
    grid-column: 3 / 11;
    margin-top: 4.5rem;
    font-size: clamp(1.375rem, calc(var(--col) * 0.26), 1.875rem);
  }

  .anatomy-motto {
    --dot-w: 0.216em;
    --dot-h: 0.195em;
    --dot-x: -0.22em;
    margin-top: 8rem;
    padding-bottom: 4rem;
    font-stretch: 112.5%;
    font-size: calc(var(--col) * 1.25);
    white-space: nowrap;
  }
}

@media (min-width: 1200px) {
  .anatomy-legend__title {
    grid-column: 1 / 3;
    padding: 12px var(--pad);
  }

  .anatomy-legend dl {
    grid-column: 3 / 9;
    grid-template-columns: subgrid;
  }

  /* The margin note sits in the legend's band, in the free columns at its end. */
  #anatomy > .margin-note {
    grid-column: 10 / -1;
    grid-row: 2;
    align-self: center;
    margin: 2.5rem 0 0; /* the legend's own top margin, so both centre on the band */
  }
}
