/*
 * The want list, as a pick list for a card shop.
 *
 * Read standing up, in bad light, with a binder in the other hand. So: ink on
 * paper, large type, everything tappable at least 48px, and every line led by
 * a tab like the divider in a shop's box — the set code and the collector
 * number, which is what you look for. Card names in a bookish serif, as the
 * game prints them; codes, numbers and prices in monospace, so they line up
 * and are scanned rather than read. Every mark is a word; colour only helps.
 * System fonts only: the page must open with no network.
 */

:root {
  color-scheme: light dark;

  --paper: #f3eee3;
  --card: #fbf8f1;
  --ink: #1b1915;
  --ink-soft: #4f483d;   /* 7.6:1 on paper */
  --rule: #d5cbb6;
  --tab: #1b1915;
  --tab-ink: #f3eee3;
  --focus: #1f4fbf;

  --found: #2c5b36;      /* 7.0:1 on card */
  --upgrade: #7a4d00;    /* 6.6:1 */
  --grade: #3a4f7a;      /* 7.4:1 */
  --over: #9a2618;       /* 6.9:1 */

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Charter, "Bitstream Charter", Georgia, serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Cantarell, "Noto Sans", sans-serif;

  --gap: 16px;
  --radius: 4px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15130f;
    --card: #1e1b16;
    --ink: #f0e9db;
    --ink-soft: #c4baa8;  /* 9.1:1 on card */
    --rule: #3a342a;
    --tab: #f0e9db;
    --tab-ink: #15130f;
    --focus: #8fb0ff;

    --found: #8fd19c;
    --upgrade: #f0c064;
    --grade: #a9c1f5;
    --over: #ff9b8a;
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.4 var(--sans);
}

.page {
  max-width: 44rem;
  margin: 0 auto;
  padding: 0 var(--gap) 112px; /* room for the undo bar over the last line */
  padding-left: max(var(--gap), env(safe-area-inset-left));
  padding-right: max(var(--gap), env(safe-area-inset-right));
}

h1, h2 { margin: 0; font-weight: 700; }

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

button {
  min-height: 48px;
  padding: 0 18px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font: 600 16px/1 var(--sans);
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { opacity: 0.55; cursor: default; }

button:active:not(:disabled) { transform: translateY(1px); }

/* --- The bar: title, how fresh the list is, and Sync ------------------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: calc(var(--gap) * 0.75) 0;
  padding-top: max(calc(var(--gap) * 0.75), env(safe-area-inset-top));
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
}

.heading { flex: 1; min-width: 0; }

.bar h1 {
  font: 700 26px/1.1 var(--serif);
  letter-spacing: -0.01em;
}

.status {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
}

.sync { background: var(--ink); color: var(--paper); }

/* --- Filters: toggles that say whether they are on, not only show it --- */

/* Which list: the wants, or one goal. The name and what is left to find
 * are in each option, so the closed picker says both. */
.group {
  display: grid;
  gap: 6px;
  margin-top: var(--gap);
}

.filters {
  display: flex;
  gap: 10px;
  margin: var(--gap) 0 10px;
}

.filter {
  flex: 1;
  border-width: 2px;
  font-weight: 600;
}

.filter::before {
  content: "";
  display: inline-block;
  width: 1.1em;
  margin-right: 6px;
  text-align: center;
}

.filter[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.filter[aria-pressed="true"]::before { content: "✓"; }

.summary {
  margin: 14px 0 10px;
  font: 600 18px/1.3 var(--sans);
}

.empty {
  margin: 32px 0;
  color: var(--ink-soft);
  font: italic 20px/1.4 var(--serif);
  text-align: center;
}

/* --- The lines: a tab, then the card ---------------------------------- */

.lines {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.line { animation: arrive 180ms ease-out both; }

/* A whole line is one target: it opens the card's sheet, where the rest of
 * what is known about the want is, and what can be done to it. */
.open {
  display: grid;
  grid-template-columns: 4rem minmax(0, 1fr) auto;
  align-items: stretch;
  width: 100%;
  min-height: 72px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  text-align: left;
  overflow: hidden;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 2px 14px;
  background: var(--tab);
  color: var(--tab-ink);
  font-family: var(--mono);
  text-align: center;
  /* The notch of a box divider, at the foot. */
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 12px), 88% calc(100% - 7px), 88% 100%, 0 100%);
}

.code {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.number {
  font-size: 14px;
  opacity: 0.92;
}

.body {
  display: grid;
  align-content: center;
  gap: 3px;
  min-width: 0;
  padding: 8px 10px;
}

/* Two lines at most: a long double-faced name is cut, and said whole in
 * the sheet's title. */
.name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  font: 700 18px/1.2 var(--serif);
  overflow-wrap: anywhere;
}

.facts {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  font: 600 14px/1.3 var(--mono);
}

.count { white-space: nowrap; }

.finish { color: var(--ink-soft); font-weight: 400; }

.facts .price { margin-left: auto; }

.price {
  color: var(--ink);
  font: 600 14px/1.3 var(--mono);
  white-space: nowrap;
}

/* The card as it looks in the box, whole and as Scryfall draws it: never
 * cropped, blurred or recoloured. */
.thumb {
  display: block;
  align-self: center;
  width: 44px;
  height: auto;
  margin: 6px 8px 6px 0;
  aspect-ratio: 63 / 88;
  border-radius: 2px;
  background: var(--paper);
}

.marks {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 1px;
}

.mark {
  padding: 1px 5px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  font: 700 11px/1.3 var(--sans);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.mark.found { color: var(--found); }
.mark.upgrade { color: var(--upgrade); }
.mark.unknown-grade { color: var(--grade); }
.mark.unknown { color: var(--ink-soft); border-style: dashed; }

/* What a want says besides the card, in its sheet. */
.says {
  margin: 12px 0 0;
  color: var(--ink-soft);
  font: italic 16px/1.35 var(--serif);
  text-align: center;
}

.large-picture { margin: 16px 0 0; text-align: center; }

.large-picture img {
  display: block;
  width: min(100%, 26rem);
  height: auto;
  margin: 0 auto;
  aspect-ratio: 63 / 88;
  border-radius: 4.75% / 3.5%;
  background: var(--card);
}

.large-picture figcaption {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--ink-soft);
}

/* Every printing of a want, in a row to swipe along. The one shown is
 * ticked and edged in ink, not only shaded. With no signal a printing is
 * its set, number and price, and no picture. */
.printings { margin-top: 20px; }

.printings ul {
  display: flex;
  gap: 10px;
  margin: 8px 0 0;
  padding: 0 0 10px;
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x proximity;
}

.printings li { flex: none; scroll-snap-align: start; }

.printing {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  width: 96px;
  padding: 6px 4px 8px;
  border-color: var(--rule);
  font: 600 13px/1.25 var(--mono);
}

.printing[aria-pressed="true"] { border-color: var(--ink); background: var(--card); }

.printing[aria-pressed="true"] .code::before { content: "✓ "; }

.printing img {
  display: block;
  width: 64px;
  height: auto;
  aspect-ratio: 63 / 88;
  border-radius: 3px;
  background: var(--card);
}

.printing .code { font-size: 13px; letter-spacing: 0; }

.printing .price { font-weight: 400; color: var(--ink-soft); }

/* --- Pairing ----------------------------------------------------------- */

.pair {
  padding-top: max(40px, env(safe-area-inset-top));
}

.pair h1 {
  font: 700 32px/1.1 var(--serif);
  margin-bottom: 12px;
}

.pair p { margin: 0 0 var(--gap); }

.pair form { display: grid; gap: 10px; margin-top: 24px; }

.pair label { font-weight: 700; }

.pair input {
  min-height: 56px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: 600 24px/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.pair input::placeholder { color: var(--ink-soft); opacity: 0.6; }

.hint { color: var(--ink-soft); font-size: 15px; }

.problem { color: var(--over); font-weight: 600; min-height: 1.4em; }

.pair button[type="submit"] {
  min-height: 56px;
  background: var(--ink);
  color: var(--paper);
  font-size: 18px;
}

.loading {
  margin-top: 40vh;
  text-align: center;
  font: 32px var(--serif);
  color: var(--ink-soft);
}

/* --- Changing the list ------------------------------------------------- */

.add { padding: 0 16px; }

button.quiet { border-color: var(--rule); }

.mark.pending { color: var(--ink-soft); border-style: dotted; }



/* The last change, and its undo, held at the foot of the page. */
.offer {
  position: fixed;
  left: 0;
  right: 0;
  margin: 0 auto;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(40rem, calc(100% - 32px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  font-weight: 600;
  animation: arrive 160ms ease-out both;
}

.offer span { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.offer button { border-color: var(--paper); color: var(--paper); }

/* A sheet rises from the foot on a phone, and sits in the middle on a desk. */
dialog.sheet {
  width: min(40rem, 100%);
  max-width: 100%;
  max-height: calc(100% - 24px);
  margin: auto auto 0;
  padding: 0 var(--gap) max(var(--gap), env(safe-area-inset-bottom));
  border: 0;
  border-top: 3px solid var(--ink);
  border-radius: 8px 8px 0 0;
  background: var(--paper);
  color: var(--ink);
  overflow-y: auto;
}

/* The search hangs from the top instead, so its field stays put while the
 * results under it come and go, and the keyboard never covers it. */
dialog.sheet.at-top {
  margin: 0 auto auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: var(--gap);
  border-top: 0;
  border-bottom: 3px solid var(--ink);
  border-radius: 0 0 8px 8px;
}

@media (min-width: 44rem) {
  dialog.sheet { margin: auto; border-radius: 8px; border: 2px solid var(--ink); }
  dialog.sheet.at-top { margin: 10vh auto auto; }
}

dialog.sheet::backdrop { background: rgb(0 0 0 / 0.45); }

dialog.sheet > header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

dialog.sheet h2 { font: 700 22px/1.2 var(--serif); }

.search {
  width: 100%;
  min-height: 56px;
  margin-top: 14px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: 20px/1 var(--serif);
}

.results { list-style: none; margin: 10px 0 0; padding: 0; }

.result {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  text-align: left;
  font: 600 19px/1.2 var(--serif);
}

.form { display: grid; gap: 16px; padding-top: 14px; }

.picked { margin: 0; font: 700 24px/1.2 var(--serif); }

.field { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }

.label { font-weight: 700; font-size: 15px; }

.field input,
.field select,
.group select {
  width: 100%;
  max-width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: 17px var(--sans);
}

.group select { font-weight: 600; }

.stepper { display: flex; align-items: center; gap: 12px; }

.stepper button { width: 56px; padding: 0; font-size: 24px; }

.stepper output { min-width: 3ch; text-align: center; font: 700 24px/1 var(--mono); }

.choices { display: grid; gap: 6px; }

.choices.row { grid-auto-flow: column; justify-content: start; gap: 16px; }

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  min-width: 48px;
  font: 16px var(--mono);
}

.choice input { flex: none; width: 22px; height: 22px; accent-color: var(--ink); }

.buttons { display: flex; gap: 10px; justify-content: flex-end; padding-bottom: 6px; }

.buttons .primary { flex: 1; background: var(--ink); color: var(--paper); }

.large-picture ~ .buttons { margin-top: 14px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@keyframes arrive {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .line { animation: none; }
  button:active:not(:disabled) { transform: none; }
}
