/* ============================================================
   Rare Foil — a collector's-card aesthetic for the Gauntlet app.
   Graphite/paper neutrals, a restrained holo-foil accent spent
   only on primary actions, Fraunces for headings, Work Sans for
   body copy, Space Mono for every number (Elo, life, join codes).
   ============================================================ */

:root {
  --bg: #f2f0f5;
  --card: #ffffff;
  --card-2: #f6f4f8;
  --text: #181620;
  --muted: #6b6578;
  --border: #dad6e2;

  --violet: #6e54c9;
  --violet-strong: #5a41b3;
  --felt: #2f9e83;
  --danger: #c24b5a;
  --info: #3f76b8;
  --on-accent: #ffffff;

  --foil: linear-gradient(120deg, #8b5cf6, #22d3c7, #d4a73a);

  --shadow: 0 1px 0 rgba(24,22,32,.04), 0 10px 24px -16px rgba(24,22,32,.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111014;
    --card: #1a1820;
    --card-2: #221f29;
    --text: #f1eef6;
    --muted: #948fa0;
    --border: #2c2836;

    --violet: #a894f0;
    --violet-strong: #bfacf5;
    --felt: #4fd1ac;
    --danger: #e0717e;
    --info: #7fb2ec;
    --on-accent: #14101c;

    --shadow: 0 1px 0 rgba(0,0,0,.4), 0 14px 28px -16px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  --bg: #111014;
  --card: #1a1820;
  --card-2: #221f29;
  --text: #f1eef6;
  --muted: #948fa0;
  --border: #2c2836;

  --violet: #a894f0;
  --violet-strong: #bfacf5;
  --felt: #4fd1ac;
  --danger: #e0717e;
  --info: #7fb2ec;
  --on-accent: #14101c;

  --shadow: 0 1px 0 rgba(0,0,0,.4), 0 14px 28px -16px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.mono {
  font-family: "Space Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--violet);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.brand {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 19px;
  letter-spacing: -.01em;
  cursor: pointer;
}
.icon-btn {
  background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer;
  padding: 4px 8px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
/* Hero cards — the one place the foil accent is spent (join actions, the
   current event's own summary). Everything else stays quiet graphite. */
.card.hero {
  border: 1px solid transparent;
  background:
    linear-gradient(var(--card), var(--card)) padding-box,
    var(--foil) border-box;
}
.auth-card { width: 100%; max-width: 360px; }
.card h2 {
  margin: 24px 0 6px;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -.005em;
}
/* App cards lead with their heading; article pages run h2s mid-document. */
.card h2:first-child { margin-top: 0; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  margin: 6px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
textarea, #deckText, .decklist { font-family: "Space Mono", ui-monospace, monospace; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--violet); outline-offset: 1px; }
#joinCode, #lifeTopNum, #lifeBottomNum { font-family: "Space Mono", ui-monospace, monospace; }

.field-label { display: block; margin-top: 10px; font-size: 13px; color: var(--muted); }
.checkbox { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 14px; }
.checkbox input { width: auto; margin: 0; }

.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-family: "Work Sans", sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin: 4px 4px 4px 0;
}
.btn.primary {
  background-image: var(--foil);
  border-color: transparent;
  color: #14101c;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn-link {
  background: none; border: none; color: var(--violet);
  font-size: 13px; cursor: pointer; padding: 4px; text-decoration: underline;
  font-family: "Work Sans", sans-serif;
}

.btn.google {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; background: #fff; color: #1f1f1f; border-color: #dadce0;
}
.btn.google:hover { background: #f5f5f5; }

.divider { display: flex; align-items: center; gap: 10px; margin: 12px 0; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.space-between { justify-content: space-between; align-items: center; }
.mt { margin-top: 12px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

.error-box {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  margin: 8px 0;
}
.success-box {
  background: color-mix(in srgb, var(--felt) 14%, transparent);
  border: 1px solid var(--felt);
  color: var(--felt);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  margin: 8px 0;
}

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { border-color: var(--violet); }

.stat-row { display: flex; gap: 16px; margin-top: 12px; }
.stat { text-align: center; flex: 1; }
.stat-value {
  font-family: "Space Mono", ui-monospace, monospace;
  font-size: 21px; font-weight: 700;
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; font-family: "Space Mono", ui-monospace, monospace; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.table th {
  color: var(--muted); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em;
  font-family: "Work Sans", sans-serif;
}
.me-row { background: color-mix(in srgb, var(--violet) 12%, transparent); font-weight: 700; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 100px;
  font-size: 11px; font-weight: 600;
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
}
.badge.ok { background: color-mix(in srgb, var(--felt) 16%, transparent); border-color: transparent; color: var(--felt); }
.badge.warn { background: color-mix(in srgb, var(--info) 16%, transparent); border-color: transparent; color: var(--info); }
.badge.bad { background: color-mix(in srgb, var(--danger) 16%, transparent); border-color: transparent; color: var(--danger); }

.join-code {
  font-family: "Space Mono", ui-monospace, monospace;
  font-size: 18px; font-weight: 700; letter-spacing: 2px;
  padding: 2px 10px; background: var(--card-2); border-radius: 8px;
}

.decklist {
  white-space: pre-wrap; background: var(--card-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px; font-size: 13px; max-height: 240px; overflow-y: auto;
}

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px);
  background: var(--card); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all 0.2s ease;
  max-width: 90vw; text-align: center;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

details summary { cursor: pointer; color: var(--violet); font-weight: 600; margin-bottom: 8px; }

/* Quiet footer — the legal disclaimer has to be reachable, not prominent. */
.app-footer {
  text-align: center;
  padding: 4px 16px 28px;
  margin-top: -48px;
}
.app-footer .btn-link {
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
  padding: 4px 2px;
}
.app-footer .btn-link:hover { color: var(--violet); text-decoration: underline; }
.footer-sep { color: var(--muted); font-size: 12px; opacity: .5; }

/* Legal/about pages read as prose, not UI */
.card p { line-height: 1.6; }
.card p + p { margin-top: 10px; }
.card a { color: var(--violet); }

/* ---- Static content pages (guides, about, legal) ---- */
.static-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.static-topbar .brand { text-decoration: none; color: var(--text); }
.static-nav { display: flex; gap: 16px; flex-wrap: wrap; }
.static-nav a {
  color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600;
}
.static-nav a:hover { color: var(--violet); }
.static-nav a:last-child { color: var(--violet); }

.static-footer {
  max-width: 640px; margin: 0 auto; padding: 24px 16px 48px;
  border-top: 1px solid var(--border);
}
.static-footer nav { margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.static-footer nav a { color: var(--muted); text-decoration: none; }
.static-footer nav a:hover { color: var(--violet); text-decoration: underline; }
.static-footer p { font-size: 11.5px; line-height: 1.5; }

.card h1 {
  font-family: "Fraunces", Georgia, serif;
  font-size: 26px; font-weight: 600; margin: 0 0 14px; line-height: 1.2;
}
a.list-item { text-decoration: none; color: inherit; }

/* Guide articles */
.guide-body h2, .guide-body h3 {
  font-family: "Fraunces", Georgia, serif;
  font-size: 17px;
  font-weight: 600;
  margin: 24px 0 6px;
}
.guide-body h2:first-child, .guide-body h3:first-child { margin-top: 6px; }
.guide-body p { font-size: 14.5px; }
.guide-body ul { margin: 10px 0; padding-left: 20px; }
.guide-body li { font-size: 14.5px; line-height: 1.6; margin-bottom: 6px; }
.guide-body em { color: var(--muted); font-style: normal; }

.link-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.link-row a {
  font-size: 13px; font-weight: 600; text-decoration: none;
  padding: 7px 13px; border-radius: 100px;
  border: 1px solid var(--border); background: var(--card-2);
  color: var(--text);
}
.link-row a:hover { border-color: var(--violet); color: var(--violet); }

/* Donation call — present, never pushy */
.link-row a.support-primary {
  background-image: var(--foil);
  border-color: transparent;
  color: #14101c;
  font-weight: 700;
}
.link-row a.support-primary:hover { filter: brightness(1.05); color: #14101c; }

/* Deck card-search picker */
.search-wrap { position: relative; }
.suggestions {
  position: absolute; left: 0; right: 0; top: calc(100% - 4px); z-index: 5;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 240px; overflow-y: auto;
}
.suggestion {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; font-size: 14px; cursor: pointer;
}
.suggestion:hover, .suggestion:active { background: var(--card-2); }
.suggestion + .suggestion { border-top: 1px solid var(--border); }
.suggestion-thumb {
  width: 38px; height: 53px; object-fit: cover; object-position: top;
  border-radius: 3px; flex-shrink: 0; background: var(--card-2);
}
.suggestion-text { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.suggestion-text strong, .suggestion-text span {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.suggestion-peek {
  background: none; border: none; color: var(--muted);
  font-size: 17px; cursor: pointer; padding: 4px 6px; flex-shrink: 0;
}
.suggestion-peek:hover { color: var(--violet); }

.deck-list { display: flex; flex-direction: column; margin-top: 4px; }
.deck-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.deck-row:last-child { border-bottom: none; }
.deck-row-card {
  display: flex; align-items: center; gap: 9px;
  flex: 1; min-width: 0;
  background: none; border: none; padding: 0;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.deck-row-card:hover .deck-row-name { color: var(--violet); }
.deck-thumb {
  width: 30px; height: 42px; object-fit: cover; object-position: top;
  border-radius: 3px; flex-shrink: 0; background: var(--card-2);
}
.deck-thumb-empty { display: inline-block; border: 1px dashed var(--border); }
.deck-row-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-row-remove {
  background: none; border: none; color: var(--muted); font-size: 18px; line-height: 1;
  cursor: pointer; padding: 2px 6px;
}
.deck-row-remove:hover { color: var(--danger); }
.qty-stepper {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 100px;
  padding: 3px 6px; font-family: "Space Mono", monospace; font-size: 13px;
}
.qty-stepper button {
  width: 20px; height: 20px; border-radius: 50%; border: none;
  background: var(--card); color: var(--text); cursor: pointer;
  font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.qty-stepper span { min-width: 14px; text-align: center; }

/* Card detail overlay */
.card-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 7, 11, 0.82);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px 16px; overflow-y: auto;
}
.card-overlay-panel {
  position: relative;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px; max-width: 420px; width: 100%; margin: auto;
}
.card-overlay-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; color: var(--muted);
  font-size: 26px; line-height: 1; cursor: pointer; padding: 4px 8px;
}
.card-overlay-close:hover { color: var(--text); }
/* Full card image, unmodified — the printed copyright and artist credit
   stay legible, per Scryfall's image guidelines. */
.card-overlay-img {
  display: block; width: 100%; max-width: 340px; margin: 4px auto 14px;
  border-radius: 4.75% / 3.5%;
}
.card-oracle {
  white-space: pre-wrap; font-family: "Work Sans", sans-serif; font-size: 14px;
  line-height: 1.55; background: var(--card-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px; margin: 10px 0;
}

/* Life counter — restyled to match Rare Foil: graphite halves, a thin
   foil-gradient seam at the divider instead of a flat purple gradient. */
.life-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #0c0b0f;
  overscroll-behavior: none;
  z-index: 50;
}
.life-half {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(120% 100% at 50% 30%, #201c2c 0%, #0c0b0f 70%);
}
.life-top { transform: rotate(180deg); }
.life-number {
  font-family: "Space Mono", ui-monospace, monospace;
  font-size: min(24vh, 22vw);
  font-weight: 700;
  color: #f1eef6;
  font-variant-numeric: tabular-nums;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
  z-index: 2;
  text-shadow: 0 2px 16px rgba(0,0,0,0.5);
}
.life-zone {
  position: absolute;
  top: 0; bottom: 0; width: 50%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.life-zone-left { left: 0; }
.life-zone-right { right: 0; }
.life-zone:active { background: rgba(255,255,255,0.06); }
.life-divider {
  flex-shrink: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0c0b0f;
  position: relative;
  z-index: 3;
}
.life-divider::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: var(--foil);
}
.life-divider::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: var(--foil);
}
.life-reset {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid #3a3648;
  background: #1a1820;
  color: #f1eef6;
  font-size: 18px;
  cursor: pointer;
}
.life-back {
  position: absolute;
  bottom: 10px; left: 10px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 16px;
  z-index: 4;
}
@keyframes pulsePlus { 0% { color: #4fd1ac; transform: scale(1.08); } 100% { color: #f1eef6; transform: scale(1); } }
@keyframes pulseMinus { 0% { color: #e0717e; transform: scale(1.08); } 100% { color: #f1eef6; transform: scale(1); } }
.pulse-plus { animation: pulsePlus 0.3s ease; display: inline-block; }
.pulse-minus { animation: pulseMinus 0.3s ease; display: inline-block; }

/* --- Life counter: match mode --- */
/* Names sit above each total so a phone passed across the table is never
   ambiguous about whose life is whose. Inherits the half's rotation. */
.life-name {
  color: #f1eef6;
  z-index: 2;
  pointer-events: none;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.55;
  margin-bottom: 0.25rem;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.life-done {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: inherit;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
}
.life-done:active { background: rgba(255,255,255,0.08); }
/* Deliberately unrotated: whoever is deciding the result holds the phone.
   The [hidden] rule is load-bearing: a class setting display:flex outranks
   the UA stylesheet's [hidden]{display:none}, so without it the overlay
   shows permanently — including on the plain, non-match life counter. */
.life-result[hidden] { display: none; }
.life-result {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.72);
  padding: 1.25rem;
}
.life-result-card {
  color: #f1eef6;
  width: min(22rem, 100%);
  background: var(--surface, #1b1a1f);
  border-radius: 1rem;
  padding: 1.25rem;
  text-align: center;
  display: grid;
  gap: 0.5rem;
}
.life-result-card h2 { margin: 0; }
