/* print-tracker
 *
 * Two rules in here pull against each other and both are deliberate:
 *
 *   TYPE IS SIZED IN rem.  Page zoom scales px, so a px-only stylesheet does
 *   nothing at all for a reader who instead raised their browser's or phone's
 *   default text size — a different setting, and a common one among exactly the
 *   people who need it. `check-textsize.mjs` gates this.
 *
 *   TOUCH TARGETS ARE SIZED IN px.  A finger does not get bigger when text does.
 *   A 44px floor written as 2.75rem doubles every control at 200% text, and the
 *   target-size check goes GREENER as that happens, because 88 is further above a
 *   floor of 44 than 44 is. Elsewhere that single token pushed an app's main
 *   instrument 707px down a 640px screen.
 *
 * MEDIA-QUERY THRESHOLDS ARE ALSO IN px, because `rem` inside a media query
 * resolves against the INITIAL root font size rather than the reader's, so a
 * breakpoint written for the 200%-text case never matches.
 *
 * Colours come from palettes/3d-printing-pal.json and are measured by the hub's
 * palette gate. Dimmed text uses a colour TOKEN, never `opacity` — an opacity is
 * invisible to a contrast gate, which is how a build stamp measured 2.54:1 to a
 * reader while its gate read 4.79 and passed.
 */

:root {
  color-scheme: dark light;

  --page: #1a1a1a;
  --page-alt: #232323;
  --surface: #3a3a3a;
  --surface-raised: #414141;
  --surface-pressed: #484848;
  --rail: rgba(255, 255, 255, 0.62);
  --hairline: rgba(255, 255, 255, 0.17);

  --text: #eaeaea;
  --text-2: #d2d2d2;
  --text-3: #c1c1c1;

  --primary: #9fc2f5;
  --wanted: #f0c674;
  --fun: #8fd6a4;
  --danger: #f2aecd;


  --radius: 10px;
  --tap: 44px;
  --gap: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --page: #c4bcab;
    --page-alt: #ccc4b3;
    --surface: #eee6d6;
    --surface-raised: #f4ecdd;
    --surface-pressed: #faf3e5;
    --rail: rgba(39, 33, 25, 0.68);
    --hairline: rgba(39, 33, 25, 0.22);

    --text: #272119;
    --text-2: #363026;
    --text-3: #4a4436;

    --primary: #17458f;
    --wanted: #63400a;
    --fun: #14532d;
    --danger: #7a1548;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  /* minmax(0, 1fr) rather than a bare 1fr: an `auto`-sized grid track takes its
   * widest descendant's min-content, so a horizontally scrolling board would
   * widen the whole page and make it scroll sideways at 320px. */
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--page-alt), var(--page));
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

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

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

/* ------------------------------------------------------------ update strip */
/* A standing indicator, in the flow. Not a modal, not a timed toast, and never
 * over anything being used. Two ways out, both real buttons. */
.strip {
  grid-row: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap);
  padding: 12px 16px;
  background: var(--surface-raised);
  border-bottom: 2px solid var(--rail);
}
.strip[hidden] { display: none; }
.strip-text { margin: 0; flex: 1 1 16rem; font-size: 0.9375rem; }
.strip-actions { display: flex; gap: var(--gap); flex-wrap: wrap; }

/* ----------------------------------------------------------------- topbar */
.topbar {
  grid-row: 2;
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--hairline);
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
}
.wordmark {
  margin: 0;
  /* 1.0625rem, not 1.25: at 200% text "print-tracker" at 1.25rem is wider than a
   * 320px screen minus the (i) button, so it wrapped to two lines and cost 60px
   * of chrome before the reader saw anything. */
  font-size: 1.0625rem;
  font-weight: 660;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
}

.tabs {
  display: flex;
  gap: var(--gap);
  margin-top: 10px;
  overflow-x: auto;
}
.tab {
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 0 16px;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text-2);
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}
.tab[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ------------------------------------------------------------------ main */
#main {
  grid-row: 3;
  min-width: 0;
  padding: 16px;
}
.view { min-width: 0; }
.view[hidden] { display: none; }

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
h2 { margin: 0; font-size: 1.125rem; font-weight: 640; }
h3 { margin: 22px 0 6px; font-size: 1rem; font-weight: 640; }
p { margin: 0 0 12px; }
a { color: var(--primary); }

.note { color: var(--text-3); font-size: 0.875rem; margin: 0 0 12px; }
.empty { color: var(--text-2); font-size: 0.9375rem; }
.empty[hidden] { display: none; }
.noscript { padding: 16px; color: var(--text); }

/* ----------------------------------------------------------------- chips */
.chips {
  display: flex;
  /* Scrolls rather than wraps: wrapping cost three rows and 167px of chrome at
   * 200% text, which is height taken from the board itself. */
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: var(--gap);
  margin-bottom: 14px;
  padding-bottom: 2px;
}
.chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 14px;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--rail);
  border-radius: 999px;
  cursor: pointer;
}
.chip[aria-pressed="false"] { background: transparent; color: var(--text-2); }
/* The tick occupies its space in BOTH states and only its visibility changes.
 * A tick that appears on press widens the control under a finger already on its
 * way, and reflows every chip after it in a wrapping row. */
.chip-tick { visibility: hidden; }
.chip[aria-pressed="true"] .chip-tick { visibility: visible; }

/* ----------------------------------------------------------------- board */
.board {
  display: flex;
  /* Columns size to their own content. Stretching them to match the tallest
   * sibling turned an empty Research column into a 490px void on a phone. */
  align-items: flex-start;
  gap: 12px;
  overflow-x: auto;
  /* Positioned so it is the containing block for the .sr-only spans inside the
   * cards. Without this their containing block is the initial one, so they
   * ESCAPE this scroll container entirely: the body stayed 320px wide while
   * <html> measured 834 and the page scrolled sideways, with no element visibly
   * out of place. */
  position: relative;
  padding-bottom: 12px;
  min-width: 0;
  scroll-snap-type: x proximity;
}
.column {
  flex: 0 0 17rem;
  min-width: 0;
  scroll-snap-align: start;
  background: var(--surface);
  border: 1px solid var(--rail);
  border-radius: var(--radius);
  padding: 10px;
}
.column.is-target { outline: 3px dashed var(--primary); outline-offset: -3px; }
.column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 8px;
}
.column-title { margin: 0; font-size: 0.9375rem; font-weight: 640; }
.column-count { color: var(--text-3); font-size: 0.8125rem; }
.column-toggle {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 12px;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--rail);
  border-radius: var(--radius);
  cursor: pointer;
}
.column-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: var(--gap);
  /* A generous empty drop target. Snap radius is an accessibility feature, not
   * polish: an empty column that is 20px tall is a target nobody with a tremor
   * can hit. */
  min-height: 88px;
}
.column.is-collapsed .column-list { display: none; }

.card {
  background: var(--surface-raised);
  border: 1px solid var(--rail);
  border-radius: var(--radius);
  padding: 10px;
}
.card.is-dragging { outline: 3px solid var(--primary); }
.card-top { display: flex; align-items: flex-start; gap: 8px; }
.card-title { margin: 0; font-size: 0.9375rem; font-weight: 620; overflow-wrap: anywhere; flex: 1 1 auto; }
.card-meta { margin: 6px 0 0; color: var(--text-2); font-size: 0.8125rem; }
.card-meta span { display: block; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 640;
  border: 1px solid currentColor;
  margin-bottom: 6px;
}
.badge-request { color: var(--primary); }
.badge-wanted { color: var(--wanted); }
.badge-fun { color: var(--fun); }

/* The drag handle. `touch-action: none` on the HANDLE only, so a drag starts on
 * movement rather than on a timer, and the board still scrolls normally
 * everywhere else. Timed gestures are banned (SC 2.2.1): there is no
 * press-and-hold anywhere in this app. */
.card-grip {
  flex: 0 0 auto;
  min-width: var(--tap);
  min-height: var(--tap);
  display: grid;
  place-items: center;
  font: inherit;
  color: var(--text-2);
  background: var(--surface-raised);
  border: 2px solid var(--rail);
  border-radius: var(--radius);
  cursor: grab;
  touch-action: none;
}
.card-actions { display: flex; gap: var(--gap); margin-top: 10px; flex-wrap: wrap; }

/* ----------------------------------------------------------------- cards */
.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.rowcard {
  background: var(--surface);
  border: 1px solid var(--rail);
  border-radius: var(--radius);
  padding: 12px;
}
.rowcard-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.rowcard-title { margin: 0; font-size: 1rem; font-weight: 640; overflow-wrap: anywhere; }
.rowcard-sub { margin: 2px 0 0; color: var(--text-2); font-size: 0.875rem; }
.rowcard-body { margin-top: 10px; }
.rowcard ul { margin: 6px 0 0; padding-left: 20px; }
.rowcard li { margin-bottom: 4px; }

.swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid var(--rail);
  vertical-align: -2px;
  margin-right: 6px;
}

.bar {
  height: 10px;
  background: var(--surface-pressed);
  border: 1px solid var(--rail);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 4px;
}
.bar-fill { height: 100%; background: var(--primary); }
.remaining { font-size: 1rem; font-weight: 640; }
.remaining-low { color: var(--danger); }

/* --------------------------------------------------------------- controls */
.controls { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 12px; align-items: end; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; min-width: 0; }
.field-inline { margin-bottom: 0; }
.field-check { flex-direction: row; align-items: center; gap: 8px; margin-bottom: 0; min-height: var(--tap); }
.field label, .fieldset legend { font-size: 0.875rem; color: var(--text-2); font-weight: 600; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row .field { flex: 1 1 9rem; }

input[type="text"], input[type="number"], input[type="date"], input[type="file"], select, textarea {
  font: inherit;
  font-size: 1rem;
  min-height: var(--tap);
  padding: 8px 10px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--rail);
  border-radius: var(--radius);
  width: 100%;
  min-width: 0;
}
textarea { min-height: 88px; resize: vertical; }
input[type="color"] { min-height: var(--tap); width: 100%; padding: 4px; background: var(--surface-raised); border: 1px solid var(--rail); border-radius: var(--radius); }
/* The input itself is the 44px target AND the visible box, rather than a 24px
 * control inside a larger label: a native checkbox reports its own small rect to
 * any target-size check, and styling a pseudo-element leaves the input drawing no
 * boundary of its own for SC 1.4.11 to measure. */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: var(--tap);
  height: var(--tap);
  min-height: var(--tap);
  padding: 0;
  background: var(--surface-raised);
  border: 2px solid var(--rail);
  border-radius: 8px;
  cursor: pointer;
}
input[type="checkbox"]:checked { background: var(--primary); border-color: var(--primary); }
/* A drawn tick, so checked and unchecked differ by shape as well as by fill. */
input[type="checkbox"]:checked::after {
  content: "";
  display: block;
  width: 10px;
  height: 18px;
  margin: 6px auto 0;
  border: solid var(--surface-raised);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}

.fieldset {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 12px;
  margin: 0 0 14px;
  min-width: 0;
}

.linkrow { display: flex; gap: var(--gap); align-items: end; flex-wrap: wrap; margin-bottom: var(--gap); }
.linkrow .field { flex: 1 1 8rem; margin-bottom: 0; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 16px;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-raised);
  border: 2px solid var(--rail);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: var(--surface-pressed); }
.btn[disabled] { color: var(--text-3); cursor: not-allowed; border-style: dashed; }
/* Accent text on an OPAQUE surface, never on a tint of its own accent: a 12%
 * primary wash over the page pulls the backdrop toward the text colour and took
 * this button from 4.82:1 to 4.13:1 in the light theme. The accent lives in the
 * border and the text; the fill stays a real surface. */
.btn-primary { color: var(--primary); border-color: var(--primary); }
.btn-danger { color: var(--danger); border-color: var(--danger); }

.iconbtn {
  flex: 0 0 auto;
  min-width: var(--tap);
  min-height: var(--tap);
  display: grid;
  place-items: center;
  font: inherit;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--rail);
  border-radius: 999px;
  cursor: pointer;
}
.iconbtn-glyph { line-height: 1; }

.linkbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 0.8125rem;
  color: var(--text-3);
  background: transparent;
  border: 0;
  padding: 6px 10px;
  min-height: var(--tap);
  min-width: var(--tap);
  cursor: pointer;
  text-decoration: underline;
}

/* ---------------------------------------------------------------- footer */
.footer {
  grid-row: 4;
  padding: 16px;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
}
.footer-data { display: flex; gap: var(--gap); flex-wrap: wrap; }
.lastexport { margin: 0; flex: 1 1 14rem; color: var(--text-3); font-size: 0.8125rem; }
/* The build stamp. Always on screen in the normal working view, written at boot,
 * selectable, and dimmed with a token rather than an opacity so the contrast gate
 * measures what the reader actually sees. */
.stamp { margin: 0; }
.stamp .linkbtn { user-select: text; -webkit-user-select: text; }

/* --------------------------------------------------------------- dialogs */
/* `display` is scoped to [open]. An unscoped `display` on a <dialog> beats the
 * user agent's own `dialog:not([open]) { display: none }` on specificity, and the
 * panel stays on screen after close() succeeds and every handler has run. */
dialog.panel {
  border: 1px solid var(--rail);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(46rem, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  /* Measured against the space available at the moment it opens, never a
   * constant. Content that cannot fit scrolls inside itself. */
  max-height: calc(100dvh - 24px);
}
dialog.panel[open] { display: flex; flex-direction: column; }
dialog.panel-narrow { width: min(30rem, calc(100vw - 24px)); }
dialog.panel::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.panel form { display: flex; flex-direction: column; min-height: 0; }

/* Head and foot sit outside the scroll container rather than being sticky, so
 * the way out is on screen in the first frame AND after scrolling to the very
 * end, without a pinned header that can take the whole dialog at 200% text. */
.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--hairline);
}
.panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}
.panel-foot {
  flex: 0 0 auto;
  padding: 14px 16px;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  align-items: center;
}
/* A destructive control never sits next to a routine one: tremor overshoots, and
 * 8px of clear space is not enough between "Cancel" and "Delete". */
.panel-foot-split { justify-content: space-between; gap: 16px 32px; }
.foot-main { display: flex; gap: var(--gap); flex-wrap: wrap; }
.foot-danger { display: flex; }
.panel-foot-note { margin: 0; flex: 1 1 12rem; color: var(--text-3); font-size: 0.8125rem; }

.diag-actions { display: flex; gap: var(--gap); flex-wrap: wrap; margin-bottom: 12px; }
.diag-text {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.45;
  white-space: pre;
  overflow: auto;
}

.report { border: 1px solid var(--rail); border-radius: var(--radius); padding: 12px; background: var(--surface-raised); }
.report[hidden] { display: none; }
.report h3 { margin-top: 0; }
.report ul { margin: 6px 0 0; padding-left: 20px; }
.report-bad { color: var(--danger); }

.movelist { display: flex; flex-direction: column; gap: var(--gap); }
.movelist .btn { justify-content: flex-start; }

.snapshot { display: flex; gap: var(--gap); align-items: center; flex-wrap: wrap; margin-bottom: var(--gap); }
.snapshot-when { flex: 1 1 12rem; font-size: 0.875rem; color: var(--text-2); }

.release { margin-bottom: 18px; }
.release-head { margin: 0 0 4px; font-size: 0.9375rem; font-weight: 640; }
.release h4 { margin: 10px 0 4px; font-size: 0.875rem; font-weight: 640; color: var(--text-2); }
.release ul { margin: 0; padding-left: 20px; }
.release li { margin-bottom: 6px; }

/* ------------------------------------------------------------ small phone */
@media (max-width: 380px) {
  #main { padding: 12px; }
  .column { flex-basis: 15rem; }
}

/* A reader at 200% text on a small phone is, in layout terms, on a much smaller
 * screen. Give the board back the chrome it does not need. */
@media (max-height: 640px) {
  .view-head h2 {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  /* Measured: "print-tracker" wants 245px at 1.0625rem/200% and the box is 234,
   * so it broke at the hyphen and cost a second 51px line of chrome. */
  .wordmark { font-size: 0.9375rem; }
  .topbar { padding-top: 8px; }
  .tabs { margin-top: 10px; }
  #main { padding: 10px 12px; }
  .view-head { margin-bottom: 8px; }
  .chips { margin-bottom: 8px; }
}

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

@media (prefers-contrast: more) {
  :root { --hairline: var(--rail); }
}
