@import url('https://fonts.googleapis.com/css2?family=Staatliches&family=Nunito+Sans:wght@400;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --canvas: #17140f;
  --canvas-elevated: #211c15;
  --canvas-border: rgba(232, 220, 194, 0.09);
  --canvas-border-hover: rgba(232, 220, 194, 0.22);
  --parchment: #e8dcc2;
  --ink: #efe6d3;
  --ink-muted: #a99a80;
  --ink-faint: #766a54;

  --font-display: "Staatliches", "Arial Narrow", sans-serif;
  --font-body: "Nunito Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", Menlo, monospace;

  /* Rarity accents — a crafting-camp palette (rust, moss, ember, denim,
     berry) instead of tech neons. Each tier gets a distinct hue, same
     structural idea as a supply crate's stencilled tier stamps. */
  --rarity-C: #8f8168;    /* Common     — worn canvas       */
  --rarity-TD: #7c8f7a;   /* Trial base — faded sage        */
  --rarity-U: #6b8a52;    /* Uncommon   — moss green        */
  --rarity-R: #4a7089;    /* Rare       — faded denim       */
  --rarity-RR: #9c4a5c;   /* Dbl Rare   — berry             */
  --rarity-SR: #c2622d;   /* Super Rare — rust orange       */
  --rarity-OSR: #b8863a;  /* Ultra Rare — burnished copper  */
  --rarity-SP: #4a7089;   /* Special    — denim (2nd tier)  */
  --rarity-SSP: #f0c869;  /* Spec.Secret— campfire gold     */
  --rarity-TSP: #c2622d;  /* trial parallel — rust          */
  --rarity-TSR: #c2622d;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* Faint canvas-weave texture instead of a digital noise grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.5;
  background-image:
    repeating-linear-gradient(45deg, rgba(232,220,194,0.02) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(-45deg, rgba(232,220,194,0.02) 0 1px, transparent 1px 4px);
}

::selection { background: #c2622d55; color: var(--ink); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--canvas); }
::-webkit-scrollbar-thumb { background: #c2622d40; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #c2622d75; }

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--rarity-SR);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 18px 24px;
  background: rgba(23, 20, 15, 0.92);
  border-bottom: 2px dashed var(--canvas-border);
}

.eyebrow {
  flex: 1 1 100%;
  display: inline-flex;
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #17140f;
  background: var(--parchment);
  padding: 3px 10px;
  border-radius: 3px;
  margin-bottom: 2px;
}

.topbar h1 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.02em;
  font-size: 1.75rem;
  margin: 0;
  flex: 1 1 100%;
  color: var(--ink);
  text-transform: uppercase;
}

#search {
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid var(--canvas-border);
  background: var(--canvas-elevated);
  color: var(--ink);
  font-family: var(--font-body);
  min-width: 240px;
  transition: border-color 0.15s;
}
#search:hover, #search:focus-visible { border-color: var(--canvas-border-hover); }
#search::placeholder { color: var(--ink-faint); }

.set-tabs { display: flex; gap: 6px; }

.tab {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--canvas-border);
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.15s;
}
.tab:hover { border-color: var(--canvas-border-hover); color: var(--ink); }
.tab.active {
  background: rgba(194, 98, 45, 0.16);
  border-color: rgba(194, 98, 45, 0.5);
  color: #e2934f;
}

.stats-meter {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 240px;
}

.meter-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.meter-label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  width: 60px;
  flex-shrink: 0;
}

.meter-track {
  flex: 1;
  height: 9px;
  border-radius: 5px;
  background: var(--canvas-border);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 5px;
  width: 0%;
  transition: width 0.4s ease;
  box-shadow: 0 0 8px 0 var(--meter-glow, transparent);
}

.meter-fill.base { background: var(--rarity-SR); --meter-glow: rgba(194, 98, 45, 0.6); }
.meter-fill.variant { background: var(--rarity-R); --meter-glow: rgba(74, 112, 137, 0.6); }

.meter-value {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink);
  width: 56px;
  flex-shrink: 0;
  text-align: right;
}

.io-buttons { display: flex; gap: 8px; margin-left: auto; }

.io-buttons button {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--canvas-border);
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.io-buttons button:hover { border-color: var(--canvas-border-hover); color: var(--ink); }

.grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 18px;
  padding: 24px;
  max-width: 1600px;
  margin: 0 auto;
}

.card-tile {
  --rx: 0deg;
  --ry: 0deg;
  --tile-scale: 1;
  background: var(--canvas-elevated);
  border-radius: 10px;
  border: 1px solid var(--canvas-border);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: settleIn 0.3s ease backwards;
  transform: perspective(700px) rotateX(var(--rx)) rotateY(var(--ry)) scale(var(--tile-scale));
  transform-style: preserve-3d;
  transition: transform 0.1s ease-out, border-color 0.15s ease;
}

.card-tile:hover {
  --tile-scale: 1.03;
  border-color: var(--rarity-color, var(--canvas-border-hover));
  z-index: 1;
}

.card-tile.hidden { display: none; }

@keyframes settleIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .card-tile { animation: none; transform: none; }
  .card-tile:hover { --tile-scale: 1; }
}

.card-tile .card-number {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.03em;
  color: var(--rarity-color, var(--ink-faint));
}

.card-tile .card-name {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
  /* Fixed to exactly 2 lines so the meta row below always lands at the
     same height, whether the name is short or wraps. */
  height: calc(0.8125rem * 1.25 * 2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* The art is the point — one large, uninterrupted image per tile,
   filling its box edge-to-edge. Every tile uses the same portrait
   shape, even Structure cards (which print landscape on the physical
   card) — their art is rotated 90° via .rotate-wrap below so the grid
   reads as one consistent shape. Clicking a card shows its true
   orientation in the detail view instead. */
.art-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
  border-radius: 8px;
  overflow: hidden;
  background: #0c0a08;
  border: 1px solid var(--canvas-border);
}

/* Width/height are set in JS (see sizeRotatedArt) to the container's
   actual pixel dimensions, swapped — the exact sizing a 90deg rotation
   needs to fill the portrait .art-wrap with no crop and no gap. */
.rotate-wrap {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
}

.rotate-wrap .card-art { width: 100%; height: 100%; }

/* Holo shine — a light band that tracks the cursor across the art,
   like tilting a foil card under a lamp. Position set via JS. */
.art-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255,255,255,0.28) 50%, transparent 65%);
  background-size: 250% 250%;
  background-position: var(--shine-x, 50%) var(--shine-y, 50%);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.card-tile:hover .art-wrap::after { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .art-wrap::after { display: none; }
}

.card-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.variant-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  padding-top: 8px;
  border-top: 1px dashed var(--canvas-border);
  cursor: pointer;
}

.rarity-badge {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--canvas);
  color: var(--rarity-color, var(--ink));
  border: 1px solid var(--rarity-color, var(--canvas-border-hover));
}

.rarity-badge.foil {
  background: linear-gradient(100deg, var(--rarity-color), #fff, var(--rarity-color));
  background-size: 220% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  border-color: var(--rarity-color);
}

/* Capture-sphere toggle. Unowned = an empty ring outline. Owned = the
   two-tone capsule fills in with a glow — the two states read as
   obviously different at a glance, not just a subtle shadow change. */
.variant-meta input[type="checkbox"] {
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--rarity-color, var(--canvas-border-hover));
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}

.variant-meta input[type="checkbox"]:hover {
  border-color: var(--rarity-color, var(--ink-muted));
  transform: scale(1.08);
}

.variant-meta input[type="checkbox"]::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--canvas);
  border: 1px solid rgba(0,0,0,0.3);
  opacity: 0;
}

.variant-meta input[type="checkbox"]:checked {
  background:
    linear-gradient(var(--parchment), var(--parchment)) top / 100% 46% no-repeat,
    linear-gradient(var(--rarity-color, var(--ink-faint)), var(--rarity-color, var(--ink-faint))) bottom / 100% 54% no-repeat;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--rarity-color, #fff) 35%, transparent), 0 1px 4px rgba(0,0,0,0.5);
}

.variant-meta input[type="checkbox"]:checked::after { opacity: 1; }

/* Per-rarity accent binding: sets --rarity-color for the tile/variant subtree */
.rarity-C   { --rarity-color: var(--rarity-C); }
.rarity-TD  { --rarity-color: var(--rarity-TD); }
.rarity-U   { --rarity-color: var(--rarity-U); }
.rarity-R   { --rarity-color: var(--rarity-R); }
.rarity-RR  { --rarity-color: var(--rarity-RR); }
.rarity-SR  { --rarity-color: var(--rarity-SR); }
.rarity-OSR { --rarity-color: var(--rarity-OSR); }
.rarity-SP  { --rarity-color: var(--rarity-SP); }
.rarity-SSP { --rarity-color: var(--rarity-SSP); }
.rarity-TSP { --rarity-color: var(--rarity-TSP); }
.rarity-TSR { --rarity-color: var(--rarity-TSR); }

@media (max-width: 480px) {
  .topbar { padding: 14px 16px; }
  .grid { padding: 14px; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); }
}

/* Detail showcase — the clicked card lifts from its grid slot and
   grows into this centered view (see openDetail's FLIP transform). */
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 8, 6, 0.72);
  backdrop-filter: blur(3px);
}

.detail-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  gap: 18px;
  width: min(760px, 92vw);
  max-height: 90vh;
  background: var(--canvas-elevated);
  border: 1px solid var(--canvas-border-hover);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,0.7);
}

/* Side-by-side (image left, text right) keeps the whole card short
   enough to read without scrolling. Falls back to a stack + scroll
   only on narrow screens where that's unavoidable. */
@media (max-width: 560px) {
  .detail-card {
    flex-direction: column;
    max-height: 85vh;
    overflow-y: auto;
  }
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--canvas-border-hover);
  background: rgba(23, 20, 15, 0.8);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.detail-img {
  width: 230px;
  flex-shrink: 0;
  aspect-ratio: 5 / 7;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  background: #0c0a08;
  border: 1px solid var(--canvas-border);
}

/* Structure cards are rotated in the grid to keep tiles uniform, but
   here in the detail view they show their true landscape orientation. */
.detail-img.landscape {
  width: 320px;
  aspect-ratio: 7 / 5;
}

.detail-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

@media (max-width: 560px) {
  .detail-img { width: 100%; aspect-ratio: 5 / 7; }
  .detail-img.landscape { aspect-ratio: 7 / 5; }
  .detail-body { padding-top: 12px; justify-content: flex-start; }
}

.detail-number {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
}

.detail-name {
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 4px 0 12px;
}

.detail-stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px dashed var(--canvas-border);
}

.detail-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-stat-label {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.detail-stat-value {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--ink);
}

.howto-card {
  display: block;
  width: min(560px, 92vw);
}

.howto-body { padding-top: 0; }

.howto-p {
  font-family: var(--font-body);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--ink-muted);
  margin: 0 0 12px;
}

.howto-p strong { color: var(--ink); }

.howto-p a {
  color: var(--rarity-SR);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--rarity-SR) 50%, transparent);
}

.detail-effect {
  font-family: var(--font-body);
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--ink-muted);
  white-space: pre-line;
  margin: 0;
}
