@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Crimson+Text:ital,wght@0,400;0,600;1,400&display=swap');

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

:root {
  --bg-dark: #1a1a2e;
  --bg-darker: #0f0f1a;
  --card-bg: #16213e;
  --card-border: #2a3a5e;
  --gold: #d4af37;
  --gold-dim: #8b7355;
  --red: #c0392b;
  --red-bright: #e74c3c;
  --green: #27ae60;
  --blue: #3498db;
  --purple: #9b59b6;
  --monster-color: #8b0000;
  --weapon-color: #c9a227;
  --potion-color: #e91e63;
  --text-primary: #ecf0f1;
  --text-secondary: #bdc3c7;
}

body {
  font-family: 'Crimson Text', Georgia, serif;
  background: var(--bg-darker);
  background-image: 
    radial-gradient(ellipse at 50% 0%, rgba(212, 175, 55, 0.1) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-darker) 0%, var(--bg-dark) 100%);
  min-height: 100vh;
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  padding: 20px;
}

.game-container {
  max-width: 1400px;
  width: 100%;
  transition: filter 0.3s ease;
}

/* Background overlay that sits between the page background and the game container.
   This darkens the scene while keeping interactive elements accessible. */
.bg-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7); /* 70% opacity black */
  z-index: 5; /* below the game container (which will be positioned above) */
  pointer-events: none; /* allow clicks to pass through to interactive elements */
}

.game-container {
  position: relative;
  z-index: 10; /* sits above the overlay */
}

.game-container.dimmed {
  filter: brightness(0.5) blur(2px);
}

header {
  text-align: center;
  margin-bottom: 30px;
}

h1 {
  font-family: 'Cinzel', serif;
  font-size: 3.5rem;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(212, 175, 55, 0.5), 0 2px 4px rgba(0,0,0,0.8);
  letter-spacing: 8px;
  margin-bottom: 5px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}

.subtitle {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 1.1rem;
  letter-spacing: 2px;
  margin: 0;
}

.how-to-play-btn {
  position: relative !important;
  display: inline-block !important;
  background: linear-gradient(145deg, #3b3b3b, #2a2a2a);
  color: var(--text-primary);
  border: 1px solid var(--card-border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Cinzel', serif;
}

.how-to-play-btn:hover {
  transform: translateY(-2px);
}

/* Confirmation modal styles */
.confirm-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  background: rgba(0,0,0,0.45);
}
.confirm-modal.active { display: flex; }
.confirm-modal-content {
  background: linear-gradient(145deg, var(--card-bg), var(--bg-darker));
  border: 1px solid var(--card-border);
  padding: 20px;
  border-radius: 12px;
  width: 420px;
  text-align: center;
}
.confirm-actions { display:flex; gap: 10px; justify-content: center; margin-top: 12px; }
.confirm-actions button { padding: 8px 16px; border-radius: 8px; cursor: pointer; }
.confirm-yes { background: var(--green); color: #fff; border: none; }
.confirm-no { background: #444; color: #fff; border: none; }

.game-board {
  display: grid;
  grid-template-columns: 200px 1fr 200px;
  gap: 30px;
  margin-bottom: 20px;
}

.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.health-stat {
  display: flex;
  justify-content: center;
}

.health-stat-box {
  background-image: url('img/stone_health.png') !important;
  /* Use cover so the stone texture fills the box naturally and preserves aspect ratio */
  background-size: cover !important;
  background-repeat: no-repeat;
  background-position: center;
  border: 3px solid #000;
  border-radius: 16px;
  padding: 15px;
  text-align: center;
  position: relative;
  overflow: hidden;
  width: 100%;
}

.health-stat-box::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.weapon-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.weapon-card-inner {
  width: 200px;
  height: 280px;
}

.weapon-card-inner .card-image img {
  opacity: 0.4;
}

.weapon-card-inner .card-image {
  background: linear-gradient(145deg, #2a2510, #1a180a);
}

.weapon-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  text-align: center;
  z-index: 20;
  text-shadow: 2px 2px 2px #000;
  max-width: 90%;
  line-height: 1.3;
  border-radius: 4px;
  padding: 4px 6px;
}

.weapon-card-inner.has-weapon .weapon-message {
  display: block;
}

.monsters-slain-stat {
  background-image: url('img/stone_slain.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  border: 3px solid #000;
  border-radius: 16px;
  padding: 15px;
  text-align: center;
}

.monsters-slain-stat .stat-icon {
  font-size: 1.8rem;
  margin-bottom: 5px;
}

.monsters-slain-stat .stat-value {
  font-family: 'Cinzel', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold);
}

.monsters-slain-stat .stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat {
  background: none; /* removed background color per request */
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 15px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.stat-icon {
  font-size: 1.8rem;
  margin-bottom: 5px;
}

.stat-value {
  font-family: 'Cinzel', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.health-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-darker);
  border-radius: 4px;
  margin-top: 10px;
  overflow: hidden;
}

.health-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--red-bright));
  border-radius: 4px;
  transition: width 0.5s ease;
  box-shadow: 0 0 10px var(--red);
}

.weapon-kills {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 5px;
}

.room-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.room-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 15px;
}

.room-label {
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 3px;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 10px;
  padding: 8px 15px;
  background: linear-gradient(145deg, var(--card-bg), var(--bg-darker));
  border: 1px solid var(--card-border);
  border-radius: 6px;
}

.room-cards {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 300px;
  align-items: center;
}

.card-slot { width: 200px; height: 280px; display:flex; align-items:center; justify-content:center; }
.card-slot .card { width: 100%; height: 100%; }

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.room-cards.fan-out .card {
  animation: fadeIn 0.3s ease-out forwards;
  opacity: 0;
}

.room-cards.fan-out .card:nth-child(1) { animation-delay: 0s; }
.room-cards.fan-out .card:nth-child(2) { animation-delay: 0.1s; }
.room-cards.fan-out .card:nth-child(3) { animation-delay: 0.2s; }
.room-cards.fan-out .card:nth-child(4) { animation-delay: 0.3s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes modalBounceOut {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  30% { transform: translateY(20px) scale(1.1); }
  60% { transform: translateY(-10px) scale(0.95); }
  100% { transform: translateY(-50px) scale(0.9); opacity: 0; }
}

.room-cards.shake,
.card-modal.shake {
  animation: shake 0.4s ease-in-out;
}

.card-modal.closing {
  animation: modalBounceOut 0.4s ease-out forwards;
}

.card {
  width: 200px;
  height: 280px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  font-family: 'Cinzel', serif;
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
  border: none;
  overflow: hidden;
}

.card.room-card-dealt {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.room-cards .card:hover {
  transform: translateY(-10px) scale(1.05);
  box-shadow: 0 10px 30px rgba(0,0,0,0.7);
}

.card.monster {
  background: linear-gradient(145deg, #2c1810, #1a0f0a);
  color: #ff6b6b;
}

.card.monster:hover {
  box-shadow: 0 10px 30px rgba(139, 0, 0, 0.5);
}

.card.weapon {
  background: linear-gradient(145deg, #2a2510, #1a180a);
  color: var(--gold);
}

.card.weapon:hover {
  box-shadow: 0 10px 30px rgba(201, 162, 39, 0.3);
}

.card.potion {
  background: linear-gradient(145deg, #2a1018, #1a0a10);
  color: #ff69b4;
}

.card.potion:hover {
  box-shadow: 0 10px 30px rgba(233, 30, 99, 0.3);
}

.card-face {
  font-size: 2.5rem;
  font-weight: 700;
}

.card-image {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 8px;
  overflow: hidden;
  z-index: 1;
}

.card-corner {
  position: absolute;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border: none;
  border-radius: 50%;
  width: 50px;
  height: 50px;
}

.card-top-left {
  top: -7px;
  left: -10px;
}

.card-bottom-right {
  bottom: -7px;
  right: -10px;
}

.card-rank {
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: none;
}

.card-suit {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: none;
}

.card-image {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 8px;
  overflow: hidden;
  z-index: 1;
}

.card-image img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
}

.card-back {
  display: none;
}

.card.faced {
  opacity: 0.4;
  pointer-events: none;
}

.card-placeholder {
  width: 200px;
  height: 280px;
  border: 2px dashed var(--card-border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-style: italic;
  font-family: 'Cinzel', serif;
  font-size: 1rem;
}

.avoid-btn-container {
  margin-top: 20px;
}

.avoid-btn {
  /* Match the how-to-play button style but with a red theme */
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  padding: 8px 14px;
  background: linear-gradient(145deg, #9b1f1f, #6b0f0f); /* deep red gradient */
  color: #ffffff; /* white text */
  border: 1px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.avoid-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 20px rgba(155, 31, 31, 0.25);
}

.avoid-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.decks-area {
  display: flex;
  flex-direction: column;
  gap: 30px;
  align-items: center;
}

.deck {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.deck-stack {
  width: 200px;
  height: 280px;
  background: linear-gradient(145deg, #0d1b2a, #051015);
  /* border removed per request */
  border: none;
  border-radius: 8px;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background-position: center;
}

/* Floating card used when animating a draw from the dungeon to the room */
.floating-card {
  position: fixed;
  width: 200px;
  height: 280px;
  pointer-events: none;
  border-radius: 10px;
  overflow: hidden;
  z-index: 2000;
  transition: transform 450ms cubic-bezier(.2,.9,.2,1), opacity 300ms ease;
}

.floating-card .card-image img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

/* When rendering a full card inside the deck stack (discard preview),
   ensure the card corners and rank are visible and not clipped by
   the card's overflow or the deck stack. */
.deck-stack .card {
  overflow: visible; /* allow the corner badges to render outside the card box */
}

.deck-stack .card .card-image img {
  position: relative;
  z-index: 1;
}

.deck-stack .card .card-corner {
  z-index: 10; /* make sure corners sit above the card image */
}

.dungeon-deck .deck-stack {
  background-image: url('img/dungeon.png'), linear-gradient(145deg, #0d1b2a, #051015);
}

.discard-deck .deck-stack {
  background-image: url('img/discard.png'), linear-gradient(145deg, #0d1b2a, #051015);
}

.discard-deck .deck-stack::after {
  content: '';
  font-size: 2rem;
  color: var(--text-secondary);
}

/* When explicitly empty, remove any decorative background from the discard slot. */
.discard-deck .deck-stack.empty {
  background: none !important;
}

.discard-deck .deck-stack.empty .card-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-style: italic;
  background: transparent;
}

.dungeon-deck .deck-stack::after {
  content: '';
  font-size: 2rem;
  color: var(--gold-dim);
}

.deck-label {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.deck-count {
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  color: var(--gold);
  margin-top: 5px;
}

.message-area {
  text-align: center;
  padding: 0;
  width: 100%;
  min-height: 170px;
  margin-top: 15px;
  background-image: url('img/stone.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-area.hidden {
  display: none;
}

.message {
  font-size: 1.5rem;
  color: #ffffff;
  font-family: 'Cinzel', serif;
  font-style: italic;
  padding: 20px 40px;
  text-shadow: 0 1px 1px rgba(139, 119, 83, 0.3);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.legend-icon {
  font-size: 1.2rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-family: 'Cinzel', serif;
  font-weight: 700;
}

.monster-icon {
  background: linear-gradient(145deg, #2c1810, #1a0f0a);
  color: #ff6b6b;
  border: 4px solid #000;
}

.weapon-icon {
  background: linear-gradient(145deg, #2a2510, #1a180a);
  color: var(--gold);
  border: 4px solid #000;
}

.potion-icon {
  background: linear-gradient(145deg, #2a1018, #1a0a10);
  color: #ff69b4;
  border: 4px solid #000;
}

.game-over-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000; /* very high to avoid being under other stacking contexts */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.game-over-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.game-over-content {
  background: linear-gradient(145deg, var(--card-bg), var(--bg-darker));
  border: 2px solid var(--gold);
  border-radius: 20px;
  padding: 50px;
  text-align: center;
  box-shadow: 0 0 50px rgba(212, 175, 55, 0.3);
  max-width: 500px;
}

.game-over-content h2 {
  font-family: 'Cinzel', serif;
  font-size: 2.5rem;
  color: var(--gold);
  margin-bottom: 20px;
}

.game-over-content p {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.final-score {
  font-family: 'Cinzel', serif;
  font-size: 4rem;
  color: var(--gold);
  margin-bottom: 30px;
  text-shadow: 0 0 20px rgba(212, 175, 55, 0.5);
}

.final-score.negative {
  color: var(--red);
  text-shadow: 0 0 20px rgba(192, 57, 43, 0.5);
}

.game-over-stats {
  margin-bottom: 30px;
  text-align: left;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-row .stat-label {
  color: var(--text-secondary);
  font-size: 1rem;
}

.stat-row .stat-value {
  color: var(--text-primary);
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  font-weight: bold;
}

.new-game-btn {
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  padding: 15px 40px;
  background: linear-gradient(145deg, var(--gold), var(--gold-dim));
  border: none;
  border-radius: 10px;
  color: var(--bg-darker);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 2px;
  transition: all 0.3s ease;
}

.new-game-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(212, 175, 55, 0.5);
}

.card-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.card-modal.active {
  opacity: 1;
  pointer-events: all;
}

.modal-battle {
  padding: 40px;
  text-align: center;
  max-width: 450px;
}

.battle-cards {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
  margin-bottom: 20px;
}

.battle-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.battle-card-label {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.battle-vs {
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--red-bright);
}

.battle-message {
  font-size: 1rem;
  color: var(--text-primary);
  min-height: 24px;
  margin-bottom: 20px;
}

.battle-actions {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.battle-btn {
  font-family: 'Cinzel', serif;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 150px;
}

.battle-btn .battle-btn-label {
  font-size: 0.9rem;
  font-weight: 700;
}

.battle-btn .battle-btn-damage {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-top: 5px;
}

.battle-btn.fight-bare {
  background: linear-gradient(145deg, #2c1810, #1a0f0a);
  border: 2px solid var(--monster-color);
  color: #ff6b6b;
}

.battle-btn.fight-bare:hover {
  background: var(--monster-color);
  color: white;
}

.battle-btn.fight-weapon {
  background: linear-gradient(145deg, #2a2510, #1a180a);
  border: 2px solid var(--weapon-color);
  color: var(--gold);
}

.battle-btn.fight-weapon:hover {
  background: var(--weapon-color);
  color: var(--bg-darker);
}

.modal-content {
  padding: 40px;
  text-align: center;
  max-width: 450px;
}

.modal-content h3 {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  color: var(--red-bright);
  margin-bottom: 15px;
}

.modal-content p {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.modal-buttons {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.modal-btn {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  padding: 15px 25px;
  border: 2px solid;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.fight-bare {
  background: linear-gradient(145deg, #2c1810, #1a0f0a);
  border-color: var(--monster-color);
  color: #ff6b6b;
}

.fight-bare:hover {
  background: var(--monster-color);
  color: white;
}

.fight-weapon {
  background: linear-gradient(145deg, #2a2510, #1a180a);
  border-color: var(--weapon-color);
  color: var(--gold);
}

.fight-weapon:hover {
  background: var(--weapon-color);
  color: var(--bg-darker);
}

.equipped-weapon-card {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
}

@media (max-width: 900px) {
  .game-board {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .stats-panel {
    flex-direction: row;
    justify-content: center;
  }
  
  .decks-area {
    flex-direction: row;
    justify-content: center;
  }
  
  .legend {
    flex-wrap: wrap;
    gap: 20px;
  }
}
