/* ------------------------------------------------------------------
   Type Specimen Playground
   The UI is set in one neutral face (Inter) and stays out of the way;
   the specimens carry the page.
------------------------------------------------------------------- */

:root {
  --bg: #f7f5f0;
  --ink: #1c1b18;
  --muted: #8b877c;
  --hair: #e1ddd3;
  --hair-strong: #c9c4b8;
  --ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
}

[data-theme="dark"] {
  --bg: #161512;
  --ink: #eae7e0;
  --muted: #827e73;
  --hair: #2c2a25;
  --hair-strong: #403d35;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 13px;
  line-height: 1.5;
  overflow-x: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

::selection { background: var(--ink); color: var(--bg); }

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

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Masthead ---------------------------------------------------- */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 32px;
}

.masthead h1 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.masthead-meta {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.masthead-meta a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--hair-strong);
  padding-bottom: 1px;
}

.masthead-meta a:hover {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* ---- Toolbar ------------------------------------------------------ */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-block: 1px solid var(--hair);
  padding: 14px 32px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: background-color 0.25s ease;
}

.toolbar-row {
  display: flex;
  align-items: flex-end;
  gap: 28px;
  flex-wrap: wrap;
}

.toolbar-row--lower {
  align-items: center;
  justify-content: space-between;
}

/* ---- Fields ------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-label output {
  color: var(--ink);
  letter-spacing: 0.02em;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

.grow { flex: 1 1 300px; }

.preset-select {
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: right;
}

.preset-select:hover { color: var(--ink); }

.preset-select option {
  text-transform: none;
  color: initial;
  background: initial;
}

.field--range { width: 170px; }

input[type="text"] {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--hair-strong);
  border-radius: 0;
  padding: 8px 11px;
  width: 100%;
}

input[type="text"]::placeholder { color: var(--muted); opacity: 1; }

input[type="text"]:focus {
  outline: none;
  border-color: var(--ink);
}

/* Sliders: a hairline track and a hollow thumb */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 1px;
  background: var(--hair-strong);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--ink);
}

input[type="range"]::-moz-range-track {
  height: 1px;
  background: var(--hair-strong);
}

input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--ink);
}

/* Weight: segmented control */

.seg {
  display: inline-flex;
  border: 1px solid var(--hair-strong);
}

.seg button {
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  padding: 7px 15px;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
}

.seg button + button { border-left: 1px solid var(--hair-strong); }

.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

/* Category chips */

.chips {
  display: flex;
  align-items: baseline;
  gap: 20px;
  flex-wrap: wrap;
}

.chip {
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.05em;
  background: none;
  border: 0;
  border-bottom: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 0 3px;
}

.chip:hover { color: var(--ink); }

.chip[aria-pressed="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.shown-count {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.sort-pill {
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: none;
  border: 1px solid var(--hair-strong);
  padding: 3px 10px;
  cursor: pointer;
}

.sort-pill:hover { border-color: var(--ink); }

/* Buttons */

.btn {
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.03em;
  padding: 7px 14px;
  background: none;
  border: 1px solid var(--hair-strong);
  border-radius: 0;
  color: var(--ink);
  cursor: pointer;
}

.btn:hover { border-color: var(--ink); }

.btn--icon {
  font-size: 14px;
  line-height: 1;
  padding: 7px 11px;
}

.toolbar-end {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

.grid {
  --size: 40px;
  --leading: 1.3;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
  gap: 1px;
}

.card {
  /* outlines fall into the 1px gap to draw the hairline lattice */
  outline: 1px solid var(--hair);
  padding: 24px 30px 22px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  /* offscreen cards skip layout AND their font downloads — this is
     what lets the sheet hold hundreds of families */
  content-visibility: auto;
  contain-intrinsic-size: auto 280px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
}

.card-id {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.idx {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.name {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat {
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--hair);
  padding: 2px 6px;
  flex: none;
}

.card-actions {
  display: flex;
  gap: 12px;
  flex: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.card:hover .card-actions,
.card:focus-within .card-actions { opacity: 1; }

@media (hover: none) {
  .card-actions { opacity: 1; }
}

.card-actions button {
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.04em;
  background: none;
  border: 0;
  border-bottom: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 1px 0 2px;
}

.card-actions button:hover {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.specimen {
  font-size: var(--size);
  line-height: var(--leading);
  overflow-wrap: break-word;
  flex: 1;
}

.note {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Context view: headline over a fixed 16px body paragraph, like a page */

.context-body { display: none; }

.grid--context .context-body {
  display: block;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.6;
  max-width: 62ch;
}

.grid--context .card {
  gap: 14px;
}

.grid--context .specimen {
  /* the size slider still drives the headline, but it shouldn't grow
     past what a page headline would plausibly be */
  font-size: min(var(--size), 56px);
  flex: none;
}

/* List view: name column on the left, specimen flowing beside it */

.grid--list { grid-template-columns: 1fr; }

.grid--list .card {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  column-gap: 44px;
  row-gap: 10px;
  align-items: start;
  min-height: 0;
  padding: 26px 32px 24px;
}

.grid--list .card-head {
  grid-column: 1;
  grid-row: 1;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.grid--list .specimen {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.grid--list .note {
  grid-column: 1;
  grid-row: 2;
}

/* ---- Detail view (inspect dialog) ---------------------------------- */

.card { cursor: pointer; }
.card .specimen { cursor: text; }

.detail {
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  margin: auto;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--hair-strong);
  padding: 0;
}

.detail::backdrop {
  background: rgba(20, 19, 16, 0.55);
}

body:has(.detail[open]) { overflow: hidden; }

.detail-inner {
  padding: 26px 36px 40px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 6px 0 16px;
  border-bottom: 1px solid var(--hair);
  z-index: 1;
}

.detail-name {
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.detail-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-section { margin-top: 30px; }

.detail-section-title {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hair);
}

.detail-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  column-gap: 24px;
  align-items: baseline;
  padding: 12px 0;
}

.detail-row + .detail-row { border-top: 1px solid var(--hair); }

.detail-row-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.detail-sample {
  overflow-wrap: break-word;
}

@media (max-width: 720px) {
  .detail-inner { padding: 18px 18px 28px; }

  .detail-row {
    grid-template-columns: 1fr;
    row-gap: 4px;
  }
}

/* ---- Footer -------------------------------------------------------- */

footer {
  border-top: 1px solid var(--hair);
  padding: 64px 32px 72px;
  text-align: center;
}

.footer-tag {
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.footer-note {
  margin-top: 10px;
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--muted);
}

/* ---- Small screens -------------------------------------------------- */

@media (max-width: 720px) {
  .masthead { padding: 18px 18px 14px; }

  .toolbar { padding: 12px 18px; gap: 12px; }

  .toolbar-row { gap: 16px; }

  .grow { flex-basis: 100%; }

  .field--range { width: auto; flex: 1 1 130px; }

  .toolbar-row--lower { row-gap: 14px; }

  .grid { grid-template-columns: 1fr; }

  .card { padding: 20px 18px; min-height: 0; }

  /* list view collapses to the stacked card layout on small screens */
  .grid--list .card {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    row-gap: 16px;
    padding: 20px 18px;
  }

  .grid--list .card-head { flex-direction: row; align-items: baseline; }

  .grid--list .specimen,
  .grid--list .note { grid-column: 1; grid-row: auto; }

  footer { padding: 48px 18px 56px; }
}

/* ---- Reduced motion -------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
