/* --- BASE TYPOGRAPHY --- */
html {
  font-size: 16px;
}
body {
  font-family: 'Georgia', serif;
  background: linear-gradient(to bottom, #111, #222);
  color: #f0e6d2;
  margin: 0;
  padding: 0;
}

/* --- HEADER STYLES --- */
header {
  background-color: #2b2b2b;
  padding: 1rem;
  text-align: center;
  border-bottom: 1px solid #444;
}

/* --- PANEL STYLES --- */
.codex-panel {
  margin: 1rem;
  padding: 1rem;
  background-color: #1c1c1c;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.05);
  position: relative; /* Ensure stacking context for overlays */
  z-index: 20; /* Bring panels above other content */
  pointer-events: auto; /* Always allow interaction */
  opacity: 1 !important; /* Ensure visible when active */
  visibility: visible !important;
  transition: opacity 0.2s, min-height 0.2s;
  min-height: 400px; /* Adjust as needed for your typical content */
}

/* Hide inactive panels robustly for all browsers */
.codex-panel[style*="display: none"] {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

/* --- LORE ARCHIVE STYLES --- */
.archive-separator {
  margin: 2.5em 0 1em 0;
  text-align: left;
}
.aether-header {
  color: #ffe066;
  font-size: 1.3em;
  letter-spacing: 1px;
  margin-top: 1.2 em;
}
.aether-entry {
  background: #23232b;
  border: 2px solid #ffe066;
  box-shadow: 0 2px 8px rgba(255, 224, 102, 0.08);
  padding: 1rem;
}

/* --- NAV BUTTONS FOR ARCHIVE/LORE PANELS --- */
#archive nav button,
#lorePanel nav button,
#loreEditor nav button {
  position: relative;
  z-index: 30;
  pointer-events: auto !important;
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* --- FILTER BUTTONS --- */
section nav button,
#archive nav button,
#lorePanel nav button,
#loreEditor nav button {
  margin: 0.3rem;
  padding: 0.5rem 1rem;
  background: #444;
  color: #f0e6d2;
  border: 2px solid transparent;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s, color 0.2s, border-color 0.2s;
}

/* Selected and hover states for nav/filter buttons */
section nav button.selected,
#archive nav button.selected,
#lorePanel nav button.selected,
#loreEditor nav button.selected,
section nav button:focus {
  background-color: #8a6239;
  color: white;
  border-color: #d4af37;
}
section nav button:hover:not(.selected) {
  background-color: #353b47;
  color: #ffe082;
  border-color: #ffe082;
}

/* --- QUEST STATE STYLES --- */
.completed {
  color: #888;
  text-decoration: line-through;
  opacity: 0.7;
  transition: all 0.3s ease;
}
.completed:hover {
  color: #d4af37;
  text-decoration: none;
  opacity: 1;
}
.active {
  color: #f0e6d2;
  font-weight: 500;
}

/* --- QUEST CARD STYLES --- */
.quest-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}
.quest-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 6px;
  margin-bottom: 1rem;
  padding: 0.75rem;
  transition: background 0.3s ease;
}
.quest-card:hover {
  background: #333;
}
.quest-line {
  font-size: 0.95rem;
  line-height: 1.4;
  word-break: break-word;
}
.desc {
  font-style: italic;
  color: #bbb;
  margin: 0.4rem 0;
}
.quest-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* --- BUTTONS & SELECTS --- */
button,
select {
  height: 2.2rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  border-radius: 6px;
  border: 1px solid #555;
  background-color: #2a2a2a;
  color: #f0e6d2;
}
button:hover {
  background-color: #8a6239;
  color: white;
}
button.toggle-active {
  background-color: #444;
  cursor: pointer;
}

/* --- REPEATABLE TAG --- */
.repeatable {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-color: #000;
  color: white;
  font-size: 1rem;
  font-weight: bold;
  text-align: center;
  line-height: 24px;
  border-radius: 4px;
  margin-left: 8px;
}

/* --- PRIORITY TAG --- */
.priority {
  font-size: 0.75rem;
  padding: 2px 6px;
  background-color: #444;
  color: #f0e6d2;
  border-radius: 4px;
  text-transform: capitalize;
  margin-left: 6px;
}

/* --- ZONE CARD STYLES --- */
.zone-card,
.life-zone {
  background-color: #2a2a2a;
  margin-bottom: 2rem;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.life-zone {
  border-left: 6px solid #8a6239;
}
.life-zone h4 {
  margin-top: 0.75rem;
  color: #e0cfa0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.main-quest {
  font-style: italic;
  font-size: 1rem;
  color: #f4dcb2;
  margin-bottom: 0.5rem;
}
.zone-card h4 {
  margin-bottom: 0.25rem;
  font-size: 1.25rem;
  color: #d4af37;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.zone-card h5 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
  color: #f0e6d2;
  position: relative;
}
.zone-card h5::before {
  content: '';
  display: block;
  height: 1px;
  background-color: #555;
  margin-bottom: 0.5rem;
}

.zone-list-item {
  background: #181a20;
  color: #fff;
  border-radius: 6px;
  margin: 8px 0;
  padding: 12px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 1rem;
}

.zone-list-item strong {
  font-size: 1.1em;
  margin-right: 12px;
}

.zone-list-item button {
  margin-left: 8px;
  background: #222;
  color: #ffd700;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}

.zone-list-item button:hover {
  background: #333;
}

/* --- REWARD BOX --- */
.reward-box {
  background: #333;
  padding: 0.75rem;
  margin-top: 1rem;
  border-radius: 6px;
  font-weight: bold;
  color: #d4af37;
  border-top: 1px solid #555;
}

/* --- PROGRESS BAR STYLES --- */
.progress-bar {
  display: inline-block;
  height: 8px;
  background: #4caf50;
  border-radius: 4px;
  min-width: 40px;
  max-width: 100px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  transition: width 0.4s ease;
}
.progress-fill.complete {
  background: #d4af37;
}
.progress-fill.halfway {
  background: #e2b970;
}
.progress-fill.starting {
  background: #555;
}
.zone-progress-wrapper {
  margin-top: 0.5rem;
}
.zone-progress-label {
  font-size: 0.85rem;
  color: #d4af37;
  font-weight: 500;
  margin-left: 1rem;
}

/* --- ACHIEVEMENTS PANEL --- */
.achievement-card {
  background: #282828;
  padding: 1rem;
  margin: 1rem 0;
  border-left: 6px solid #8a6239;
  border-radius: 8px;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.05);
}
.achievement-card.unlocked {
  border-left-color: #d4af37;
  background: #1f1f1f;
}
.badge {
  font-size: 1.5rem;
  margin-right: 0.5rem;
}

/* --- SECTION BREAKS --- */
.zone-break {
  border-top: 2px solid #555;
  margin: 2rem 0 1rem;
  opacity: 0.6;
  width: 80%;
}
.zone-break.glow {
  border-top: 2px solid #d4af37;
  box-shadow: 0 0 6px rgba(212,175,55,0.4);
  opacity: 0.8;
}

/* --- TAGS --- */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.tag {
  background: #444;
  color: #f0e6d2;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

/* --- ADD/EDIT TAB --- */
#add {
  padding: 2rem;
  background-color: #1c1c1c;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  max-width: 600px;
  margin: 2rem auto;
}
#questEditorForm {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
#questEditorForm label {
  font-weight: 600;
  color: #f0e6d2;
  margin-bottom: 0.3rem;
}
#questEditorForm input[type="text"],
#questEditorForm input[type="number"],
#questEditorForm textarea,
#questEditorForm select {
  padding: 0.6rem;
  font-size: 0.95rem;
  border-radius: 6px;
  border: 1px solid #555;
  background-color: #2a2a2a;
  color: #f0e6d2;
}
#questEditorForm input[type="checkbox"] {
  margin-right: 0.5rem;
}
#questEditorForm label[for="questRepeatable"] {
  display: flex;
  align-items: center;
}
#questEditorForm button[type="submit"],
#questEditorForm button[type="button"] {
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  border: none;
  border-radius: 6px;
  background-color: #8a6239;
  color: white;
  cursor: pointer;
  transition: background-color 0.2s ease;
}
#questEditorForm button[type="button"]:hover {
  background-color: #a67c52;
}

/* --- INACTIVE QUEST CARD --- */
.quest-card.inactive {
  opacity: 0.5;
  filter: grayscale(0.7);
  pointer-events: auto;
}

/* --- UTILITY/FALLBACK --- */
.fallback {
  color: #999;
  font-style: italic;
  margin-top: 1rem;
}

/* --- RESPONSIVE LAYOUT --- */
@media (max-width: 768px) {
  .tab-nav {
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
  }
  .quest-line,
  .quest-actions,
  .quest-controls {
    flex-direction: column;
    align-items: flex-start;
  }
  .zone-card,
  .life-zone,
  .codex-panel {
    margin: 0.5rem;
    padding: 0.75rem;
  }
  button,
  select,
  textarea,
  input {
    max-width: 100%;
    font-size: 1rem;
  }
}

/* --- ZONE PROGRESS LABEL --- */
.zone-progress-label {
  font-size: 0.85rem;
  color: #d4af37;
  font-weight: 500;
  margin-left: 1rem;
}

/* --- LEGEND KEY --- */
.legend-key {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1rem 0;
  font-size: 0.85rem;
  color: #f0e6d2;
  align-items: center;
}
.legend-key span {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* --- STATUS ICONS --- */
.status-icon {
  font-size: 1rem;
}
.active-icon {
  color: #4caf50;
}
.inactive-icon {
  color: #555;
}

/* --- LOGO STYLES --- */
.codex-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  color: #d4af37;
  margin-bottom: 0.5rem;
}
.logo-symbol {
  font-size: 2rem;
}
.logo-text {
  font-family: 'Georgia', serif;
  font-weight: bold;
  letter-spacing: 1px;
}

/* --- ZONE CARD (DUPLICATE, FOR CONSISTENCY) --- */
.zone-card {
  margin-bottom: 2.5rem;
  padding: 1.25rem;
  border-radius: 8px;
  background-color: #2a2a2a;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.zone-card h4 {
  margin-bottom: 0.25rem;
  font-size: 1.25rem;
  color: #d4af37;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.zone-card h5 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
  color: #f0e6d2;
  position: relative;
}
.zone-card h5::before {
  content: '';
  display: block;
  height: 1px;
  background-color: #555;
  margin-bottom: 0.5rem;
}

/* --- COLLAPSIBLE HEADERS --- */
.collapsible-header {
  cursor: pointer;
  font-weight: bold;
  position: relative;
}
.collapsible-header::after {
  content: '▼';
  font-size: 0.8rem;
  margin-left: 0.5rem;
  color: #d4af37;
  transition: transform 0.2s ease;
}
.quest-list.collapsed {
  display: none;
}
.collapsible-header.open::after {
  transform: rotate(180deg);
}

/* --- SMART INPUT STYLES --- */
#smartInput {
  width: 100%;
  font-family: 'Courier New', monospace;
  background-color: #1e1e1e;
  color: #f0e6d2;
  border: 1px solid #555;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  resize: vertical;
  border-radius: 4px;
}
#add label[for="smartInput"] {
  font-weight: bold;
  color: #d4af37;
  display: block;
  margin-top: 1rem;
}
#add button[onclick="processSmartInput()"] {
  display: block;
  margin-left: auto;
  margin-top: -0.5rem;
  background-color: #333;
  color: #d4af37;
  border: 1px solid #555;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 4px;
}

/* --- SUGGESTION BOX --- */
.suggestion-box {
  background-color: #1c1c1c;
  border: 1px solid #444;
  padding: 0.75rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}
.suggestion-box h4 {
  color: #d4af37;
  margin-bottom: 0.5rem;
}
.suggestion-box ul {
  list-style: disc;
  padding-left: 1.25rem;
  color: #f0e6d2;
  font-size: 0.95rem;
}
.suggestion-box li {
  margin-bottom: 0.3rem;
}

/* --- COMPLETED QUEST CARD --- */
.quest-card.completed {
  opacity: 0.6;
  text-decoration: line-through;
  background-color: #f0f0f0;
}

/* --- LORE ENTRY STYLES --- */
.lore-entry {
  margin-bottom: 1.5em;
  padding: 1em 1.2em;
  background: #232323; /* Dark background */
  border-left: 4px solid #c8a344;
  border-radius: 6px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
  color: #f0e6d2; /* Light text */
  transition: background 0.3s ease;
}
.lore-entry:hover {
  background: #181817;
}
.lore-entry h4 {
  margin: 0 0 0.2em;
  font-size: 1.25em;
  color: #5a3b00;
}
.lore-entry small {
  display: block;
  margin-bottom: 0.5em;
  color: #6d6d6d;
  font-size: 0.85em;
}
.lore-entry p {
  margin: 0.3em 0;
  line-height: 1.4;
  color: #f9f6ec;
}
.lore-entry em {
  font-style: italic;
  color: #946d00;
}

/* --- LORE EDITOR --- */
#loreEditor {
  margin-bottom: 2em;
  padding: 1em;
  background: #f9f6ec;
  border: 1px solid #d4c8a3;
  border-radius: 6px;
  position: relative; /* Ensure stacking context */
  z-index: 10; /* Bring above possible overlays */
  pointer-events: auto; /* Always allow interaction */
  overflow: visible; /* Prevent clipping of children */
}
#loreEditor h4 {
  margin-top: 0;
  font-size: 1.1em;
  color: #5a4600;
}
#loreEditor input,
#loreEditor textarea {
  display: block;
  width: 100%;
  margin: 0.5em 0;
  padding: 0.6em;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1em;
}
#loreEditor button {
  background: #c8a344;
  color: white;
  padding: 0.5em 1em;
  border: none;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.3s ease;
  z-index: 11; /* Ensure button is above other elements */
  position: relative;
  pointer-events: auto;
}
#loreEditor button:hover {
  background: #a78430;
}

/* --- LORE PANEL --- */
#lorePanel {
  margin-top: 1em;
  position: relative;
  z-index: 5;
}

/* --- TAB NAVIGATION --- */
.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5em;
  justify-content: center;
  margin-bottom: 1.5em;
  background: #1c1c1c;
  padding: 0.75rem;
  border-radius: 8px 8px 0 0;
}
.tab-nav button {
  background: #23272f;
  color: #f0e6d2;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 0.7em 1.4em;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, color 0.2s, border-color 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 160px; /* Optional: makes all buttons same width */
}

/* --- NAVIGATION BUTTONS --- */
.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5em;
  justify-content: center;
  margin-bottom: 1.5em;
  background: #1c1c1c;
  padding: 0.75rem;
  border-radius: 8px 8px 0 0;
}
.nav-group {
  display: flex;
  gap: 0.5em;
}
.tab-nav button {
  background: #23272f;
  color: #f0e6d2;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 0.7em 1.4em;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, color 0.2s, border-color 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 160px; /* Optional: makes all buttons same width */
}
.tab-nav button.selected,
.tab-nav button:focus {
  background: #d4af37;
  color: #23272f;
  border-color: #d4af37;
  box-shadow: 0 2px 8px rgba(212,175,55,0.15);
}
.tab-nav button:hover:not(.selected) {
  background: #353b47;
  color: #ffe082;
  border-color: #ffe082;
}
.tab-nav button:active {
  outline: none;
  box-shadow: 0 2px 8px rgba(212,175,55,0.15);
}

/* --- PANELS --- */
.codex-panel {
  background: #181a20;
  border-radius: 10px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.12);
  padding: 2em 1.5em;
  margin: 1.5em auto;
  max-width: 1100px; /* or more, as needed */
  width: 98%;
  transition: box-shadow 0.2s;
}

/* --- PANEL HEADER --- */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2em;
}
.edit-btn {
  background: #d4af37;
  color: #23272f;
  border: none;
  border-radius: 4px;
  padding: 0.4em 1em;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.edit-btn:hover,
.edit-btn:focus {
  background: #ffe082;
  color: #181a20;
}

/* --- RESPONSIVE DESIGN --- */
@media (max-width: 700px) {
  .codex-panel {
    padding: 1em 0.5em;
    max-width: 100vw;
  }
  .tab-nav {
    flex-direction: column;
    gap: 0.7em;
  }
  .nav-group {
    flex-direction: column;
    gap: 0.3em;
  }
  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5em;
  }
}

/* --- ADD TO JOURNAL BUTTON --- */
.add-to-journal {
  margin-left: 8px;
  margin-top: 2px;
  margin-bottom: 2px;
}

/* --- ACTIVE OBJECTIVE LIST ITEM --- */
li.active {
  margin-bottom: 10px;
}

/* --- PENDING BADGE --- */
.pending-badge {
  margin-left: 8px;
  color: #b8860b;
  font-weight: bold;
  font-size: 0.95em;
}
.progress-tracker {
  display: inline-block;
  margin-left: 10px;
  vertical-align: middle;
}
.progress-bar {
  display: inline-block;
  height: 8px;
  background: #4caf50;
  border-radius: 4px;
  min-width: 40px;
  max-width: 100px;
}
.progress-label {
  margin-left: 6px;
  font-size: 0.9em;
  color: #333;
}
.retract-quest, .restart-quest {
  margin-left: 10px;
  font-size: 0.95em;
  background: #f5f5f5;
  color: #222;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 4px 12px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}
.retract-quest:hover, .restart-quest:hover {
  background: #e0e0e0;
}