:root {
  --paper: #faf7f2;
  --card: #fffdf9;
  --ink: #1c1a17;
  --ink-soft: #6b6459;
  --rule: #e6dfd4;
  --live: #2f6f5e;
  --passed: #ded7cb;
  --passed-edge: #9c8e78;
  --kept: #1f4f42;
  --focus: #8a6f3f;

  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 3.5rem 1.25rem 5rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 46rem;
  margin: 0 auto;
}

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

.masthead { margin-bottom: 1.75rem; }

.masthead h1 {
  margin: 0 0 .5rem;
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: .01em;
}

.lede {
  margin: 0;
  max-width: 34rem;
  color: var(--ink-soft);
  font-size: .95rem;
}

/* ---------- legend ---------- */

/* A caption, not a tutorial: it teaches the three states without pretending to be
   a control. Sits above the first card so it is read before the grid is guessed at. */
.legend {
  margin: 0 0 2rem;
  padding: .85rem 1rem;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem 1.4rem;
  margin: 0;
  font-size: .82rem;
  color: var(--ink-soft);
}

.key {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}

.key-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

.legend-how {
  margin: .7rem 0 0;
  padding-top: .7rem;
  border-top: 1px solid var(--rule);
  font-size: .82rem;
  color: var(--ink);
}

/* ---------- total ---------- */

.total {
  margin: 0 0 1.75rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-soft);
}

.total:empty { display: none; }

/* ---------- stack ---------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1.4rem;
}

.card-name {
  margin: 0 0 .2rem;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 400;
}

.card-meta {
  margin: 0 0 1.1rem;
  font-size: .78rem;
  color: var(--ink-soft);
}

.card-counts {
  display: flex;
  align-items: baseline;
  gap: 1.75rem;
  margin: 0 0 .7rem;
}

.count {
  margin: 0;
  font-family: var(--serif);
  line-height: 1;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}

/* The honest number, and the one you control. Weight is deliberately unequal. */
.count-left {
  font-size: 2.1rem;
  color: var(--ink);
}

.count-kept {
  font-size: 1.35rem;
  color: var(--ink-soft);
}

.count .unit {
  font-family: var(--sans);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-soft);
  margin-left: .45rem;
}

.card-when {
  margin: 0 0 1.1rem;
  font-size: .85rem;
  color: var(--ink-soft);
}

/* What slipped by since the user last looked. The payoff for coming back, so it
   sits above the grid and carries a little more weight than the next-date line. */
.card-slip {
  margin: -0.55rem 0 1.1rem;
  font-family: var(--serif);
  font-size: .95rem;
  font-style: italic;
  color: var(--ink);
}

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

.grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.sq {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--live);
  cursor: pointer;
  transition: background-color 150ms ease;
}

.grid.is-sm .sq { width: 15px; height: 15px; }
.grid.is-xs .sq { width: 11px; height: 11px; }
.grid.is-xxs .sq { width: 9px; height: 9px; }

/* The three states, shared by the grid and the legend so the two can never
   disagree about what a colour means.
   Passed is paler than upcoming, not darker: the past recedes and the future
   stays available. The opposite of a progress bar, which fills up. */
.sq.is-passed,
.key-swatch.is-passed {
  background: var(--passed);
  box-shadow: inset 0 0 0 1px var(--passed-edge);
}

/* A moment you were there for. The darkest thing on the card. */
.sq.is-kept,
.key-swatch.is-kept {
  background: var(--kept);
  box-shadow: none;
}

.sq.is-passed:hover { background: #d3cabb; }
.sq.is-kept:hover { background: #173b31; }

/* Upcoming squares are not interactive — nothing to record yet. */
.sq.is-upcoming { cursor: default; }
.key-swatch.is-upcoming { background: var(--live); }

/* The next one to come. Heavier, not alarming: no red, no pulse. */
.sq.is-next,
.key-swatch.is-next {
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

/* Marking a passed square: it fills toward kept before the redraw. */
.sq.is-marking {
  background: var(--kept);
}

/* ---------- card states ---------- */

.card.is-over { border-color: var(--passed); }

.card-over-how {
  margin: .35rem 0 0;
  font-size: .8rem;
  color: var(--ink-soft);
}

.card-over {
  margin: .9rem 0 0;
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--ink-soft);
}

.card-remove-wrap {
  margin: 1.1rem 0 0;
  padding-top: .9rem;
  border-top: 1px solid var(--rule);
}

.card-remove {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  cursor: pointer;
}

.card-remove:hover { color: #8c3b2e; }

.empty {
  margin: 0;
  padding: 2rem 1.4rem;
  border: 1px dashed var(--rule);
  border-radius: 6px;
  color: var(--ink-soft);
  font-size: .95rem;
}

/* ---------- add form ---------- */

.add { margin-top: 1.6rem; }

.add-toggle {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.05rem;
  cursor: pointer;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 2px;
}

.add-toggle:hover { border-bottom-color: var(--ink); }

.add-fields {
  margin-top: 1.4rem;
  padding: 1.4rem;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
}

.field { margin-bottom: 1.1rem; }

.field label {
  display: block;
  margin-bottom: .35rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-soft);
}

.field input,
.field select {
  width: 100%;
  padding: .55rem .6rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: .95rem;
}

.field input:focus,
.field select:focus,
.sq:focus-visible,
.add-toggle:focus-visible,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.dur { display: flex; gap: .5rem; }
.dur input { flex: 1 1 auto; min-width: 0; }
.dur select { flex: 0 0 8.5rem; }

.err {
  margin: .35rem 0 0;
  min-height: 1em;
  font-size: .78rem;
  color: #8c3b2e;
}

.err:empty { min-height: 0; }

.hint {
  margin: .35rem 0 0;
  font-size: .76rem;
  color: var(--ink-soft);
}

.add-actions { display: flex; gap: .75rem; align-items: center; }

.btn-primary {
  padding: .55rem 1.1rem;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: .85rem;
  cursor: pointer;
}

.btn-quiet {
  padding: .55rem .2rem;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: .85rem;
  cursor: pointer;
}

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

/* ---------- storage note ---------- */

.storage-note {
  margin: 2.5rem 0 0;
  font-size: .72rem;
  color: var(--ink-soft);
}

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