/* ================================================================
  STYLE.CSS — MTG Life Counter
  Aesthetic: Dark arcane tavern board. Deep blacks, aged parchment
  accents, gold trim. Feels like a physical card game.
================================================================ */

/* ---- CSS Custom Properties (Variables) ----------------------
   Variables let us define colors/values once and reuse them
   everywhere. Change --gold here and it changes everywhere.
---------------------------------------------------------------- */
:root {
  --bg-deep:        #0a0a0f;
  --bg-card:        #12121a;
  --bg-card-hover:  #1a1a26;
  --bg-modal:       #16161f;
  --gold:           #c9a84c;
  --gold-light:     #e8c96a;
  --gold-dim:       #7a6030;
  --crimson:        #8b1a1a;
  --crimson-bright: #cc2222;
  --text-primary:   #f0e8d8;
  --text-dim:       #8a8070;
  --text-muted:     #4a4540;
  --border:         #2a2520;
  --border-gold:    #3a3020;

  /* MTG color identity colors */
  --mana-W: #f9f6e8;
  --mana-U: #4a90d9;
  --mana-B: #8b6bb1;
  --mana-R: #e05030;
  --mana-G: #4a9a60;

  /* Infect warning color */
  --infect-color: #7abf3a;

  --radius:   8px;
  --radius-lg: 14px;
  --shadow:   0 4px 24px rgba(0,0,0,0.6);
}

/* ---- Reset & Base ------------------------------------------ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden; /* prevents scroll bouncing on mobile */
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'Rajdhani', sans-serif;
  font-size: 16px;
  /* Prevent text selection during rapid tapping */
  -webkit-user-select: none;
  user-select: none;
}

/* ---- Screen system -----------------------------------------
   Both screens exist in the DOM at once.
   "active" makes one visible; the other stays hidden (display:none).
---------------------------------------------------------------- */
.screen {
  display: none;
  height: 100%;
  width: 100%;
}
.screen.active {
  display: flex;
  flex-direction: column;
}


/* ================================================================
  SETUP SCREEN
================================================================ */
#setup-screen {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(201,168,76,0.12) 0%, transparent 60%),
    var(--bg-deep);
  overflow-y: auto;
  padding: 2rem 1rem;
}

.setup-container {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  align-items: center;
}

.logo {
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: clamp(2rem, 6vw, 3rem);
  text-align: center;
  line-height: 1.1;
  color: var(--gold);
  /* Text shadow gives a soft glow */
  text-shadow: 0 0 40px rgba(201,168,76,0.4), 0 2px 4px rgba(0,0,0,0.8);
  letter-spacing: 0.05em;
}

.setup-section {
  width: 100%;
}

.setup-section h2 {
  font-family: 'Cinzel', serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gold-dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-gold);
}

/* Option buttons - the segmented selector look */
.option-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.option-btn {
  flex: 1;
  min-width: 80px;
  padding: 0.6rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.05em;
}

.option-btn:hover {
  border-color: var(--gold-dim);
  color: var(--text-primary);
}

/* The selected state - gold border + glow */
.option-btn.selected {
  background: rgba(201,168,76,0.12);
  border-color: var(--gold);
  color: var(--gold-light);
  box-shadow: 0 0 12px rgba(201,168,76,0.2), inset 0 0 8px rgba(201,168,76,0.05);
}

.begin-btn {
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, #8b6010, var(--gold), #8b6010);
  border: none;
  border-radius: var(--radius);
  color: #1a0e00;
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 20px rgba(201,168,76,0.3);
}

.begin-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(201,168,76,0.5);
}

.begin-btn:active {
  transform: translateY(0);
}


/* ================================================================
  GAME SCREEN
================================================================ */
#game-screen {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
#game-screen.active {
  display: flex;
}

/* Thin header bar */
#game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 1rem;
  background: rgba(0,0,0,0.4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; /* don't let it squish */
}

#game-info-label {
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  color: var(--gold-dim);
  letter-spacing: 0.1em;
}

.header-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.header-btn:hover {
  border-color: var(--gold-dim);
  color: var(--text-primary);
}

/* ---- Players Grid ------------------------------------------
   CSS Grid auto-places player cards based on player count.
   We set grid-template-columns via JavaScript (or media queries)
   depending on how many players there are.
---------------------------------------------------------------- */
#players-grid {
  flex: 1;
  display: grid;
  gap: 3px;
  overflow: hidden;
  background: #050508; /* gap color */
}

/* Grid layout rules: 1-2 players = 1 column, 3-4 = 2 cols, 5-6 = 3 cols */
#players-grid.players-2  { grid-template-columns: 1fr; }
#players-grid.players-3,
#players-grid.players-4  { grid-template-columns: 1fr 1fr; }
#players-grid.players-5,
#players-grid.players-6  { grid-template-columns: 1fr 1fr 1fr; }

/* On narrow screens, collapse to fewer columns */
@media (max-width: 480px) {
  #players-grid.players-3,
  #players-grid.players-4,
  #players-grid.players-5,
  #players-grid.players-6 {
    grid-template-columns: 1fr 1fr;
  }
}


/* ================================================================
  PLAYER CARD
  Each player gets one of these.
================================================================ */
.player-card {
  position: relative;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  overflow: hidden;
  transition: background 0.2s;
  /* Subtle top border that picks up the player's accent color via JS */
  border-top: 3px solid var(--border);
  gap: 0.25rem;
}

/* Color identity glow applied dynamically via JS inline style */
.player-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 60px;
  background: var(--player-glow, transparent);
  opacity: 0.15;
  pointer-events: none;
}

/* Eliminated state */
.player-card.eliminated {
  opacity: 0.45;
  background: #0a0808;
}
.player-card.eliminated::after {
  content: '💀';
  position: absolute;
  font-size: 2rem;
  opacity: 0.3;
}

/* ---- Player Name ------------------------------------------- */
.player-name-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.player-name {
  font-family: 'Cinzel', serif;
  font-size: clamp(0.7rem, 2vw, 0.9rem);
  color: var(--text-dim);
  letter-spacing: 0.1em;
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.player-name:hover {
  border-color: var(--gold-dim);
  color: var(--text-primary);
}

/* Inline edit input for player name */
.name-input {
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 0.1rem 0.4rem;
  width: 120px;
  text-align: center;
  outline: none;
}

/* ---- Life Total -------------------------------------------- */
.life-display {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* The big +/- tap targets */
.life-btn {
  width: clamp(36px, 8vw, 52px);
  height: clamp(36px, 8vw, 52px);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s;
  display: flex; align-items: center; justify-content: center;
  /* Large tap target for mobile accuracy */
  touch-action: manipulation;
}
.life-btn:hover  { background: rgba(255,255,255,0.08); color: var(--text-primary); }
.life-btn:active { background: rgba(255,255,255,0.12); transform: scale(0.94); }

/* The number itself */
.life-number {
  font-family: 'Rajdhani', sans-serif;
  font-size: clamp(2.8rem, 8vw, 5rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  min-width: clamp(60px, 12vw, 100px);
  text-align: center;
  /* Flash animation when life changes */
  transition: color 0.1s;
}
.life-number.flash-up   { color: #5adb7a; }
.life-number.flash-down { color: var(--crimson-bright); }

/* Low life warning */
.player-card.low-life .life-number {
  color: var(--crimson-bright);
  text-shadow: 0 0 20px rgba(204,34,34,0.5);
}

/* ---- Color Identity Pills ----------------------------------
   WUBRG: White, blUe, Black, Red, Green — official MTG ordering
---------------------------------------------------------------- */
.color-identity {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}

.mana-pip {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  cursor: pointer;
  transition: all 0.15s;
  opacity: 0.25;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: rgba(0,0,0,0.7);
}
.mana-pip.active {
  opacity: 1;
  border-color: rgba(255,255,255,0.5);
  box-shadow: 0 0 8px currentColor;
  transform: scale(1.1);
}
.mana-pip[data-color="W"] { background: var(--mana-W); color: #333; }
.mana-pip[data-color="U"] { background: var(--mana-U); color: #fff; }
.mana-pip[data-color="B"] { background: var(--mana-B); color: #fff; }
.mana-pip[data-color="R"] { background: var(--mana-R); color: #fff; }
.mana-pip[data-color="G"] { background: var(--mana-G); color: #fff; }

/* ---- Counters row (Commander Damage + Infect) -------------- */
.counters-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.counter-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.counter-btn:hover {
  border-color: var(--gold-dim);
  color: var(--text-primary);
}

/* Infect counter - green themed */
.infect-display {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  background: rgba(122,191,58,0.06);
  border: 1px solid rgba(122,191,58,0.2);
  border-radius: var(--radius);
}
.infect-label {
  font-size: 0.65rem;
  color: var(--infect-color);
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.7;
}
.infect-count {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--infect-color);
  min-width: 20px;
  text-align: center;
}
.infect-btns {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.infect-adj {
  background: none;
  border: none;
  color: var(--infect-color);
  font-size: 0.65rem;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.6;
  line-height: 1;
}
.infect-adj:hover { opacity: 1; }

/* Warning when infect is getting high */
.infect-display.infect-warning {
  background: rgba(122,191,58,0.15);
  border-color: var(--infect-color);
  animation: pulse-infect 1.5s ease-in-out infinite;
}
@keyframes pulse-infect {
  0%, 100% { box-shadow: 0 0 0 0 rgba(122,191,58,0.3); }
  50%       { box-shadow: 0 0 12px 4px rgba(122,191,58,0.2); }
}


/* ================================================================
  COMMANDER DAMAGE MODAL
================================================================ */
.modal {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 200;
  /* Slide up animation */
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.modal.visible {
  transform: translateY(0);
}
.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-modal);
  border-top: 1px solid var(--border-gold);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.25rem;
  max-height: 75vh;
  overflow-y: auto;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-header h3 {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  color: var(--gold);
  letter-spacing: 0.1em;
}

#cmd-modal-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px; height: 28px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center;
}
#cmd-modal-close:hover { color: var(--text-primary); border-color: var(--gold-dim); }

/* Each row in the CMD damage list */
.cmd-damage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.cmd-damage-row:last-child { border-bottom: none; }

.cmd-opponent-name {
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  color: var(--text-primary);
  flex: 1;
}

.cmd-damage-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cmd-adj-btn {
  width: 28px; height: 28px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.1s;
}
.cmd-adj-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }

.cmd-damage-value {
  font-family: 'Rajdhani', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--crimson-bright);
  min-width: 36px;
  text-align: center;
}

/* At or above 21, the value glows red as a warning */
.cmd-damage-value.lethal {
  text-shadow: 0 0 16px var(--crimson-bright);
}

.modal-note {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 1rem;
  font-style: italic;
}

/* Overlay behind the modal */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 199;
  backdrop-filter: blur(2px);
}
#modal-overlay.hidden { display: none; }


/* ================================================================
  DEATH OVERLAY
================================================================ */
#death-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Fade in */
  animation: fadeInDeath 0.4s ease;
}
#death-overlay.hidden { display: none; }

@keyframes fadeInDeath {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.death-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.death-skull {
  font-size: 5rem;
  animation: skullBounce 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
@keyframes skullBounce {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.death-name {
  font-family: 'Cinzel', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--crimson-bright);
  text-shadow: 0 0 30px rgba(204,34,34,0.6);
}

.death-msg {
  font-family: 'Rajdhani', sans-serif;
  font-size: 1.1rem;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* ================================================================
  INFECT MODAL
================================================================ */
.infect-modal-body {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 2rem 1rem;
}

.infect-modal-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(122,191,58,0.1);
  border: 2px solid var(--infect-color);
  color: var(--infect-color);
  font-size: 2.5rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  touch-action: manipulation;
}
.infect-modal-btn:hover  { background: rgba(122,191,58,0.2); }
.infect-modal-btn:active { transform: scale(0.94); }

.infect-modal-count-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

#infect-modal-count {
  font-family: 'Rajdhani', sans-serif;
  font-size: 5rem;
  font-weight: 700;
  color: var(--infect-color);
  line-height: 1;
  min-width: 80px;
  text-align: center;
}

.infect-modal-label {
  font-family: 'Rajdhani', sans-serif;
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ================================================================
  UTILITY
================================================================ */
.hidden { display: none !important; }