/* Responsive Overlay System - Story Aesthetic */

/* Base overlay improvements */
.overlay {
  position: fixed;
  top: var(--overlay-top-offset, 72px);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 22000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  padding: 20px;
}

.overlay.active {
  opacity: 1;
  visibility: visible;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 8, 11, 0.85);
  backdrop-filter: blur(8px);
  z-index: 1;
  pointer-events: none;
}

.overlay-panel {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 900px;
  max-height: 85vh;
  min-height: 50vh;
  background: linear-gradient(180deg, rgba(16, 18, 26, 0.95), rgba(12, 14, 19, 0.98));
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 0 0 1px var(--accent-border) inset;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.98);
  transition: transform 0.3s var(--ease);
}

/* Better vertical utilization on larger screens */
@media (min-height: 900px) {
  .overlay-panel {
    max-height: 88vh;
    min-height: 65vh;
  }
}

@media (min-height: 1200px) {
  .overlay-panel {
    max-height: 90vh;
    min-height: 75vh;
  }
}

.overlay.active .overlay-panel {
  transform: translateY(0) scale(1);
}

/* Panel sizing variants */
.overlay-panel.wide {
  max-width: 1100px;
}

@media (min-height: 900px) {
  .overlay-panel.wide {
    max-height: 88vh;
    min-height: 65vh;
  }
}

@media (min-height: 1200px) {
  .overlay-panel.wide {
    max-height: 90vh;
    min-height: 75vh;
  }
}

.overlay-panel.compact {
  max-width: 600px;
}

.overlay-panel.fullscreen {
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
}

/* Header */
.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--accent-border);
  background: linear-gradient(180deg, var(--accent-soft), transparent);
  flex-shrink: 0;
}

.overlay-header h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.overlay-close {
  position: relative;
  z-index: 100;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.overlay-close:hover,
.overlay-close:active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--accent);
  transform: scale(1.05);
}

.overlay-close:active {
  transform: scale(0.95);
}

/* Content area */
.overlay-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

/* Scrollbar styling */
.overlay-content::-webkit-scrollbar {
  width: 8px;
}

.overlay-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.overlay-content::-webkit-scrollbar-thumb {
  background: var(--accent-border);
  border-radius: 4px;
}

.overlay-content::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ============================================
   COMPENDIUM SPECIFIC STYLES
   ============================================ */

.compendium-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.compendium-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
}

.compendium-search {
  flex: 1;
  min-width: 200px;
}

.compendium-search input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.compendium-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.compendium-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compendium-filter {
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 120px;
}

.compendium-filter:hover {
  border-color: var(--accent);
  color: var(--text);
}

.compendium-filter.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.compendium-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--accent-border);
  padding: 12px 0;
  background: linear-gradient(180deg, rgba(25, 26, 38, 0.95), rgba(20, 21, 32, 0.9));
  margin: 0 -20px;
  padding-left: 20px;
  padding-right: 20px;
}

.compendium-tab {
  padding: 10px 20px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.compendium-tab:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.compendium-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.compendium-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.compendium-card {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.compendium-card:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.compendium-card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}

.compendium-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.compendium-card-tag {
  padding: 4px 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: capitalize;
  transition: all 0.2s ease;
}

.compendium-card:hover .compendium-card-tag {
  border-color: var(--accent);
}

.compendium-card-tag.rarity-common { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }
.compendium-card-tag.rarity-uncommon { background: rgba(94, 234, 212, 0.15); color: #5eead4; }
.compendium-card-tag.rarity-rare { background: var(--accent-soft); color: var(--accent); }
.compendium-card-tag.rarity-very-rare { background: rgba(255, 184, 74, 0.15); color: #ffb84a; }
.compendium-card-tag.rarity-legendary { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

.compendium-card-desc {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================
   CHARACTER SHEET STYLES
   ============================================ */

.char-sheet-container {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
}

.char-sheet-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.char-sheet-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.char-sheet-header-card {
  background: linear-gradient(180deg, var(--accent-soft), rgba(0, 0, 0, 0.2));
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}

.char-sheet-avatar {
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
}

.char-sheet-name {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.char-sheet-subtitle {
  font-size: 0.9rem;
  color: var(--muted);
}

.char-sheet-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.char-sheet-stat-card {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--accent-border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.char-sheet-stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.char-sheet-stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}

.char-sheet-stat-mod {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

.char-sheet-section {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  padding: 20px;
}

.char-sheet-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--accent-border);
}

.char-sheet-abilities {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.char-sheet-ability {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.char-sheet-ability-name {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.char-sheet-ability-score {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.char-sheet-ability-mod {
  font-size: 0.8rem;
  color: var(--accent2);
}

.char-sheet-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.char-sheet-tag {
  padding: 8px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text);
}

/* ============================================
   EQUIPMENT & SPELLS STYLES
   ============================================ */

.equipment-container,
.spells-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.equipment-header,
.spells-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
}

.equipment-gold {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ember);
}

.equipment-grid,
.spells-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.equipment-card,
.spell-card {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  padding: 16px;
  transition: all 0.2s ease;
}

.equipment-card:hover,
.spell-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.equipment-card.equipped {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.equipment-card-header,
.spell-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.equipment-card-name,
.spell-card-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.equipment-card-type,
.spell-card-level {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
}

.equipment-card-actions,
.spell-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

/* ============================================
   JOURNAL STYLES
   ============================================ */

.journal-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  min-height: 400px;
}

.journal-nav-vertical {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  height: fit-content;
}

.journal-nav-item {
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.journal-nav-item:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.journal-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.journal-content-area {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  padding: 24px;
}

.journal-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--accent-border);
}

.journal-entry-card {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
}

.journal-entry-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.journal-entry-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.journal-entry-desc {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .overlay {
    padding: calc(max(6px, env(safe-area-inset-top)) + 2px) 6px 6px;
    align-items: flex-start;
  }
  
  .overlay-panel {
    max-width: 100%;
    width: 100%;
    max-height: calc(100vh - var(--overlay-top-offset, 0px) - max(12px, env(safe-area-inset-top)) - env(safe-area-inset-bottom));
    min-height: auto;
    border-radius: 12px;
    border: 1px solid var(--accent-border);
    margin-top: 0;
  }

  .overlay-header {
    padding: 16px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(180deg, rgba(12, 14, 19, 0.98), rgba(12, 14, 19, 0.95));
  }

  .overlay-header h2 {
    font-size: 1.2rem;
  }

  .overlay-close {
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
    background: var(--accent-soft);
    border-color: var(--accent-border);
  }

  .overlay-content {
    padding: 16px;
    padding-top: 8px;
  }
  
  /* Character sheet mobile */
  .char-sheet-container {
    grid-template-columns: 1fr;
  }
  
  .char-sheet-sidebar {
    order: 2;
  }
  
  .char-sheet-main {
    order: 1;
  }
  
  .char-sheet-abilities {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .char-sheet-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  /* Compendium mobile */
  .compendium-grid {
    grid-template-columns: 1fr;
  }
  
  .compendium-toolbar {
    flex-direction: column;
  }
  
  .compendium-search {
    min-width: 100%;
  }
  
  .compendium-filters {
    width: 100%;
  }
  
  .compendium-filter {
    flex: 1;
    min-width: auto;
  }
  
  /* Journal mobile */
  .journal-layout {
    grid-template-columns: 1fr;
  }
  
  .journal-nav-vertical {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
  }
  
  .journal-nav-item {
    flex: 1;
    min-width: 100px;
    text-align: center;
    padding: 10px 12px;
  }
  
  /* Equipment/Spells mobile */
  .equipment-grid,
  .spells-grid {
    grid-template-columns: 1fr;
  }
  
  .equipment-header,
  .spells-header {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .overlay-content {
    padding: 12px;
  }
  
  .char-sheet-abilities {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .compendium-tabs {
    flex-wrap: wrap;
  }
  
  .compendium-tab {
    flex: 1;
    min-width: 100px;
    text-align: center;
    padding: 8px 12px;
    font-size: 0.85rem;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-style: italic;
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--accent-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Detail view for compendium items - Matching Character Sheet Style */
.compendium-detail {
  background: rgba(25, 26, 38, 0.6);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  padding: 20px;
}

.compendium-detail-header {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--accent-border);
}

.compendium-detail-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
}

/* Improved Stat Block for Monsters */
.compendium-detail-block {
  font-size: 0.9rem;
  line-height: 1.7;
  color: rgba(238, 240, 244, 0.95);
  background: rgba(25, 26, 38, 0.8);
  border: 1px solid rgba(180, 188, 199, 0.1);
  padding: 20px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
}

/* Stat Block Styling */
.compendium-detail-block .stat-block-header {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent-border);
}

.compendium-detail-block .stat-block-line {
  margin: 6px 0;
  padding: 4px 0;
}

.compendium-detail-block .stat-block-section {
  margin: 16px 0;
  padding: 12px;
  background: rgba(180, 188, 199, 0.05);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.compendium-detail-block .stat-block-section-title {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
  font-size: 0.95rem;
}

/* Ability Scores Grid */
.compendium-detail-block .ability-scores {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 12px 0;
  padding: 12px;
  background: rgba(180, 188, 199, 0.05);
  border-radius: 6px;
}

.compendium-detail-block .ability-score {
  text-align: center;
  padding: 8px;
  background: rgba(25, 26, 38, 0.6);
  border-radius: 4px;
  border: 1px solid rgba(180, 188, 199, 0.1);
}

.compendium-detail-block .ability-score-name {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
}

.compendium-detail-block .ability-score-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.compendium-detail-body {
  line-height: 1.7;
  color: rgba(238, 240, 244, 0.95);
}

.compendium-detail-body p {
  margin: 0 0 14px 0;
  line-height: 1.7;
}

.compendium-detail-body p:last-child {
  margin-bottom: 0;
}

.compendium-detail-body strong {
  color: var(--accent);
  font-weight: 600;
}

/* Item Properties Grid */
.compendium-detail-properties {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.compendium-detail-property {
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(25, 26, 38, 0.6);
  border: 1px solid rgba(180, 188, 199, 0.1);
  border-radius: 6px;
}

.compendium-detail-property-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.compendium-detail-property-value {
  color: var(--text);
  font-weight: 500;
}

/* Spell Meta Styling */
.compendium-detail-spell-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(180, 188, 199, 0.05);
  border-radius: 8px;
}

.compendium-detail-spell-meta .meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(25, 26, 38, 0.6);
  border-radius: 4px;
  border: 1px solid rgba(180, 188, 199, 0.1);
}

.compendium-detail-spell-meta .meta-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
}

.compendium-detail-spell-meta .meta-value {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}
