.topbar {
  position: relative; /* the overflow menu hangs off it */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  color: #f2ece2;
}

/*
 * The bar is deliberately one row — see the overflow menu in app.js, which
 * exists so that a narrow screen spends its height on cards rather than on a
 * third row of buttons. One row only works if its contents can give way,
 * though, and a flex item's default minimum size is its content, so without
 * `min-width: 0` the wordmark and the buttons simply push past the edge
 * instead. The wordmark is the right thing to lose first.
 */
.topbar h1 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-width: 0;
}

/* The same artwork as the favicon. Fixed, because it is a mark and not type. */
.topbar .mark {
  width: 24px;
  height: 24px;
  flex: none;
}

/*
 * The trimming lives on the word rather than on the heading, because the
 * heading is now a flex row and a flex container cannot ellipsis its own
 * children. `.value` and the danger button are nowrap by intent, so when the
 * bar runs short this is still the thing that gives — but the mark is `flex:
 * none` and stays whole, which is the point of putting it here.
 */
.topbar .wordmark {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  /* The value reads as "matches / album" under a filter, which is about twice as
     wide as the album total alone. Wrapping lets a narrow window take a second
     row rather than pushing the buttons off the edge. */
  flex-wrap: wrap;
  gap: 0.75rem;
  /* Wrapping only helps once the group is allowed to be narrower than its
     contents; as a flex item it otherwise floors at its widest button. */
  min-width: 0;
}

.muted {
  color: rgba(242, 236, 226, 0.6);
  font-size: 0.85rem;
}

.btn {
  font: inherit;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  border: 1px solid rgba(242, 236, 226, 0.35);
  background: transparent;
  color: #f2ece2;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
  color: #fff;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.ghost {
  border-color: rgba(27, 26, 23, 0.25);
  color: var(--ink);
}

a.btn.ghost {
  text-decoration: none;
  line-height: 1.5;
}

/*
 * The binding, in the top bar: a chip wearing the colour it opens, so the
 * control says what it does without a word and without taking a button's width
 * from a bar that already has four.
 */
.swatch {
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(242, 236, 226, 0.45);
  /* The same top-left sheen the cover itself is lit with, in miniature. */
  background:
    radial-gradient(120% 120% at 30% 15%, rgba(255, 255, 255, 0.35), transparent 60%),
    var(--swatch, var(--cover));
  cursor: pointer;
}

.swatch:hover {
  border-color: var(--accent);
}

/* The palette inside the dialog: the same chip, laid out and checkable. */
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.swatch-option {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(27, 26, 23, 0.25);
  background:
    radial-gradient(120% 120% at 30% 15%, rgba(255, 255, 255, 0.35), transparent 60%),
    var(--swatch);
  cursor: pointer;
}

/* A ring set off the chip, so the mark reads on a dark hide and a light one. */
.swatch-option[aria-checked="true"] {
  box-shadow:
    0 0 0 2px var(--paper),
    0 0 0 4px var(--accent);
}

.color-input {
  width: 3rem;
  height: 2rem;
  padding: 0;
  border: 1px solid rgba(27, 26, 23, 0.25);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}

/* Binder value at Cardmarket prices; doubles as the refresh button. */
.value {
  font: inherit;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  /* Two figures and the slash between them are one label, never two lines. */
  white-space: nowrap;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  border: 1px solid transparent;
  background: rgba(180, 112, 58, 0.18);
  color: #f0d9c0;
  cursor: pointer;
}

.value:hover:not(:disabled) {
  border-color: var(--accent);
  color: #fff;
}

.value:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* A quiet dot marks prices that are no longer from today. */
.value.stale::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 0.4rem;
  vertical-align: middle;
  border-radius: 50%;
  background: #e0a030;
}

/* --- filter bar --- */

.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem 0.85rem;
  border-block: 1px solid rgba(242, 236, 226, 0.12);
  background: rgba(0, 0, 0, 0.18);
}

.filterbar input,
.filterbar select {
  font: inherit;
  font-size: 0.87rem;
  padding: 0.32rem 0.5rem;
  border-radius: 5px;
  border: 1px solid rgba(242, 236, 226, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: #f2ece2;
}

.filterbar input::placeholder {
  color: rgba(242, 236, 226, 0.45);
}

.filterbar input:focus,
.filterbar select:focus {
  outline: none;
  border-color: var(--accent);
}

.filterbar option {
  color: #1b1a17;
}

/*
 * A select is as wide as its widest option, and as a flex item its automatic
 * minimum size is that same width — so it does not shrink, it overflows. The
 * set list is built from Scryfall's own names, and "The Lord of the Rings:
 * Tales of Middle-earth (2)" is already wider than a phone's filter bar with
 * nothing to stop it; the longest names in the catalogue are longer still.
 *
 * `min-width: 0` releases that floor and `max-width: 100%` caps the worst case
 * at one full line. The closed control then clips its label, which costs
 * nothing: the place the name has to be readable is the open dropdown, and on a
 * phone that is a full-screen picker. Shortening the labels themselves would
 * trade away the readable half to fix the half nobody reads.
 */
.f-select {
  min-width: 0;
  /* 100% keeps it on the line; the 18rem stops one long set name from taking a
     whole row to itself and pushing every other control down. */
  max-width: min(100%, 18rem);
  text-overflow: ellipsis;
}

.f-search {
  flex: 1 1 16rem;
  min-width: 10rem;
}

.f-type {
  width: 11rem;
}

.f-colors {
  display: flex;
  gap: 0.25rem;
}

/* Mana pips: colour-coded so the row reads at a glance, letter kept for clarity. */
.pip {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.35);
  font: 600 0.75rem/1 system-ui, sans-serif;
  color: rgba(0, 0, 0, 0.55);
  cursor: pointer;
  opacity: 0.45;
  transition:
    opacity 120ms ease,
    box-shadow 120ms ease;
}

.pip:hover {
  opacity: 0.8;
}

.pip.on {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--accent);
}

.pip-w { background: #f8f2e0; }
.pip-u { background: #9fd3f0; }
.pip-b { background: #a29a94; }
.pip-r { background: #f0a08c; }
.pip-g { background: #9ed3ac; }
.pip-c { background: #d6d0c6; }

.f-range {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: rgba(242, 236, 226, 0.75);
  white-space: nowrap;
}

.f-range input {
  width: 4.4rem;
}

.f-check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: rgba(242, 236, 226, 0.8);
  white-space: nowrap;
}

.f-check.empty {
  opacity: 0.35;
}

/* Held on by the sort order rather than by the reader. */
.f-check.forced {
  opacity: 0.5;
  cursor: not-allowed;
}

.f-check input {
  accent-color: var(--accent);
}

#toggle-filters.active,
#select-cards.active {
  border-color: var(--accent);
  color: #fff;
}

/* How many cards are picked out, beside the album's own count. */
.selected-count {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/*
 * Removing a selection is bulk and final, so the button that does it does not
 * look like the ones beside it. Outlined rather than filled: it sits in the top
 * bar the whole time a selection is up, and a solid red block there would read
 * as an alarm rather than an action.
 */
.btn.danger {
  border-color: #b4463a;
  color: #f3b8b0;
  white-space: nowrap;
}

.btn.danger:hover:not(:disabled) {
  background: #b4463a;
  border-color: #b4463a;
  color: #fff;
}

.btn.danger:disabled {
  opacity: 0.6;
  cursor: progress;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 0.75rem 0 1.5rem;
}

.arrow {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: 1px solid rgba(242, 236, 226, 0.3);
  background: rgba(255, 255, 255, 0.04);
  color: #f2ece2;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.arrow:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.arrow:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Holding a dragged card over an arrow: fills up, then the page turns. */
.arrow.turning {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  animation: arrow-pulse 600ms ease-out;
}

@keyframes arrow-pulse {
  from {
    box-shadow: 0 0 0 0 rgba(180, 112, 58, 0.6);
  }
  to {
    box-shadow: 0 0 0 10px rgba(180, 112, 58, 0);
  }
}

.pager-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 11rem;
}

.page-indicator {
  text-align: center;
  color: #f2ece2;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}

.match-indicator {
  font-size: 0.78rem;
  color: var(--accent);
}

.match-indicator.none {
  color: rgba(242, 236, 226, 0.4);
}

/*
 * One page or two. Out of the flow at the pager's left, the legal line's
 * counterpart on the right, so the arrows stay centred on the album.
 */
.pages-toggle {
  position: absolute;
  left: 1.25rem;
  bottom: 1.35rem;
  display: flex;
  border: 1px solid rgba(242, 236, 226, 0.3);
  border-radius: 6px;
  overflow: hidden;
}

.pages-toggle button {
  font: inherit;
  font-size: 0.8rem;
  min-width: 2rem;
  padding: 0.2rem 0.55rem;
  border: none;
  background: transparent;
  color: rgba(242, 236, 226, 0.7);
  cursor: pointer;
}

.pages-toggle button + button {
  border-left: 1px solid rgba(242, 236, 226, 0.3);
}

.pages-toggle button:hover {
  color: #fff;
}

.pages-toggle button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

/* A phone always shows one page; see the note on the markup. */
@media (max-width: 40rem) {
  .pages-toggle {
    display: none;
  }
}

/* Secondary arrows that skip to the next page actually holding a match. */
.arrow.jump {
  width: 2.1rem;
  height: 2.1rem;
  font-size: 0.95rem;
  border-style: dashed;
}

/* --- dialogs --- */

.dialog {
  border: none;
  border-radius: 10px;
  padding: 1.25rem;
  max-width: min(34rem, 92vw);
  max-height: 92dvh;
  overflow: auto;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

/* The card detail carries a lot of metadata, so it gets room to lay it out wide. */
#card-dialog {
  max-width: min(46rem, 94vw);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.dialog h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.dialog-body {
  display: flex;
  gap: 1rem;
}

.dialog-fields {
  flex: 1;
  min-width: 0;
}

.preview-frame {
  flex: none;
  align-self: flex-start;
  width: 9rem;
}

.preview {
  display: block;
  width: 100%;
  aspect-ratio: 63 / 88;
  object-fit: cover;
  border-radius: 4.5% / 3.2%;
  background: var(--slot);
}

/* Stand-in while the card is still just a name in the box. */
.preview.placeholder {
  display: grid;
  place-items: center;
  border: 1.5px dashed var(--slot-line);
  background: transparent;
  color: var(--slot-line);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
}

.spacer {
  flex: 1;
}

.dialog label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

/* The pasted list. Monospaced so the amounts line up and a mistyped line shows. */
#import-text {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--slot-line);
  background: #fff;
  color: var(--ink);
}

#import-text:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* How far through a long list the lookups have got. */
.progress {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.progress-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 200ms ease;
}

.dialog code {
  font-size: 0.9em;
  padding: 0.05rem 0.25rem;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.07);
}

/* A checkbox and its label on one line, among the detail's stacked fields. */
.detail-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.detail-check input {
  accent-color: var(--accent);
  margin: 0;
}

.detail-check .checkbox-label {
  margin: 0;
  cursor: pointer;
}

/* Ticking Proxy zeroes the card's worth everywhere, so it reads at body size. */
.detail-check .proxy-label {
  font-size: 1rem;
}

/* Marks the one field that has to be filled in before a card can be added. */
.dialog label .required {
  color: var(--accent);
  font-weight: 700;
}

/*
 * A dimmed primary button, for "not yet" rather than "busy" — the card cannot be
 * added until it has been named, and the button says so by looking unavailable
 * instead of the press quietly doing nothing.
 */
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dialog input[type="text"],
.dialog input[type="email"],
.dialog input[type="password"],
.dialog input:not([type]) {
  width: 100%;
  font: inherit;
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(27, 26, 23, 0.25);
  border-radius: 5px;
  background: #fff;
}

/*
 * Selects inside a dialog, matching the text inputs above rather than the filter
 * bar's, which is light-on-dark and belongs to the felt. A step down in size
 * because the widest grade — "Light Played" — plus the platform's dropdown arrow
 * is tight in a column only as wide as a card.
 */
.dialog select,
.dialog textarea {
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid rgba(27, 26, 23, 0.25);
  border-radius: 5px;
  background: #fff;
  color: inherit;
}

/* A note grows downward if it is dragged, never sideways out of the column. */
.dialog textarea {
  resize: vertical;
  line-height: 1.4;
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: rgba(27, 26, 23, 0.6);
}

.status {
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
  border-radius: 5px;
  background: rgba(224, 160, 48, 0.15);
}

.status.error {
  background: rgba(200, 60, 40, 0.14);
}

.status.ok {
  background: rgba(60, 150, 90, 0.14);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* --- card detail --- */

.detail {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
}

/*
 * The text column must be allowed to shrink, or long rules text forces a
 * scrollbar. Named rather than matched as `.detail > div`, which would also
 * catch the art column beside it and stretch that to the same width.
 */
.detail-body {
  flex: 1 1 18rem;
  min-width: 0;
}

/*
 * The artwork and what belongs to this copy of it, stacked.
 *
 * A flex item stretches to the row height by default, which squashed the card out
 * of shape whenever the details column was taller or shorter than the artwork.
 * Opting out of the stretch lets the image keep its own proportions.
 *
 * The width lives here rather than on the image so that everything under it —
 * the condition picker — is exactly as wide as the card above.
 */
.detail-art {
  display: flex;
  flex-direction: column;
  flex: none;
  align-self: flex-start;
  /* Card height is width x 88/63, so cap the width to keep it inside a short window. */
  width: min(12rem, 38dvh);
}

.detail img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4.5% / 3.2%;
  cursor: zoom-in;
}

.detail img:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- the card at full size --- */

/*
 * A dialog that is nothing but the card: no chrome of its own, so what the
 * viewer sees is the printing and the dark around it.
 */
.zoom {
  border: none;
  padding: 0;
  margin: auto;
  max-width: none;
  max-height: none;
  background: transparent;
  overflow: visible;
}

.zoom::backdrop {
  background: rgba(0, 0, 0, 0.82);
}

/*
 * Both dimensions are capped and neither is set, so the card grows to fill the
 * window along whichever axis runs out first and keeps its proportions doing
 * it. Scryfall's image rules forbid distorting or stretching a card image, and
 * a fixed width with `height: auto` would be one bad viewport away from that.
 */
.zoom img {
  display: block;
  width: auto;
  height: auto;
  max-width: 94vw;
  max-height: 94dvh;
  border-radius: 2.6% / 1.9%;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  cursor: zoom-out;
}

/* The fields that describe the copy rather than the card, stacked under it. */
.detail-field {
  margin-top: 0.55rem;
}

/*
 * Two label/value pairs per row: with a dozen-odd fields a single column made the
 * dialog taller than the screen. Collapses to one pair when there is no room.
 */
.detail dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 0.2rem 0.75rem;
  font-size: 0.88rem;
  align-content: start;
}

@media (max-width: 40rem) {
  .detail dl {
    grid-template-columns: auto minmax(0, 1fr);
  }
}

.detail dt {
  font-weight: 600;
  color: rgba(27, 26, 23, 0.6);
}

.detail dd {
  margin: 0;
}

.detail h2 {
  margin: 0 0 0.15rem;
}

/* The card's text box: newlines separate abilities, so they are preserved. */
.rules {
  white-space: pre-line;
  margin: 0.5rem 0 0.75rem;
  padding: 0.5rem 0.7rem;
  font-size: 0.88rem;
  line-height: 1.45;
  border-left: 3px solid rgba(180, 112, 58, 0.5);
  background: rgba(27, 26, 23, 0.045);
  border-radius: 0 5px 5px 0;
}

/* --- tags --- */

.tag-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.9rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(27, 26, 23, 0.12);
}

.tag-chips {
  display: contents;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.2rem 0.3rem 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.82rem;
  color: #fdfcf9;
  background: rgba(20, 18, 15, 0.82);
}

.chip-x {
  border: none;
  background: none;
  padding: 0 0.25rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  color: rgba(253, 252, 249, 0.65);
  cursor: pointer;
}

.chip-x:hover {
  color: #fff;
}

/* Sized to the placeholder so an empty editor still looks like somewhere to type. */
.tag-input {
  flex: 0 1 11rem;
  min-width: 7rem;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border: 1px dashed rgba(27, 26, 23, 0.3);
  border-radius: 999px;
  background: transparent;
  color: inherit;
}

.tag-input:focus {
  outline: none;
  border-style: solid;
  border-color: var(--accent);
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.suggestions button {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(27, 26, 23, 0.25);
  background: #fff;
  cursor: pointer;
}

.suggestions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* The art is showing a printing under the pointer, not the card in the pocket. */
.detail img.previewing {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}

/* --- signing in --- */

/*
 * The login page has none of the album's furniture, just one card on the felt.
 * It borrows .dialog and the form styles above rather than restating them, so
 * it cannot drift away from the look of the dialogs inside the app.
 */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  width: min(26rem, 100%);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.4rem;
}

/* Bigger than the bar's, because here it is the first thing on the page rather
   than a corner of furniture. The tile carries it: this card is paper, and the
   bare ring would leave its white centre floating on white. */
.login-card .mark {
  width: 34px;
  height: 34px;
  flex: none;
}

.login-card .tagline {
  margin: 0 0 1.25rem;
  font-size: 0.85rem;
  color: rgba(27, 26, 23, 0.6);
}

/* Fields want a little air between them when they are stacked this closely. */
.login-card label {
  margin-top: 0.85rem;
}

.login-card label:first-of-type {
  margin-top: 0;
}

/* --- the privacy notice --- */

/*
 * binder.css pins the body to the viewport and hides its overflow, because the
 * album is furniture that must not scroll. A notice is a document and must, so
 * the one page that is prose hands the scrollbar back.
 */
body.page-legal {
  height: auto;
  min-height: 100dvh;
  display: block;
  overflow: auto;
}

/*
 * A column of prose on the same felt as the login card, but not inside .login:
 * that grid centres its child, and a notice taller than the viewport centred
 * vertically puts its own first line above the top of the page, out of reach.
 */
.legal-page {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1.5rem;
}

/* .dialog is sized for a dialog: narrow, and capped at 92dvh with its own
   scrollbar. A document wants the page's scrollbar and a readable measure. */
.legal {
  width: min(44rem, 100%);
  max-width: 100%;
  max-height: none;
  overflow: visible;
  padding: 1.75rem;
  line-height: 1.55;
}

.legal h1 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
}

.legal h2 {
  margin: 1.75rem 0 0.5rem;
  font-size: 1rem;
}

.legal h3 {
  margin: 1.25rem 0 0.35rem;
  font-size: 0.9rem;
  color: rgba(27, 26, 23, 0.75);
}

.legal p {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

.legal code {
  font-size: 0.85em;
  padding: 0.05rem 0.25rem;
  border-radius: 3px;
  background: rgba(27, 26, 23, 0.07);
}

.legal-back {
  margin-top: 1.75rem;
  font-size: 0.85rem;
}

/* The notice has to be readable before there is an account, so the link to it
   sits under the sign-in form rather than only in the album's top bar. Inside
   the card, not on the felt: the muted ink below is paper ink. */
.login-footer {
  margin: 1.1rem 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: rgba(27, 26, 23, 0.6);
}

/*
 * The album's own link to the notice. It sits in the pager rather than the top
 * bar, which is already full, and it is positioned out of the flow so that the
 * arrows stay centred on the page they turn.
 */
.pager {
  position: relative;
}

.pager-legal {
  position: absolute;
  right: 1.25rem;
  bottom: 1.5rem;
  margin: 0;
  font-size: 0.75rem;
  color: rgba(242, 236, 226, 0.45);
}

.pager-legal a {
  color: inherit;
  text-decoration: none;
}

.pager-legal a:hover {
  color: #f2ece2;
  text-decoration: underline;
}

/* No room beside the arrows on a phone, so it takes a row of its own — and
   sheds the words it can spare, because every line it wraps to is a line the
   album does not get. What is left still names the source and the copyright. */
@media (max-width: 34rem) {
  .pager {
    flex-wrap: wrap;
  }

  .pager-legal {
    position: static;
    width: 100%;
    text-align: center;
    font-size: 0.68rem;
  }

  .wide-only {
    display: none;
  }
}

/* --- the overflow menu, and everything else a phone needs --- */

/* A ⋮ the same size as the buttons beside it, so the row keeps one baseline. */
.more {
  padding: 0.4rem 0.6rem;
  line-height: 1.5;
}

/*
 * The menu hangs under the bar rather than sitting in it: absolute, so it is
 * out of the flex flow and cannot push the album down when it opens.
 */
.menu {
  position: absolute;
  top: 100%;
  right: 0.75rem;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 11rem;
  padding: 0.35rem;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

/* In here the buttons are list rows: full width, left aligned, thumb-sized. */
.menu .btn {
  width: 100%;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0.7rem 0.75rem;
}

.menu .btn:hover {
  background: rgba(27, 26, 23, 0.07);
  color: var(--ink);
}

.menu .btn.danger {
  color: #a3382c;
}

@media (max-width: 40rem) {
  /*
   * The bar gives back what it can: less padding, a smaller wordmark, and
   * buttons that grow rather than shrink, because a 31px target is a mouse
   * target and this is a thumb.
   */
  .topbar {
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
  }

  /*
   * The word steps off the bar here; the mark stays.
   *
   * Nine controls want about 380px and the bar has 378 to give, so at this
   * width the name was costing a fifth of the row and getting "Spell…" for it —
   * a trimmed name reads as breakage, not as design. The mark says the same
   * thing in 24px, which the bar can afford, and it holds the left corner so
   * the album is still identifiably itself.
   *
   * Clipped rather than `display: none`, so the heading keeps its text and a
   * screen reader still opens on the album's name. Out of flow, so the word
   * contributes no width at all.
   */
  .topbar .wordmark {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* No gap to close up around, once the word beside the mark is gone. */
  .topbar h1 {
    gap: 0;
  }

  /* Takes the rest of the bar so the controls sit against the right edge,
     with the mark alone in the left corner. */
  .topbar-actions {
    flex: 1;
    gap: 0.4rem;
  }

  .btn {
    padding: 0.55rem 0.8rem;
  }

  .value {
    padding: 0.55rem 0.6rem;
  }

  /* Every millimetre here is a millimetre of card. */
  .binder {
    padding: 0.35rem 0.5rem;
  }

  .pager {
    gap: 0.75rem;
    padding: 0.4rem 0 0.5rem;
  }

  /*
   * The filter bar is a dozen controls stacked; unchecked it would take half
   * the screen, so it scrolls within its own half instead of pushing the album
   * off the bottom.
   */
  .filterbar {
    gap: 0.4rem;
    padding: 0.5rem 0.75rem 0.6rem;
    max-height: 45dvh;
    overflow-y: auto;
  }

  .f-search {
    flex: 1 1 100%;
  }

  .f-type {
    width: auto;
    flex: 1 1 8rem;
  }

  .pip {
    width: 2.1rem;
    height: 2.1rem;
  }

  .dialog {
    padding: 1rem;
  }

  /* Room to actually look at the card while editing what is under it. */
  .detail-art {
    width: min(14rem, 45vw);
  }
}

/*
 * Sixteen pixels, and not a fraction less.
 *
 * Safari on iOS zooms the page whenever a form control smaller than 16px takes
 * focus. The zoom shrinks the visual viewport inside the layout one, and the
 * page can be dragged sideways from then on — which reads as a horizontal
 * scrollbar that no element actually causes, and which survives the keyboard
 * being dismissed. Every control here was under the threshold: the filter
 * bar's at 0.87rem, the dialogs' selects and notes at 0.85rem, and the text
 * inputs at the body's own 15px.
 *
 * Keyed on `pointer: coarse` rather than on a width, because it is touch that
 * triggers the behaviour, not narrowness: an iPad does this too and is nowhere
 * near 40rem, while a narrow desktop window does not and keeps the compact
 * bar it was designed with. Stated in px rather than rem so that changing the
 * root size later cannot quietly push it back under 16.
 *
 * The obvious alternative — user-scalable=no — removes pinch-zoom for people
 * who need it, to fix a layout problem. It is not on the table.
 *
 * This pairs with `.f-select` above and cannot ship without it: larger text
 * makes the widest option wider still, so the cap is what keeps the bar inside
 * the screen once the type grows.
 */
@media (pointer: coarse) {
  .filterbar input,
  .filterbar select,
  .dialog select,
  .dialog textarea,
  .tag-input,
  /*
   * The four text inputs are spelled out in full rather than caught by a plain
   * `.dialog input`. The rule they have to beat selects on the type attribute
   * and so outweighs a bare element selector — the shorthand `font: inherit`
   * would have kept winning, and these fields would have stayed at the body's
   * 15px while looking, in the stylesheet, as though they had been fixed.
   */
  .dialog input[type="text"],
  .dialog input[type="email"],
  .dialog input[type="password"],
  .dialog input:not([type]) {
    /* px because the threshold is an absolute 16 CSS px, max() because a
       reader who has raised their default size should keep the larger one. */
    font-size: max(16px, 1rem);
  }
}

/*
 * The shelf: the album and the decks beside it, down the left of everything
 * below the bar. The workspace is the row that holds it and the album; the
 * album's column inside keeps the layout it always had, so `.binder` still
 * takes whatever height is left and still sizes the page from its container.
 */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}

.workspace-main {
  flex: 1;
  min-width: 0; /* a flex item floors at its content otherwise, and pushes the page sideways */
  display: flex;
  flex-direction: column;
}

.sidebar {
  flex: none;
  width: 13rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 0.5rem 0.75rem 1rem;
  overflow-y: auto;
  color: #f2ece2;
  border-right: 1px solid rgba(242, 236, 226, 0.12);
}

.shelf {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.shelf-heading {
  margin: 0.9rem 0 0.25rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(242, 236, 226, 0.5);
}

.shelf-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.shelf-row {
  display: flex;
  align-items: center;
}

.shelf-item {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
}

.shelf-item:hover {
  background: rgba(242, 236, 226, 0.08);
}

.shelf-item[aria-current="page"] {
  background: rgba(242, 236, 226, 0.14);
  box-shadow: inset 3px 0 0 var(--accent);
}

.shelf-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shelf-count {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.shelf-empty {
  margin: 0.2rem 0.6rem;
}

.shelf-edit {
  flex: none;
  font: inherit;
  padding: 0.3rem 0.5rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(242, 236, 226, 0.7);
  cursor: pointer;
}

.shelf-edit:hover {
  background: rgba(242, 236, 226, 0.1);
  color: #fff;
}

.shelf-new {
  align-self: flex-start;
  margin-left: 0.6rem;
}

/* On paper, the deck dialog's delete needs a red that reads against white. */
.dialog .btn.danger {
  color: #a3382c;
}

/* Wide screens keep the shelf in view; the toggle is for the drawer only. */
.sidebar-toggle {
  display: none;
}

/*
 * On a phone the shelf steps off the page into a drawer, so the album keeps
 * the full width. Moved out with a transform and hidden as well, so the drawer
 * cannot be tabbed into while it is shut — and positioned fixed, so it takes
 * no width from the row and cannot bring back the sideways scroll.
 */
@media (max-width: 40rem) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(17rem, 82vw);
    padding-top: 1rem;
    background: var(--felt-2);
    border-right: none;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
    transform: translateX(-100%);
    visibility: hidden;
    transition:
      transform 200ms ease,
      visibility 0s linear 200ms;
  }

  .sidebar.open {
    transform: none;
    visibility: visible;
    transition: transform 200ms ease;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 29;
    background: rgba(0, 0, 0, 0.45);
  }

  .shelf-item {
    padding: 0.7rem 0.75rem;
  }

  /* The toggle stands in the mark's corner, which is where a phone looks for it. */
  .sidebar-toggle {
    display: inline-block;
    flex: none;
  }

  .topbar .mark {
    display: none;
  }
}

/* --- title page dialog --- */

/* The two picture slots, side by side; the pressed one is what the buttons fill. */
.title-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.title-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem;
  font: inherit;
  border: 2px solid rgba(27, 26, 23, 0.15);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.title-slot[aria-pressed="true"] {
  border-color: var(--accent);
}

.title-slot img,
.title-slot-empty {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border-radius: 3px;
}

.title-slot-empty {
  display: grid;
  place-items: center;
  border: 1.5px dashed var(--slot-line);
  font-size: 0.8rem;
  color: rgba(27, 26, 23, 0.45);
}

.title-slot-label {
  font-size: 0.8rem;
  font-weight: 600;
}

.title-slot[aria-pressed="true"] .title-slot-label {
  color: var(--accent);
}

.title-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.title-sources .btn {
  font-size: 0.85rem;
  padding: 0.3rem 0.7rem;
}

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

.title-source {
  margin-top: 0.75rem;
}

#title-text {
  margin-bottom: 0.85rem;
}

/* Art crops are landscape; cards keep their own shape. */
.title-choices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  gap: 0.5rem;
  max-height: 16rem;
  overflow: auto;
  margin-top: 0.6rem;
  font-size: 0.85rem;
}

.title-choices.cards {
  grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
}

.title-choice {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 5px;
  background: none;
  cursor: pointer;
  line-height: 0;
}

.title-choice:hover,
.title-choice:focus-visible {
  border-color: var(--accent);
}

.title-choice img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 3px;
}

.title-choices.cards .title-choice img {
  aspect-ratio: 63 / 88;
}
