/* Little Letters · A Closer Look (Phase 05.6A): three letters from the sketchbook.
   Loaded after styles.css, which supplies the tokens and the .label rule.

   Every glyph is live text in the release font, so the letters are exactly the ones in the
   download. Dots sit on the shipped outlines: --x and --y are font units (y up from the
   baseline), --adv is the glyph's advance width, and --gs is the glyph size. The line box is
   1 em tall at line-height 1, with the baseline 0.8 em down (ascent 800, descent 200). */

.closer {
  position: relative;
  padding-top: clamp(40px, 8vw, 64px);
  padding-bottom: clamp(72px, 12vw, 128px);
}

.closer::before {
  content: "";
  position: absolute;
  top: 0;
  left: var(--edge);
  right: var(--edge);
  border-top: 1px solid var(--border);
}

.closer-title {
  margin: 0;
  font-family: var(--letters);
  font-weight: 400;
  font-size: clamp(44px, 12vw, 72px);
  line-height: 1.1;
}

.closer-lede,
.closer-coda {
  margin: 0.35em 0 0;
  font-family: var(--letters);
  font-size: clamp(22px, 5.4vw, 28px);
  line-height: 1.3;
  color: var(--graphite-soft);
}

.closer-coda {
  max-width: 34rem;
  margin-top: clamp(24px, 4vw, 32px);
  font-size: clamp(20px, 4.6vw, 22px);
}

/* Sheet and plates: on phones each letter is its own plate; from 720 px they share one sheet. */

.closer-sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  margin-top: clamp(28px, 6vw, 48px);
}

.closer-plate {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(52, 52, 47, 0.04), 0 12px 32px -24px rgba(52, 52, 47, 0.18);
}

.closer-plate {
  --gs: clamp(118px, 34vw, 148px);
  margin: 0;
  min-width: 0;
  padding: 14px 20px 18px;
}

/* The writing line: one em of guides drawn from the font's metrics. */
.closer-stage { position: relative; }

.closer-line {
  position: relative;
  height: 1em;
  font-family: var(--letters);
  font-size: var(--gs);
  line-height: 1;
  background-image:
    linear-gradient(rgba(132, 148, 123, 0.45), rgba(132, 148, 123, 0.45)),
    repeating-linear-gradient(90deg, rgba(132, 148, 123, 0.5) 0 2px, transparent 2px 8px),
    repeating-linear-gradient(90deg, rgba(132, 148, 123, 0.5) 0 2px, transparent 2px 8px);
  background-repeat: no-repeat;
  background-size: 100% 1px;
  /* baseline 0.8 em, x-height 0.266 em, cap height 0.066 em down from the top */
  background-position: 0 0.8em, 0 0.266em, 0 0.066em;
}

.closer-glyph {
  position: absolute;
  top: 0;
  left: calc(50% - var(--adv) / 2000 * var(--gs));
  color: var(--graphite);
}

/* Where a note points: a terracotta dot on the drawing, ringed in paper so it reads on ink. */
.closer-dot {
  --dot-x: calc(50% + (var(--x) - var(--adv) / 2) / 1000 * var(--gs));
  --dot-y: calc((800 - var(--y)) / 1000 * var(--gs));
  position: absolute;
  left: var(--dot-x);
  top: var(--dot-y);
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: var(--terracotta);
  box-shadow: 0 0 0 1.5px var(--paper);
}

/* Its number, beside the dot on whichever side is open paper. */
.closer-dot::after {
  content: attr(data-n);
  position: absolute;
  top: 50%;
  font: 400 15px/1 var(--letters);
  color: var(--terracotta);
  transform: translateY(-0.4em);
}
.closer-dot[data-at="right"]::after { left: 11px; }
.closer-dot[data-at="left"]::after { right: 11px; }
/* Up and to the left, clear of the &'s loop, which falls away on both sides of its top. */
.closer-dot[data-at="upleft"]::after { right: 9px; transform: translateY(-1.3em); }

/* Notes: a numbered list under the letter, until the sheet is wide enough to write beside it. */
.closer-notes {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: closer-note;
}

.closer-note {
  display: grid;
  grid-template-columns: 1.3em minmax(0, 1fr);
  font-family: var(--letters);
  font-size: 17px;
  line-height: 1.35;
  color: var(--graphite-soft);
  counter-increment: closer-note;
}
.closer-note + .closer-note { margin-top: 4px; }

.closer-note::before {
  content: counter(closer-note);
  color: var(--terracotta);
}

.closer-leader { display: none; }

.closer-caption {
  margin-top: 12px;
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.01em;
  color: var(--graphite-soft);
}

/* One shared sheet: three columns, one baseline running straight across. -------- */

@media (min-width: 720px) {
  /* The sheet only becomes paper here; on phones each plate is its own card, with no frame around them. */
  .closer-sheet--shared {
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 1px 0 rgba(52, 52, 47, 0.04), 0 12px 32px -24px rgba(52, 52, 47, 0.18);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    padding: 40px 24px 30px;
  }

  /* The plates join up: no paper of their own, and stages that meet so the guides run on. */
  .closer-plate {
    --gs: clamp(140px, 15vw, 176px);
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .closer-notes,
  .closer-caption { padding-inline: clamp(12px, 2vw, 22px); }
  .closer-notes { margin-top: 22px; }
  .closer-note { font-size: 16px; }
}

/* Wide sheets: notes sit beside the letter, joined to their dot by a pencil leader. */
@media (min-width: 1280px) {
  .closer-sheet--shared { padding: 52px 40px 36px; }

  .closer-plate { --gs: 236px; }

  .closer-stage { padding-bottom: 30px; }

  .closer-notes {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 0;
  }

  .closer-note {
    --dot-x: calc(50% + (var(--x) - var(--adv) / 2) / 1000 * var(--gs));
    --dot-y: calc((800 - var(--y)) / 1000 * var(--gs));
    position: absolute;
    top: calc(var(--dot-y) - 16px);
    display: block;
    width: max-content;
    padding: 0 3px;
    font-size: 17px;
    /* Written over the ruling: the guides break behind the words. */
    background: var(--paper);
  }
  .closer-note + .closer-note { margin-top: 0; }
  .closer-note::before { content: none; }
  .closer-note-text span { display: block; }

  .closer-note[data-at="right"] { left: calc(var(--dot-x) + 44px); }
  .closer-note[data-at="left"] { right: calc(100% - var(--dot-x) + 44px); text-align: right; }

  .closer-dot::after { content: none; }

  .closer-leader {
    display: block;
    position: absolute;
    top: 1px;
    width: 40px;
    height: 18px;
    overflow: visible;
    fill: none;
    stroke: var(--terracotta);
    stroke-width: 1.3;
    stroke-linecap: round;
    opacity: 0.8;
  }
  .closer-note[data-at="right"] .closer-leader { left: -44px; }
  .closer-note[data-at="left"] .closer-leader { right: -44px; transform: scaleX(-1); }

  .closer-caption {
    margin-top: 14px;
    text-align: center;
  }
}

@media (forced-colors: active) {
  .closer-dot { background: CanvasText; box-shadow: none; }
  .closer-dot::after { color: CanvasText; }
  .closer-leader { stroke: CanvasText; }
}
