:root {
  color-scheme: dark;
}

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

body {
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  overflow-y: auto;
}

/* Custom scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(20, 15, 10, 0.6);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb {
  background: rgba(160, 130, 60, 0.4);
  border-radius: 4px;
  border: 1px solid rgba(160, 130, 60, 0.2);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(180, 150, 70, 0.6);
}
::-webkit-scrollbar-corner {
  background: transparent;
}
* {
  scrollbar-color: rgba(160, 130, 60, 0.4) rgba(20, 15, 10, 0.6);
  scrollbar-width: thin;
}

body::after {
  content: 'v0.13.24';
  position: fixed;
  bottom: 6px;
  right: 10px;
  font-size: 13px;
  color: rgba(200, 180, 140, 0.6);
  font-family: monospace;
  z-index: 999;
  pointer-events: none;
}

/* ── Loading bar ── */
.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, #c9a84c, #ffe066, #c9a84c);
  z-index: 9999;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(201, 168, 76, 0.6);
}

.loading-bar.active {
  animation: loading-pulse 1.5s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

header {
  text-align: center;
  padding: 1rem 1rem 0.5rem;
}

.page-subtitle {
  text-align: center;
  padding: 0.75rem 1rem 0.25rem;
}

header h1 {
  font-size: 2rem;
  color: #c9a84c;
  text-shadow: 0 2px 8px rgba(201, 168, 76, 0.3);
  letter-spacing: 0.05em;
}

.page-logo {
  max-width: 280px;
  height: auto;
  display: block;
  margin: 0 auto 0.5rem;
}

.subtitle {
  color: #888;
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.filters {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  flex-wrap: wrap;
}

.filters input[type="text"] {
  background: #16213e;
  color: #e0e0e0;
  border: 1px solid #333;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 180px;
  outline: none;
}

.filters input[type="text"]:focus {
  border-color: #c9a84c;
}

.filters input[type="text"]::placeholder {
  color: #666;
}

.filters select {
  background: #16213e;
  color: #e0e0e0;
  border: 1px solid #333;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}

.filters select:hover {
  border-color: #c9a84c;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  justify-items: center;
  align-items: start;
}

/* Card detail modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Cards taller than the viewport scroll instead of clipping; margin:auto
     on the modal keeps short content centered */
  overflow-y: auto;
  padding: 1.25rem 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-backdrop > .modal-card {
  margin: auto;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: all;
}

.modal-card {
  background: #16213e;
  border: 1px solid #333;
  border-radius: 16px;
  max-width: 400px;
  width: 90%;
  padding: 2rem;
  position: relative;
}
/* Wide cards (boss + campaign) render landscape, so give the modal more room. */
.modal-card:has(.tos-wide) {
  max-width: 620px;
}

/* Zoomed-card modal: the card IS the detail view, so the modal shrinks to
   the zoomed card. Cards keep their native fixed-px metrics here (the
   generic modal --tos-w:100% stretch would widen without enlarging text);
   JS applies CSS zoom to scale everything proportionally. */
.modal-card-zoom {
  width: auto;
  max-width: none;
  padding: 1.25rem;
}
.modal-card-zoom .modal-tos-wrap {
  margin: 0;
}
/* Triple selector outranks the generic .modal-tos-wrap context rules below */
.modal-card-zoom .modal-tos-wrap .tos-card {
  --tos-w: 330px;
  border-radius: 12px;
}
/* Physical 5/7 proportions in the detail view; the textbox absorbs the
   slack (flex fill rules above) and the card can still grow taller if an
   ability text overruns, since nothing here clips overflow. */
.modal-card-zoom .modal-tos-wrap .tos-card:not(.tos-wide) {
  aspect-ratio: 5 / 7;
}
.modal-card-zoom .modal-tos-wrap .tos-wide {
  --tos-w: 480px;
  /* Detail view favors readability over the 10/7 print ratio: let the card
     grow so long boss/campaign ability text is never clipped, and render
     the body text larger than the thumbnail metrics. */
  aspect-ratio: auto;
  min-height: 336px;
  --tos-body-fs: 14px;
  --tos-circ-sz: 24px;
  --tos-circ-fs: 12px;
  --tos-ab-py: 8px;
}
/* With the 10/7 lock off, a tall portrait's intrinsic height would balloon
   the card; absolutely fill the art cell so the TEXT column drives height */
.modal-card-zoom .modal-tos-wrap .tos-wide .tos-art > img.portrait {
  position: absolute;
  inset: 0;
  height: 100%;
}
/* Text-heavy bosses read better with a wider text column (default is 1:1) */
.modal-card-zoom .modal-tos-wrap .tos-wide .tos-frame {
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
}

/* Detail + hover views must never clip ability text: the textbox refuses to
   shrink below its content, so the card grows past its preferred aspect. */
.modal-card-zoom .modal-tos-wrap .tos-card:not(.tos-wide) .tos-textbox,
.hover-preview .tos-card:not(.tos-wide) .tos-textbox,
.deck-hover-preview .tos-card:not(.tos-wide) .tos-textbox,
.select-hover-preview .tos-card:not(.tos-wide) .tos-textbox {
  min-height: auto;
  overflow: visible;
}
.hover-preview .tos-card:not(.tos-wide),
.deck-hover-preview .tos-card:not(.tos-wide),
.select-hover-preview .tos-card:not(.tos-wide) {
  overflow: visible;
  height: auto;
}

/* Wide (boss) hover previews grow to fit their long ability text */
.hover-preview .tos-wide,
.deck-hover-preview .tos-wide,
.select-hover-preview .tos-wide {
  aspect-ratio: auto;
  min-height: 294px;
  overflow: visible;
}
.hover-preview .tos-wide .tos-art > img.portrait,
.deck-hover-preview .tos-wide .tos-art > img.portrait,
.select-hover-preview .tos-wide .tos-art > img.portrait {
  position: absolute;
  inset: 0;
  height: 100%;
}

/* Metadata the card frame does not render (attack form, damage type, level) */
.modal-caption {
  margin-top: 0.75rem;
  text-align: center;
  color: #9a8f78;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid #555;
  color: #e0e0e0;
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.modal-close:hover { color: #fff; background: rgba(0, 0, 0, 0.9); }

.modal-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.modal-stat {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.modal-stat-label {
  color: #888;
  font-size: 0.7rem;
  text-transform: uppercase;
}

.modal-stat-wide {
  grid-column: 1 / -1;
}

/* Navigation bar */
.nav-bar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid #333;
}

.nav-bar a {
  color: #888;
  text-decoration: none;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.nav-bar a:hover {
  color: #c9a84c;
  background: rgba(201, 168, 76, 0.1);
}

.nav-bar a.active {
  color: #c9a84c;
  background: rgba(201, 168, 76, 0.15);
}

/* ── Shared buttons and dice ── */
.btn-action {
  background: rgba(30, 25, 15, 0.9);
  color: #c9a84c;
  border: 1px solid rgba(160, 130, 60, 0.4);
  padding: 0.5rem 1.2rem;
  border-radius: 22px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.btn-action:hover {
  background: rgba(50, 40, 20, 0.95);
  border-color: #c9a84c;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.dice-area {
  display: flex;
  gap: 0.5rem;
}

.die {
  width: 40px;
  height: 40px;
  background: rgba(30, 25, 15, 0.8);
  border: 2px solid rgba(160, 130, 60, 0.4);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: bold;
  color: #c9a84c;
  cursor: pointer;
  transition: transform 0.1s;
}

.die:hover {
  transform: scale(1.1);
  border-color: #c9a84c;
}

/* ── Card Backs ──────────────────────────────────────────────────────────── */
.card-back {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}

/* Outer ornamental border */
.card-back::before {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 5px;
  border: 2px solid rgba(201, 168, 76, 0.6);
  z-index: 2;
  pointer-events: none;
}

/* Inner decorative frame */
.card-back::after {
  content: '';
  position: absolute;
  inset: 11px;
  border-radius: 3px;
  border: 1px solid rgba(201, 168, 76, 0.3);
  z-index: 2;
  pointer-events: none;
}

/* Central emblem */
.card-back .back-emblem {
  position: relative;
  z-index: 3;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.7));
  border: 2px solid rgba(201, 168, 76, 0.3);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
}

/* Card type label */
.card-back .back-title {
  position: relative;
  z-index: 3;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-weight: 700;
  margin-top: 10px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}

/* Bottom branding */
.card-back .back-logo {
  position: absolute;
  bottom: 14px;
  z-index: 3;
  font-size: 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: rgba(201, 168, 76, 0.5);
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* Diamond lattice pattern */
.card-back .back-pattern {
  position: absolute;
  inset: 12px;
  z-index: 1;
  opacity: 0.12;
  background-image:
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      currentColor 10px,
      currentColor 11px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 10px,
      currentColor 10px,
      currentColor 11px
    );
}

/* Center glow vignette */
.card-back .back-glow {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 8px;
  pointer-events: none;
}

/* ── Allied Unit (Hero) back ── */
.card-back.allied {
  background: linear-gradient(160deg, #1e3d1e 0%, #143014 30%, #0d220d 60%, #081408 100%);
}
.card-back.allied .back-glow {
  background: radial-gradient(ellipse at 50% 45%, rgba(60, 160, 60, 0.2) 0%, transparent 55%);
}
.card-back.allied::before { border-color: rgba(80, 180, 80, 0.5); }
.card-back.allied::after { border-color: rgba(80, 180, 80, 0.25); }
.card-back.allied .back-emblem { color: #5cb85c; border-color: rgba(80, 180, 80, 0.4); }
.card-back.allied .back-title { color: #7dce7d; }
.card-back.allied .back-pattern { color: #3a8a3a; }

/* ── Villain back ── */
.card-back.villain {
  background: linear-gradient(160deg, #3d1e1e 0%, #301414 30%, #220d0d 60%, #140808 100%);
}
.card-back.villain .back-glow {
  background: radial-gradient(ellipse at 50% 45%, rgba(180, 50, 50, 0.2) 0%, transparent 55%);
}
.card-back.villain::before { border-color: rgba(200, 70, 70, 0.5); }
.card-back.villain::after { border-color: rgba(200, 70, 70, 0.25); }
.card-back.villain .back-emblem { color: #c95050; border-color: rgba(200, 70, 70, 0.4); }
.card-back.villain .back-title { color: #e07070; }
.card-back.villain .back-pattern { color: #8a3030; }

/* ── Boss back ── */
.card-back.boss {
  background: linear-gradient(160deg, #2e1e4a 0%, #221440 30%, #180d30 60%, #0e081e 100%);
}
.card-back.boss .back-glow {
  background: radial-gradient(ellipse at 50% 45%, rgba(130, 70, 200, 0.2) 0%, transparent 55%);
}
.card-back.boss::before { border-color: rgba(150, 90, 220, 0.5); }
.card-back.boss::after { border-color: rgba(150, 90, 220, 0.25); }
.card-back.boss .back-emblem { color: #a06ad0; border-color: rgba(150, 90, 220, 0.4); }
.card-back.boss .back-title { color: #b88ae0; }
.card-back.boss .back-pattern { color: #6a3a90; }

/* ── Treasure back ── */
.card-back.treasure {
  background: linear-gradient(160deg, #3d3018 0%, #302410 30%, #221a0a 60%, #141005 100%);
}
.card-back.treasure .back-glow {
  background: radial-gradient(ellipse at 50% 45%, rgba(201, 168, 76, 0.2) 0%, transparent 55%);
}
.card-back.treasure::before { border-color: rgba(201, 168, 76, 0.6); }
.card-back.treasure::after { border-color: rgba(201, 168, 76, 0.3); }
.card-back.treasure .back-emblem { color: #c9a84c; border-color: rgba(201, 168, 76, 0.4); }
.card-back.treasure .back-title { color: #ddc070; }
.card-back.treasure .back-pattern { color: #8a7030; }

/* ── Map back (landscape) ── */
.card-back.map {
  background: linear-gradient(160deg, #3a3528 0%, #2a2618 30%, #1e1a10 60%, #121008 100%);
  flex-direction: row;
  gap: 12px;
}
.card-back.map .back-glow {
  background: radial-gradient(ellipse at 50% 45%, rgba(180, 160, 90, 0.15) 0%, transparent 55%);
}
.card-back.map::before { border-color: rgba(180, 160, 90, 0.5); }
.card-back.map::after { border-color: rgba(180, 160, 90, 0.25); }
.card-back.map .back-emblem { color: #b0a050; border-color: rgba(180, 160, 90, 0.4); }
.card-back.map .back-title { color: #c8b870; }
.card-back.map .back-pattern { color: #7a6e30; }

/* Mobile responsive */
@media (max-width: 768px) {
  header h1 { font-size: 1.4rem; }
  .subtitle { font-size: 0.75rem; }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    padding: 1rem;
  }

  .card-grid .tos-card {
    --tos-w: 160px;
    --tos-art-h: 100px;
    --tos-banner-h: 20px;
    --tos-banner-mb: 4px;
    --tos-name-fs: 8px;
    --tos-icon-sz: 20px;
    --tos-cost-w: 18px;
    --tos-cost-h: 18px;
    --tos-cost-fs: 11px;
    --tos-stat-fs: 24px;
    --tos-sta-fs: 22px;
    --tos-body-fs: 9px;
    --tos-ab-py: 3px;
    --tos-ab-px: 5px;
    --tos-ab-gap: 3px;
    --tos-footer-h: 14px;
    --tos-footer-py: 2px;
    --tos-footer-px: 5px;
    --tos-qc-fs: 8px;
  }

  .nav-bar { gap: 0.25rem; }
  .nav-bar a { font-size: 0.65rem; padding: 0.3rem 0.5rem; }
  .filters { gap: 0.5rem; padding: 0.5rem; }
  .filters select { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
  .filters input[type="text"] { min-width: 0; width: 100%; padding: 0.4rem 0.6rem; font-size: 0.8rem; }

  .modal-card { padding: 1rem; max-width: 95%; }
}

@media (max-width: 480px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .card-grid .tos-card {
    --tos-w: 100%;
    --tos-art-h: 80px;
    --tos-banner-h: 18px;
    --tos-banner-mb: 3px;
    --tos-name-fs: 7px;
    --tos-icon-sz: 18px;
    --tos-cost-w: 16px;
    --tos-cost-h: 16px;
    --tos-cost-fs: 10px;
    --tos-stat-fs: 20px;
    --tos-sta-fs: 18px;
    --tos-body-fs: 8px;
    --tos-ab-py: 2px;
    --tos-ab-px: 4px;
    --tos-ab-gap: 2px;
    --tos-gutter-w: 20px;
    --tos-sq-sz: 12px;
    --tos-sq-fs: 8px;
    --tos-circ-sz: 14px;
    --tos-circ-fs: 7px;
    --tos-tri-side: 3px;
    --tos-tri-h: 6px;
    --tos-footer-h: 12px;
    --tos-footer-py: 2px;
    --tos-footer-px: 4px;
    --tos-qc-fs: 9px;
  }

  .filters { flex-wrap: wrap; gap: 0.4rem; padding: 0.5rem; }
  .filters select, .filters input[type="text"] { font-size: 0.75rem; padding: 0.35rem 0.5rem; }
  .btn-action { font-size: 0.7rem; padding: 0.35rem 0.6rem; }
}

/* ── TOS Physical Card Style (shared across ALL pages) ────────────
   Sizing is driven by CSS custom properties. Each rendering context
   (card grid, hover preview, modal, pool, etc.) overrides only the
   properties it needs. No more per-element overrides scattered across
   board.css / deck.css.
   ─────────────────────────────────────────────────────────────────── */

.tos-card {
  /* ── colour (set per-card via inline style) ── */
  --frame-a: #b88a3e;
  --frame-b: #6e4a20;
  --frame-c: #d9b066;

  /* ── scalable dimensions (override per context) ── */
  --tos-w:         330px;
  --tos-art-h:     196px;
  --tos-banner-h:  30px;
  --tos-banner-mb: 8px;
  --tos-name-fs:   13px;
  --tos-icon-sz:   30px;
  --tos-cost-w:    26px;
  --tos-cost-h:    28px;
  --tos-cost-fs:   18px;
  --tos-stat-fs:   44px;
  --tos-sta-fs:    42px;
  --tos-body-fs:   13.5px;
  --tos-ab-py:     7px;
  --tos-ab-px:     9px;
  --tos-ab-gap:    7px;
  --tos-gutter-w:  34px;
  --tos-sq-sz:     20px;
  --tos-sq-fs:     13px;
  --tos-circ-sz:   22px;
  --tos-circ-fs:   12px;
  --tos-tri-side:  7px;
  --tos-tri-h:     12px;
  --tos-footer-h:  22px;
  --tos-footer-py: 4px;
  --tos-footer-px: 9px;
  --tos-qc-fs:     10.5px;

  width: var(--tos-w);
  background: #0c0a08;
  border-radius: 12px;
  padding: 7px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.55);
  font-family: Georgia, 'Times New Roman', serif;
  color: #1c150c;
}

.tos-frame {
  border-radius: 7px;
  padding: 9px 9px 6px;
  overflow: hidden;
  background:
    linear-gradient(135deg,
      var(--frame-c) 0%,
      var(--frame-a) 25%,
      var(--frame-b) 55%,
      var(--frame-a) 80%,
      var(--frame-c) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.45),
    inset 0 2px 3px rgba(255,255,255,0.25),
    inset 0 -2px 4px rgba(0,0,0,0.35);
}

.tos-banner {
  position: relative;
  height: var(--tos-banner-h);
  margin-bottom: var(--tos-banner-mb);
  display: flex;
  align-items: center;
}
.tos-banner-pill {
  flex: 1;
  height: 100%;
  background: linear-gradient(#fdfbf2, #ece3cd);
  border: 1px solid #6b5224;
  border-radius: 16px;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.8), 0 1px 2px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  padding: 0 calc(var(--tos-icon-sz) + 10px) 0 16px;
  overflow: hidden;
}
.tos-name {
  font-size: var(--tos-name-fs);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #20180c;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tos-class-icon {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: var(--tos-icon-sz);
  height: var(--tos-icon-sz);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #4a4036, #161210);
  border: 1px solid #6b5224;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5), inset 0 1px 2px rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.tos-class-icon img {
  width: 74%;
  height: 74%;
  object-fit: contain;
  filter: brightness(1.6) contrast(1.1);
}

.tos-art {
  position: relative;
  height: var(--tos-art-h);
  border: 2px solid #100c08;
  border-radius: 3px;
  overflow: hidden;
  background: #2a2620;
}
.tos-art > img.portrait {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 22%;
  display: block;
}
.tos-art .portrait-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 12px;
  color: #8a7a55;
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background:
    radial-gradient(ellipse at center, rgba(160, 130, 60, 0.16), transparent 75%),
    linear-gradient(160deg, #2a2316, #17120b);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.tos-cost {
  position: absolute;
  top: 6px;
  left: 6px;
  min-width: var(--tos-cost-w);
  height: var(--tos-cost-h);
  padding: 0 5px 3px;
  background: linear-gradient(#f2efe6, #c8c2b2);
  border: 1.5px solid #2a241a;
  border-radius: 5px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.6), inset 0 1px 1px rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--tos-cost-fs);
  font-weight: 700;
  color: #1c150c;
  line-height: 1;
}

.tos-stat {
  position: absolute;
  bottom: 7px;
  font-size: var(--tos-stat-fs);
  font-weight: 700;
  line-height: 1;
  text-shadow:
    -2px -2px 0 #000, 2px -2px 0 #000,
    -2px 2px 0 #000, 2px 2px 0 #000,
    0 0 7px rgba(0,0,0,0.85);
}
.tos-stat.atk { left: 10px; color: #ff9999; }
.tos-stat.sta { right: 12px; color: #99ccff; font-size: var(--tos-sta-fs); }

.tos-textbox {
  background: #e9dcbe;
  border: 2px solid #100c08;
  border-top: none;
  border-radius: 0 0 3px 3px;
  padding: 0;
  color: #1c150c;
}
.tos-ability {
  display: flex;
  gap: var(--tos-ab-gap);
  padding: var(--tos-ab-py) var(--tos-ab-px);
  border-bottom: 1px solid rgba(60,46,24,0.18);
  line-height: 1.28;
}
.tos-ability:nth-child(even) { background: #ddcca6; }
.tos-ability:nth-child(odd)  { background: #efe4c9; }
.tos-ability.empty { min-height: 80px; }
.tos-ability:last-child { border-bottom: none; }

.tos-gutter {
  flex: 0 0 auto;
  min-width: var(--tos-gutter-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  padding-top: 1px;
}
.tos-icon-sq {
  min-width: var(--tos-sq-sz);
  height: var(--tos-sq-sz);
  padding: 0 3px 2px;
  background: linear-gradient(#f6f2e6, #d9d1bd);
  border: 1.5px solid #2a241a;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--tos-sq-fs); font-weight: 700; color: #1c150c;
  line-height: 1;
}
.tos-icon-circ {
  min-width: var(--tos-circ-sz);
  height: var(--tos-circ-sz);
  padding: 0 4px 2px;
  background: linear-gradient(#f6f2e6, #d9d1bd);
  border: 1.5px solid #2a241a;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--tos-circ-fs); font-weight: 700; color: #1c150c;
  white-space: nowrap;
  line-height: 1;
}
.tos-tri {
  width: 0; height: 0;
  border-left: var(--tos-tri-side) solid transparent;
  border-right: var(--tos-tri-side) solid transparent;
  border-bottom: var(--tos-tri-h) solid #2a241a;
}

.tos-body { flex: 1; font-size: var(--tos-body-fs); }
.tos-evade {
  font-style: italic;
  font-weight: 700;
  display: block;
}
.tos-aname {
  font-style: italic;
  font-weight: 700;
}
.tos-atext { font-weight: 400; }

.tos-footer {
  position: relative;
  padding: var(--tos-footer-py) var(--tos-footer-px) calc(var(--tos-footer-py) + 1px);
  /* Darker tone band so the quality/class label reads against the textbox */
  background: #d3bf94;
  border: 2px solid #100c08;
  border-top: 1px solid rgba(60, 46, 24, 0.45);
  border-radius: 0 0 3px 3px;
  min-height: var(--tos-footer-h);
}
.tos-credit {
  text-align: center;
  font-size: 7.5px;
  color: #5a4a2c;
  letter-spacing: 0.02em;
}
.tos-quality-class {
  position: absolute;
  right: var(--tos-footer-px);
  bottom: var(--tos-footer-py);
  font-size: var(--tos-qc-fs);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #241a0c;
  text-transform: uppercase;
}
.tos-textbox + .tos-footer { margin-top: -2px; }

/* ── Card type variants (global, not context-specific) ─────────── */

/* Wide landscape cards (boss + campaign characters): art left, abilities
   right. ONE shared layout block governs both card types. Changing .tos-wide
   updates boss and campaign cards together, everywhere they render. */
.tos-wide {
  --tos-w: 480px;
}
.tos-wide .tos-frame {
  display: grid;
  /* minmax(0,..) so a long nowrap name in the banner can't inflate the art
     column's min-content and squeeze the text column */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  gap: 0;
  padding: 9px;
}
.tos-wide .tos-banner {
  grid-column: 1;
  grid-row: 1;
  margin-bottom: 4px;
}
.tos-wide .tos-art {
  grid-column: 1;
  grid-row: 2;
  height: auto;
  min-height: 160px;
}
.tos-wide .tos-textbox {
  grid-column: 2;
  grid-row: 1 / 4;
  border: 2px solid #100c08;
  border-radius: 3px;
  margin-left: 6px;
  align-self: stretch;
}
.tos-wide .tos-footer {
  grid-column: 1;
  grid-row: 3;
  border-radius: 0;
  margin-top: -2px;
}

/* Boss-specific: hide ATK, center STA pip. */
.tos-boss .tos-stat.atk { display: none; }
.tos-boss .tos-stat.sta {
  font-size: calc(var(--tos-stat-fs) * 1.18);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

/* Campaign character cards: no ATK/STA */
.tos-campaign-char .tos-stat { display: none; }

/* Achievement cards: portrait only, no stats */
.tos-achievement .tos-stat { display: none; }
.tos-achievement .tos-textbox { display: none; }

/* Treasure art fills the whole frame (cover) and bleeds a few px past the
   left/right edges so no border seam shows. Treasure cards carry little
   text, so the art box also grows to absorb the slack (flex rule below). */
.tos-treasure .tos-art { background: #17120b; }
.tos-treasure .tos-art > img.portrait {
  object-fit: cover;
  object-position: center;
  width: calc(100% + 6px);
  margin-left: -3px;
}

/* ── Context: Card browser grid ────────────────────────────────── */

/* Section header rows separating card groups in the browser grid */
.grid-section-header {
  grid-column: 1 / -1;
  margin: 0.9rem 0 0.1rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(160, 130, 60, 0.25);
  color: #c9a84c;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}
.grid-section-header:first-child { margin-top: 0; }

.card-grid .tos-card {
  --tos-w: 240px;
  --tos-art-h: 120px;
  --tos-banner-h: 24px;
  --tos-banner-mb: 6px;
  --tos-name-fs: 10px;
  --tos-icon-sz: 24px;
  --tos-cost-w: 20px;
  --tos-cost-h: 22px;
  --tos-cost-fs: 14px;
  --tos-stat-fs: 32px;
  --tos-sta-fs: 30px;
  --tos-body-fs: 10px;
  --tos-ab-py: 4px;
  --tos-ab-px: 7px;
  --tos-ab-gap: 4px;
  --tos-gutter-w: 28px;
  --tos-sq-sz: 16px;
  --tos-sq-fs: 10px;
  --tos-circ-sz: 18px;
  --tos-circ-fs: 9px;
  --tos-tri-side: 5px;
  --tos-tri-h: 9px;
  --tos-footer-h: 18px;
  --tos-footer-py: 3px;
  --tos-footer-px: 7px;
  --tos-qc-fs: 9px;

  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
  aspect-ratio: 5 / 7;
}
.card-grid .tos-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 32px rgba(0,0,0,0.6);
}
/* Wide cards (boss + campaign) span 2 columns in the grid for landscape layout */
/* Actual boss card images: 1494x1044 = 10:7 ratio (exactly 2x regular width) */
.card-grid:not(.list-view) .tos-wide {
  --tos-w: 100%;
  /* span 2 only in the grid; in list view it would force an implicit second
     column and break the single-column rows */
  grid-column: span 2;
  aspect-ratio: 10 / 7;
}
/* Achievement cards (portrait-only, no textbox) */
.card-grid .tos-achievement {
  aspect-ratio: 5 / 7;
}

/* Uniform full-quality cards across EVERY context (card browser grid, board
   hover, deck hover, select hover, and the card-templates page which reuses
   these same classes): the frame fills the aspect-locked box and the textbox
   absorbs the slack, so short cards no longer leave a black gap below and long
   ability text clips inside the parchment box instead of spilling off the card.
   One shared rule = identical rendering everywhere. list-view is intentionally
   excluded (it lays cards out horizontally). */
.card-grid:not(.list-view) .tos-card:not(.tos-wide),
.hover-preview .tos-card:not(.tos-wide),
.deck-hover-preview .tos-card:not(.tos-wide),
.select-hover-preview .tos-card:not(.tos-wide),
.modal-tos-wrap .tos-card:not(.tos-wide) { display: flex; }

.card-grid:not(.list-view) .tos-card:not(.tos-wide) .tos-frame,
.hover-preview .tos-card:not(.tos-wide) .tos-frame,
.deck-hover-preview .tos-card:not(.tos-wide) .tos-frame,
.select-hover-preview .tos-card:not(.tos-wide) .tos-frame,
.modal-tos-wrap .tos-card:not(.tos-wide) .tos-frame {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  /* Reserve the footer strip: the footer itself is ANCHORED to the card
     bottom (absolute) so no flex/aspect-ratio quirk in any engine can ever
     push it out of view */
  position: relative;
  padding-bottom: calc(var(--tos-footer-h) + 4px);
}

.card-grid:not(.list-view) .tos-card:not(.tos-wide) .tos-footer,
.hover-preview .tos-card:not(.tos-wide) .tos-footer,
.deck-hover-preview .tos-card:not(.tos-wide) .tos-footer,
.select-hover-preview .tos-card:not(.tos-wide) .tos-footer,
.modal-tos-wrap .tos-card:not(.tos-wide) .tos-footer {
  position: absolute;
  left: 9px;
  right: 9px;
  bottom: 6px;
  z-index: 3;
}

.card-grid:not(.list-view) .tos-card:not(.tos-wide) .tos-banner,
.card-grid:not(.list-view) .tos-card:not(.tos-wide) .tos-art,
.card-grid:not(.list-view) .tos-card:not(.tos-wide) .tos-footer,
.hover-preview .tos-card:not(.tos-wide) .tos-banner,
.hover-preview .tos-card:not(.tos-wide) .tos-art,
.hover-preview .tos-card:not(.tos-wide) .tos-footer,
.deck-hover-preview .tos-card:not(.tos-wide) .tos-banner,
.deck-hover-preview .tos-card:not(.tos-wide) .tos-art,
.deck-hover-preview .tos-card:not(.tos-wide) .tos-footer,
.select-hover-preview .tos-card:not(.tos-wide) .tos-banner,
.select-hover-preview .tos-card:not(.tos-wide) .tos-art,
.select-hover-preview .tos-card:not(.tos-wide) .tos-footer,
.modal-tos-wrap .tos-card:not(.tos-wide) .tos-banner,
.modal-tos-wrap .tos-card:not(.tos-wide) .tos-art,
.modal-tos-wrap .tos-card:not(.tos-wide) .tos-footer { flex: 0 0 auto; }

.card-grid:not(.list-view) .tos-card:not(.tos-wide) .tos-textbox,
.hover-preview .tos-card:not(.tos-wide) .tos-textbox,
.deck-hover-preview .tos-card:not(.tos-wide) .tos-textbox,
.select-hover-preview .tos-card:not(.tos-wide) .tos-textbox,
.modal-tos-wrap .tos-card:not(.tos-wide) .tos-textbox {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.card-grid:not(.list-view) .tos-card.tos-achievement .tos-art,
.hover-preview .tos-card.tos-achievement .tos-art,
.deck-hover-preview .tos-card.tos-achievement .tos-art,
.select-hover-preview .tos-card.tos-achievement .tos-art,
.modal-tos-wrap .tos-card.tos-achievement .tos-art,
.card-grid:not(.list-view) .tos-card.tos-treasure .tos-art,
.hover-preview .tos-card.tos-treasure .tos-art,
.deck-hover-preview .tos-card.tos-treasure .tos-art,
.select-hover-preview .tos-card.tos-treasure .tos-art,
.modal-tos-wrap .tos-card.tos-treasure .tos-art { flex: 1 1 auto; }

/* Wide-card fill: same goal but the wide frame is a grid (art left, abilities
   right). Let the frame stretch to the full 10/7 box; its auto/1fr/auto rows
   absorb the slack so the card no longer renders short with a black gap. */
.card-grid:not(.list-view) .tos-wide,
.hover-preview .tos-wide,
.deck-hover-preview .tos-wide,
.select-hover-preview .tos-wide { display: flex; flex-direction: column; }
.card-grid:not(.list-view) .tos-wide .tos-frame,
.hover-preview .tos-wide .tos-frame,
.deck-hover-preview .tos-wide .tos-frame,
.select-hover-preview .tos-wide .tos-frame { flex: 1 1 auto; min-height: 0; }

/* ── Context: Hover previews (board + deck builder) ────────────── */

.hover-preview .tos-card,
.deck-hover-preview .tos-card {
  --tos-w: 260px;
  --tos-art-h: 150px;
  --tos-banner-h: 24px;
  --tos-banner-mb: 6px;
  --tos-name-fs: 10px;
  --tos-icon-sz: 24px;
  --tos-cost-w: 22px;
  --tos-cost-h: 22px;
  --tos-cost-fs: 14px;
  --tos-stat-fs: 34px;
  --tos-sta-fs: 32px;
  --tos-body-fs: 11px;
  --tos-ab-py: 5px;
  --tos-ab-px: 7px;
  --tos-ab-gap: 5px;
  --tos-gutter-w: 28px;
  --tos-sq-sz: 16px;
  --tos-sq-fs: 11px;
  --tos-circ-sz: 18px;
  --tos-circ-fs: 10px;
  --tos-tri-side: 5px;
  --tos-tri-h: 9px;
  --tos-footer-h: 18px;
  --tos-footer-py: 3px;
  --tos-footer-px: 7px;
  --tos-qc-fs: 9px;

  pointer-events: none;
  aspect-ratio: 5 / 7;
  overflow: hidden;
}
/* Wide hover previews need wider card (10:7 = actual boss card ratio) */
.hover-preview .tos-wide,
.deck-hover-preview .tos-wide,
.select-hover-preview .tos-wide {
  --tos-w: 420px;
  aspect-ratio: 10 / 7;
}

/* ── Context: Deck pool cards (tiny) ───────────────────────────── */

.pool-card-wrap .tos-card {
  --tos-w: 100%;
  --tos-art-h: 90px;
  --tos-banner-h: 18px;
  --tos-banner-mb: 4px;
  --tos-name-fs: 8px;
  --tos-icon-sz: 18px;
  --tos-cost-w: 16px;
  --tos-cost-h: 16px;
  --tos-cost-fs: 10px;
  --tos-stat-fs: 22px;
  --tos-sta-fs: 20px;
  --tos-body-fs: 9px;
  --tos-ab-py: 3px;
  --tos-ab-px: 5px;
  --tos-ab-gap: 3px;
  --tos-gutter-w: 20px;
  --tos-sq-sz: 13px;
  --tos-sq-fs: 9px;
  --tos-circ-sz: 14px;
  --tos-circ-fs: 8px;
  --tos-tri-side: 4px;
  --tos-tri-h: 7px;
  --tos-footer-h: 14px;
  --tos-footer-py: 2px;
  --tos-footer-px: 5px;
  --tos-qc-fs: 8px;
  aspect-ratio: 5 / 7;
  overflow: hidden;
}

/* ── Context: Modals (card browser + board) ────────────────────── */

.modal-tos-wrap {
  margin: -0.5rem -0.5rem 1rem -0.5rem;
}
.modal-tos-wrap .tos-card,
.modal-card .tos-card,
.card-modal .tos-card {
  --tos-w: 100%;
  border-radius: 12px 12px 0 0;
}
/* Wide cards (boss + campaign) keep their landscape ratio + filled frame in
   the modal, matching the hover/grid rendering (no shortness). */
.modal-tos-wrap .tos-wide {
  aspect-ratio: 10 / 7;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-tos-wrap .tos-wide .tos-frame { flex: 1 1 auto; min-height: 0; }

/* ── Context: Card browser list view ───────────────────────────── */

.card-grid.list-view {
  grid-template-columns: 1fr;
  gap: 0.5rem;
  max-width: 800px;
}
.card-grid.list-view .tos-card {
  --tos-w: 100%;
  --tos-stat-fs: 16px;
  --tos-sta-fs: 15px;
  --tos-cost-w: 16px;
  --tos-cost-h: 16px;
  --tos-cost-fs: 10px;
  --tos-body-fs: 10px;
  --tos-ab-py: 3px;
  --tos-ab-px: 7px;
  --tos-ab-gap: 4px;
  --tos-gutter-w: 22px;
  --tos-sq-sz: 14px;
  --tos-sq-fs: 9px;
  --tos-circ-sz: 16px;
  --tos-circ-fs: 8px;
  --tos-tri-side: 4px;
  --tos-tri-h: 7px;
  flex-direction: row;
  display: flex;
  padding: 4px;
  border-radius: 8px;
  /* Rows are content-height; without this the grid's 5/7 lock applies to
     the full row width and produces 1000px-tall cards */
  aspect-ratio: auto;
  /* Uniform row height even for cards with little or no ability text
     (Seedy Lurker, achievements) */
  min-height: 78px;
}
.card-grid.list-view .tos-frame {
  display: flex;
  flex-direction: row;
  padding: 4px;
  gap: 8px;
  align-items: stretch;
  width: 100%;
}
.card-grid.list-view .tos-banner { display: none; }
.card-grid.list-view .tos-art {
  width: 60px;
  min-width: 60px;
  height: 60px;
  border-radius: 3px;
}
.card-grid.list-view .tos-cost { top: 2px; left: 2px; padding: 0 2px; }
.card-grid.list-view .tos-textbox {
  flex: 1;
  border: none;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: visible;
}
.card-grid.list-view .tos-textbox::before {
  content: attr(data-name);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #20180c;
  padding: 4px 7px 0;
  margin-bottom: 4px;
}
/* Quality/class label rides along the row's right edge instead of a footer bar */
.card-grid.list-view .tos-footer {
  display: flex;
  align-items: center;
  background: none;
  border: none;
  padding: 0 6px 0 0;
  min-height: 0;
}
.card-grid.list-view .tos-credit { display: none; }
.card-grid.list-view .tos-quality-class {
  font-size: 7.5px;
  color: #8a7a55;
  white-space: nowrap;
}
