/*
 * Bent Mace Apps — the gallery's own stylesheet.
 *
 * This file is served publicly. Keep it self-contained: no internal project
 * names, no repository paths, nothing that only makes sense from inside. The
 * build asserts on that, but it is easier to just not write it.
 *
 * The sub-apps have their own styles and never load this; it dresses one page.
 *
 * The premise, which the rest of Bent Mace shares: the page has no colour of
 * its own — every saturated pixel on screen belongs to an artist. That lands
 * harder here than anywhere else, because the artwork is nineteen thumbnails,
 * all of them somebody's shader or synth, sitting on paper. So the page is ink,
 * rule and weight, and the work is the only colour. Do not add an accent.
 *
 * Dark mode is a media query with no toggle, matching the website — a toggle
 * needs persisted state and a control to hang it on, and this page has neither.
 */

:root {
  color-scheme: light;

  --paper: #dfdedb;
  --ink: #1d1d1d;
  /* Rules carry the structure here, so they are full ink rather than a
     hairline grey — a printed rule, not a UI divider. */
  --edge: #1d1d1d;
  /*
   * Quiet text — the eyebrow and the colophon.
   *
   * Both are set at 13-14px, and everything else in this palette carries a
   * muted grey of #6b6a66, which measures 4.02:1 against this paper. That is
   * under the 4.5:1 floor for text this size, and this page happens to use it
   * only at those sizes. #5f5e5a is 4.82:1 and is otherwise the same colour.
   * The dark value below needs no such nudge: it is already 7.6:1.
   */
  --muted: #5f5e5a;

  --measure: 84rem;
  --gutter: clamp(1.25rem, 4vw, 3rem);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  /*
   * A display face for the masthead, and only the masthead — see the note on
   * .masthead__title for why it is not the system font like everything else.
   */
  --display: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    /* Not pure black: #121212 against #e8e6e1 keeps contrast high without the
       halation white-on-black causes for astigmatic readers. Same values the
       website uses. */
    --paper: #121212;
    --ink: #e8e6e1;
    /* Light mode's full-ink rule would invert to a white hairline, which
       glares. #666666 is 3.26:1 against this paper — enough that the grid
       holds, which is the whole job of a rule. */
    --edge: #666666;
    --muted: #a8a5a0;
  }
}

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

/* The filter hides tiles with the `hidden` attribute, and `display: flex` on
   .tile would otherwise beat the browser's default `[hidden] { display: none }`
   on specificity alone. Stated once, here, rather than remembered per rule. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a {
  color: inherit;
}

/* ---------------------------------------------------------------- masthead */

.masthead {
  max-width: var(--measure);
  margin-inline: auto;
  padding: clamp(2rem, 6vw, 4.5rem) var(--gutter) clamp(1.5rem, 3vw, 2.5rem);
}

/* The venue's name sits above the page's name, small and tracked. The wordmark
   proper is a drawn logo and lives in the favicon and the share card; setting
   it in a system face at display size would only invite the comparison. */
.masthead__mark {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

/* The one way back to the rest of the site. This page is served from inside
   bentmace.org but shares none of its chrome — by design, so an app opens on a
   bare screen — which means nothing else here points home. */
.masthead__mark a {
  color: inherit;
  text-decoration: none;
}

.masthead__mark a:hover,
.masthead__mark a:focus-visible {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 0.3em;
}

/*
 * The margin looks too small written down, and is not.
 *
 * A font reserves space above its cap height for accents and ascenders, and
 * that space is there whether or not any glyph uses it. Measured on the stack
 * below: at 104px the ascent is 101px while the caps reach only 74.6px, so
 * every line of this carries 26.4px — a quarter of an em — of empty room above
 * the letters that no margin asked for and no rule can see. Set 0.35em here and
 * the gap under the eyebrow reads as 0.6em.
 *
 * `text-box: trim-start cap` removes exactly that and is the right answer, but
 * it is too new to rely on (unsupported in the Chrome this was built against),
 * and a fix only some visitors get is worse than a smaller number everywhere.
 * So the margin is set to what is left after the font's own space is counted.
 * If you change the font stack, re-measure: the ratio is the font's, not ours.
 */
/*
 * The one place on this page that is not set in the system font.
 *
 * Set in SF Pro, the A and both P's grow a narrow, hard-edged tab above their
 * flat tops — like a smaller letter tucked behind the word. Subtle, and once
 * seen, not unseeable.
 *
 * It is NOT the glyph design. That was the first explanation here and it was
 * wrong. Two tests killed it: rendered at 600px, SF Pro's and Helvetica Neue's
 * top edges are near-identical, so there is no crown in one that the other
 * lacks; and rendering at 650px then downscaling to 65px gives a perfectly
 * uniform top row, where rendering *directly* at 65px gives the tab. Same
 * outline, same size, different rasterisation — so the outline is flat and the
 * small-size rasteriser is what puts the bump there.
 *
 * Which stage of it, nobody here has isolated. Hinting is the obvious suspect:
 * SF Pro is hinted hard so it stays crisp at 11-14px, which is the size it is
 * built for. That is worth stating as a suspicion and not as a finding — the
 * confident mechanical explanation was already wrong once.
 *
 * Measured, not guessed. It appears in WebKit and in Chromium, at every weight
 * from 400 to 900, with and without letter-spacing, and whether the text is
 * written APPS or uppercased from Apps. None of those are the cause. Swept
 * across 641 sizes from 40px to 104px in tenths, at device ratios 1, 1.5, 2,
 * 2.2 and 3:
 *
 *     SF Pro            611 of 641 bad
 *     Helvetica Neue      0 of 641
 *
 * Hunting for a clean size was the wrong approach — at fractional sizes, which
 * is what any fluid unit produces, SF Pro is bad almost everywhere. Changing
 * the face fixes it outright and hands back fluid sizing, which a fixed-size
 * workaround had to give up.
 *
 * None of which makes SF Pro faulty. It is a UI face being set at 65px in
 * near-maximum contrast, which is not what its tuning is for. Helvetica Neue
 * carries no such tuning to get in the way.
 *
 * The cost: Helvetica Neue stops at Bold, so `font-weight: 800` renders at 700
 * and this reads lighter than SF Pro Heavy did. The declaration stays at 800 —
 * it says take the heaviest thing available, which is what we want on whatever
 * machine this lands on. Body text keeps the system font, where it is better.
 *
 * The margin looks too small and is not: a font reserves space above its cap
 * height for accents that no capital uses, so the visible gap is always larger
 * than the number here. Re-measure if the face changes; the ratio is the
 * font's, not ours.
 */
.masthead__title {
  margin: 0.1em 0 0;
  font-family: var(--display);
  font-size: clamp(2.5rem, 7vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 0.9;
  text-transform: uppercase;
}

.masthead__lede {
  margin: 1.25rem 0 0;
  max-width: 44ch;
  font-size: clamp(1rem, 2.2vw, 1.125rem);
  text-wrap: pretty;
}

/* ----------------------------------------------------------------- filters */

/*
 * Rectangles, because that is what the rest of the page is: the tiles are
 * rectangles with a one-pixel ink rule, and a button that matched them was
 * already drawn. No radius, no fill, no accent — the page still has no colour
 * of its own, and the pressed state is the same inversion a tile uses on hover.
 * One visual idea, used twice, rather than two.
 */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: var(--measure);
  margin-inline: auto;
  padding: 0 var(--gutter) clamp(1.25rem, 3vw, 2rem);
}

.filter {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5em;
  padding: 0.6em 1.1em;
  border: 1px solid var(--edge);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

@media (prefers-reduced-motion: no-preference) {
  .filter {
    transition: background-color 120ms ease, color 120ms ease;
  }
}

.filter:hover {
  background: var(--ink);
  color: var(--paper);
}

.filter:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* aria-pressed is the state, so the style hangs off it directly rather than a
   class kept in step with it by hand. There is only one truth to update. */
.filter[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

/*
 * The count is the useful half of the label — how many apps are behind this
 * button — set quieter so the name still reads first.
 *
 * Quieter has a floor. The button is 13px, so 0.75em put this at 9.75px, and
 * 0.65 opacity measured 4.65:1 against light paper — over the 4.5:1 minimum for
 * small text by almost nothing, at a size where almost nothing is not enough.
 * 0.85em and 0.7 is 11.1px at 5.42:1, still clearly the secondary half of the
 * label. Dark mode and the pressed state were never close to the line (7.9:1
 * and 6.8:1); light mode at rest is the case that decides this.
 */
.filter__count {
  font-size: 0.85em;
  letter-spacing: 0.08em;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

/* Cannot happen while every category has members and the build asserts it, but
   a filter with no visible result and no message reads as a broken page. */
.grid__empty {
  max-width: var(--measure);
  margin-inline: auto;
  padding: 0 var(--gutter) clamp(3rem, 8vw, 5rem);
  color: var(--muted);
}

/* -------------------------------------------------------------------- grid */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(19rem, 100%), 1fr));
  gap: clamp(1rem, 2.2vw, 1.75rem);
  max-width: var(--measure);
  margin-inline: auto;
  padding: 0 var(--gutter) clamp(3rem, 8vw, 5rem);
}

/*
 * A tile is the thumbnail and its rule — no caption, because the title is
 * painted into the artwork.
 *
 * That takes away the state this page used to have. Inverting the card worked
 * when a third of it was text on paper; with the image edge to edge there is no
 * paper left to invert, and the same rule would do nothing at all. So the state
 * is weight instead: the rule thickens. Hover and focus are the one mechanism
 * rather than two, and a transparent outline held at rest means the ring has
 * somewhere to animate from and nothing reflows when it arrives.
 */
.tile {
  display: block;
  border: 1px solid var(--edge);
  outline: 3px solid transparent;
  text-decoration: none;
  background: var(--paper);
  color: var(--ink);
}

@media (prefers-reduced-motion: no-preference) {
  .tile {
    transition: outline-color 120ms ease;
  }
}

.tile:hover,
.tile:focus-visible {
  outline-color: var(--ink);
}

/* The thumbnails are 600x400 and carry the app's title painted into the SVG,
   so the image is decorative and takes an empty alt; the link's accessible
   name comes from its aria-label instead, which is also where "opens in a new
   tab" is said. */
.tile__thumb {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
}

/* --------------------------------------------------------------- colophon */

.colophon {
  max-width: var(--measure);
  margin-inline: auto;
  padding: clamp(1.5rem, 4vw, 2.5rem) var(--gutter)
    calc(clamp(2rem, 5vw, 3.5rem) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--edge);
  font-size: 0.875rem;
  color: var(--muted);
}

.colophon p {
  margin: 0 0 0.5rem;
  max-width: 60ch;
}

.colophon p:last-child {
  margin-bottom: 0;
}

.colophon strong {
  font-weight: 600;
  color: var(--ink);
}

.colophon a {
  color: var(--ink);
  text-underline-offset: 0.2em;
}
