/* Home page — cross.msimoes.dev
   Shared design tokens live in /assets/tokens.css. The block below is only a
   safety net: an unlayered :root there wins over anything inside a layer here. */
@layer home-fallback {
  :root {
    --xw-bg: #ffffff;
    --xw-ink: #121212;
    --xw-accent: #4f85e5;
    --xw-cell-active: #ffda00;
    --xw-cell-word: #a7d8ff;
    --xw-muted: #6f6f6f;
    --xw-font-ui: "Libre Franklin", -apple-system, "Helvetica Neue", Arial, sans-serif;
    --xw-font-mast: "Zilla Slab", Georgia, serif;
  }
  :root[data-theme="dark"] {
    --xw-bg: #121212;
    --xw-ink: #f0f0f0;
    --xw-muted: #9a9a9a;
  }
}

/* Surfaces derive from the tokens, so they follow whatever theme is live. */
:root {
  --home-card: color-mix(in srgb, var(--xw-ink) 4%, var(--xw-bg));
  --home-line: color-mix(in srgb, var(--xw-ink) 14%, var(--xw-bg));
  --home-mute: var(--xw-muted, color-mix(in srgb, var(--xw-ink) 70%, var(--xw-bg)));
  --home-shade: color-mix(in srgb, var(--xw-ink) 9%, transparent);
  /* Accent pulled toward the page ink so it stays readable as small text in
     either scheme; the flat accent is only used behind white button text. */
  --home-accent-text: color-mix(in srgb, var(--xw-accent) 60%, var(--xw-ink));
  --home-on-accent: #fff;
  --home-pad: 1.25rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 var(--home-pad) 4rem;
  background: var(--xw-bg);
  color: var(--xw-ink);
  font-family: var(--xw-font-ui);
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 40rem; margin: 0 auto; }

a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 3px solid var(--xw-accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ── Masthead ─────────────────────────────────────────────── */
.mast {
  max-width: 40rem;
  margin: 0 auto;
  padding: 2.25rem 0 1.75rem;
  text-align: center;
}

.mast h1 {
  margin: 0;
  font-family: var(--xw-font-mast);
  font-weight: 600;
  font-size: clamp(2.6rem, 13vw, 3.4rem);
  letter-spacing: -0.015em;
  line-height: 1;
}

.mast-sub {
  margin: 0.55rem 0 0;
  color: var(--home-mute);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ── Hero card ────────────────────────────────────────────── */
.hero {
  background: var(--home-card);
  border: 1px solid var(--home-line);
  border-radius: 18px;
  padding: 1.25rem;
  box-shadow: 0 1px 2px var(--home-shade), 0 8px 24px -14px var(--home-shade);
}

.hero-top {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.hero-text { min-width: 0; }

.date {
  margin: 0 0 0.15rem;
  color: var(--home-mute);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hero-title {
  margin: 0;
  font-family: var(--xw-font-mast);
  font-weight: 600;
  font-size: clamp(1.4rem, 6vw, 1.75rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.byline {
  margin: 0.3rem 0 0;
  color: var(--home-mute);
  font-size: 0.95rem;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.7rem 0 0;
}

.chip {
  border: 1px solid var(--home-line);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  color: var(--home-mute);
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chip.done {
  border-color: color-mix(in srgb, var(--home-accent-text) 45%, transparent);
  color: var(--home-accent-text);
}

/* A puzzle's own tag, on the hero card. Same pill, accent ink. */
.chip.tag {
  border-color: color-mix(in srgb, var(--home-accent-text) 35%, transparent);
  color: var(--home-accent-text);
  font-variant-numeric: normal;
}

.play {
  display: block;
  margin-top: 1.15rem;
  padding: 0.95rem 1.5rem;
  border-radius: 999px;
  background: var(--xw-accent);
  color: var(--home-on-accent);
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-align: center;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.play:hover { filter: brightness(1.06); }
.play:active { transform: scale(0.985); }

/* ── Mini grid glyph (decorative) ─────────────────────────── */
/* Deliberately paper-coloured in both schemes — the cell tints are designed
   against white, and a small light grid reads as "a puzzle" on a dark card. */
.glyph {
  --glyph-paper: #ffffff;
  --glyph-block: #121212;
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  width: 78px;
  height: 78px;
  padding: 1px;
  background: var(--glyph-block);
  border-radius: 5px;
  overflow: hidden;
}

.glyph .c { background: var(--glyph-paper); }
.glyph .b { background: var(--glyph-block); }
.glyph .w { background: var(--xw-cell-word); }
.glyph .a { background: var(--xw-cell-active); }

/* ── Archive ──────────────────────────────────────────────── */
.archive-wrap { margin-top: 2.25rem; }

.section-label {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--home-mute);
}

/* ── Tag filter ───────────────────────────────────────────── */
/* Built from the tags the manifest actually carries, so this styles however
   many chips there turn out to be — including none, when the row is hidden. */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 0.8rem;
}
.filters[hidden] { display: none; }

.filter {
  flex: 0 0 auto;
  border: 1px solid var(--home-line);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  background: transparent;
  color: var(--home-mute);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.filter:hover {
  color: var(--xw-ink);
  border-color: color-mix(in srgb, var(--xw-ink) 30%, var(--xw-bg));
}
.filter[aria-pressed="true"] {
  background: var(--xw-accent);
  border-color: var(--xw-accent);
  color: var(--home-on-accent);
}

.archive[hidden] { display: none; }

.archive {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--home-line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--home-card);
}

.archive li + li { border-top: 1px solid var(--home-line); }

.row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-height: 60px;
  padding: 0.7rem 0.9rem;
}

.row:hover { background: color-mix(in srgb, var(--xw-accent) 7%, transparent); }
.row:active { background: color-mix(in srgb, var(--xw-accent) 13%, transparent); }

.n {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--xw-accent) 12%, transparent);
  color: var(--home-accent-text);
  font-size: 0.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.row-text { min-width: 0; flex: 1; }

.row-title {
  display: block;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.25;
}

/* One line of small pills under the title. Wraps rather than clips: a tag is
   short, and at 390px two of them still fit. */
.row-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.28rem;
}
.row-tags .tag {
  border: 1px solid color-mix(in srgb, var(--home-accent-text) 35%, transparent);
  border-radius: 999px;
  padding: 0.02rem 0.5rem;
  color: var(--home-accent-text);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.6;
}

.row-meta {
  display: block;
  margin-top: 0.15rem;
  color: var(--home-mute);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-done {
  flex: none;
  color: var(--home-accent-text);
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chev {
  flex: none;
  color: var(--home-mute);
  font-size: 1.5rem;
  line-height: 1;
}

/* ── States ───────────────────────────────────────────────── */
.loading, .note {
  margin: 0;
  padding: 0.5rem 0;
  color: var(--home-mute);
  font-size: 0.95rem;
}

@media (prefers-reduced-motion: reduce) {
  .play { transition: none; }
  .play:active { transform: none; }
}

/* ── Wider screens ────────────────────────────────────────── */
@media (min-width: 40rem) {
  body { font-size: 18px; }
  .mast { padding: 3.5rem 0 2.25rem; }
  .hero { padding: 1.75rem; display: flex; align-items: center; gap: 1.75rem; }
  .hero-top { flex: 1; gap: 1.5rem; }
  .glyph { width: 108px; height: 108px; border-radius: 7px; }
  .play { margin-top: 0; flex: none; padding: 1rem 2.5rem; }
  .row { padding: 0.85rem 1.1rem; }
}
