/* --- panels ------------------------------------------------------------ */

.panel {
  background: var(--surface);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.panel.padded {
  padding: 20px;
}

.panel-head {
  display: grid;
  align-items: center;
  column-gap: 16px;
  min-height: 44px;
  padding: 0 20px;
  border-bottom: var(--border-w) solid var(--line);
  font-size: 12px;
  letter-spacing: var(--label-spacing);
  text-transform: var(--label-transform);
  color: var(--muted);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

/* --- topic grid ------------------------------------------------------ */

.topic-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 20px;
}

.topic-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 236px;
  padding: 20px 20px 12px;
  background: var(--surface);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.topic-card.editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.glyph {
  height: 60px;
  font-family: var(--font-display);
  font-size: 48px;
  line-height: 60px;
  color: var(--accent-text);
  overflow: hidden;
}

.topic-name {
  font-size: 21px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-name:hover {
  color: var(--accent-text);
  text-decoration: none;
}

/* The edit form replaces the card's body, so it has to stretch like one or the
   footer stops sitting at the bottom. */
.topic-card > .row-main {
  flex-grow: 1;
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
}

.card-foot-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.open-link {
  font-size: 14px;
  font-weight: 500;
}

/* The dashed "new topic" tile at the end of the grid. */
button.add-tile {
  min-height: 236px;
  flex-direction: column;
  gap: 10px;
  background: transparent;
  border: 1.5px dashed var(--dash);
  border-radius: var(--radius-lg);
  color: var(--muted);
  font-weight: 500;
  font-size: 16px;
}

button.add-tile:hover:not(:disabled) {
  background: transparent;
  border-color: var(--accent);
  color: var(--ink);
}

.add-tile-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--chip);
  color: var(--ink);
}

/* A form opening where a tile or a row just was — rather than swapped in
   between two frames. The list around it glides to its new height (see
   `motion.rs`); this settles the form itself into place. */
@keyframes form-in {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
}

.row.editing,
.topic-card.editing {
  animation: form-in 200ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  .row.editing,
  .topic-card.editing {
    animation: none;
  }
}

/* --- rows (decks, cards) ----------------------------------------------- */

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.row {
  position: relative;
  display: grid;
  align-items: start;
  column-gap: 16px;
  row-gap: 10px;
  padding: 16px 20px;
  border-bottom: var(--border-w) solid var(--line);
}

.rows > .row:last-child {
  border-bottom: none;
}

.row.editing,
.row.adding {
  background: var(--row-edit);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* The end of a topic's deck list: where a new deck goes, and the button
   that opens the form for it right there. A row like the others, only
   quieter. */
.row.add-row {
  display: block;
  padding: 0;
}

/* The list's end: the "New deck" row and the create form, one folding shut
   as the other opens. It is the last thing in the list, so neither of them
   draws a line under it. */
.create-slot {
  list-style: none;
}

.create-slot .row {
  border-bottom: none;
}

button.add-row-btn {
  justify-content: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 12px 20px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}

button.add-row-btn:hover:not(:disabled) {
  background: var(--row-edit);
  color: var(--ink);
}

button.add-row-btn .add-tile-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

/* What the deck page shows only while editing — the composer and the select
   bar — is always in the list, folded shut otherwise: entering edit mode
   slides it open rather than dropping it in. It folds by its one grid row,
   to its content's own height (`.fold-body` holds the content and its
   layout); a `max-height` to a guess played the slide in its first frame. */
.folds {
  display: grid;
  grid-template-rows: 1fr;
  transition:
    grid-template-rows 220ms cubic-bezier(0.2, 0.7, 0.2, 1),
    padding 220ms cubic-bezier(0.2, 0.7, 0.2, 1),
    border-width 220ms cubic-bezier(0.2, 0.7, 0.2, 1),
    opacity 180ms ease;
}

.folds > .fold-body {
  min-height: 0;
  overflow: clip;
  overflow-clip-margin: 6px;
}

.folds.folded {
  grid-template-rows: 0fr;
  padding-block: 0;
  border-bottom-width: 0;
  opacity: 0;
}

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

/* --- favourites --------------------------------------------------------------- */

/* Deck, author, cards, the star: a panel's head and its rows. */
.fav-cols {
  grid-template-columns: minmax(0, 1fr) 200px 100px auto;
}

.row.fav-cols {
  align-items: center;
}

/* A star whose deck no longer opens: its name struck through, and what
   became of it beneath. */
.row.gone .row-title {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.gone-note {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

/* The star: outlined while off, filled in the accent while on. */
button.star-btn[aria-pressed="true"] {
  color: var(--accent-text);
}

button.ghost.star-btn[aria-pressed="true"] {
  border-color: var(--accent);
}

button.star-btn[aria-pressed="true"] .ico {
  fill: currentColor;
}

/* The favourites' entry in the topics panel: a topic's row, a star for its
   glyph, a little apart from the topics themselves. */
.side-link.side-favorites {
  margin-top: 12px;
}
