/* HordeHunt — Global Styles */
:root {
  --bg: #0a0a0f;
  --bg-card: #16161e;
  --bg-input: #1e1e28;
  --border: #2a2a3a;
  --text: #e0e0e8;
  --muted: #8888a0;
  --primary: #27ae60;
  --primary-hover: #2ecc71;
  --danger: #c0392b;
  --danger-hover: #e74c3c;
  --warn: #e67e22;
  --zombie: #6b8e23;
  --human: #3498db;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
}

.container { max-width: 900px; margin: 0 auto; padding: 20px; }

/* Nav */
.nav {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.nav a { color: var(--text); text-decoration: none; font-size: 14px; }
.nav a:hover { color: var(--primary); }
.nav-logo { font-size: 18px; font-weight: bold; margin-right: auto; }
.nav-user { color: var(--muted); font-size: 13px; margin-left: auto; }

/* Hero */
.hero { text-align: center; padding: 40px 0 20px; }
.hero h1 { font-size: 3rem; }
.hero-subtitle { color: var(--muted); font-size: 1.2rem; margin-top: 8px; }

/* Cards */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin: 16px 0;
}
.center-content { text-align: center; }

/* Forms */
label { display: block; font-size: 14px; margin: 12px 0 4px; color: var(--muted); }
.input {
  width: 100%; padding: 10px 14px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  font-size: 15px;
}
.input:focus { outline: none; border-color: var(--primary); }

/* Buttons */
.btn {
  display: inline-block; padding: 10px 20px; border: none; border-radius: 8px;
  font-size: 15px; cursor: pointer; text-decoration: none; color: var(--text);
  background: var(--bg-input); margin: 8px 4px 8px 0; transition: background 0.2s;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-input); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* Health bar */
.health-bar {
  position: relative; height: 28px; background: var(--bg-input);
  border-radius: 14px; overflow: hidden; margin: 12px 0;
  border: 1px solid var(--border);
}
.health-fill {
  position: absolute; top: 0; left: 0; height: 100%;
  background: linear-gradient(90deg, var(--danger), var(--warn), var(--primary));
  transition: width 0.5s;
}
.health-text {
  position: relative; z-index: 1; display: flex; align-items: center;
  justify-content: center; height: 100%; font-weight: bold; font-size: 13px;
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
}

/* Stats */
.stats-row { display: flex; gap: 16px; margin: 16px 0; flex-wrap: wrap; }
.stat { flex: 1; text-align: center; background: var(--bg-input); padding: 12px; border-radius: 8px; }
.stat-label { display: block; font-size: 12px; color: var(--muted); }
.stat-value { display: block; font-size: 24px; font-weight: bold; }

/* QR display */
.qr-display {
  display: flex; justify-content: center; align-items: center;
  margin: 16px auto; padding: 16px; background: #fff; border-radius: 8px;
  width: fit-content; min-height: 200px;
}
.qr-display canvas, .qr-display img { display: block; }
.qr-large { min-height: 360px; padding: 24px; }
.qr-in-chest { margin: 0; border-radius: 0 0 8px 8px; }

/* Loot chest */
.loot-chest {
  position: relative; width: 300px; max-width: 100%; margin: 20px auto;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4));
}
.loot-chest-large { width: 440px; }
.loot-chest-lid {
  height: 24px; background: linear-gradient(180deg, #8b6914 0%, #a67c1a 40%, #6b4f0f 100%);
  border-radius: 12px 12px 0 0; border: 2px solid #5a3e0a; border-bottom: none;
  position: relative; z-index: 2;
}
.loot-chest-lid::before {
  content: '🔒'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 14px;
}
.loot-chest-lid::after {
  content: ''; position: absolute; top: 2px; left: 8px; right: 8px; height: 4px;
  background: rgba(255,255,255,0.15); border-radius: 4px;
}
.loot-chest-body {
  background: linear-gradient(180deg, #6b4f0f 0%, #5a3e0a 100%);
  border: 2px solid #4a3008; border-top: none; border-radius: 0 0 12px 12px;
  padding: 4px; position: relative;
}
.loot-chest-body::before, .loot-chest-body::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 6px;
  background: rgba(255,255,255,0.05);
}
.loot-chest-body::before { left: 0; }
.loot-chest-body::after { right: 0; }
.loot-chest-body .qr-display {
  border-radius: 0 0 8px 8px; margin: 0; width: 100%;
}
.loot-scan-count {
  text-align: center; font-size: 14px; color: var(--muted); margin: 12px 0;
  font-family: monospace; letter-spacing: 2px;
}

/* Avatar — layered PNG compositing */
.avatar-display {
  display: flex; justify-content: center; align-items: center;
  background: linear-gradient(180deg, var(--bg-input) 0%, rgba(30,30,40,0.5) 100%);
  border-radius: 8px; padding: 16px; margin: 8px 0;
}
.avatar-sprite {
  position: relative; display: inline-block;
  image-rendering: pixelated;
  width: 128px; height: 128px;
}
.avatar-layer {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  image-rendering: pixelated;
}
/* Explicit z-index per layer guarantees correct stacking */
.avatar-layer[alt="body"]     { z-index: 1; }
.avatar-layer[alt="head"]      { z-index: 2; }
.avatar-layer[alt="hair"]      { z-index: 3; }
.avatar-layer[alt="arms"]      { z-index: 4; }
.avatar-layer[alt="torso"]     { z-index: 5; }
.avatar-layer[alt="legs"]      { z-index: 6; }
.avatar-layer[alt="feet"]      { z-index: 7; }
.avatar-layer[alt="headwear"]  { z-index: 8; }
.avatar-layer[alt="tools"]     { z-index: 9; }
.avatar-layer[alt="weapons"]   { z-index: 10; }
.avatar-large .avatar-sprite { width: 192px; height: 192px; }

/* View toggle */
.view-toggle {
  display: flex; gap: 4px; justify-content: center; margin: 8px 0;
}
.view-btn {
  padding: 6px 16px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 13px;
  transition: all 0.2s;
}
.view-btn:hover { border-color: var(--primary); color: var(--text); }
.view-btn.view-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Character QR card — avatar with QR on chest */
.char-qr-card {
  position: relative; display: flex; justify-content: center; align-items: center;
  margin: 16px auto; width: fit-content;
}
.char-qr-avatar {
  position: relative; z-index: 1;
}
.char-qr-avatar .avatar-sprite {
  width: 256px !important; height: 256px !important;
}
.char-qr-avatar .avatar-layer {
  image-rendering: pixelated;
}
.char-qr-overlay {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -15%);
  z-index: 2; pointer-events: none;
}
.qr-on-chest {
  background: #fff; padding: 6px; border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
}
.qr-on-chest canvas, .qr-on-chest img {
  display: block; image-rendering: pixelated;
}
.char-qr-actions {
  display: flex; gap: 8px; justify-content: center; margin: 16px 0; flex-wrap: wrap;
}
.char-card { text-align: center; }
.char-faction {
  display: inline-block; padding: 4px 12px; border-radius: 20px;
  font-size: 14px; font-weight: bold; margin: 8px 0;
}
.char-faction-zombie { background: rgba(107,142,35,0.2); color: var(--zombie); }
.char-faction-human { background: rgba(52,152,219,0.2); color: var(--human); }
.play-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

/* Effects */
.effects-list { margin: 12px 0; }
.effect-badge {
  display: inline-block; padding: 6px 12px; border-radius: 20px;
  font-size: 13px; margin: 4px 4px 4px 0; border: 1px solid;
}
.effect-shield { border-color: var(--human); color: var(--human); }
.effect-double_damage { border-color: var(--danger); color: var(--danger); }
.effect-kingpin { border-color: gold; color: gold; }
.effect-one_bite_killer { border-color: darkred; color: #ff4444; }

/* Titles */
.title-badge {
  display: inline-block; padding: 6px 12px; border-radius: 20px;
  background: rgba(255,215,0,0.1); border: 1px solid gold; color: gold;
  font-size: 13px; margin: 4px;
}

/* Play grid */
.play-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .play-grid { grid-template-columns: 1fr; } }

/* Faction choice */
.faction-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.faction-card {
  display: flex; flex-direction: column; align-items: center; padding: 20px;
  background: var(--bg-input); border: 2px solid var(--border); border-radius: 12px;
  cursor: pointer; transition: border-color 0.2s; text-align: center;
}
.faction-card:hover { border-color: var(--primary); }
.faction-card input { display: none; }
.faction-card input:checked + .faction-emoji { transform: scale(1.2); }
.faction-card:has(input:checked) { border-color: var(--primary); }
.faction-emoji { font-size: 48px; margin: 8px 0; }
.faction-name { font-weight: bold; font-size: 1.2rem; }
.faction-desc { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Customize */
.customize-grid { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
@media (max-width: 700px) { .customize-grid { grid-template-columns: 1fr; } }
.custom-category { margin: 12px 0; }
.custom-category h4 { margin-bottom: 8px; color: var(--muted); }
.custom-options { display: flex; flex-wrap: wrap; gap: 8px; }
.custom-opt {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; transition: all 0.2s; position: relative;
}
.custom-opt:hover { border-color: var(--primary); }
.custom-opt.selected { border-color: var(--primary); background: rgba(39,174,96,0.1); }
.custom-opt.locked { opacity: 0.4; cursor: not-allowed; }
.custom-opt.locked-next {
  opacity: 0.35; cursor: not-allowed; border-style: dashed;
  display: flex; flex-direction: column; gap: 2px; padding: 6px 12px;
}
.lock-note { font-size: 10px; color: var(--muted); }
.custom-opt input { display: none; }
.opt-label { font-size: 14px; }
.lock-icon { font-size: 12px; }
.color-swatch { width: 16px; height: 16px; border-radius: 4px; display: inline-block; }
.unlock-info {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 12px; background: var(--bg-input); border-radius: 8px; margin-bottom: 16px;
}
.score-display { font-weight: bold; }
.unlocks-display { color: var(--primary); font-weight: bold; }

/* Leaderboard */
.tabs { display: flex; gap: 4px; margin: 16px 0; }
.tab {
  padding: 8px 16px; background: var(--bg-input); border-radius: 8px;
  text-decoration: none; color: var(--muted); font-size: 14px;
}
.tab:hover { background: var(--border); }
.tab-active { background: var(--primary); color: #fff; }
.region-filter { margin-bottom: 16px; }
.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table th {
  text-align: left; padding: 10px; background: var(--bg-card);
  border-bottom: 2px solid var(--border); font-size: 14px; color: var(--muted);
}
.leaderboard-table td { padding: 10px; border-bottom: 1px solid var(--border); }
.row-zombie td { border-left: 3px solid var(--zombie); }
.row-human td { border-left: 3px solid var(--human); }
.rank-cell { font-weight: bold; text-align: center; width: 50px; }
.score-cell { text-align: right; font-weight: bold; font-family: monospace; }

/* Scan result */
.scan-result { padding: 32px 24px; }
.scan-changes { margin: 20px 0; text-align: left; }
.change-row { padding: 8px 12px; margin: 4px 0; border-radius: 8px; }
.change-row.good { background: rgba(39,174,96,0.15); }
.change-row.bad { background: rgba(192,57,43,0.15); }
.change-row.neutral { background: var(--bg-input); }
.scan-health-display { margin: 16px 0; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin: 12px 0; }
.alert-info { background: rgba(52,152,219,0.15); border:1px solid var(--human); }
.alert-success { background: rgba(39,174,96,0.15); border: 1px solid var(--primary); }
.alert-warn { background: rgba(230,126,34,0.15); border: 1px solid var(--warn); }
.alert-danger { background: rgba(192,57,43,0.15); border: 1px solid var(--danger); }
.alert-power { background: rgba(155,89,182,0.15); border: 1px solid #9b59b6; }

/* Revive */
.revive-options { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin: 20px 0; }
@media (max-width: 700px) { .revive-options { grid-template-columns: 1fr; } }

/* Misc */
.muted { color: var(--muted); }
.center { text-align: center; }
.rules-list { list-style: none; padding: 0; }
.rules-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.rules-list li:last-child { border-bottom: none; }

/* Print — ink-saving: white backgrounds, no gradients/shadows, only the card */
@media print {
  /* Hide everything by default, then show only what we need */
  body * { visibility: hidden; }
  .char-qr-card, .char-qr-card *,
  .loot-chest-card, .loot-chest-card *,
  #loot-qr, .loot-chest, .loot-chest * { visibility: visible; }

  body { background: #fff !important; color: #000 !important; margin: 0; }
  .nav, .play-actions, .btn, .view-toggle, .char-qr-actions,
  .play-left, .stats-row, .char-faction, .loot-scan-count { display: none !important; }

  /* Strip all decorative backgrounds and shadows */
  .card, .qr-card, .avatar-display, .char-qr-card, .qr-display,
  .loot-chest, .loot-chest-lid, .loot-chest-body {
    background: #fff !important;
    border: none !important;
    box-shadow: none !important;
    filter: none !important;
  }

  /* Enlarge character for print */
  .char-qr-card { position: static; page-break-inside: avoid; }
  .char-qr-avatar .avatar-sprite { width: 400px !important; height: 400px !important; }
  .qr-on-chest { padding: 10px; box-shadow: none !important; }
  .qr-on-chest canvas { width: 180px !important; height: 180px !important; }

  /* Loot chest: drop wood styling, just show the QR */
  .loot-chest { width: 100% !important; max-width: 400px; margin: 0 auto; }
  .loot-chest-lid, .loot-chest-body { background: #fff !important; border: none !important; }
  .loot-chest-lid::before, .loot-chest-lid::after,
  .loot-chest-body::before, .loot-chest-body::after { display: none !important; }
  .qr-in-chest { border: none !important; }
}