:root {
  --bg: #0a0a0e;
  --bg-panel: #121218;
  --border: #2a2a35;
  --text: #c9c9d4;
  --text-dim: #6a6a78;
  --accent: #8b2fc9;
  --accent-2: #4bc9f0;
  --danger: #c9385a;
  --ok: #52c97a;
  font-family: 'Share Tech Mono', 'Courier New', monospace;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  color: var(--text);
  font-family: 'Share Tech Mono', 'Courier New', monospace;
}
body {
  /* A soft atmospheric backdrop so wide viewports don't read as an empty
     void around the centered content -- a faint red glow plus a very fine
     hatch texture, all CSS, no image assets. The purple glow lives on
     ::before below instead, so it can pulse independently. */
  background:
    radial-gradient(ellipse 800px 560px at 100% 100%, rgba(201, 56, 90, 0.09), transparent 70%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.015) 0px, rgba(255, 255, 255, 0.015) 1px, transparent 1px, transparent 3px),
    var(--bg);
  background-attachment: fixed;
}
/* The purple glow, isolated on its own layer so opacity/scale can animate
   smoothly (cheap, GPU-friendly) without repainting the gradient itself.
   ::before paints behind body's normal-flow content by default stacking
   order, so no content is ever covered by it. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse 1300px 750px at 50% 0%, rgba(139, 47, 201, 0.4), transparent 75%);
  transform-origin: 50% 0%;
  animation: bg-heartbeat 4s ease-in-out infinite;
}
@keyframes bg-heartbeat {
  0%, 100% { opacity: 0.7;  transform: scale(1); }
  14%      { opacity: 0.9;  transform: scale(1.03); }
  28%      { opacity: 0.7;  transform: scale(1); }
  42%      { opacity: 1;    transform: scale(1.06); }
  70%      { opacity: 0.7;  transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; opacity: 0.8; }
}
.hidden { display: none !important; }

button {
  font-family: inherit;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 0.92rem;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; }
button:disabled:hover { border-color: var(--border); color: var(--text); }

input[type="text"], textarea {
  font-family: inherit;
  background: #050507;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 8px;
  width: 100%;
  resize: none;
}
.muted { color: var(--text-dim); font-size: 0.82rem; }
.error { color: var(--danger); min-height: 1.2em; font-size: 0.82rem; }

.screen {
  min-height: 100vh; padding: 20px 16px 60px;
  display: flex; flex-direction: column; align-items: center;
  width: 100%;
  /* Fires whenever a screen's display flips from none to flex (i.e. every
     showScreen() switch) -- an animation restarts on that transition even
     with no class change, so plain map<->combat<->shop swaps get a soft
     fade+rise instead of an instant snap, no JS timing required. */
  animation: screen-fade-in 0.28s ease-out;
}
@keyframes screen-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
}
.title-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }

/* ---------- Top bar (shown on every in-run screen) ---------- */
#top-bar {
  position: sticky; top: 0; z-index: 20; width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--bg); border-bottom: 1px solid var(--border);
}
#top-bar-title { color: var(--accent); font-weight: bold; letter-spacing: 0.12em; font-size: 0.85rem; }
#top-bar-actions { display: flex; gap: 8px; }
#top-bar-actions button { padding: 5px 12px; font-size: 0.78rem; }

/* ---------- Title screen ---------- */
#title-screen { display: flex; align-items: center; justify-content: center; }
.title-box {
  position: relative;
  max-width: 620px; width: 100%; text-align: center;
  border: 1px solid var(--border); background: var(--bg-panel);
  padding: 36px 28px; border-radius: 6px;
}
.music-toggle {
  position: absolute; top: 10px; right: 10px;
  padding: 4px 10px; font-size: 0.72rem; color: var(--text-dim);
}
#banner {
  display: inline-block; margin: 0; text-align: left;
  font-size: clamp(8px, 2vw, 12px); line-height: 1.15;
  color: var(--accent);
  animation: banner-drift 6s ease-in-out infinite;
}
@keyframes banner-drift {
  0%, 100% { transform: translateY(0); text-shadow: 0 0 12px rgba(139, 47, 201, 0.6); }
  50%      { transform: translateY(-6px); text-shadow: 0 0 22px rgba(139, 47, 201, 0.95); }
}
@media (prefers-reduced-motion: reduce) {
  #banner { animation: none; text-shadow: 0 0 12px rgba(139, 47, 201, 0.6); }
}
.subtitle { color: var(--text-dim); margin-top: 10px; letter-spacing: 0.1em; }
#resume-form { margin-top: 22px; max-width: 360px; margin-left: auto; margin-right: auto; }
#resume-form .title-actions { margin-top: 8px; }
.ad-slot {
  width: 100%; min-height: 90px; margin-top: 20px;
  border: 1px dashed var(--border); border-radius: 6px;
  background: var(--bg-panel);
  display: flex; align-items: center; justify-content: center;
}
.footer-links {
  margin-top: 14px; display: flex; gap: 16px; justify-content: center;
  flex-wrap: wrap;
}
.footer-links a { color: var(--text-dim); font-size: 0.75rem; text-decoration: none; }
.footer-links a:hover { color: var(--text); }

/* ---------- Map screen ---------- */
#run-bar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 20px; font-size: 0.85rem;
}
.rb-stat { color: var(--text-dim); }
.rb-stat span { color: var(--accent-2); font-weight: bold; }

#node-map { display: flex; flex-direction: column; gap: 14px; align-items: center; max-width: 500px; margin: 0 auto; }
.map-row { display: flex; gap: 22px; justify-content: center; }
.map-node {
  width: 48px; height: 48px; border-radius: 50%; font-size: 1.3rem;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--border); background: var(--bg-panel); color: var(--text-dim);
}
.map-node.available { border-color: var(--accent); color: var(--accent); cursor: pointer; }
.map-node.available:hover { background: rgba(139, 47, 201, 0.15); }
.map-node.cleared { border-color: var(--ok); color: var(--ok); opacity: 0.6; }
.map-node.current { border-color: var(--accent-2); color: var(--accent-2); }
.map-node.locked { opacity: 0.3; }

/* ---------- Combat screen ---------- */
#combat-screen { max-width: 900px; width: 100%; margin: 0 auto; }
#combat-top { display: flex; gap: 16px; margin-bottom: 12px; align-items: stretch; }
#enemy-panel, #player-panel {
  flex: 1; min-width: 0;
  border: 1px solid var(--border); background: var(--bg-panel); border-radius: 6px;
  padding: 18px; text-align: center;
  position: relative; overflow: hidden;
}
#player-panel { display: flex; flex-direction: column; justify-content: center; }
#player-panel-label { color: var(--ok); font-weight: bold; margin-bottom: 10px; letter-spacing: 0.06em; }
#enemy-art { color: var(--danger); font-size: 0.95rem; line-height: 1.15; margin: 0 0 10px; }
#enemy-name { color: var(--accent); font-weight: bold; margin-bottom: 8px; font-size: 1.05rem; }
/* Elites reuse the regular roster's art/stats-shape but read as a distinct,
   tougher threat via an amber tint instead of just a bigger HP bar. */
#enemy-panel.elite { border-color: #d9a441; box-shadow: 0 0 16px rgba(217, 164, 65, 0.35); }
#enemy-panel.elite #enemy-name { color: #d9a441; text-shadow: 0 0 8px rgba(217, 164, 65, 0.6); }
#enemy-panel.elite #enemy-art { color: #d9a441; }
.hp-bar { height: 12px; background: #050507; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.hp-fill { height: 100%; background: var(--danger); transition: width 0.2s ease; }
.hp-fill.player { background: var(--ok); }
.hp-text { font-size: 0.85rem; color: var(--text-dim); margin-top: 5px; }
.status-row { font-size: 0.82rem; color: var(--accent-2); min-height: 1.2em; margin-top: 5px; }
.intent { font-size: 0.9rem; color: var(--danger); margin-top: 10px; font-weight: bold; }
.intent-secondary { font-size: 0.78rem; color: var(--text-dim); font-weight: normal; margin-top: 3px; }
#player-meta { display: flex; justify-content: center; gap: 22px; margin-top: 10px; font-size: 0.9rem; }
#player-meta span span { color: var(--accent-2); font-weight: bold; }

#hand { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 20px 0; }
@media (max-width: 720px) {
  #combat-top { flex-direction: column; }
}

/* ---------- Combat FX: floating numbers + panel impact flashes ---------- */
.fx-layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 5; }
.fx-number {
  position: absolute; left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  font-weight: bold; white-space: nowrap; font-size: 1.7rem;
  animation: fx-float 0.9s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}
.fx-number.fx-big { font-size: 2.5rem; }
.fx-number.dmg      { color: #ff4d4d; text-shadow: 0 0 6px rgba(255, 77, 77, 0.9), 0 0 16px rgba(255, 77, 77, 0.5); }
.fx-number.dmg-self { color: #ff9a4d; text-shadow: 0 0 6px rgba(255, 154, 77, 0.9), 0 0 16px rgba(255, 154, 77, 0.5); }
.fx-number.heal     { color: #50f080; text-shadow: 0 0 6px rgba(80, 240, 128, 0.9), 0 0 16px rgba(80, 240, 128, 0.5); }
.fx-number.block    { color: #4bc9f0; text-shadow: 0 0 6px rgba(75, 201, 240, 0.9), 0 0 16px rgba(75, 201, 240, 0.5); }
.fx-number.status   { color: #e06bd8; font-size: 1.1rem; text-shadow: 0 0 6px rgba(224, 107, 216, 0.8); }
.fx-number.survive  { color: #ffe066; font-size: 2.1rem; text-shadow: 0 0 10px rgba(255, 224, 102, 0.9), 0 0 22px rgba(255, 224, 102, 0.6); }

@keyframes fx-float {
  0%   { transform: translate(-50%, -50%) scale(1.7); opacity: 0; }
  18%  { transform: translate(-50%, -62%) scale(1);   opacity: 1; }
  100% { transform: translate(-50%, -160%) scale(0.85); opacity: 0; }
}

/* ---------- Enemy turn telegraph ---------- */
/* The instant End Turn is clicked, a brief wind-up plays on the enemy
   panel matching its already-shown intent, so the hit that follows a
   beat later (see main.js's ENEMY_TELEGRAPH_MS) reads as anticipation-
   then-strike instead of landing with no warning. Cleared the moment the
   real action fx (panel-hit etc. below) take over. */
#enemy-panel.telegraph-attack, #enemy-panel.telegraph-defend, #enemy-panel.telegraph-debuff {
  animation: telegraph-panel 0.38s ease-in forwards;
}
#enemy-panel.telegraph-attack #enemy-art,
#enemy-panel.telegraph-defend #enemy-art,
#enemy-panel.telegraph-debuff #enemy-art {
  animation: telegraph-art 0.38s ease-in forwards;
}
#enemy-panel.telegraph-attack { --telegraph-rgb: 201, 56, 90; }  /* --danger, matches an incoming hit */
#enemy-panel.telegraph-defend { --telegraph-rgb: 75, 201, 240; } /* --accent-2, matches Block fx */
#enemy-panel.telegraph-debuff { --telegraph-rgb: 224, 107, 216; } /* matches .fx-number.status */

@keyframes telegraph-panel {
  0%   { box-shadow: inset 0 0 0 rgba(0, 0, 0, 0); }
  100% { box-shadow: inset 0 0 30px rgba(var(--telegraph-rgb), 0.55); }
}
@keyframes telegraph-art {
  0%   { transform: scale(1); filter: brightness(1); }
  100% { transform: scale(1.1); filter: brightness(1.5) drop-shadow(0 0 8px rgba(var(--telegraph-rgb), 0.9)); }
}

.panel-hit     { animation: panel-shake 0.35s ease-out, panel-hit-flash 0.4s ease-out; }
.panel-blocked { animation: panel-block-flash 0.4s ease-out; }
.panel-heal    { animation: panel-heal-flash 0.45s ease-out; }

@keyframes panel-hit-flash {
  0%   { box-shadow: inset 0 0 50px rgba(201, 56, 90, 0.9); filter: brightness(1.7) saturate(1.4); border-color: var(--danger); }
  100% { box-shadow: inset 0 0 0 rgba(201, 56, 90, 0); filter: brightness(1) saturate(1); }
}
@keyframes panel-block-flash {
  0%   { box-shadow: inset 0 0 40px rgba(75, 201, 240, 0.85); filter: brightness(1.4); border-color: var(--accent-2); }
  100% { box-shadow: inset 0 0 0 rgba(75, 201, 240, 0); filter: brightness(1); }
}
@keyframes panel-heal-flash {
  0%   { box-shadow: inset 0 0 40px rgba(80, 240, 128, 0.8); filter: brightness(1.35); border-color: var(--ok); }
  100% { box-shadow: inset 0 0 0 rgba(80, 240, 128, 0); filter: brightness(1); }
}
@keyframes panel-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}
.card-btn {
  width: 120px; min-height: 130px; display: flex; flex-direction: column;
  align-items: center; text-align: center; padding: 8px; gap: 4px;
  border-width: 2px; position: relative;
}
.card-btn .card-cost {
  position: absolute; top: 4px; left: 6px; color: var(--accent-2); font-weight: bold; font-size: 0.85rem;
}
.card-btn .card-name { font-weight: bold; font-size: 0.85rem; margin-top: 14px; }
.card-btn .card-type { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; }
.card-btn .card-desc { font-size: 0.72rem; color: var(--text); line-height: 1.3; }
.card-btn.rarity-common { border-color: var(--border); }
.card-btn.rarity-uncommon { border-color: var(--accent-2); }
.card-btn.rarity-rare { border-color: var(--accent); }
.card-btn.rarity-starter { border-color: var(--border); }
.card-btn.type-power { background: rgba(139, 47, 201, 0.1); }
/* Upgraded cards (Rest node) -- a persistent violet inset glow so "this
   one's been upgraded" reads at a glance, distinct from the brief played
   animation below which uses the same color for the opposite reason (a
   one-off flourish, not a standing marker). */
.card-btn.upgraded { box-shadow: inset 0 0 0 1px var(--accent), 0 0 10px rgba(139, 47, 201, 0.45); }
.card-btn.upgraded .card-name { color: var(--accent); }

/* The moment you click a card: it pops, glows in its rarity color, lifts,
   and fades -- so the payoff of playing a card is felt on the card itself,
   not only on the target panel's fx. main.js delays the hand's re-render
   until this finishes (see CARD_PLAY_ANIM_MS) so there's time to see it. */
.card-btn.played { animation: card-play-pop 0.32s ease-out forwards; pointer-events: none; }
.card-btn.played.rarity-common { box-shadow: 0 0 20px rgba(201, 201, 212, 0.5); }
.card-btn.played.rarity-uncommon { box-shadow: 0 0 22px rgba(75, 201, 240, 0.7); }
.card-btn.played.rarity-rare { box-shadow: 0 0 26px rgba(139, 47, 201, 0.85); }
.card-btn.played.rarity-starter { box-shadow: 0 0 18px rgba(255, 255, 255, 0.4); }
@keyframes card-play-pop {
  0%   { transform: scale(1) translateY(0); opacity: 1; }
  35%  { transform: scale(1.14) translateY(-8px); opacity: 1; }
  100% { transform: scale(0.85) translateY(-46px); opacity: 0; }
}

.combat-actions { display: flex; justify-content: center; margin-bottom: 12px; }
#combat-log {
  max-width: 640px; width: 100%; margin: 0 auto; max-height: 140px; overflow-y: auto;
  font-size: 0.8rem; color: var(--text-dim); border-top: 1px solid var(--border); padding-top: 10px;
}

/* ---------- Shop / Event / Rest ---------- */
#shop-screen, #event-screen, #rest-screen { max-width: 560px; margin: 0 auto; text-align: center; }
#shop-screen h2, #event-screen h2, #rest-screen h2 { color: var(--accent); }
#event-text { color: var(--text); line-height: 1.5; margin: 14px 0 22px; }
#event-choices { display: flex; flex-direction: column; gap: 8px; max-width: 360px; margin: 0 auto; }

.shop-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--border); background: var(--bg-panel); border-radius: 4px;
  padding: 10px 14px; margin-bottom: 8px; text-align: left;
}
.shop-row-name { font-weight: bold; color: var(--accent); font-size: 0.88rem; }
.shop-row-desc { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }
#shop-removal { margin-top: 16px; }
#shop-remove-list, #rest-remove-list, #rest-upgrade-list { display: flex; flex-direction: column; gap: 6px; max-width: 320px; margin: 10px auto 0; }
.remove-card-btn { text-align: left; }
.remove-card-btn.upgraded { border-color: var(--accent); color: var(--accent); }

/* ---------- Reward / Deck / Relics / Leaderboard modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
.modal-box {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 22px 24px; max-width: 480px; width: 100%; max-height: 85vh; overflow-y: auto;
}
.modal-box h2 { color: var(--accent); margin-top: 0; }
.modal-box h3 { color: var(--accent-2); font-size: 0.95rem; margin: 18px 0 6px; }
.modal-box h3:first-of-type { margin-top: 4px; }
.modal-box p { font-size: 0.88rem; line-height: 1.5; }
.help-list { list-style: none; padding: 0; margin: 0 0 4px; font-size: 0.85rem; line-height: 1.7; }
.node-glyph { display: inline-block; width: 1.3em; text-align: center; color: var(--accent); }

#reward-cards { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 14px 0; }

.act-transition-box { text-align: center; }
.act-transition-sigil {
  color: var(--accent); font-size: 1.1rem; letter-spacing: 0.3em;
  text-shadow: 0 0 10px rgba(139, 47, 201, 0.7); margin-bottom: 6px;
}
#act-transition-title {
  color: var(--accent); font-size: 1.5rem; letter-spacing: 0.12em;
  margin: 10px 0; text-shadow: 0 0 12px rgba(139, 47, 201, 0.6);
}
#act-transition-flavor { font-style: italic; }
.act-transition-divider { color: var(--danger); letter-spacing: 0.6em; margin: 16px 0; opacity: 0.8; }
#act-transition-next { color: var(--text); font-size: 0.95rem; margin-bottom: 18px; }
#btn-continue-act { padding: 10px 28px; }

.deck-row {
  font-size: 0.82rem; padding: 6px 0; border-bottom: 1px solid var(--border); color: var(--text);
}
.deck-row.upgraded { color: var(--accent); }

#leaderboard-list { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; margin: 12px 0; }
.leaderboard-row {
  display: flex; align-items: center; gap: 10px; font-size: 0.85rem;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-panel);
}
.leaderboard-row.you { border-color: var(--accent); color: var(--accent); }
.lb-rank { width: 22px; color: var(--text-dim); text-align: right; }
.leaderboard-row.you .lb-rank { color: var(--accent); }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: var(--text-dim); }
.leaderboard-row.you .lb-score { color: var(--accent); }

/* ---------- Run-over ---------- */
#run-over-screen { max-width: 480px; margin: 0 auto; text-align: center; }
#run-over-screen h2 { color: var(--accent); }
#run-over-stats { margin: 14px 0; line-height: 1.6; }
#run-over-leaderboard-submit { max-width: 320px; margin: 0 auto 14px; }
#run-over-leaderboard-submit .title-actions { margin-top: 8px; }

@media (max-width: 560px) {
  #run-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .map-row { gap: 14px; }
  .map-node { width: 42px; height: 42px; font-size: 1.1rem; }
  .card-btn { width: 100px; min-height: 115px; }
}
