/* MTG Creatures: shared tokens, base elements, reusable controls, and the browse layout. */

:root {
  color-scheme: dark;
  --bg: #090d16;
  --surface: #0d1117;
  --surface-2: #141b28;
  --border: #283044;
  --control-border: #6b7690;   /* >= 3:1 against --surface for input edges */
  --text: #c9d3e8;
  --text-dim: #95a0b8;         /* 7:1 on --surface (old #48536a failed) */
  --accent: #a78bfa;           /* text, rings and underlines */
  --accent-strong: #7c4dea;    /* filled buttons, with --on-accent text */
  --on-accent: #ffffff;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --danger: #ff8a80;
  --focus: #ffd166;
  --parchment: #fdf1dc;
  --parchment-ink: #4e3c1e;
  --font-ui: 'Open Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-serif: Georgia, 'Times New Roman', serif;
  --font-head: 'Barlow Semi Condensed', 'Arial Narrow', 'Roboto Condensed', system-ui, sans-serif;
  --font-display: Cinzel, 'Trajan Pro', Georgia, 'Times New Roman', serif;
  --radius: 6px;
  --sidebar-w: 340px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f4f8;
    --surface: #ffffff;
    --surface-2: #eceef4;
    --border: #d3d8e3;
    --control-border: #6f7890;
    --text: #1b2333;
    --text-dim: #535d73;
    --accent: #5b2fd0;
    --accent-strong: #5b2fd0;
    --accent-soft: rgba(91, 47, 208, 0.1);
    --danger: #b3261e;
    --focus: #8a4b00;
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }
h1, h2, h3, .btn { font-family: var(--font-head); letter-spacing: 0.01em; }
.btn { font-size: 1rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1:focus, h2:focus { outline: none; }               /* programmatic focus targets */
h1:focus-visible, h2:focus-visible { outline: 3px solid var(--focus); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

.icon { flex: none; vertical-align: -0.15em; }

/* ---- Reusable pieces ---------------------------------------------------- */

.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 2.5rem; padding: 0.4rem 0.8rem;
  font: inherit; font-size: 0.9rem; font-weight: 600; line-height: 1.2;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--control-border); border-radius: var(--radius);
  text-decoration: none; cursor: pointer;
  transition: background-color 0.15s;
}
.btn:hover { background: var(--accent-soft); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); filter: brightness(1.12); }

.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > label, .field > legend { font-size: 0.8rem; color: var(--text-dim); padding: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.field-row-cr { grid-template-columns: 5.5rem 5.5rem minmax(0, 1fr); }
.field-end { align-items: flex-end; }

.input {
  width: 100%; min-height: 2.5rem; padding: 0.4rem 0.6rem;
  font: inherit; font-size: 1rem;      /* 16px: no zoom-on-focus on iOS */
  color: var(--text); background: var(--bg);
  border: 1px solid var(--control-border); border-radius: var(--radius);
}
.input::placeholder { color: var(--text-dim); opacity: 1; }

.status { margin: 0; font-size: 0.85rem; color: var(--text-dim); min-height: 0; }
.status:empty { display: none; }
.error { color: var(--danger); }

.tag {
  display: inline-block; padding: 0.05rem 0.45rem; border-radius: 4px;
  font-size: 0.78rem; white-space: nowrap;
  color: var(--text); background: var(--accent-soft); border: 1px solid var(--border);
}

/* Colour pips (decorative dots; the accessible name lives on the wrapper). */
.pips { display: inline-flex; gap: 3px; vertical-align: middle; }
.pip { width: 0.7rem; height: 0.7rem; border-radius: 50%; border: 1px solid var(--text-dim); }
.pip-W { background: #f0f0e8; color: #2a2a2a; }
.pip-U { background: #1565c0; color: #fff; }
.pip-B { background: #1a1500; color: #d0d0d0; }
.pip-R { background: #c62828; color: #fff; }
.pip-G { background: #2e7d32; color: #fff; }
.pip-C { background: #b9c0cc; color: #1c2230; }

.mana-cost { display: inline-flex; gap: 2px; vertical-align: middle; }
.mana {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.35rem; height: 1.35rem; padding: 0 0.25rem; border-radius: 0.7rem;
  font-size: 0.72rem; font-weight: 800; line-height: 1;
  background: #cfcfcf; color: #1c1c1c; border: 1px solid rgba(0, 0, 0, 0.45);
}
.mana-W { background: #f0f0e8; color: #2a2a2a; }
.mana-U { background: #1565c0; color: #fff; }
.mana-B { background: #1a1500; color: #d0d0d0; border-color: #6b6350; }
.mana-R { background: #c62828; color: #fff; }
.mana-G { background: #2e7d32; color: #fff; }

.rarity-badge { padding: 0.1rem 0.55rem; border-radius: 4px; font-weight: 700; font-size: 0.8rem; text-transform: capitalize; background: #c8c8c8; color: #2a2a2a; }
.rarity-badge.uncommon { background: #6a9ab0; color: #04181f; }
.rarity-badge.rare { background: #c9a227; color: #1e1000; }
.rarity-badge.mythic { background: #b8460f; color: #fff; }

/* Card art: cropped to fit, never stretched, never overlaid. */
.art { margin: 0; }
.art img {
  display: block; width: 100%; height: auto; max-height: 340px;
  object-fit: cover; object-position: center 25%;
  border-radius: var(--radius); background: var(--surface-2);
}
.tactics { font-style: italic; border-left: 3px solid #7A200D; padding-left: 0.6em; }
.tactics strong { font-style: normal; font-variant: small-caps; color: #7A200D; }
.plane-line { margin: 0; font-size: 0.9rem; color: var(--text-dim); }
.credit { margin: 0.3rem 0 0; font-size: 0.8rem; color: var(--text-dim); }

.creature-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ---- Browse page layout ------------------------------------------------- */

.browse {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  align-items: start;
}

.sidebar {
  position: sticky; top: 0;
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.pane-title { margin: 0; padding: 0.7rem 0.8rem 0; font-size: 1.3rem; line-height: 1.3; }
.pane-intro { margin: 0; padding: 0.15rem 0.8rem 0; font-size: 0.85rem; color: var(--text-dim); }
.filter-n { color: var(--accent); font-weight: 700; }
.quick { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.empty-note .btn { margin-top: 0.6rem; }
.skeleton { color: var(--text-dim); }

.filters { flex: none; display: flex; flex-direction: column; gap: 0.6rem; padding: 0.6rem 0.8rem; max-height: 50%; overflow-y: auto; }
.filters details { display: flex; flex-direction: column; }
.filters .field, .filters details, .filters .quick { flex: none; }
.filters details > :not(summary) { margin-top: 0.6rem; }
.filters summary {
  cursor: pointer; font-size: 0.9rem; font-weight: 600; padding: 0.35rem 0.2rem;
  border-radius: var(--radius); color: var(--text);
}
.filters summary .icon { margin-right: 0.4rem; }

.color-btns { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.25rem 0.15rem; }
.color-btn {
  width: 2.1rem; height: 2.1rem; border-radius: 50%;
  border: 1px solid var(--text-dim);
  font: inherit; font-size: 0.8rem; font-weight: 800; cursor: pointer;
  transition: box-shadow 0.12s;
}
.color-btn[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 5px var(--accent);
}

.count { flex: none; padding: 0.4rem 0.8rem; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

.list-wrap { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.creature-list { list-style: none; margin: 0; padding: 0; }
.creature-list li { border-bottom: 1px solid var(--border); }

.row {
  display: block; padding: 0.5rem 0.8rem;
  color: var(--text); text-decoration: none;
  border-left: 3px solid transparent;
}
a.row:hover { background: var(--surface-2); }
a.row:focus-visible { outline-offset: -3px; }
a.row[aria-current="true"] { background: var(--accent-soft); border-left-color: var(--accent); }
.row-main { display: flex; align-items: baseline; gap: 0.5rem; }
.row { padding-left: 0.8rem; }
.row-name { flex: 1; min-width: 0; font-family: var(--font-display); font-size: 0.95rem; font-weight: 600; overflow-wrap: anywhere; }
.row-main .tag { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3.6rem; text-align: center; }
a.row:hover .row-name { text-decoration: underline; text-underline-offset: 3px; }
.row-sub { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--text-dim); }
.row-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-rarity { text-transform: capitalize; white-space: nowrap; }
.row-missing .row-name { color: var(--text-dim); font-weight: 400; }
.list-note { padding: 1.2rem 0.8rem; text-align: center; color: var(--text-dim); font-size: 0.9rem; }
.sentinel { height: 1px; border: 0 !important; }

.detail { min-width: 0; }
.detail-inner { max-width: 940px; margin: 0 auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.8rem; }
#detailBody { display: flex; flex-direction: column; gap: 0.8rem; min-width: 0; }
.welcome { margin-top: 2rem; }
.welcome h2, .detail h1.plain { margin: 0 0 0.5rem; font-family: var(--font-serif); font-size: 1.4rem; line-height: 1.25; }
.welcome p { margin: 0 0 0.5rem; }
.back-btn { display: none; align-self: flex-start; }
.unofficial { margin: 0; font-size: 0.85rem; color: var(--text-dim); }
.card-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: 0.2rem 0.1rem 0; font-size: 0.85rem; background: none; border: 0; }
.card-bar .type-line { flex-basis: 100%; font-style: italic; color: var(--text-dim); }
#detailBody { gap: 0.6rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.detail-actions > span { display: inline-flex; }
.stat-wrap { min-width: 0; }

@media (max-width: 767px) {
  .browse { display: block; }
  .sidebar { display: block; position: static; height: auto; border-right: 0; }
  .filters { max-height: none; overflow: visible; }
  .list-wrap { overflow: visible; }
  .browse[data-view="detail"] .sidebar,
  .browse[data-view="list"] .detail { display: none; }
  .back-btn { display: inline-flex; }
  .detail-inner { padding: 0.75rem; }
  .art img { max-height: 240px; }
  .detail-actions .btn { flex: 1 1 auto; }
  .row { padding-top: 0.6rem; padding-bottom: 0.6rem; }   /* touch-sized rows */
}

@media print {
  :root {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --surface-2: #fff; --border: #999;
    --text: #000; --text-dim: #333; --accent: #000;
  }
  body { background: #fff; color: #000; }
  #site-header, #site-footer .footer-links, .sidebar, .ad-slot, #detailAd, .art img, .back-btn, .unofficial, .detail-actions, .welcome { display: none !important; }
  .browse, .browse[data-view] .detail { display: block; }
  .detail-inner { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; }
  .card-bar, .tag { border: 0; padding: 0; background: none; }
  .tactics { border-left-color: #000; }
  .credit { font-size: 9pt; }
}
