/* =========================
   DUNGEON WRAPPER & BASE (UPDATED FOR PIXEL ART)
   ========================= */
body {
  margin: 0;
  overflow: hidden;
  background-color: #000; /* Backup */
  font-family: "Courier New", Courier, monospace;
}

#dungeon-wrapper {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  transform: translate3d(0,0,0); /* Hardware Acceleration */
}

.dungeon-bg {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  
  /* Base Fallback */
  background-color: #0c0a08; 
  
  /* HIGH-QUALITY PIXEL ART IMAGE IMPLEMENTATION */
  /* Go up one folder, then look into the images folder */
  background-image: url('../assets/pixel_dungeon.png'); 
  
  /* Standard backdrop settings */
  background-size: cover; 
  background-repeat: no-repeat;
  background-position: center bottom; /* Anchor perspective to the table */
  
  /* --- CRITICAL FOR PIXEL ART --- */
  /* Prevent browser blurring/smoothing when scaled */
  image-rendering: pixelated; 
  image-rendering: crisp-edges;
  
  /* Add slight dimming to ensure white text/tokens pop,
     while preserving the rich yellow hue. */
  filter: brightness(0.6) contrast(1.1);
  
  z-index: -2;
}

/* =========================
   TORCHLIGHT CURSOR
   ========================= */
.torch-glow {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: radial-gradient(
    circle 250px at var(--x, 50%) var(--y, 50%), 
    rgba(255, 130, 40, 0.14), 
    rgba(180, 50, 10, 0.04), 
    transparent 100%
  );
  z-index: -1; 
  pointer-events: none;
  animation: flicker 0.15s infinite alternate;
}

@keyframes flicker {
  0% { opacity: 0.95; }
  100% { opacity: 1; }
}

/* =========================
   UI & NAVIGATION
   ========================= */
.dungeon-exit {
  position: absolute;
  top: 30px; left: 30px;
  color: rgba(255, 140, 50, 0.6);
  text-decoration: none;
  font-size: 0.9rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  z-index: 10;
}
.dungeon-exit:hover {
  color: #ffaa55;
  text-shadow: 0 0 8px rgba(255, 140, 50, 0.5);
}

/* =========================
   PARTY TOKENS
   ========================= */
.token-container {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-wrap: wrap;
  gap: 40px;
  justify-content: center;
  width: 80%;
  max-width: 800px;
  z-index: 5;
}

.party-token {
  font-size: 3.5rem;
  cursor: pointer;
  filter: drop-shadow(0 10px 10px rgba(0,0,0,0.9));
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  opacity: 0.65;
}
.party-token:hover {
  transform: translateY(-12px) scale(1.25);
  opacity: 1;
  filter: drop-shadow(0 0 20px rgba(255, 130, 40, 0.5));
}

/* =========================
   BULLETPROOF FULL SCREEN MAGIC OVERLAYS
   ========================= */
#flash-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
  z-index: 110; /* Put this ABOVE the character sheet (100) */
  opacity: 0; 
}

/* Force elements to become fully visible when active, letting keyframes control colors */
#flash-overlay.spell-nature    { opacity: 1; animation: flashGreen 1.2s ease-out forwards; }
#flash-overlay.spell-explosion { opacity: 1; animation: flashRed 0.8s ease-out forwards; }
#flash-overlay.spell-bard      { opacity: 1; animation: flashPink 1.0s ease-out forwards; }
#flash-overlay.spell-holy      { opacity: 1; animation: flashGold 1.8s cubic-bezier(0.1, 0.8, 0.3, 1) forwards; }
#flash-overlay.spell-death     { opacity: 1; animation: flashShadow 2.0s ease-in-out forwards; }
#flash-overlay.spell-lightning { opacity: 1; animation: lightningStrobe 0.4s ease-out forwards; }
#flash-overlay.spell-dm-chaos  { opacity: 1; animation: dmCosmicWarp 1.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

/* 1. Limetongue - Organic Wild Green Aura */
@keyframes flashGreen {
  0% { background-color: rgba(34, 197, 94, 0.5); }
  100% { background-color: rgba(34, 197, 94, 0); }
}

/* 2. Steve French - Sharp, Fiery High-Intensity Explosion */
@keyframes flashRed {
  0% { background-color: rgba(239, 68, 68, 0.8); }
  15% { background-color: rgba(249, 115, 22, 0.6); }
  100% { background-color: rgba(239, 68, 68, 0); }
}

/* 3. Thistle - Playful Neon Pink Glow */
@keyframes flashPink {
  0% { background-color: rgba(236, 72, 153, 0.5); }
  100% { background-color: rgba(236, 72, 153, 0); }
}

/* 4. Lumiel - Majestic, Slow Divine Radiance Fade */
@keyframes flashGold {
  0% { background-color: rgba(251, 191, 36, 0.85); }
  20% { background-color: rgba(253, 224, 71, 0.6); }
  100% { background-color: rgba(251, 191, 36, 0); }
}

/* 5. Miamorgul - Deep Ambient Cold Shadow Wash */
@keyframes flashShadow {
  0% { background-color: rgba(12, 12, 14, 0.9); }
  40% { background-color: rgba(24, 24, 35, 0.75); }
  100% { background-color: rgba(0, 0, 0, 0); }
}

/* 6. Silent One - Double Lightning Arc Strobe */
@keyframes lightningStrobe {
  0%, 45% { background-color: rgba(224, 242, 254, 0.95); }
  20%, 70% { background-color: rgba(224, 242, 254, 0); }
  100% { background-color: rgba(0, 0, 0, 0); }
}

/* 7. Rob - Omnipotent Weaver of Fates Reality Warp */
@keyframes dmCosmicWarp {
  0% { 
    background-color: rgba(67, 20, 130, 0.95);
    box-shadow: inset 0 0 150px rgba(0, 0, 0, 1);
  }
  25% {
    background-color: rgba(30, 10, 60, 0.85);
  }
  100% { 
    background-color: rgba(0, 0, 0, 0); 
    box-shadow: inset 0 0 0px rgba(0, 0, 0, 0);
  }
}

/* =========================
   HARDWARE-ACCELERATED CAMERA SHAKE
   ========================= */
.shake-screen {
  animation: cameraRattle 0.45s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes cameraRattle {
  10%, 90% { transform: translate3d(-3px, 1px, 0); }
  20%, 80% { transform: translate3d(5px, -2px, 0); }
  30%, 50%, 70% { transform: translate3d(-7px, 3px, 0); }
  40%, 60% { transform: translate3d(7px, -3px, 0); }
}

/* =========================
   CHARACTER SHEET MODAL
   ========================= */
#character-sheet {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}
#character-sheet.hidden {
  display: none;
}
.sheet-inner {
  background: #110e0c;
  border: 2px solid #2e241f;
  padding: 40px;
  border-radius: 12px;
  max-width: 400px;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.9);
  color: #c9b9ae;
}
.sheet-icon { font-size: 4rem; margin-bottom: -5px; }
#sheet-name { font-size: 2rem; margin: 10px 0 5px 0; color: #ffaa55; text-transform: uppercase; letter-spacing: 2px; }
#sheet-class { font-size: 1rem; margin: 0 0 20px 0; color: #736357; font-style: italic; }
.divider { height: 1px; background: linear-gradient(90deg, transparent, #47372c, transparent); margin: 20px 0; }
#sheet-desc { font-size: 0.95rem; line-height: 1.6; margin-bottom: 30px; }
.action-buttons { display: flex; justify-content: center; gap: 15px; }
.dnd-btn { background: transparent; color: #ffaa55; border: 1px solid #ffaa55; padding: 8px 16px; cursor: pointer; font-family: inherit; transition: all 0.2s; }
.dnd-btn:hover { background: #ffaa55; color: #110e0c; }
#close-sheet { position: absolute; top: 15px; right: 15px; background: transparent; border: none; color: #736357; font-size: 1.2rem; cursor: pointer; }

/* =========================
   CHARACTER SHEET TABS & CONTENT
   ========================= */
.sheet-tabs {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
  border-bottom: 1px solid #47372c;
  padding-bottom: 10px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: #736357;
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  padding: 5px 10px;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.tab-btn:hover {
  color: #ffaa55;
}

.tab-btn.active {
  color: #ffaa55;
  border-bottom: 2px solid #ffaa55;
}

.tab-content {
  display: none;
  text-align: left;
  animation: fadeIn 0.3s ease-in;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Stats & Lists */
.stats-grid {
  display: flex;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 20px;
  border-radius: 6px;
  margin-bottom: 15px;
  border: 1px solid #2e241f;
}

.stats-grid strong {
  color: #ffaa55;
}

.section-title {
  color: #736357;
  border-bottom: 1px dashed #47372c;
  padding-bottom: 5px;
  margin-bottom: 10px;
}

.dnd-list {
  list-style-type: square;
  padding-left: 20px;
  color: #c9b9ae;
  line-height: 1.8;
}

.dnd-list li::marker {
  color: #ffaa55;
}

/* Gallery */
.gallery-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

#gallery-image {
  max-width: 100%;
  max-height: 250px;
  border-radius: 8px;
  border: 2px solid #2e241f;
  object-fit: contain;
  background: #000;
}

.gallery-nav {
  display: flex;
  gap: 20px;
}
#close-sheet:hover { color: #ffaa55; }

/* =========================
   GLOBAL D20 DICE WIDGET
   ========================= */
#dice-container {
  position: fixed;
  bottom: 40px;
  right: 38px;
  z-index: 90; /* Sits securely above background but under modals */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#d20-die {
  font-size: 3.5rem;
  cursor: pointer;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.7));
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  user-select: none;
}

#d20-die:hover {
  transform: scale(1.15) rotate(10deg);
}

/* Shuffling Strobe Animation */
#d20-die.rolling {
  animation: spinDice 0.15s linear infinite;
}

@keyframes spinDice {
  0% { transform: scale(1.1) rotate(0deg); }
  100% { transform: scale(1.1) rotate(360deg); }
}

/* Result Card popup */
#roll-result-box {
  background: #110e0c;
  border: 2px solid #ffaa55;
  padding: 15px;
  border-radius: 8px;
  text-align: center;
  width: 180px;
  box-shadow: 0 15px 40px rgba(0,0,0,0.9);
  color: #c9b9ae;
  animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

#roll-result-box.hidden {
  display: none;
}

#roll-number {
  font-size: 1.8rem;
  font-weight: bold;
  color: #ffaa55;
  margin-bottom: 5px;
}

#roll-flavor {
  font-size: 0.85rem;
  line-height: 1.4;
  font-style: italic;
  color: #a39284;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.8) translateY(15px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* =========================
   INTERACTIVE INVENTORY LORE
   ========================= */
.interactive-list li {
  cursor: pointer;
  transition: color 0.2s, transform 0.2s;
}

.interactive-list li:hover {
  color: #ffaa55;
  text-shadow: 0 0 5px rgba(255, 170, 85, 0.4);
}

#inventory-lore-box {
  margin-top: 20px;
  padding: 15px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px dashed #47372c;
  border-radius: 8px;
  animation: fadeIn 0.3s ease-in;
}

#inventory-lore-box.hidden {
  display: none;
}

#lore-name {
  margin: 0 0 8px 0;
  color: #ffaa55;
  font-size: 1.1rem;
  letter-spacing: 1px;
}

#lore-desc {
  margin: 0;
  color: #a39284;
  font-size: 0.9rem;
  font-style: italic;
  line-height: 1.5;
}

/* =========================
   THE TOME OF FEYFOR MODAL
   ========================= */
.atlas-toggle {
  position: absolute;
  top: 30px;
  right: 30px;
  z-index: 10;
}

#atlas-modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(5, 4, 3, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 105; /* Securely stacked above standard character card elements */
}

#atlas-modal.hidden { display: none; }

.atlas-inner {
  background: #0f0c0a;
  border: 2px solid #3d3028;
  padding: 35px;
  border-radius: 12px;
  width: 95%;          /* Bumped up from 90% for a bit more side-room */
  max-width: 1150px;   /* Increased from 950px to make it grander */
  height: 85vh;        /* Increased from 80vh to give it vertical breathing room */
  position: relative;
  box-shadow: 0 25px 70px rgba(0,0,0,0.95);
  display: flex;
  flex-direction: column;
}

#close-atlas {
  position: absolute;
  top: 15px;
  right: 15px;
  background: transparent;
  border: none;
  color: #736357;
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.2s;
}
#close-atlas:hover { color: #ffaa55; }

.tome-title {
  margin: 0 0 15px 0;
  color: #ffaa55;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 1.6rem;
}

/* Tome Multi-Tabs Navigation Layout */
.tome-tabs {
  display: flex;
  gap: 15px;
  border-bottom: 1px solid #3d3028;
  margin-bottom: 20px;
  padding-bottom: 5px;
}

.tome-tab-btn {
  background: transparent;
  border: none;
  color: #736357;
  font-family: inherit;
  font-size: 1.05rem;
  cursor: pointer;
  padding: 5px 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: color 0.2s;
}
.tome-tab-btn:hover { color: #ffaa55; }
.tome-tab-btn.active { color: #ffaa55; border-bottom: 2px solid #ffaa55; }

.tome-content { display: none; flex-grow: 1; overflow-y: auto; }
.tome-content.active { display: block; }

/* =========================
   MAP GRID ENGINE
   ========================= */
.atlas-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 25px;
  height: calc(100% - 10px);
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(85px, auto);
  gap: 10px;
  padding: 6px; /* NEW: Acts as a safety buffer zone so the hover zoom doesn't get cut off! */
}

.map-cell {
  background: rgba(26, 20, 16, 0.8);
  border: 1px solid #3d3028;
  border-radius: 6px;
  padding: 12px 5px;
  text-align: center;
  cursor: pointer;
  font-weight: bold;
  color: #c9b9ae;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease-in-out;
  font-size: 0.95rem;
  user-select: none;
}

.map-cell:hover, .map-cell.active-cell {
  background: #2e221a;
  border-color: #ffaa55;
  color: #ffaa55;
  transform: scale(1.02);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.cell-lord {
  font-size: 0.75rem;
  font-weight: normal;
  color: #736357;
  font-style: italic;
}
.map-cell:hover .cell-lord, .map-cell.active-cell .cell-lord { color: #c9b9ae; }

/* Spans across all 3 grid columns at the bottom */
.ice-plains {
  grid-column: span 3;
  background: rgba(20, 26, 32, 0.6);
  border-color: #2c3847;
}
.ice-plains:hover, .ice-plains.active-cell {
  background: #1c2630;
  border-color: #7099c2;
  color: #a6cbf0;
}

/* =========================
   INSPECTOR SIDE PANEL
   ========================= */
#atlas-inspector {
  background: #080605;
  border: 1px solid #29201a;
  border-radius: 8px;
  padding: 20px;
  overflow-y: auto;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
}

#atlas-prompt {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #54473e;
  font-style: italic;
  font-size: 1rem;
  line-height: 1.5;
}

#region-title {
  margin: 0 0 10px 0;
  color: #ffaa55;
  font-size: 1.4rem;
  border-bottom: 1px solid #3d3028;
  padding-bottom: 8px;
  text-transform: uppercase;
}

.region-meta {
  display: flex;
  justify-content: space-between;
  background: rgba(0,0,0,0.3);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.9rem;
  margin-bottom: 15px;
  border-left: 3px solid #ffaa55;
}
.region-meta strong { color: #736357; text-transform: uppercase; font-size: 0.75rem; margin-right: 4px;}

.inspector-sub {
  color: #ffaa55;
  font-size: 0.9rem;
  text-transform: uppercase;
  margin: 18px 0 6px 0;
  letter-spacing: 1px;
}

#region-features {
  font-size: 0.9rem;
  line-height: 1.5;
  color: #c9b9ae;
  margin: 0;
}

#region-cities {
  margin: 0;
  padding-left: 18px;
  font-size: 0.9rem;
  color: #c9b9ae;
  line-height: 1.6;
}

/* =========================
   JOURNAL AREA STYLING (UPDATED)
   Handling Nested Campaigns and Collapsable Sessions
   ========================= */
#tome-journal {
  overflow-y: auto; /* Ensure main tab still scrolls */
}

.journal-intro { 
  font-style: italic; 
  color: #736357; 
  margin-bottom: 25px; 
  padding-left: 5px;
}

/* =========================
   CAMPAIGN ACCORDIONS
   ========================= */

/* 1. Campaign Headers (Main titles acts as accordion buttons) */
.campaign-accordion {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #ffaa55;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 1.2rem; /* Slightly smaller to feel more integrated */
  margin: 15px 0 0 0; /* Tightened margins */
  border: 1px solid #3d3028; /* Enclose in a clickable box */
  border-radius: 6px;
  padding: 12px 20px;
  background-color: rgba(26, 20, 16, 0.4);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s, border-color 0.2s;
}

.campaign-accordion:hover {
  background-color: rgba(46, 34, 26, 0.6);
  border-color: #ffaa55;
}

/* 2. State Indicators (Arrows) */
.campaign-accordion::after {
  content: '❯'; /* Standard CSS Arrow */
  font-size: 0.9rem;
  color: #736357;
  transition: transform 0.3s, color 0.3s;
}

/* Arrow rotates and changes color when active */
.campaign-accordion.active {
  background-color: rgba(46, 34, 26, 0.8);
  border-color: #ffaa55;
}
.campaign-accordion.active::after {
  transform: rotate(90deg);
  color: #ffaa55;
}

/* =========================
   SESSIONS PANEL ENGINE
   ========================= */

/* 3. The container holding sessions for one campaign */
.campaign-sessions-panel {
  max-height: 0; /* Completely closed by default */
  overflow: hidden; /* Hide overflowing text */
  transition: max-height 0.3s ease-out; /* Smooth slide animation */
  border-left: 2px solid #2e241f; /* Indentation line */
  margin-left: 10px;
  margin-bottom: 20px; /* Space between campaigns */
  padding-left: 5px; /* Alignment with intro */
}

/* Class applied by JS to expand the panel */
.campaign-sessions-panel.active {
  max-height: 1000px; /* A sufficiently large height to accommodate content */
  padding-top: 15px; /* Reveal padding only when open */
}

/* =========================
   SESSION ENTRIES STYLING (Inside the panel)
   ========================= */

/* 4. Session Entries (Contain title and notes) */
.journal-entry {
  background: rgba(0,0,0,0.3);
  border: 1px solid #241c17;
  padding: 15px 20px;
  border-radius: 6px;
  margin-bottom: 12px;
}
.journal-entry:hover {
  border-color: #3d3028;
}

/* 5. Session Metadata (Session titles) */
.journal-meta { 
  color: #c9b9ae; 
  font-weight: bold; 
  margin-bottom: 6px; 
  font-size: 0.95rem; 
  letter-spacing: 1px;
}

/* 6. The actual notes text */
.journal-entry p { 
  margin: 0; 
  color: #a39284; 
  line-height: 1.6; 
  font-size: 0.9rem;
  white-space: pre-wrap; /* NEW: Forces HTML to respect your "Enter" key line breaks! */
}

/* =========================
   BESTIARY CARD GRID
   ========================= */
.bestiary-grid {
  display: grid;
  /* Automatically fits as many 250px cards as possible in a row */
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  padding: 5px;
}

.monster-card {
  background: rgba(15, 12, 10, 0.8);
  border: 1px solid #3d3028;
  border-radius: 8px;
  overflow: hidden; /* Keeps the image inside the rounded corners */
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, border-color 0.2s;
  box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.monster-card:hover {
  transform: translateY(-5px);
  border-color: #ef4444; /* Aggressive red hover for monsters */
  box-shadow: 0 10px 20px rgba(239, 68, 68, 0.2);
}

.monster-image {
  width: 100%;
  height: 160px;
  object-fit: cover; /* Ensures images fill the box without squishing */
  border-bottom: 2px solid #2e241f;
  background: #050403; /* Fallback color if image is missing */
}

.monster-content {
  padding: 15px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.monster-name {
  color: #ef4444; 
  font-size: 1.2rem;
  margin: 0 0 5px 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.monster-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #736357;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px dashed #3d3028;
  text-transform: uppercase;
}

.monster-lore {
  color: #c9b9ae;
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0;
}

/* =========================
   CUSTOM SCROLLBAR STYLING
   Applies the dark fantasy aesthetic to all scrollbars
   ========================= */

/* Firefox Support */
* {
  scrollbar-width: thin;
  scrollbar-color: #47372c #0a0806;
}

/* Chrome, Edge, and Safari Support */
::-webkit-scrollbar {
  width: 10px; /* Width of the vertical scrollbar */
}

::-webkit-scrollbar-track {
  background: #0a0806; /* Very dark background for the track */
  border-left: 1px solid #2e241f; /* Subtle border separating it from content */
}

::-webkit-scrollbar-thumb {
  background: #47372c; /* Muted brown/grey for the draggable thumb */
  border-radius: 5px; /* Rounded edges */
  border: 2px solid #0a0806; /* Creates a bit of padding around the thumb */
}

::-webkit-scrollbar-thumb:hover {
  background: #ffaa55; /* Glows amber when the user hovers over it! */
  cursor: pointer;
}

/* =========================
   BESTIARY ENLARGED MODAL
   ========================= */
.monster-card {
  cursor: pointer; /* Makes the mouse turn into a clicking hand */
}

#monster-modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 120; /* Ensure it sits HIGHER than the Tome (105) */
}

#monster-modal.hidden {
  display: none;
}

.monster-modal-inner {
  border-color: #ef4444; /* Gives monsters a dangerous red border instead of brown */
  max-width: 500px; /* Slightly wider than character sheets */
}

#modal-monster-image {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid #3d3028;
  margin-bottom: 15px;
  background: #050403;
}

#modal-monster-name {
  color: #ef4444;
  margin: 0 0 10px 0;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 1.8rem;
}

#modal-monster-lore {
  color: #c9b9ae;
  font-size: 0.95rem;
  line-height: 1.6;
  text-align: left; /* Keeps the reading text neat */
  white-space: pre-wrap;
}

#close-monster-modal {
  position: absolute;
  top: 15px; right: 15px;
  background: transparent;
  border: none;
  color: #736357;
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.2s;
}
#close-monster-modal:hover { color: #ef4444; }

/* =========================
   FEYFOR BATTLE ARENA
   ========================= */
.arena-selectors {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 20px;
  background: rgba(30, 22, 17, 0.6);
  padding: 15px;
  border-radius: 8px;
  border: 1px solid #5a4a3f;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.selector-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.selector-box label {
  font-size: 0.8rem;
  color: #c9b9ae;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.dnd-input {
  background: #150f0c;
  border: 1px solid #736357;
  color: #f4eae1;
  padding: 8px 12px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  outline: none;
  min-width: 180px;
}
.dnd-input:focus {
  border-color: #ffaa55;
}

.combat-btn {
  background: linear-gradient(180deg, #991b1b, #7f1d1d) !important;
  border-color: #ef4444 !important;
  color: #ffffff !important;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 10px 20px !important;
  transition: transform 0.1s, box-shadow 0.2s;
}
.combat-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
}
.combat-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.arena-grid {
  display: grid;
  grid-template-columns: 180px 1fr 180px;
  gap: 15px;
  align-items: stretch;
  margin-top: 10px;
}

@media (max-width: 768px) {
  .arena-grid {
    grid-template-columns: 1fr;
  }
}

.arena-fighter-card {
  background: #1a130f;
  border: 2px solid #5a4a3f;
  border-radius: 8px;
  padding: 15px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.6);
}

#arena-hero-card { border-color: #3b82f6; }
#arena-monster-card { border-color: #ef4444; }

.fighter-avatar {
  font-size: 3rem;
  margin-bottom: 10px;
  line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));
}

.arena-fighter-card h3 {
  margin: 0 0 12px 0;
  font-size: 1.1rem;
  color: #f4eae1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.arena-hp-bar-wrapper {
  width: 100%;
  margin-bottom: 12px;
}

.arena-hp-label {
  font-size: 0.8rem;
  color: #c9b9ae;
  text-align: left;
  margin-bottom: 4px;
}

.arena-hp-bar {
  width: 100%;
  height: 12px;
  background: #2a1f1a;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #45342a;
}

.hp-fill-inner {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  transition: width 0.25s ease-out;
}
.hp-fill-inner.enemy-hp {
  background: linear-gradient(90deg, #dc2626, #f87171);
}

.fighter-stat-badge {
  background: #2a1f1a;
  border: 1px solid #736357;
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 0.8rem;
  color: #f4eae1;
  font-weight: bold;
}

.arena-console {
  background: #090706;
  border: 2px solid #3d3028;
  border-radius: 8px;
  height: 240px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.9);
}

.console-scroll-inner {
  flex: 1;
  overflow-y: auto;
  text-align: left;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  padding-right: 5px;
}

.console-scroll-inner::-webkit-scrollbar { width: 6px; }
.console-scroll-inner::-webkit-scrollbar-track { background: #090706; }
.console-scroll-inner::-webkit-scrollbar-thumb { background: #3d3028; border-radius: 3px; }

/* Console Text Logging Themes */
.console-system-msg { color: #887466; font-style: italic; margin: 4px 0; }
.console-round { color: #ffaa55; font-weight: bold; margin: 8px 0 4px 0; border-bottom: 1px dashed #2d241e; padding-bottom: 2px; }
.console-hit { color: #4ade80; margin: 3px 0; }
.console-miss { color: #a1a1aa; margin: 3px 0; }
.console-crit { color: #facc15; font-weight: bold; text-transform: uppercase; margin: 3px 0; text-shadow: 0 0 4px rgba(250,204,21,0.3); }
.console-victory { color: #3b82f6; font-weight: bold; font-size: 0.95rem; margin: 10px 0; text-align: center; border: 1px solid #3b82f6; padding: 6px; background: rgba(59,130,246,0.1); border-radius: 4px; }
.console-defeat { color: #ef4444; font-weight: bold; font-size: 0.95rem; margin: 10px 0; text-align: center; border: 1px solid #ef4444; padding: 6px; background: rgba(239,68,68,0.1); border-radius: 4px; }

/* =========================
   BATTLE ARENA MODAL & UI
   ========================= */
.arena-toggle {
  position: absolute;
  top: 75px; /* Safely stacks underneath the World Tome button */
  right: 30px;
  z-index: 10;
  border-color: #ef4444 !important;
  color: #ef4444 !important;
}

.arena-toggle:hover {
  background: #ef4444 !important;
  color: #110e0c !important;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
}

#arena-modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(10, 8, 8, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 110; /* Clean separation level */
}

#arena-modal.hidden {
  display: none;
}

.arena-inner {
  max-width: 850px;
  width: 92%;
  border-color: #ef4444 !important; /* Combat warning color */
  background: #14110f;
  box-shadow: 0 20px 50px rgba(239, 68, 68, 0.15);
}

.arena-title {
  color: #ef4444;
  text-align: center;
  font-family: inherit;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 10px;
}

.arena-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1c1815;
  padding: 15px;
  border-radius: 6px;
  border: 1px solid #3a2f28;
  margin-bottom: 20px;
  gap: 15px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-group label {
  color: #a39284;
  font-size: 0.9rem;
}

#arena-picker {
  background: #110e0c;
  color: #c9b9ae;
  border: 1px solid #47372c;
  padding: 6px 12px;
  font-family: inherit;
  border-radius: 4px;
  cursor: pointer;
}

#arena-picker optgroup {
  background: #14110f;
  color: #ffaa55;
}

.style-danger {
  border-color: #b91c1c !important;
  color: #f87171 !important;
}
.style-danger:hover {
  background: #b91c1c !important;
  color: #fff !important;
}

.arena-workspace {
  max-height: 380px;
  overflow-y: auto;
  border: 1px solid #332720;
  border-radius: 4px;
  background: #0d0b0a;
}

.arena-table-header {
  display: grid;
  grid-template-columns: 2fr 1fr 2fr 1fr;
  padding: 10px;
  background: #1a1512;
  border-bottom: 1px solid #332720;
  color: #736357;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: bold;
}

.combat-row {
  display: grid;
  grid-template-columns: 2fr 1fr 2fr 1fr;
  align-items: center;
  padding: 12px 10px;
  border-bottom: 1px solid #241c17;
  transition: background 0.2s;
}

.combat-row:hover {
  background: #161210;
}

.combatant-info {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #c9b9ae;
}

.combatant-emoji {
  font-size: 1.5rem;
}

.combatant-name {
  font-weight: bold;
}

.combatant-type {
  font-size: 0.75rem;
  color: #736357;
  display: block;
}

.init-input, .hp-input {
  background: #110e0c;
  color: #ffaa55;
  border: 1px solid #47372c;
  padding: 4px 8px;
  border-radius: 4px;
  width: 55px;
  text-align: center;
  font-family: inherit;
}

.hp-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}

.hp-max-label {
  color: #736357;
  font-size: 0.85rem;
}

.hp-btn {
  background: #241c17;
  border: 1px solid #47372c;
  color: #c9b9ae;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 0.85rem;
}
.hp-btn:hover {
  background: #47372c;
  color: #fff;
}

#close-arena {
  position: absolute;
  top: 15px;
  right: 15px;
  background: transparent;
  border: none;
  color: #736357;
  font-size: 1.2rem;
  cursor: pointer;
}
#close-arena:hover {
  color: #ef4444;
}
