/* Module components — step 2 (revised for originality). Built against
   tokens.css custom properties. Not yet linked from any live page;
   previewed in isolation via components-preview.html.

   Signature devices unique to this system, replacing the reference's
   own vocabulary rather than reskinning it:
   - a fleuron mark (--mark-fleuron) opens every header bar, in place of
     a plain bullet/icon
   - a dotted leader rule (a table-of-contents idiom) runs between a
     label and its value, in header bars and link rows alike
   - list rows are auto-numbered via CSS counters, not manually marked up */

/* === Box ===
   Hairline border on three sides; the top edge is a heavier pine rule —
   a masthead line, not a uniform four-sided card border. */
.mod-box {
  border: var(--border-hair) solid var(--color-panel-border);
  border-top: var(--border-thick) solid var(--color-pine);
  background: var(--color-panel-bg);
  border-radius: var(--radius-0);
}
.mod-box__body {
  padding: var(--space-4);
}
.mod-box__body > *:first-child { margin-top: 0; }
.mod-box__body > *:last-child { margin-bottom: 0; }
.mod-box__body p {
  /* Box width can stretch to fill a wide grid track — the box itself
     stays dense — but prose measure stays controlled independent of
     that, so paragraphs don't wrap into unreadably long lines. */
  max-width: 62ch;
}
.mod-box__body a,
.mod-box__body a:visited {
  color: var(--color-link);
}
.mod-box__body a:hover {
  color: var(--color-link-hover);
}

/* === Header bar ===
   No fill, no pill — just the fleuron mark, the label, a dotted leader
   that stretches to fill the row, and an optional trailing meta value.
   Markup only needs a label and (optionally) a meta span; the mark is
   generated from the token. */
.mod-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-hair) solid var(--color-panel-border);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-heading);
}
.mod-header::before {
  content: var(--mark-fleuron);
  color: var(--color-accent);
  font-family: var(--font-body);
  font-size: 1.15em;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
}
.mod-header__leader {
  flex: 1 1 auto;
  align-self: center;
  height: 0;
  min-width: var(--space-4);
  border-bottom: var(--border-hair) dotted var(--color-panel-border);
  margin: 0 var(--space-1);
}
.mod-header__meta {
  color: var(--color-text-faint);
  letter-spacing: var(--tracking-normal);
  text-transform: none;
  white-space: nowrap;
}

/* === Link row ===
   Auto-numbered (CSS counter, not markup) + a dotted leader running
   from the title to the date — the same leader device as the header
   bar, tying the whole system together. */
.link-rows {
  counter-reset: row;
}
.link-row {
  counter-increment: row;
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: var(--border-hair) solid var(--color-panel-border);
}
.link-rows .link-row:last-child {
  border-bottom: none;
}
.link-row::before {
  content: counter(row, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
}
.link-row:hover::before {
  color: var(--color-accent);
}
.link-row a,
.link-row a:visited {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--color-text);
  text-decoration: none;
}
.link-row a:hover {
  color: var(--color-link);
}
.link-row__leader {
  flex: 1 1 auto;
  align-self: center;
  height: 0;
  min-width: var(--space-4);
  border-bottom: var(--border-hair) dotted var(--color-panel-border);
}
.link-row__date {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
  white-space: nowrap;
}

/* File-metaphor modifier — used by /blog's index so it reads as "pick a
   file to open" rather than a plain list. Same row/leader/counter shape
   as .link-row, just a header row above it and a filename-styled title. */
.link-rows__head {
  display: flex;
  justify-content: space-between;
  padding: 0 0 var(--space-2);
  margin-bottom: var(--space-1);
  border-bottom: var(--border-hair) solid var(--color-panel-border);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-text-faint);
}
.link-row--file a {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.link-row--file a::after {
  content: ".md";
  color: var(--color-text-faint);
}

/* === Tag list ===
   Small mono chips linking back to an index filtered to that tag —
   used on diary/blog entries and diary's stream. */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0 0;
}
.tag {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  text-decoration: none;
  border: var(--border-hair) solid var(--color-panel-border);
  border-radius: var(--radius);
  padding: 1px var(--space-2);
}
.tag::before {
  content: "#";
  color: var(--color-text-faint);
}
.tag:hover {
  color: var(--color-link);
  border-color: var(--color-accent);
}

/* === Now row ===
   Same label -> dotted leader -> value idiom as the link row, minus the
   auto-numbering (these aren't a ranked list) and minus the link styling
   (the value is plain text, not a destination). */
.now-rows {
  display: flex;
  flex-direction: column;
}
.now-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: var(--border-hair) solid var(--color-panel-border);
}
.now-rows .now-row:last-child {
  border-bottom: none;
}
.now-row__label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  white-space: nowrap;
}
.now-row__leader {
  flex: 1 1 auto;
  align-self: center;
  height: 0;
  min-width: var(--space-4);
  border-bottom: var(--border-hair) dotted var(--color-panel-border);
}
.now-row__value {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--color-text);
  text-align: right;
}

/* === Now player ===
   The "now" box's optional audio widget — a custom-styled <audio>
   wrapper (play/pause + seek + time), not the browser's default
   <audio controls> chrome. Sits above .now-rows when a track is set. */
.now-player {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-2);
  border-bottom: var(--border-hair) solid var(--color-panel-border);
}
.now-player__toggle {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-panel-bg);
  border: var(--border-hair) solid var(--color-panel-border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
}
.now-player__toggle:hover {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-bg);
}
.now-player__title {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 9rem;
}
.now-player__seek {
  flex: 1 1 auto;
  /* A real floor, not 0 -- the thumb below is a fixed 9px regardless of
     track width, so a seek allowed to shrink to nothing renders as a
     dot floating with no visible track under it. */
  min-width: 2.5rem;
  appearance: none;
  height: var(--border-hair);
  background: var(--color-panel-border);
  cursor: pointer;
}
.now-player__seek::-webkit-slider-thumb {
  appearance: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-accent);
}
.now-player__seek::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border: none;
  border-radius: 50%;
  background: var(--color-accent);
}
.now-player__time {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
  white-space: nowrap;
}
/* Wrapped with a "vol" label -- on its own, a bare range input looks
   identical to .now-player__seek (same thin line, same round thumb),
   which reads as two unlabeled seek bars rather than seek + volume. */
.now-player__volume-wrap {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.now-player__volume-label {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
  white-space: nowrap;
}
.now-player__volume {
  flex: 0 0 auto;
  width: 3.5rem;
  appearance: none;
  height: var(--border-hair);
  background: var(--color-panel-border);
  cursor: pointer;
}
.now-player__volume::-webkit-slider-thumb {
  appearance: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-accent);
}
.now-player__volume::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border: none;
  border-radius: 50%;
  background: var(--color-accent);
}

/* Floating variant -- player.js appends one of these straight to
   <body>, outside any page's swappable content, so it survives
   client-side navigation instead of resetting on every page. Widened
   and the title tightened vs. the base size to leave the seek bar
   usable now that a volume slider is a fifth flex item competing for
   the same row -- even so, `min-width` on the seek track above is what
   actually guarantees it stays visible; these sizes just keep that
   floor from being needed in the common case. */
.now-player--floating {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 500;
  max-width: 24rem;
  padding: var(--space-2) var(--space-3);
  margin-bottom: 0;
  border: var(--border-hair) solid var(--color-panel-border-strong);
  border-radius: var(--radius);
  background: var(--color-panel-bg);
}
.now-player--floating .now-player__title {
  max-width: 4.5rem;
}
.now-player--floating .now-player__volume {
  width: 3rem;
}

/* Below ~480px there isn't room for five controls in one row at any
   title length, and a box anchored only by `right` will happily push
   past the left edge of the viewport instead of shrinking. Anchor both
   edges so it's always exactly viewport-width-minus-margins, and drop
   to a two-row grid so the seek bar gets a full-width row of its own
   instead of fighting four other controls for scraps. */
@media (max-width: 480px) {
  .now-player--floating {
    left: var(--space-3);
    right: var(--space-3);
    max-width: none;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "toggle title time" "seek seek volume";
    align-items: center;
    column-gap: var(--space-3);
    row-gap: var(--space-2);
  }
  .now-player--floating .now-player__toggle {
    grid-area: toggle;
  }
  .now-player--floating .now-player__title {
    grid-area: title;
    max-width: none;
  }
  .now-player--floating .now-player__time {
    grid-area: time;
  }
  .now-player--floating .now-player__seek {
    grid-area: seek;
    width: 100%;
    min-width: 0;
  }
  .now-player--floating .now-player__volume-wrap {
    grid-area: volume;
    width: 100%;
  }
  .now-player--floating .now-player__volume {
    flex: 1 1 auto;
    width: auto;
  }
}

/* === Button wall ===
   Collapsing shared-border grid — reads as a ruled ledger, not stacked
   cards — each cell auto-numbered like the rest of the system. Hover
   inverts a single cell to the accent, the one moment the reserved
   color appears at full strength. */
.button-wall {
  counter-reset: btn;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  border-top: var(--border-hair) solid var(--color-panel-border);
  border-left: var(--border-hair) solid var(--color-panel-border);
}
.button-wall__item {
  counter-increment: btn;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-text);
  text-decoration: none;
  background: var(--color-panel-bg);
  border-right: var(--border-hair) solid var(--color-panel-border);
  border-bottom: var(--border-hair) solid var(--color-panel-border);
}
.button-wall__item::before {
  content: counter(btn, decimal-leading-zero);
  color: var(--color-text-faint);
  font-size: 0.9em;
}
.button-wall__item:hover {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-bg);
}
.button-wall__item:hover::before {
  color: var(--color-bg);
}

/* === Media marquee ===
   Retokenized version of the old profile.html marquee: same infinite
   scroll (the track's content is duplicated once by the caller, and the
   animation includes the center gap in its travel distance), same
   idea, hairline borders + 2px radius instead of the old rounded
   thumbnails. */
.media-marquee {
  overflow: hidden;
  border-top: var(--border-hair) solid var(--color-panel-border);
  border-bottom: var(--border-hair) solid var(--color-panel-border);
  padding: var(--space-4) 0;
  /* Cards would otherwise get hard-clipped mid-image at the strip's
     edges — fading them out first reads as "scrolling past the frame",
     not "cut off". */
  mask-image: linear-gradient(to right, transparent, black 60px, black calc(100% - 60px), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, black 60px, black calc(100% - 60px), transparent);
}
.media-marquee-track {
  display: flex;
  gap: var(--space-4);
  width: max-content;
  animation: media-scroll 26s linear infinite;
}
.media-card {
  appearance: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  flex: 0 0 auto;
  width: 120px;
  text-align: center;
}
.media-card img {
  display: block;
  width: 120px;
  height: 120px;
  object-fit: cover;
  border: var(--border-hair) solid var(--color-panel-border);
  border-radius: var(--radius);
}
.media-card p {
  margin: var(--space-2) 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.media-card:hover img,
.media-card:focus-visible img {
  border-color: var(--color-accent);
  outline: var(--border-hair) solid var(--color-accent);
  outline-offset: var(--space-1);
}
.media-marquee:hover .media-marquee-track,
.media-marquee:focus-within .media-marquee-track,
.media-marquee-track.is-paused {
  animation-play-state: paused;
}
.scrapbook-dialog {
  width: min(32rem, calc(100vw - (2 * var(--space-5))));
  padding: 0;
  border: var(--border-thick) solid var(--color-panel-border-strong);
  border-radius: var(--radius);
  background: var(--color-panel-bg);
  color: var(--color-text);
}
.scrapbook-dialog::backdrop {
  background: color-mix(in srgb, var(--color-bg) 82%, transparent);
}
.scrapbook-dialog__body {
  padding: var(--space-5);
}
.scrapbook-dialog__body h2 {
  margin: 0 0 var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-xl);
  color: var(--color-heading);
}
.scrapbook-dialog__body p {
  margin: 0 0 var(--space-5);
  line-height: var(--leading-relaxed);
}
.scrapbook-dialog__close {
  padding: var(--space-2) var(--space-4);
  border: var(--border-hair) solid var(--color-panel-border-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-link);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  cursor: pointer;
}
.scrapbook-dialog__close:hover,
.scrapbook-dialog__close:focus-visible {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: var(--color-bg);
}
@keyframes media-scroll {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(calc(-50% - (var(--space-4) / 2)));
  }
}
