/* ============================================================
   ARCANE LEDGER — design tokens
   Palette: obsidian ground + aged-gold foil, five mana-pip accents
   Type: Cinzel (display, ceremonial) / Inter (body) / JetBrains Mono (stats)
   Signature: foil-sweep — a diagonal holographic highlight that
   travels across trophy & victory surfaces, like tilting a foil card.
   ============================================================ */

:root {
  --bg: #0b0a10;
  --bg-deep: #060509;
  --surface: #161320;
  --surface-2: #1f1a2c;
  --border: #2c2438;

  --gold: #c9a24b;
  --gold-bright: #f0d78c;
  --gold-dim: #8a7136;

  --text: #ece6f2;
  --text-dim: #a89bc2;
  --text-faint: #6f6485;

  --mana-w: #f4ecd8;
  --mana-u: #3a8fdb;
  --mana-b: #9c8bc4;
  --mana-r: #d1553a;
  --mana-g: #4f9c5c;

  --win: #4f9c5c;
  --loss: #7a6d90;
  --draw: #c9a24b;

  --radius: 10px;
  --radius-lg: 18px;
  --font-display: "Cinzel", serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #14101d 0%, var(--bg-deep) 60%);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
}

a { color: var(--gold-bright); }

/* ---------- ambient particle field ---------- */
#particle-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
#particle-field .mote {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.35;
  filter: blur(0.5px);
  animation: float-up linear infinite;
}
@keyframes float-up {
  from { transform: translateY(110vh) translateX(0); opacity: 0; }
  10% { opacity: 0.45; }
  90% { opacity: 0.3; }
  to { transform: translateY(-10vh) translateX(20px); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #particle-field { display: none; }
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: rgba(11, 10, 16, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--gold-bright); font-size: 20px; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 19px;
  color: var(--gold-bright);
  text-transform: uppercase;
}
.main-nav { display: flex; gap: 4px; }
.nav-link {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius);
  transition: all 0.15s ease;
  letter-spacing: 0.02em;
}
.nav-link:hover { color: var(--text); background: var(--surface); }
.nav-link.active { color: var(--gold-bright); background: var(--surface-2); border-color: var(--border); }
.nav-link-accent {
  background: linear-gradient(135deg, var(--mana-r), #8a2a3a);
  color: #fff;
  margin-left: 8px;
}
.nav-link-accent:hover { filter: brightness(1.1); }
.user-chip { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 13px; }
.hidden { display: none !important; }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--gold-dim); }

/* ---------- layout ---------- */
#app {
  position: relative;
  z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

h1, h2, h3 {
  font-family: var(--font-display);
  color: var(--gold-bright);
  letter-spacing: 0.02em;
  margin: 0 0 4px;
}
h1 { font-size: 28px; }
h2 { font-size: 20px; }
.subtitle { color: var(--text-faint); font-size: 14px; margin: 0 0 24px; }

.view-header { margin-bottom: 24px; display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* ---------- cards ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.card {
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.card h3 { font-size: 16px; margin-bottom: 6px; }
.card .meta { color: var(--text-faint); font-size: 12.5px; }

/* foil sweep — the signature element, used on trophy cards & victory surfaces */
.foil {
  position: relative;
  overflow: hidden;
}
.foil::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -60%;
  width: 40%;
  height: 200%;
  background: linear-gradient(
    100deg,
    transparent 0%,
    rgba(240, 215, 140, 0) 30%,
    rgba(240, 215, 140, 0.35) 48%,
    rgba(255, 245, 210, 0.55) 50%,
    rgba(240, 215, 140, 0.35) 52%,
    rgba(240, 215, 140, 0) 70%,
    transparent 100%
  );
  transform: rotate(20deg);
  animation: foil-sweep 3.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes foil-sweep {
  0% { left: -60%; }
  45% { left: 130%; }
  100% { left: 130%; }
}

/* ---------- mana pips ---------- */
.pips { display: flex; gap: 5px; }
.pip {
  width: 20px; height: 20px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #1a1a1a;
  border: 1px solid rgba(0,0,0,0.25);
  opacity: 0.25;
}
.pip.active { opacity: 1; box-shadow: 0 0 8px currentColor; }
.pip-w { background: var(--mana-w); }
.pip-u { background: var(--mana-u); color: #fff; }
.pip-b { background: var(--mana-b); }
.pip-r { background: var(--mana-r); color: #fff; }
.pip-g { background: var(--mana-g); color: #fff; }

/* ---------- forms ---------- */
.form-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  max-width: 420px;
}
label { display: block; font-size: 12.5px; color: var(--text-dim); margin: 12px 0 5px; font-weight: 600; }
input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 75, 0.15);
}
textarea { resize: vertical; min-height: 70px; }

.btn-primary {
  background: linear-gradient(135deg, var(--gold-bright), var(--gold-dim));
  color: #1a1408;
  border: none;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  letter-spacing: 0.02em;
  margin-top: 16px;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
}
.btn-secondary:hover { border-color: var(--gold-dim); }

.error-text { color: #e07a6b; font-size: 13px; margin-top: 8px; }

/* ---------- auth screen ---------- */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

/* ---------- badges ---------- */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-win { background: rgba(79, 156, 92, 0.18); color: var(--win); }
.badge-loss { background: rgba(122, 109, 144, 0.18); color: var(--loss); }
.badge-draw { background: rgba(201, 162, 75, 0.18); color: var(--draw); }

/* ============================================================
   LIVE MATCH / LIFE COUNTER
   ============================================================ */
.match-setup { max-width: 500px; }
.player-count-picker { display: flex; gap: 10px; margin: 10px 0 20px; }
.count-btn {
  flex: 1; padding: 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font-family: var(--font-display); font-size: 20px; font-weight: 700;
}
.count-btn.selected { border-color: var(--gold); color: var(--gold-bright); background: var(--surface-2); }

.life-picker { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 20px; }
.life-btn {
  padding: 10px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font-weight: 600; font-family: var(--font-mono);
}
.life-btn.selected { border-color: var(--gold); color: var(--gold-bright); }

.player-select-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 10px; margin: 10px 0 20px; max-height: 260px; overflow-y: auto; }
.player-pick {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius); padding: 10px; text-align: center; color: var(--text-dim); font-size: 13px; font-weight: 600;
}
.player-pick.selected { border-color: var(--gold); color: var(--gold-bright); background: var(--surface-2); }

.life-arena {
  position: fixed; inset: 0; z-index: 20;
  display: grid;
  background: var(--bg-deep);
}
.life-arena[data-count="2"] { grid-template-columns: 1fr 1fr; }
.life-arena[data-count="3"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.life-arena[data-count="3"] .life-panel:first-child { grid-column: 1 / span 2; }
.life-arena[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.life-panel {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  padding: 20px;
  transition: background 0.4s ease, opacity 0.4s ease;
  overflow: hidden;
}
.life-panel::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 30%, var(--panel-accent, #2c2438) 0%, transparent 65%);
  opacity: 0.35;
  pointer-events: none;
}
.life-panel.eliminated {
  opacity: 0.28;
  filter: grayscale(0.8);
}
.life-panel.eliminated::after {
  content: "✕";
  position: absolute;
  font-size: 120px;
  color: rgba(255,255,255,0.08);
  font-family: var(--font-display);
}
.life-panel-name { font-family: var(--font-display); font-size: 18px; color: var(--gold-bright); z-index: 1; }
.life-panel-commander { color: var(--text-faint); font-size: 12px; margin-top: 2px; z-index: 1; }
.life-total {
  font-family: var(--font-mono); font-weight: 700; font-size: 96px; line-height: 1;
  margin: 14px 0; z-index: 1;
  color: var(--text);
}
.life-controls { display: flex; gap: 18px; z-index: 1; }
.life-btn-adj {
  width: 62px; height: 62px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--gold-bright); font-size: 28px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
}
.life-btn-adj:active { transform: scale(0.94); background: var(--surface-2); }
.exit-match {
  position: fixed; top: 14px; right: 14px; z-index: 25;
}

/* ============================================================
   VICTORY CELEBRATIONS
   ============================================================ */
#celebration-root { position: fixed; inset: 0; pointer-events: none; z-index: 100; }

.celebration-banner {
  position: fixed; top: 40%; left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 2px solid var(--gold);
  border-radius: var(--radius-lg);
  padding: 36px 52px;
  text-align: center;
  box-shadow: 0 0 60px rgba(240, 215, 140, 0.35), 0 0 120px rgba(240, 215, 140, 0.15);
  animation: banner-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) forwards, banner-glow 1.8s ease-in-out infinite;
  pointer-events: auto;
}
@keyframes banner-in {
  to { transform: translate(-50%, -50%) scale(1); }
}
@keyframes banner-glow {
  0%, 100% { box-shadow: 0 0 60px rgba(240, 215, 140, 0.3), 0 0 120px rgba(240, 215, 140, 0.12); }
  50% { box-shadow: 0 0 90px rgba(240, 215, 140, 0.55), 0 0 160px rgba(240, 215, 140, 0.25); }
}
.celebration-banner .trophy-icon {
  font-size: 52px; display: block; margin-bottom: 10px;
  animation: trophy-float 2.4s ease-in-out infinite;
}
@keyframes trophy-float {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-10px) rotate(3deg); }
}
.celebration-banner h2 { font-size: 26px; margin-bottom: 4px; }
.celebration-banner p { color: var(--text-dim); margin: 0; font-size: 14px; }
.celebration-banner button {
  margin-top: 18px;
}

.confetti-piece {
  position: fixed;
  top: -20px;
  width: 9px; height: 14px;
  opacity: 0.95;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.3; }
}

@media (prefers-reduced-motion: reduce) {
  .foil::before, .celebration-banner, .trophy-icon, .confetti-piece { animation: none !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .main-nav { order: 3; width: 100%; overflow-x: auto; }
  .life-total { font-size: 64px; }
  .life-btn-adj { width: 50px; height: 50px; font-size: 22px; }
}
