/* ==========================================================================
   Riftbound Lab — design system.
   Deep navy, gold rules, glassy panels, HD card art as the hero.
   Everything here is shared by the table and the client pages.
   ========================================================================== */

:root {
  /* surfaces */
  --void: #04060d;
  --navy-900: #070b16;
  --navy-800: #0b1120;
  --navy-700: #111a2e;
  --navy-600: #17223c;
  --navy-500: #1f2c4c;
  --glass: rgba(16, 25, 45, 0.72);
  --glass-hi: rgba(30, 45, 78, 0.55);

  /* gold */
  --gold: #c8aa6e;
  --gold-hi: #f0e6d2;
  --gold-dim: #7d6434;
  --gold-line: rgba(200, 170, 110, 0.28);
  --gold-line-hi: rgba(200, 170, 110, 0.6);

  /* text */
  --ink: #e8eefb;
  --ink-soft: #b7c4dd;
  --ink-mute: #7f8dab;

  /* status */
  --good: #57c98a;
  --warn: #e6b24a;
  --bad: #e2584a;
  --info: #59a7e0;

  /* domains */
  --d-fury: #e0483c;
  --d-calm: #29a8bd;
  --d-mind: #8064de;
  --d-body: #6aab48;
  --d-chaos: #c94fae;
  --d-order: #e3bc55;

  /* geometry — 8px scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 14px;
  --card-ratio: 1.3965; /* 1039 / 744 — portrait cards are never squashed */
  --card-ratio-land: 0.7168; /* 744 / 1038 — battlefields are printed landscape */

  /* motion */
  --speed: 1;
  --t-fast: 140ms;
  --t-mid: 260ms;
  --t-slow: 420ms;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  --font-display: 'Cinzel', 'Trajan Pro', 'Optima', 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  --font-ui: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-num: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Roboto Mono', Menlo, Consolas, monospace;

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--void);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body::before {
  /* ambient rift glow behind everything */
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(120% 80% at 50% -20%, rgba(56, 96, 168, 0.28), transparent 60%),
    radial-gradient(90% 60% at 8% 106%, rgba(200, 170, 110, 0.12), transparent 62%),
    radial-gradient(90% 60% at 96% 8%, rgba(128, 100, 222, 0.12), transparent 60%),
    linear-gradient(180deg, var(--navy-900), var(--void));
}
.app { position: relative; z-index: 1; height: 100dvh; width: 100vw; overflow: hidden; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(200, 170, 110, 0.24); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(200, 170, 110, 0.44); }

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: 0.04em; margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-hi); }
p { margin: 0 0 var(--s3); color: var(--ink-soft); line-height: 1.55; }

/* ------------------------------ primitives ------------------------------ */

.panel {
  background: var(--glass);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-lg);
  backdrop-filter: blur(9px) saturate(1.1);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.panel-title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--gold-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  flex: 0 0 auto;
}
.rule { height: 1px; background: linear-gradient(90deg, transparent, var(--gold-line-hi), transparent); border: 0; margin: var(--s3) 0; }

.btn {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--gold-hi);
  background: linear-gradient(180deg, rgba(40, 58, 96, 0.9), rgba(18, 28, 50, 0.9));
  border: 1px solid var(--gold-line-hi);
  border-radius: var(--r-md);
  padding: 7px 14px;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease), border-color var(--t-fast);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--gold); box-shadow: 0 5px 18px rgba(200, 170, 110, 0.22); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #d8bb7c, #9c7c3e); color: #16110b; border-color: #e6d1a1; text-shadow: none; }
.btn.primary:hover:not(:disabled) { box-shadow: 0 6px 22px rgba(200, 170, 110, 0.45); }
.btn.ghost { background: transparent; border-color: var(--gold-line); color: var(--ink-soft); }
.btn.ghost:hover:not(:disabled) { color: var(--gold-hi); }
.btn.danger { border-color: rgba(226, 88, 74, 0.55); color: #ffb9b1; }
.btn.danger:hover:not(:disabled) { box-shadow: 0 5px 18px rgba(226, 88, 74, 0.3); border-color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 11px; }
.btn.xs { padding: 2px 7px; font-size: 10px; border-radius: var(--r-sm); }
.btn.wide { width: 100%; justify-content: center; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: var(--s3); }
.field > label { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-mute); }
input, select, textarea {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: rgba(5, 9, 18, 0.72);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  padding: 8px 10px;
  outline: none;
  width: 100%;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(200, 170, 110, 0.14); }
textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
select option { background: var(--navy-800); }
label.check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-soft); cursor: pointer; }
label.check input { width: auto; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--gold-line);
  background: rgba(10, 16, 30, 0.7);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  white-space: nowrap;
}
.chip.gold { border-color: var(--gold-line-hi); color: var(--gold-hi); }
.chip.good { border-color: rgba(87, 201, 138, 0.5); color: var(--good); }
.chip.bad { border-color: rgba(226, 88, 74, 0.5); color: #ff9d92; }
.chip.warn { border-color: rgba(230, 178, 74, 0.5); color: var(--warn); }
.chip.live { border-color: rgba(87, 201, 138, 0.6); color: var(--good); }
.chip.live::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px var(--good); animation: pulse-dot 1.8s infinite; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.muted { color: var(--ink-mute); }
.soft { color: var(--ink-soft); }
.tiny { font-size: 11px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: var(--s2); }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll-y { overflow-y: auto; overflow-x: hidden; min-height: 0; }
.empty-note { color: var(--ink-mute); font-size: 12px; padding: var(--s5) var(--s3); text-align: center; }

/* ------------------------------ card faces ------------------------------ */
/* A card is the official HD art at 744:1039, never squashed. Small sizes get a
   readable overlay strip because the printed name is illegible below ~110px. */

.card {
  position: relative;
  width: var(--w, 100px);
  height: calc(var(--w, 100px) * var(--card-ratio));
  border-radius: calc(var(--w, 100px) * 0.055);
  overflow: hidden;
  flex: 0 0 auto;
  background: linear-gradient(160deg, var(--navy-600), var(--navy-900));
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.5);
  transition: transform var(--t-mid) var(--ease), box-shadow var(--t-mid) var(--ease), filter var(--t-mid);
  user-select: none;
  -webkit-user-drag: none;
  contain: paint;
}
.card > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
  -webkit-user-drag: none;
  pointer-events: none;
}
.card .card-strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8% 5% 4%;
  font-size: max(8px, calc(var(--w, 100px) * 0.098));
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.1;
  color: #fff;
  text-shadow: 0 1px 3px #000, 0 0 8px #000;
  background: linear-gradient(180deg, transparent, rgba(3, 6, 14, 0.86) 55%);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
.card[data-orient='landscape'] { height: calc(var(--w, 100px) * var(--card-ratio-land)); }
.card[data-orient='landscape'] > img { object-position: center center; }
.card.lg .card-strip, .card.no-strip .card-strip { display: none; }
.card .card-frame {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1.5px solid var(--frame, rgba(200, 170, 110, 0.5));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55), inset 0 0 14px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.card .badge {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: max(9px, calc(var(--w, 100px) * 0.14));
  min-width: max(16px, calc(var(--w, 100px) * 0.23));
  height: max(16px, calc(var(--w, 100px) * 0.23));
  padding: 0 3px;
  border-radius: 999px;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  pointer-events: none;
}
.card .badge.might { right: 4%; bottom: 4%; background: radial-gradient(circle at 30% 25%, #f4dfae, #a3762c); color: #1a1206; }
.card .badge.dmg { left: 4%; bottom: 4%; background: radial-gradient(circle at 30% 25%, #ff8a7a, #a1231a); }
.card .badge.cost { left: 4%; top: 4%; background: radial-gradient(circle at 30% 25%, #9fd6ff, #23507f); }

/* card back — pure CSS, no external assets */
.card.back { background: linear-gradient(150deg, #16203a 0%, #0a1024 45%, #131c33 100%); }
.card.back::before {
  content: '';
  position: absolute;
  inset: 8%;
  border-radius: calc(var(--w, 100px) * 0.03);
  border: 1px solid rgba(200, 170, 110, 0.4);
  background:
    radial-gradient(circle at 50% 42%, rgba(200, 170, 110, 0.3), transparent 58%),
    repeating-linear-gradient(45deg, rgba(200, 170, 110, 0.07) 0 3px, transparent 3px 7px);
}
.card.back::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 1.5px solid rgba(200, 170, 110, 0.72);
  box-shadow: 0 0 14px rgba(200, 170, 110, 0.35);
}

/* interaction */
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-6px) scale(1.04); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.72), 0 0 0 1px var(--gold-line-hi); z-index: 30; }
.card.playable { box-shadow: 0 0 0 2px var(--gold), 0 0 18px rgba(200, 170, 110, 0.55), 0 6px 18px rgba(0, 0, 0, 0.6); }
.card.picked { box-shadow: 0 0 0 3px var(--good), 0 0 22px rgba(87, 201, 138, 0.6); transform: translateY(-10px); }
.card.targetable { box-shadow: 0 0 0 2px var(--info), 0 0 18px rgba(89, 167, 224, 0.5); cursor: pointer; }
.card.dimmed { filter: brightness(0.42) saturate(0.5); }
/* Flagged cards carry a badge; only a spell the client refuses to play is dimmed out. */
.card.unscripted { box-shadow: 0 3px 10px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(230, 178, 74, 0.45); }
.card.blocked { filter: grayscale(0.45) brightness(0.86); }
/* The hatch lives on the frame, which paints above the art. */
.card.blocked .card-frame {
  border-color: rgba(226, 88, 74, 0.65);
  background: repeating-linear-gradient(-45deg, rgba(226, 88, 74, 0.2) 0 5px, transparent 5px 11px);
}

/* domain frames */
.card[data-domain='fury'] { --frame: var(--d-fury); }
.card[data-domain='calm'] { --frame: var(--d-calm); }
.card[data-domain='mind'] { --frame: var(--d-mind); }
.card[data-domain='body'] { --frame: var(--d-body); }
.card[data-domain='chaos'] { --frame: var(--d-chaos); }
.card[data-domain='order'] { --frame: var(--d-order); }
.card[data-domain='multi'] { --frame: var(--gold); }

/* ------------------------------ inspector ------------------------------ */

.inspector {
  position: fixed;
  z-index: 900;
  width: 320px;
  pointer-events: none;
  animation: inspect-in 160ms var(--ease);
}
.inspector[hidden] { display: none; }
@keyframes inspect-in { from { opacity: 0; transform: translateY(6px) scale(0.97); } to { opacity: 1; transform: none; } }
.inspector .card { --w: 320px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.85), 0 0 0 1px var(--gold-line-hi); border-radius: 12px; }
.inspector .ins-body {
  margin-top: 8px;
  background: rgba(6, 10, 20, 0.95);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  padding: 10px 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
}
.inspector .ins-name { font-family: var(--font-display); font-size: 15px; color: var(--gold-hi); margin-bottom: 4px; }
.inspector .ins-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 7px; }
.inspector .ins-text { font-size: 12px; line-height: 1.55; color: var(--ink-soft); white-space: pre-wrap; max-height: 200px; overflow: auto; }
.inspector .ins-flag { margin-top: 7px; font-size: 11px; color: var(--warn); }

/* ------------------------------ overlays ------------------------------ */

.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 800; overflow: hidden; }
.caption-layer { position: fixed; inset: 0; pointer-events: none; z-index: 810; display: flex; align-items: flex-start; justify-content: center; padding-top: 26vh; }

.toast-layer { position: fixed; right: 16px; bottom: 16px; z-index: 950; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto;
  background: rgba(8, 13, 26, 0.96);
  border: 1px solid var(--gold-line-hi);
  border-left: 3px solid var(--gold);
  border-radius: var(--r-md);
  padding: 9px 14px;
  font-size: 12px;
  color: var(--ink);
  max-width: 360px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.7);
  animation: toast-in 220ms var(--ease);
}
.toast.err { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--good); }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 940;
  background: rgba(2, 4, 10, 0.74);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s5);
}
.modal-layer[hidden] { display: none; }
.modal {
  width: min(560px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  animation: modal-in 200ms var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal .modal-body { padding: var(--s4); overflow-y: auto; min-height: 0; }
.modal .modal-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--gold-line); display: flex; gap: var(--s2); justify-content: flex-end; flex: 0 0 auto; }

/* ------------------------------ reduced motion --------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
body.no-motion *, body.no-motion *::before, body.no-motion *::after {
  animation-duration: 1ms !important;
  transition-duration: 1ms !important;
}
