/* Layout after Scryfall's search (dark header bar, toolbar, plain card grid,
 * card page with image + text box). Own colours: stone neutrals, amber accent. */
:root {
  --bg: #ffffff; --bg-soft: #f6f5f4; --bg-strong: #ecebe9;
  --ink: #1c1917; --ink-soft: #44403c; --muted: #6f6a66; --faint: #a8a29e;
  --line: #e2e0de; --line-strong: #cfccc9;
  --head: #23212b; --head-ink: #f5f5f4; --head-field: #34313f; --head-muted: #b7b2bf;
  --accent: #b45309; --accent-strong: #d97706; --on-accent: #ffffff;
  --tint: rgb(217 119 6 / .10);
  --legal: #6f8f5f; --notlegal: #b5b0ab;
  --card-radius: 4.75% / 3.5%;
  --sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: ui-serif, Georgia, Cambria, 'Times New Roman', serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #141312; --bg-soft: #1c1a19; --bg-strong: #292624;
    --ink: #f2f0ee; --ink-soft: #d6d3d1; --muted: #a8a29e; --faint: #6b6560;
    --line: #2e2b29; --line-strong: #45403c;
    --head: #0f0e14; --head-field: #24212d;
    --accent: #f59e0b; --accent-strong: #f59e0b; --on-accent: #1c1917;
    --tint: rgb(245 158 11 / .14);
    --legal: #5f7f50; --notlegal: #57524e;
    color-scheme: dark;
  }
}
[data-theme='dark'] {
  --bg: #141312; --bg-soft: #1c1a19; --bg-strong: #292624;
  --ink: #f2f0ee; --ink-soft: #d6d3d1; --muted: #a8a29e; --faint: #6b6560;
  --line: #2e2b29; --line-strong: #45403c;
  --head: #0f0e14; --head-field: #24212d;
  --accent: #f59e0b; --accent-strong: #f59e0b; --on-accent: #1c1917;
  --tint: rgb(245 158 11 / .14);
  --legal: #5f7f50; --notlegal: #57524e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; width: 100%; }

/* ---------------------------------------------------------- header */
.topbar { background: var(--head); color: var(--head-ink); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--head-ink); font-weight: 600; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; color: var(--accent-strong); }
.top-search { flex: 1; position: relative; min-width: 0; }
.top-search input[type=search] { width: 100%; background: var(--head-field); border: 1px solid transparent; border-radius: 6px;
  color: var(--head-ink); padding: 8px 12px 8px 36px; font-size: 15px; }
.top-search input[type=search]::placeholder { color: var(--head-muted); }
.top-search input[type=search]:focus { outline: none; border-color: var(--accent-strong); background: #2c2937; }
.magnifier { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--head-muted); pointer-events: none; }
.top-nav { display: flex; gap: 18px; white-space: nowrap; }
.top-nav a { color: var(--head-ink); font-size: 14px; }
.top-nav a[aria-current='page'] { color: var(--accent-strong); }
@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px 12px; }
  .brand span { display: none; }
  .top-search { order: 2; flex-basis: calc(100% - 44px); }
  .top-nav { order: 3; width: 100%; justify-content: space-between; gap: 8px; }
}
.topbar.no-search .top-search { visibility: hidden; }

.app { flex: 1; }
.loading { color: var(--muted); text-align: center; padding: 64px 16px; }
.error-text { color: #b91c1c; }

/* ---------------------------------------------------------- home */
.home { max-width: 760px; margin: 0 auto; padding: 12vh 16px 64px; text-align: center; }
.home h1 { font-family: var(--serif); font-size: clamp(2rem, 5vw, 2.8rem); margin: 0 0 .3rem; letter-spacing: -0.01em; }
.home .tagline { color: var(--muted); margin: 0 0 1.6rem; }
.home-search { display: flex; flex-direction: column; gap: 10px; }
.home-search input[type=search] { width: 100%; font-size: 18px; padding: 14px 16px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); }
.home-search input[type=search]:focus { outline: none; border-color: var(--accent-strong); box-shadow: 0 0 0 3px var(--tint); }
.home-search .row { display: flex; gap: 10px; }
.home-search select { flex: 1; min-width: 0; }
.home-links { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; margin-top: 1.4rem; font-size: 14px; }
.examples { margin-top: 2.2rem; color: var(--muted); font-size: 14px; }
.examples a { font-family: var(--mono); font-size: 13px; margin: 0 .4rem; white-space: nowrap; }

/* ---------------------------------------------------------- controls */
select, input[type=text], input[type=number], input[type=search], input:not([type]) {
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 8px; min-width: 0; }
select { padding-right: 26px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--ink-soft); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; font-size: 14px; }
.btn:hover:not(:disabled) { background: var(--bg-soft); color: var(--ink); text-decoration: none; }
.btn:disabled { color: var(--faint); cursor: default; }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent-strong); color: var(--on-accent); }

/* ---------------------------------------------------------- toolbar */
.toolbar { background: var(--bg-soft); border-bottom: 1px solid var(--line); }
.toolbar-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.toolbar label { display: contents; }
.toolbar .word { color: var(--muted); font-size: 14px; }
.toolbar select { max-width: 260px; }
.toolbar #t-sub { max-width: 300px; font-weight: 600; }
.pager { margin-left: auto; display: flex; gap: 6px; }
.pager .btn { padding: 6px 10px; }
@media (max-width: 760px) {
  .pager { margin-left: 0; width: 100%; justify-content: space-between; }
  .toolbar select { max-width: 46vw; }
  .toolbar #t-sub { max-width: 100%; width: 100%; }
}
.search-info { max-width: 1280px; margin: 0 auto; padding: 12px 16px 4px; color: var(--ink-soft); font-size: 14px; }
.search-info strong { color: var(--ink); }
.search-info .note { color: #b45309; display: block; margin-top: 2px; }

/* ---------------------------------------------------------- results: images */
.results { max-width: 1280px; margin: 0 auto; padding: 12px 16px 24px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 224px), 1fr)); gap: 16px 12px; }
@media (max-width: 480px) { .grid { gap: 10px 8px; } }
.tile { position: relative; display: block; border-radius: var(--card-radius); }
.tile img, .card-image { display: block; width: 100%; height: auto; aspect-ratio: 488 / 680; border-radius: var(--card-radius);
  background: var(--bg-strong); object-fit: cover; }
.tile:hover img { box-shadow: 0 0 0 2px var(--accent-strong); }
.tile .fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 12px;
  text-align: center; color: var(--muted); font-size: 13px; pointer-events: none; }
.tile .fallback[hidden] { display: none; }
.flip { position: absolute; top: 34%; right: 10%; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgb(255 255 255 / .78); color: #1c1917; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgb(0 0 0 / .35); }
.flip:hover { background: #fff; }
.flip svg { width: 22px; height: 22px; }

/* checklist */
.checklist { width: 100%; border-collapse: collapse; font-size: 14px; }
.checklist th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--line-strong); padding: 6px 8px; white-space: nowrap; }
.checklist td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: middle; }
.checklist tr:hover td { background: var(--bg-soft); }
.checklist .set-cell { white-space: nowrap; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.seticon { width: 16px; height: 16px; vertical-align: -3px; margin-right: 4px; flex: 0 0 auto; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .seticon { filter: invert(1); } }
[data-theme='dark'] .seticon { filter: invert(1); }
@media (max-width: 760px) { .checklist .hide-mobile { display: none; } }

/* text only + full */
.text-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 12px; }
.text-card { border: 1px solid var(--line-strong); border-radius: 8px; padding: 0; background: var(--bg); overflow: hidden; }
.full { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: 20px; padding: 16px 0; border-bottom: 1px solid var(--line); }
@media (max-width: 600px) { .full { grid-template-columns: 1fr; } .full .tile { max-width: 260px; } }

/* card text box (shared by text view, full view and card page) */
.textbox { border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); }
.textbox .section { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.textbox .section:last-child { border-bottom: 0; }
.textbox .title-line { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; font-size: 17px; }
.textbox .title-line a, .textbox .title-line span.name { color: var(--ink); font-weight: 600; }
.textbox .type-line { font-size: 15px; }
.textbox .oracle p { margin: 0 0 .55em; }
.textbox .oracle p:last-child { margin-bottom: 0; }
.textbox .flavor { font-family: var(--serif); font-style: italic; color: var(--ink-soft); margin-top: .6em; }
.textbox .pt { font-weight: 600; }
.textbox .small { font-size: 13px; color: var(--muted); }
.ms { width: 1em; height: 1em; vertical-align: -0.12em; margin: 0 1px; }
.title-line .ms { width: 17px; height: 17px; vertical-align: -3px; }

/* ---------------------------------------------------------- card page */
.card-page { max-width: 1280px; margin: 0 auto; padding: 20px 16px 40px; display: grid;
  grid-template-columns: minmax(240px, 336px) minmax(0, 1fr) minmax(240px, 300px); gap: 20px; align-items: start; }
@media (max-width: 1000px) { .card-page { grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); } .card-page .side-col { grid-column: 1 / -1; } }
@media (max-width: 640px) { .card-page { grid-template-columns: 1fr; } .card-page .image-col { max-width: 336px; margin: 0 auto; width: 100%; } }
.image-col .btn { margin-top: 10px; width: 100%; }
.legal { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 6px 10px; }
.legal div { display: flex; align-items: center; gap: 6px; font-size: 12.5px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legal .badge { display: inline-block; width: 60px; flex: 0 0 60px; text-align: center; font-size: 8.5px; white-space: nowrap; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: #fff; background: var(--notlegal); border-radius: 3px; padding: 3px 0; }
.legal .badge.yes { background: var(--legal); }
.box { border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; margin-bottom: 16px; background: var(--bg); }
.box h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--head-ink); background: var(--head); padding: 8px 12px; }
.box ul { list-style: none; margin: 0; padding: 0; }
.box li { border-top: 1px solid var(--line); padding: 7px 12px; font-size: 14px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.box li:first-child { border-top: 0; }
.box li.active { background: var(--tint); }
.box .more-link { display: block; padding: 7px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.source { font-size: 11px; border: 1px solid var(--line-strong); border-radius: 999px; padding: 0 7px; color: var(--muted); white-space: nowrap; }
.prints li { justify-content: space-between; flex-wrap: nowrap; }
.prints li a { min-width: 0; }
.prints .year { color: var(--muted); font-size: 12px; font-family: var(--mono); }

/* ---------------------------------------------------------- advanced */
.page { max-width: 1000px; margin: 0 auto; padding: 20px 16px 48px; }
.page h1 { font-family: var(--serif); font-size: 1.8rem; margin: .2rem 0 1rem; }
.adv .adv-row { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 8px 20px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.adv .adv-row > .label { font-weight: 600; padding-top: 6px; }
.adv .adv-row .help { display: block; color: var(--muted); font-size: 12.5px; font-style: italic; margin-top: 6px; max-width: 560px; }
.adv input[type=text], .adv input:not([type]) { width: 100%; max-width: 420px; padding: 8px 10px; }
.adv select { padding: 7px 26px 7px 8px; }
.adv .checks { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.adv .checks label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.adv .checks .ms { width: 18px; height: 18px; }
.adv .stat-row { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.adv .stat-row input { width: 90px; }
.adv .actions { position: sticky; bottom: 0; background: var(--bg); padding: 14px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; }
input[type=checkbox] { accent-color: var(--accent-strong); width: 16px; height: 16px; }
@media (max-width: 640px) { .adv .adv-row { grid-template-columns: 1fr; gap: 6px; } .adv .adv-row > .label { padding-top: 0; } }

/* syntax + planes */
.syntax h2 { font-family: var(--serif); font-size: 1.25rem; margin: 1.6rem 0 .4rem; }
.syntax table { width: 100%; border-collapse: collapse; font-size: 14px; }
.syntax td { border-top: 1px solid var(--line); padding: 7px 8px; vertical-align: top; }
.syntax td:first-child { width: 46%; }
.syntax code, .search-info code { font-family: var(--mono); font-size: 13px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
@media (max-width: 640px) { .syntax td { display: block; width: 100% !important; } .syntax td + td { border-top: 0; padding-top: 0; } }
.plane-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 8px 24px; }
.plane-grid a { display: flex; justify-content: space-between; gap: 12px; padding: 8px 2px; border-bottom: 1px solid var(--line); color: var(--ink); }
.plane-grid a:hover { color: var(--accent); text-decoration: none; }
.plane-grid .count { color: var(--muted); font-family: var(--mono); font-size: 13px; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

.footer { border-top: 1px solid var(--line); background: var(--bg-soft); color: var(--muted); font-size: 13px; margin-top: 24px; }
.footer-inner { max-width: 1280px; margin: 0 auto; padding: 16px; }
.footer p { margin: 0 0 6px; }
