/* --- progress ---------------------------------------------------------- */

/* A card on its way to known: the known colour, lighter — told apart from
   known and from weak by lightness. Every variant sets its tokens on the
   root, so this mixes each variant's own. */
:root {
  --learning: color-mix(in srgb, var(--ok) 42%, var(--surface));
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: currentColor;
}

/* How a set of cards stands: known, learning, weak — the rest, new, is the
   bar's ground. A stacked bar with a legend, never colour alone. */
.mastery-bar {
  display: flex;
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--line-soft);
}

.mastery-bar > span {
  height: 100%;
  transition: width 0.3s ease;
}

.mastery-bar .known {
  background: var(--ok);
}

.mastery-bar .learning {
  background: var(--learning);
}

.mastery-bar .weak {
  background: var(--danger);
}

.mastery-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  padding: 16px 18px;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

/* Drawn before it is read, its room kept, its words unseen. */
.mastery-summary.pending > *,
.due-today.pending > * {
  visibility: hidden;
}

.mastery-summary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.mastery-summary-head strong {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
}

.mastery-summary-head .due-count {
  margin-left: auto;
}

.mastery-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
}

.mastery-legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mastery-legend .known .dot { color: var(--ok); }
.mastery-legend .learning .dot { color: var(--learning); }
.mastery-legend .weak .dot { color: var(--danger); }
.mastery-legend .new .dot { color: var(--line); }

/* One card's state, in its row: the chip, and under it the due mark when
   the card is due. The row's height is its buttons', which both fit in: a
   card falling due changes no row. */
.card-state {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* The clock after the state: one line, its centre on the state's. */
.due-icon {
  flex-shrink: 0;
  line-height: 0;
}

.mastery {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--chip);
  color: var(--chip-ink);
  font-size: 12px;
  white-space: nowrap;
}

.mastery.pending {
  visibility: hidden;
}

.mastery.known .dot { color: var(--ok); }
.mastery.learning .dot { color: var(--learning); }
.mastery.weak .dot { color: var(--danger); }
.mastery.new .dot { color: var(--dash); }

.due-mark {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent-text);
  font-size: 12px;
  white-space: nowrap;
}

.due-mark.idle {
  display: none;
}

.due-today {
  margin: 8px 0 4px;
}

.due-today .due-count {
  font-size: 15px;
}

/* Cards with a state column: it goes between the sides and the buttons,
   which keep the last column in every kind of row — the placeholders' and
   an open card's form among them. */
.cards-panel.with-state .card-cols {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 130px 140px;
}

.cards-panel.with-state .card-cols > .row-actions,
.cards-panel.with-state .card-cols .row-grid > .row-actions {
  grid-column: -2;
}

@media (max-width: 760px) {
  /* Stacked, the state takes a line of its own under the two sides, the
     chip and the due mark side by side. */
  .cards-panel.with-state .card-cols {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .cards-panel.with-state .row.card-cols .card-state {
    grid-column: 1;
    grid-row: 3;
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .cards-panel.with-state .row.card-cols .row-actions {
    grid-row: 1 / span 3;
  }

  .mastery-summary-head .due-count {
    margin-left: 0;
  }
}

/* Poster's tiles read top-down: the state under the back. */
[data-variant="poster"][data-layout="grid"] .cards-panel.with-state .row.card-cols {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 1fr auto;
}

[data-variant="poster"][data-layout="grid"] .cards-panel.with-state .row.card-cols .row-actions {
  grid-column: 1;
}

[data-variant="poster"][data-layout="grid"] .cards-panel.with-state .row.card-cols .card-state {
  grid-row: 4;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

/* --- the home page's study strip --------------------------------------- */

.study-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 8px 0 24px;
}

.study-tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 20px;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.study-tile.lead {
  background: var(--accent-soft);
}

.study-tile .tile-label {
  color: var(--muted);
  font-size: 13px;
}

.study-tile .tile-value {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 600;
  line-height: 1.1;
}

.study-tile .tile-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
  padding-top: 6px;
}

.study-strip.pending .tile-value {
  visibility: hidden;
}

@media (max-width: 760px) {
  .study-strip {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* --- collections ------------------------------------------------------- */

.criteria {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.criteria .criterion {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 12px;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 13px;
}

.criteria .criterion b {
  color: var(--muted);
  font-weight: 400;
}

.collection-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
}

.criteria-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
  padding: 16px 18px;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.criteria-form fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.criteria-form legend,
.criteria-form .field > span {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.criteria-form .field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.criteria-form .field-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.source-chip a {
  overflow: hidden;
  color: var(--ink-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A collection's rows: the deck a card is from sits between its sides and
   its state. */
.cards-panel.with-source .card-cols {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 170px 130px 140px;
}

.cards-panel.with-source .card-cols > .row-actions,
.cards-panel.with-source .card-cols .row-grid > .row-actions {
  grid-column: -2;
}

@media (max-width: 760px) {
  .criteria-form .field-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .cards-panel.with-source .card-cols {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .cards-panel.with-source .row.card-cols .source-chip {
    grid-column: 1;
    grid-row: 3;
  }

  .cards-panel.with-source .row.card-cols .card-state {
    grid-row: 4;
  }

  .cards-panel.with-source .row.card-cols .row-actions {
    grid-row: 1 / span 4;
  }
}

/* A collection's rows have no edit mode: a card of the user's own has its
   pencil always, and the marks of a review take its place. */
.cards-panel.with-source:not(.deck-editing) .card-cols .row-actions {
  visibility: visible;
}

.criteria-form select,
.criteria-form input:not([type="checkbox"]) {
  box-sizing: border-box;
  min-height: 44px;
  padding: 0 12px;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

/* --- kept collections -------------------------------------------------- */

.saved-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 12px;
}

.saved-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px 56px;
  align-items: center;
  gap: 16px;
}

@media (max-width: 760px) {
  .saved-cols {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .saved-cols > .muted {
    grid-column: 1;
  }
}

/* --- statistics -------------------------------------------------------- */

.stats-section {
  margin-bottom: 20px;
}

.stats-section h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

/* Twelve weeks, a column each, Monday at the top. */
.heatmap {
  display: grid;
  grid-template-rows: repeat(7, 18px);
  grid-auto-flow: column;
  grid-auto-columns: 18px;
  gap: 4px;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 4px;
}

.heat-cell {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: var(--line-soft);
}

.heat-cell.blank {
  background: transparent;
}

.heat-cell.level-1 { background: color-mix(in srgb, var(--ok) 25%, var(--line-soft)); }
.heat-cell.level-2 { background: color-mix(in srgb, var(--ok) 50%, var(--line-soft)); }
.heat-cell.level-3 { background: color-mix(in srgb, var(--ok) 75%, var(--line-soft)); }
.heat-cell.level-4 { background: var(--ok); }

.forecast {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: end;
  gap: 8px;
  height: 160px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.forecast-day {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  height: 100%;
}

.forecast-bar {
  width: 100%;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
}

.forecast-count {
  font-size: 13px;
}

.forecast-label {
  color: var(--muted);
  font-size: 12px;
}

/* A block of study put away folds up to nothing (the base's `.fold`), and the
   button that brings it back is in the page's header, where the one that put
   it away was. Folded, nothing of it is seen or reached. */
.study-fold {
  transition:
    grid-template-rows 220ms cubic-bezier(0.2, 0.7, 0.2, 1),
    margin 220ms cubic-bezier(0.2, 0.7, 0.2, 1),
    opacity 180ms ease,
    visibility 220ms;
}

.study-fold:not(.open) {
  visibility: hidden;
}

.study-fold > * {
  overflow-clip-margin: 16px;
}

.study-fold.summary.open {
  margin-bottom: 20px;
}

.study-fold.home.open {
  margin: 8px 0 24px;
}

.study-fold .mastery-summary,
.study-fold .study-strip {
  margin: 0;
}

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