@font-face {
  font-family: "TeutonFett";
  src: url("../font/TeutonFett-Regular.woff") format("woff");
  font-display: swap;
}

:root {
  --primary: #f5a623;
  --primary-dark: #d48806;
  --surface: #2b1d33;
  --card: #3d2b47;
  --on-surface: #f5f5f5;
  --muted: #bcafc6;
  --error: #ff8a80;
  --radius: 10px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--surface);
  color: var(--on-surface);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  line-height: 1.4;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
}

button,
input {
  font: inherit;
}

/* The hidden attribute always hides. A display rule, as on button, must not
   show a hidden element (the #cardload button showed as an empty oval). */
[hidden] {
  display: none !important;
}

button,
.button {
  cursor: pointer;
  border: 1px solid var(--muted);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--on-surface);
  padding: 0.4rem 0.8rem;
  text-decoration: none;
  display: inline-block;
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--surface);
  font-weight: 600;
}

button.primary:hover {
  background: var(--primary-dark);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}

.muted {
  color: var(--muted);
}

/* Header */

/* The header stays at the top of the screen, above the card view, so the
   user can type a new query at any time. */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 16px;
  border-bottom: 1px solid var(--card);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: "TeutonFett", serif;
  font-size: 1.4rem;
  color: var(--primary);
  text-decoration: none;
}

.brand .wordmark {
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  line-height: 1;
}

.brand .sub {
  font-size: 1rem;
  color: var(--muted);
}

.query {
  flex: 1 1 320px;
  display: flex;
  gap: 0.5rem;
}

.query {
  flex-wrap: wrap;
  align-items: center;
}

/* The search bar: one text input, and the completion list under it. */
.qwrap {
  flex: 1 1 260px;
  position: relative;
  min-width: 0;
}

.qwrap input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius);
  border: 1px solid var(--muted);
  background: var(--card);
  color: var(--on-surface);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.95rem;
}

.qwrap input:focus {
  outline: 2px solid var(--primary);
}

.qerror {
  flex-basis: 100%;
  color: var(--error);
  font-size: 0.85rem;
  min-height: 0;
}

.qerror:empty {
  display: none;
}

.actions {
  position: relative;
  display: flex;
  gap: 0.5rem;
}

/* The buttons of the header. On a wide screen they sit in one row, and
   only the Random button shows its word. The menu button is for phones. */
.menu-items {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.actions .menu-toggle,
.menu-items .round .label,
.random .random-icon {
  display: none;
}

.random {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

/* A narrow header shows the Random button as an icon. */
@media (max-width: 1000px) {
  .random .random-icon {
    display: block;
  }

  .random .label {
    display: none;
  }

  .random {
    padding: 0.4rem 0.55rem;
  }
}

/* On a phone, the menu button opens the buttons as a list under it. */
@media (max-width: 720px) {
  .actions .menu-toggle {
    display: inline-grid;
  }

  .menu-items {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 40;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    min-width: 12rem;
    padding: 0.35rem;
    border: 1px solid var(--muted);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: 0 6px 18px rgb(0 0 0 / 40%);
  }

  .actions.open .menu-items {
    display: flex;
  }

  .menu-items .button,
  .menu-items .round {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: auto;
    height: auto;
    padding: 0.5rem 0.7rem;
    border: none;
    border-radius: var(--radius);
    background: none;
    font: inherit;
    text-align: left;
  }

  .menu-items .button:hover,
  .menu-items .button:focus-visible {
    background: var(--surface);
  }

  .menu-items .label,
  .menu-items .round .label,
  .menu-items .random .label {
    display: inline;
  }

  .menu-items .random .random-icon {
    display: block;
  }

  .menu-items .help .mark {
    display: inline-grid;
    place-items: center;
    width: 18px;
    font-weight: bold;
  }
}

/* A round button: the same width and height, so it is a circle. */
.round {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border-radius: 50%;
  line-height: 1;
  flex: none;
}

/* Search page */

main {
  flex: 1;
  padding: 0.75rem 16px;
}


.error {
  border: 1px solid var(--error);
  border-radius: var(--radius);
  padding: 0.75rem;
  color: var(--error);
}

.error mark {
  background: var(--error);
  color: var(--surface);
}

/* The card count and the size slider: two lines at the top of the sidebar. */
.summary {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.size {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* The size slider in the theme orange, in Chrome, Safari, and Firefox. */
.size input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--primary);
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    var(--primary) var(--fill, 33%),
    var(--card) var(--fill, 33%)
  );
  cursor: pointer;
}

.size input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
}

.size input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
}

.size input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 3px;
  background: var(--primary);
}

.size input[type="range"]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.layout {
  display: grid;
  /* Wide enough for the longest set name on one line ("Call of the
     Archons", "Vault Masters 2023") with its icon and count. */
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.facet {
  margin-bottom: 1rem;
}

.facet h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.facet ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.facet a {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  position: relative;
  padding: 0.1rem 0.3rem;
  text-decoration: none;
  border-radius: 4px;
}

/* A hover mark needs a mouse or a trackpad: a tap on a phone leaves the
   hover state on, so the value would stay marked. */
@media (hover: hover) {
  .facet a:hover {
    background: var(--card);
  }
}

.facet .n {
  color: var(--muted);
  position: relative;
}

.facet .label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  white-space: nowrap;
}

.bars .bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: var(--card);
  border-radius: 4px;
}

.results {
  position: relative;
  min-width: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--tile), 45%), 1fr));
  gap: 0.6rem;
}

/* A tile is the card itself: no background, border, or shadow behind
   the image, so nothing shows at the transparent card corners or at the
   transparent edges of a gigantic tile. The radius is the card corner:
   4.5% of the width (about 13.5 px at 300 px), so it scales with the
   size slider. The focus outline follows the radius. */
.tile {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  border-radius: 4.5% / 3.2%;
  aspect-ratio: 300 / 420;
  overflow: hidden;
}

/* A tile without an image shows its title on a card-shaped box. */
.tile:has(.noimage) {
  background: var(--card);
}

.tile:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.tile img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.noimage {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0.5rem;
  color: var(--muted);
}

/* The sentinel covers the last two viewports of the grid, so the next
   batch loads before the user reaches the end. */
.sentinel {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: min(200vh, 100%);
  pointer-events: none;
}

.zoom {
  position: fixed;
  inset: var(--top-h, 0px) 0 0 0;
  background: rgb(0 0 0 / 80%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  z-index: 10;
}

/* An open card view or syntax page holds the page still: a drag on the
   backdrop does not scroll the cards under it. */
html:has(.zoom:not([hidden])),
html:has(.syntax-modal:not([hidden])) {
  overflow: hidden;
}

/* On a touch screen, overflow: hidden on the page can stop a one-finger pan
   of a pinch-zoomed page. There the card view holds the page by itself: it
   always scrolls by at least 1px (the ::after spacer), and the overscroll
   stays in it, so a drag does not move the cards under it. */
@media (pointer: coarse) {
  html:has(.zoom:not([hidden])),
  html:has(.syntax-modal:not([hidden])) {
    overflow: visible;
  }

  .zoom {
    overscroll-behavior: contain;
  }

  .zoom::after {
    content: "";
    flex: none;
    width: 0;
    height: calc(100% + 1px);
  }
}

.zoom[hidden] {
  display: none;
}

.zoom-card {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  max-width: min(960px, 100%);
  max-height: 100%;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  overflow-y: auto;
}

.zoom-image {
  flex: 0 1 380px;
  min-width: 0;
}

.zoom-image img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 80vh;
  object-fit: contain;
  /* The card corner, as on the tiles. */
  border-radius: 4.5% / 3.2%;
}

.zoom-info {
  position: relative;
  flex: 1 1 320px;
  min-width: 0;
}

.zoom-info h2 {
  font-family: "TeutonFett", sans-serif;
  padding-right: 2.5rem;
  margin-bottom: 0.5rem;
}

.zoom-info h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0.75rem 0 0.25rem;
}

.zoom-close {
  position: absolute;
  top: 0;
  right: 0;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  padding: 0;
  line-height: 0;
  border-radius: 50%;
  border: 1px solid var(--muted);
  background: var(--card);
  color: var(--on-surface);
  font-size: 1.2rem;
  cursor: pointer;
}

.zoom dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.15rem 0.75rem;
}

.zoom dt {
  color: var(--muted);
}

.zoom-text {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--card);
}

.zoom-text p + p {
  margin-top: 0.35rem;
}

.printings {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.printing {
  position: relative;
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--muted);
  background: var(--card);
  color: var(--on-surface);
  cursor: pointer;
}

.printing.active {
  border-color: var(--primary);
}

.flavor {
  margin-top: 0.5rem;
  font-style: italic;
  color: var(--muted);
}

.flavor:empty,
.flavor[hidden] {
  display: none;
}

/* Card names in the card text and the flavor text open that card. */
.mention {
  color: var(--primary);
  text-decoration: underline dotted;
  text-underline-offset: 0.2em;
}

/* The threads of related cards. */
.related h3 {
  margin-top: 1rem;
}

.related ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
}

.related-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  width: 76px;
  font-size: 0.75rem;
  text-align: center;
  color: var(--on-surface);
  text-decoration: none;
}

.related-card img {
  width: 60px;
  height: auto;
  border-radius: 4.5% / 3.2%;
}

.related-card:hover span {
  color: var(--primary);
}

/* Syntax page */

.syntax {
  max-width: 820px;
}

.syntax h1,
.syntax h2 {
  font-family: "TeutonFett", serif;
  color: var(--primary);
  margin: 1rem 0 0.5rem;
}

.syntax table {
  border-collapse: collapse;
  width: 100%;
}

.syntax td,
.syntax th {
  text-align: left;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--card);
  vertical-align: top;
}

.foot {
  padding: 1rem 16px;
  color: var(--muted);
  font-size: 0.8rem;
}

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

  /* The size slider sets the number of columns (search.js). */
  .grid {
    grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
  }

  .query {
    flex-basis: 100%;
    order: 3;
  }

  .brand {
    margin-right: auto;
  }

  /* The count and the slider sit in one row above the facets, and the
     facets scroll sideways below them. */
  .facet-list {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
  }

  .facets .summary {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
  }

  .facets .summary .size {
    flex: 1;
  }

}

/* The autocomplete list of the search bar. */
.ac {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: min(60vh, 26rem);
  overflow-y: auto;
  list-style: none;
  padding: 0.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--muted);
  background: var(--card);
  box-shadow: 0 6px 18px rgb(0 0 0 / 40%);
}

.ac[hidden] {
  display: none;
}

.ac li {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.ac-text {
  flex: none;
  font-family: ui-monospace, Menlo, monospace;
}

.ac-note {
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ac li[aria-selected="true"],
.ac li:hover {
  background: var(--surface);
  color: var(--primary);
}

.banner {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--primary);
}

/* An inset ring stays inside the row, so it does not cover the rows next
   to it. */
/* A value that the query filters on is clearly marked: a tinted fill, a
   ring, and white text. A click removes the filter. */
.facet a.active {
  background: color-mix(in srgb, var(--primary) 28%, transparent);
  box-shadow: inset 0 0 0 2px var(--primary);
}

.facet a.active .bar {
  background: color-mix(in srgb, var(--primary) 30%, var(--card));
}

.facet a.active .label,
.facet a.active .n {
  color: var(--on-surface);
  font-weight: 700;
}


/* An excluded value (a negated filter) has a dashed ring and a struck
   label. A click removes the negation. */
.facet a.excluded {
  box-shadow: inset 0 0 0 1px var(--muted);
  outline: 1px dashed var(--accent, var(--primary));
  outline-offset: -1px;
}

.facet a.excluded .label {
  color: var(--muted);
  text-decoration: line-through;
}

.facet .more summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.1rem 0.3rem;
}

.icon svg {
  display: block;
}

@media (max-width: 720px) {
  .zoom {
    align-items: flex-start;
    padding: 8px;
  }

  .zoom-card {
    flex-direction: column;
    align-items: stretch;
    /* One scroll box on a phone: the backdrop. A second scroll box in it
       takes a one-finger drag after a pinch zoom, so the page could not
       pan. */
    max-height: none;
    overflow: visible;
  }

  .zoom-image {
    flex-basis: auto;
    align-self: center;
    width: min(300px, 100%);
  }
}

/* The results change as the user types, so a narrow screen does not need the Search button. */
@media (max-width: 720px) {
  .query button.primary {
    display: none;
  }
}

/* Icons. An SVG icon is a mask in the text color, so it follows the theme.
   A webp icon (houses, aember) has its own colors. */
.ico {
  display: inline-block;
  flex: none;
  width: 1.1em;
  height: 1.1em;
  vertical-align: -0.18em;
  object-fit: contain;
}

.ico.mask {
  background-color: currentColor;
  -webkit-mask: var(--ico) center / contain no-repeat;
  mask: var(--ico) center / contain no-repeat;
}

.zoom dd .ico,
.printing .ico {
  margin-right: 0.3em;
}


/* The query syntax modal. It uses the card view's backdrop and box. */
.syntax-modal {
  align-items: flex-start;
  z-index: 11;
}

.syntax-card {
  position: relative;
  display: block;
  width: min(820px, 100%);
  padding: 1rem 1.25rem 1.5rem;
}

.syntax-card .zoom-close {
  top: 0.75rem;
  right: 0.75rem;
}

.syntax-card .syntax h1 {
  margin-top: 0;
  padding-right: 2.5rem;
}

@media (max-width: 720px) {
  .syntax-card {
    padding: 0.75rem;
  }

  .syntax-card table {
    font-size: 0.85rem;
  }
}

/* The artist of the shown printing, under the sets. */
.artist {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
}

.artist-label {
  margin-right: 0.5rem;
  color: var(--muted);
}

/* A value in the card view is a filter button: it reads as text, and a
   hover or a mark shows that a click filters on it. */
.zoom dd.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.3rem;
}

.cv-filter {
  display: inline-flex;
  align-items: center;
  padding: 0 0.35rem;
  margin: 0 -0.1rem;
  border: 1px solid transparent;
  border-radius: 0.35rem;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-touch-callout: none;
  user-select: none;
}

.cv-filter:focus-visible {
  border-color: var(--muted);
}

@media (hover: hover) {
  .cv-filter:hover {
    border-color: var(--muted);
  }

  .set-filter:hover {
    border-color: var(--muted);
    color: var(--on-surface);
  }
}

.cv-filter.active,
.set-filter.active {
  border-color: var(--primary);
  color: var(--primary);
}

.cv-filter.excluded,
.set-filter.excluded {
  border: 1px dashed var(--muted);
  color: var(--muted);
  text-decoration: line-through;
}

.printings li {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}

.set-filter {
  display: inline-grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  line-height: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  -webkit-touch-callout: none;
}

.set-filter:focus-visible {
  border-color: var(--muted);
  color: var(--on-surface);
}

/* On a phone each facet column is as wide as its longest label, so a long
   label such as Unfathomable stays on one line with a gap before its
   count. The facet list scrolls sideways. */
@media (max-width: 720px) {
  .facet {
    flex: none;
    width: max-content;
    min-width: 150px;
  }

  .facet a {
    gap: 1rem;
  }
}

/* The notes of a card (card.Note) are plain text, one on each line. */
.zoom dd.notes {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

/* A set chip whose printing has its own card text. */
.text-changed {
  display: inline-flex;
  color: var(--primary);
}

/* The side-by-side view of every printing. */
.all-sets-toggle {
  margin-top: 0.5rem;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--on-surface);
  cursor: pointer;
}

.all-sets-toggle[aria-expanded="true"] {
  border-color: var(--primary);
}

.all-sets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.all-sets[hidden] {
  display: none;
}

.all-sets-print {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
}

.all-sets-print img {
  width: 100%;
  height: auto;
  border-radius: 4.5% / 3.2%;
}

.all-sets-print figcaption {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  font-size: 0.85rem;
}

.all-sets-text {
  font-size: 0.85rem;
}

.all-sets-text p + p {
  margin-top: 0.3rem;
}

mark.diff {
  background: rgb(245 166 35 / 30%);
  color: inherit;
  border-radius: 3px;
  padding: 0 0.1rem;
}

/* The funnel is a block, so no text baseline moves it off the center. */
.set-filter svg {
  display: block;
}

/* The feedback form. It uses the card view's backdrop and box. */
.feedback-modal {
  z-index: 11;
}

.feedback-card {
  position: relative;
  flex-direction: column;
  align-items: stretch;
  gap: 0.6rem;
  width: min(520px, 100%);
}

.feedback-card h2 {
  margin: 0;
}

.feedback-help {
  color: var(--muted);
  font-size: 0.9rem;
}

.feedback-card textarea {
  width: 100%;
  resize: vertical;
  padding: 0.5rem;
  border: 1px solid var(--muted);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--on-surface);
  font: inherit;
}

.feedback-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

#feedback-status {
  color: var(--muted);
  font-size: 0.9rem;
}

/* The mark on a set chip whose printing shows another printing's art. */
.maverick-note {
  margin-left: 0.2rem;
  padding: 0 0.25rem;
  border-radius: 0.25rem;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--muted);
  border: 1px solid currentColor;
}
