/* ═══════════════════════════════════════════════════════════════
   Three Towns Quest Explorer – Stylesheet
   Dark fantasy theme: deep navy/obsidian bg, gold/amber accents
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  --bg:         #0d0f1a;
  --bg2:        #131628;
  --panel:      #181c30;
  --panel2:     #1e2340;
  --border:     #2e3460;
  --border-hi:  #4a5280;
  --gold:       #d4a843;
  --gold-hi:    #f0c86a;
  --gold-dim:   #8a6a20;
  --text:       #c8bfa0;
  --text-dim:   #7a7060;
  --text-hi:    #f0e8cc;
  --npc-clr:    #3b7fcf;
  --player-clr: #4a9e6b;
  --danger:     #c0392b;
  --warn:       #e67e22;
  --info:       #2980b9;
  --radius:     8px;
  --shadow:     0 4px 24px rgba(0,0,0,0.6);
  --font-title: 'Cinzel', serif;
  --font-body:  'Crimson Text', Georgia, serif;
  font-size: 16px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }

/* ──────────────────────────────────────────────
   LOADING OVERLAY
   ────────────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.2rem;
}
.spinner {
  width: 50px; height: 50px;
  border: 4px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--gold);
  letter-spacing: 0.08em;
}
#loading-overlay.hidden { display: none; }

/* ──────────────────────────────────────────────
   HEADER
   ────────────────────────────────────────────── */
#app-header {
  height: 52px;
  background: linear-gradient(90deg, #0d0f1a 0%, #1a1e38 50%, #0d0f1a 100%);
  border-bottom: 1px solid var(--gold-dim);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.2rem;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.6);
  position: relative;
}
.header-left { display: flex; align-items: center; gap: 0.7rem; }
.header-icon { font-size: 1.4rem; }
#app-header h1 {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.05em;
}
.header-sub {
  font-size: 0.85rem;
  color: var(--text-dim);
  padding-left: 0.5rem;
  border-left: 1px solid var(--border);
  margin-left: 0.2rem;
}
.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
  transition: all 0.2s;
}
.btn-icon:hover { border-color: var(--gold-dim); color: var(--gold); }

/* ──────────────────────────────────────────────
   MAIN LAYOUT (3 columns)
   ────────────────────────────────────────────── */
#app-main {
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  height: calc(100vh - 52px);
  overflow: hidden;
}

/* ─── Shared panel styles ─── */
aside, main {
  display: flex; flex-direction: column;
  overflow: hidden;
}
aside { border-right: 1px solid var(--border); }
aside:last-child { border-right: none; border-left: 1px solid var(--border); }

.panel-header {
  padding: 0.7rem 1rem;
  background: var(--panel2);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.06em;
  display: flex; align-items: center; gap: 0.6rem;
  flex-shrink: 0;
}

/* ──────────────────────────────────────────────
   LEFT PANEL – Quest List
   ────────────────────────────────────────────── */
#quest-panel { background: var(--panel); }

#quest-search {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  outline: none;
}
#quest-search:focus { border-color: var(--gold-dim); }

#quest-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.quest-card {
  padding: 0.55rem 0.75rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}
.quest-card:hover {
  border-color: var(--border-hi);
  border-left-color: var(--gold-dim);
  background: var(--panel2);
}
.quest-card.active {
  border-color: var(--gold-dim);
  border-left-color: var(--gold);
  background: rgba(212,168,67,0.08);
}
.quest-card-name {
  font-family: var(--font-title);
  font-size: 0.8rem;
  color: var(--text-hi);
  letter-spacing: 0.03em;
}
.quest-card-id {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
}
.quest-card-stage {
  display: inline-block;
  margin-top: 0.2rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.68rem;
  background: rgba(74,162,107,0.2);
  color: var(--player-clr);
  border: 1px solid rgba(74,162,107,0.3);
}
.quest-card-stage.stage-0 { display: none; }

/* ──────────────────────────────────────────────
   CENTER PANEL
   ────────────────────────────────────────────── */
#center-panel { background: var(--bg); }

#empty-state {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1rem;
  color: var(--text-dim);
}
.empty-icon { font-size: 3rem; filter: grayscale(1); opacity: 0.3; }

#quest-detail { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#quest-detail-header {
  padding: 0.8rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
#quest-title {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--gold);
}
#quest-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
  display: block;
}

/* View toggle */
#view-toggle { display: flex; gap: 0.4rem; }
.view-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.82rem;
  transition: all 0.2s;
}
.view-btn:hover { border-color: var(--border-hi); color: var(--text); }
.view-btn.active { background: rgba(212,168,67,0.12); border-color: var(--gold-dim); color: var(--gold); }

/* NPC selector chips */
#npc-selector {
  padding: 0.5rem 0.8rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  flex-shrink: 0;
}
.npc-chip {
  padding: 0.25rem 0.65rem 0.3rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text-dim);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.npc-chip:hover { border-color: var(--npc-clr); color: var(--text); }
.npc-chip.active {
  background: rgba(59,127,207,0.15);
  border-color: var(--npc-clr);
  color: #7ab8f0;
}
.npc-chip .chip-type { font-size: 0.65rem; opacity: 0.7; margin-left: 0.2em; }

/* NPC chip row: name-chip + optional kill button */
.npc-chip-wrap {
  display: flex;
  align-items: center;
  gap: 0.18rem;
}

/* Quest-giver: sets quest to stage 1 — gold border */
.npc-quest-giver .npc-chip {
  border-color: var(--gold);
  background: rgba(212,168,67,0.10);
  color: var(--gold-hi);
}
.npc-quest-giver .npc-chip::before {
  content: '★ ';
  color: var(--gold);
  font-size: 0.7em;
}

/* Kill target chip — subtle red tint on the chip */
.npc-kill-target .npc-chip {
  border-color: #7a2525;
}

/* Stage badge on kill-target chips */
.chip-stage {
  display: inline-block;
  margin-left: 0.35em;
  padding: 0.05em 0.35em;
  border-radius: 3px;
  font-size: 0.65rem;
  background: rgba(160,40,40,0.25);
  color: #e07070;
  border: 1px solid #7a2525;
  vertical-align: middle;
}

/* Quest path badges row */
.chip-paths {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  margin-top: 0.25rem;
}

.path-badge {
  display: inline-block;
  padding: 0.07em 0.4em;
  border-radius: 3px;
  font-size: 0.62rem;
  font-family: monospace;
  line-height: 1.4;
  cursor: default;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: opacity 0.15s;
}
.path-kill   { background: rgba(160,40,40,0.22);  border-color: #7a2525; color: #e07070; }
.path-dialog { background: rgba(59,127,207,0.18); border-color: #2e5a9a; color: #7ab8f0; }
.path-auto   { background: rgba(74,162,107,0.18); border-color: #2e6a45; color: #7acf98; }
.path-locked { opacity: 0.35; filter: grayscale(0.6); }

/* Kill button adjacent to npc chip */
.btn-kill {
  padding: 0.18rem 0.45rem;
  border-radius: 14px;
  border: 1px solid #7a2525;
  background: rgba(160,40,40,0.18);
  color: #e07070;
  font-size: 0.82rem;
  cursor: pointer;
  line-height: 1;
  transition: all 0.15s;
  user-select: none;
}
.btn-kill:hover:not(.disabled) {
  background: rgba(200,60,60,0.35);
  border-color: #c84040;
  color: #f8a0a0;
}
.btn-kill.disabled {
  opacity: 0.32;
  cursor: not-allowed;
  pointer-events: auto; /* keep tooltip hover */
}

/* Heal button */
.btn-heal {
  padding: 0.18rem 0.45rem;
  border-radius: 14px;
  border: 1px solid #2a6b3a;
  background: rgba(40,140,70,0.18);
  color: #70c090;
  font-size: 0.82rem;
  cursor: pointer;
  line-height: 1;
  transition: all 0.15s;
  user-select: none;
}
.btn-heal:hover:not(.disabled) {
  background: rgba(60,180,90,0.35);
  border-color: #40b860;
  color: #a0f0b0;
}
.btn-heal.disabled {
  opacity: 0.32;
  cursor: not-allowed;
  pointer-events: auto;
}

/* Heal result bubble */
.bubble-heal {
  align-self: stretch;
  background: rgba(35,100,55,0.18);
  border: 1px solid #2a6b3a;
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  margin: 0.15rem 0;
  color: #70c090;
  font-size: 0.85rem;
}
.bubble-heal .heal-header { font-weight: 600; }

/* Kill result bubble */
.bubble-kill {
  align-self: stretch;
  background: rgba(140,35,35,0.18);
  border: 1px solid #7a2525;
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  margin: 0.15rem 0;
  color: #e07070;
  font-size: 0.85rem;
}
.bubble-kill .kill-header { font-weight: 600; }

.dialogue-divider {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-dim);
  opacity: 0.55;
  padding: 0.3rem 0;
  user-select: none;
}

/* ──────────────────────────────────────────────
   DIALOGUE VIEW
   ────────────────────────────────────────────── */
#dialogue-view {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden;
  padding: 0;
}

#dialogue-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex; flex-direction: column;
  gap: 0.75rem;
}

/* NPC bubble */
.bubble-npc {
  max-width: 80%;
  align-self: flex-start;
}
.bubble-npc .bubble-speaker {
  font-family: var(--font-title);
  font-size: 0.7rem;
  color: #7ab8f0;
  letter-spacing: 0.05em;
  margin-bottom: 0.2rem;
}
.bubble-npc .bubble-text {
  background: var(--panel2);
  border: 1px solid rgba(59,127,207,0.35);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 0.6rem 0.9rem;
  font-size: 1rem;
  color: var(--text-hi);
  line-height: 1.55;
}
.bubble-npc .bubble-text em {
  color: var(--text-dim);
  font-style: italic;
}

/* Player choice result */
.bubble-player {
  max-width: 80%;
  align-self: flex-end;
}
.bubble-player .bubble-text {
  background: rgba(74,158,107,0.12);
  border: 1px solid rgba(74,158,107,0.35);
  border-radius: var(--radius) 0 var(--radius) var(--radius);
  padding: 0.5rem 0.9rem;
  font-size: 0.95rem;
  color: #8fd9a8;
  font-style: italic;
}

/* Script/action notification pill */
.bubble-action {
  align-self: center;
  font-size: 0.75rem;
  padding: 0.2rem 0.8rem;
  border-radius: 12px;
  border: 1px solid;
}
.bubble-action.quest   { background: rgba(212,168,67,0.1); border-color: var(--gold-dim); color: var(--gold); }
.bubble-action.item    { background: rgba(74,158,107,0.12); border-color: #3a7a50; color: #7acf98; }
.bubble-action.reward  { background: rgba(212,168,67,0.15); border-color: var(--gold); color: var(--gold-hi); }

/* Reply choices */
#reply-choices {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 0.7rem 1rem;
  display: flex; flex-direction: column; gap: 0.4rem;
  flex-shrink: 0;
}
.choice-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: all 0.15s;
  line-height: 1.4;
}
.choice-btn:hover {
  background: rgba(74,158,107,0.1);
  border-color: var(--player-clr);
  color: var(--text-hi);
}
.choice-btn .choice-num {
  font-size: 0.72rem;
  color: var(--player-clr);
  font-family: var(--font-title);
  margin-right: 0.4rem;
}

.dialogue-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-dim);
  font-style: italic;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  flex-shrink: 0;
}

.btn-sm {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.2rem 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.8rem;
  transition: all 0.15s;
}
.btn-sm:hover { border-color: var(--gold-dim); color: var(--gold); }

/* ──────────────────────────────────────────────
   GRAPH VIEW
   ────────────────────────────────────────────── */
#graph-view {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden;
  position: relative;
}

#graph-toolbar {
  padding: 0.45rem 0.8rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
  font-size: 0.78rem;
}
.graph-legend {
  display: flex; align-items: center; gap: 0.9rem;
  color: var(--text-dim);
}
.legend-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 0.3em;
}
.legend-dot.npc     { background: #1d4e89; border: 1px solid #3b7fcf; }
.legend-dot.player  { background: #1a4731; border: 1px solid #4a9e6b; }
.legend-dot.start   { background: #6b4e1a; border: 1px solid var(--gold); }
.legend-dot.end-node { background: #3a1a1a; border: 1px solid #c0392b; }
.graph-controls { display: flex; gap: 0.4rem; }

#cy-container {
  flex: 1;
  min-height: 400px;
  height: 0;          /* forces flex-grow to own the space */
  background: var(--bg);
  cursor: grab;
}
#cy-container:active { cursor: grabbing; }

/* Graph tooltip */
#graph-tooltip {
  position: absolute;
  z-index: 100;
  max-width: 280px;
  background: var(--panel2);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  pointer-events: none;
  box-shadow: var(--shadow);
}
#graph-tooltip .tt-label {
  font-family: var(--font-title);
  font-size: 0.7rem;
  color: var(--gold-dim);
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}
#graph-tooltip .tt-text {
  color: var(--text-hi);
  line-height: 1.45;
}
#graph-tooltip .tt-script {
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--warn);
  font-family: monospace;
}

/* ──────────────────────────────────────────────
   RIGHT PANEL – Character State
   ────────────────────────────────────────────── */
#state-panel { background: var(--panel); }

.state-section {
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--border);
  overflow-y: auto;
  max-height: 33vh;
}
.state-section:last-child { border-bottom: none; flex: 1; max-height: none; }
.state-section-title {
  font-family: var(--font-title);
  font-size: 0.72rem;
  color: var(--gold-dim);
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}
.muted { color: var(--text-dim); font-size: 0.82rem; }

/* Journal entries */
.journal-entry {
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.journal-entry:last-child { border-bottom: none; }
.journal-name {
  font-family: var(--font-title);
  font-size: 0.74rem;
  color: var(--gold);
  cursor: pointer;
}
.journal-name:hover { color: var(--gold-hi); text-decoration: underline; }
.journal-stage {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
}
.journal-stage-badge {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  background: rgba(212,168,67,0.12);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-size: 0.65rem;
  margin-right: 0.3rem;
}

/* Inventory items */
.inv-item {
  padding: 0.25rem 0;
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(46,52,96,0.5);
  display: flex; align-items: center; gap: 0.4rem;
}
.inv-item:last-child { border-bottom: none; }
.inv-item-icon { font-size: 0.9rem; }
.inv-item-name { color: var(--text); }

/* Activity log */
#activity-log {
  display: flex; flex-direction: column;
  gap: 0.3rem;
  max-height: calc(30vh - 2rem);
  overflow-y: auto;
}
.log-entry {
  font-size: 0.76rem;
  color: var(--text-dim);
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(46,52,96,0.3);
  line-height: 1.35;
  display: flex; align-items: flex-start; gap: 0.4rem;
}
.log-entry:last-child { border-bottom: none; }
.log-time {
  color: var(--border-hi);
  font-size: 0.68rem;
  flex-shrink: 0;
  margin-top: 0.05rem;
}
.log-msg { flex: 1; }
.log-entry.quest-log .log-msg { color: var(--gold); }
.log-entry.item-log .log-msg { color: var(--player-clr); }
.log-entry.reward-log .log-msg { color: var(--gold-hi); }

/* ──────────────────────────────────────────────
   HELPERS
   ────────────────────────────────────────────── */
.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bubble-npc, .bubble-player, .bubble-action {
  animation: fadeIn 0.2s ease;
}

/* Responsive tweaks */
@media (max-width: 900px) {
  #app-main { grid-template-columns: 200px 1fr; }
  #state-panel { display: none; }
}
@media (max-width: 620px) {
  #app-main { grid-template-columns: 1fr; }
  #quest-panel { display: none; }
}

/* ──────────────────────────────────────────────
   GLOBAL TABS  (header center)
   ────────────────────────────────────────────── */
.header-center {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.global-tab {
  font-family: var(--font-title);
  font-size: 0.82rem;
  padding: 0.3rem 1rem;
  border-radius: 4px;
  border: 1px solid var(--gold-dim);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.04em;
}
.global-tab:hover { background: rgba(212,168,67,0.08); color: var(--gold); }
.global-tab.active {
  background: rgba(212,168,67,0.14);
  color: var(--gold);
  border-color: var(--gold);
}

/* ──────────────────────────────────────────────
   JOURNAL PANEL  (two-column: TOC + reader)
   ────────────────────────────────────────────── */
#journal-panel {
  display: flex;
  height: calc(100vh - 52px);
  box-sizing: border-box;
  overflow: hidden;
}
#journal-toc {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--gold-dim);
  background: var(--sidebar-bg, #10131f);
  height: 100%;
  overflow: hidden;
}
.journal-toc-header {
  padding: 0.7rem 0.8rem 0.6rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}
.journal-toc-title {
  font-family: var(--font-title);
  font-size: 0.82rem;
  color: var(--gold);
  letter-spacing: 0.04em;
}
#journal-toc-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.4rem 0;
}
.journal-toc-item {
  padding: 0.55rem 1rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}
.journal-toc-item:hover  { background: rgba(212,168,67,0.07); }
.journal-toc-item.active { background: rgba(212,168,67,0.12); border-left-color: var(--gold); }
.journal-toc-name {
  font-family: var(--font-body);
  font-size: 0.84rem;
  color: var(--text);
  line-height: 1.3;
}
.journal-toc-done { color: #7acf98; }
.journal-toc-badge {
  font-size: 0.68rem;
  color: var(--text-dim);
  font-family: var(--font-title);
  letter-spacing: 0.04em;
}
.journal-toc-item.active .journal-toc-name { color: var(--gold); font-weight: 600; }
.journal-toc-item.active .journal-toc-badge { color: var(--gold-dim); }

/* Reader pane */
#journal-reader {
  flex: 1;
  overflow-y: auto;
  background: #fdf6e3;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: 100%;
  box-sizing: border-box;
}
#journal-reader-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  color: #b0a080;
  gap: 0.8rem;
}
#journal-reader-empty p {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 1.05rem;
  color: #b0a080;
  margin: 0;
}
#journal-reader-content {
  width: 100%;
  max-width: 640px;
  padding: 3rem 2.5rem 5rem;
  box-sizing: border-box;
}
.journal-reader-meta {
  margin-bottom: 0.7rem;
}
.journal-reader-badge {
  display: inline-block;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  padding: 0.18rem 0.65rem;
  border-radius: 3px;
  background: rgba(212,168,67,0.12);
  border: 1px solid rgba(180,140,50,0.4);
  color: #7a6530;
}
.journal-reader-badge.badge-done {
  background: rgba(122,207,152,0.12);
  border-color: rgba(80,160,100,0.35);
  color: #3a7a50;
}
#journal-reader-title {
  font-family: 'Cinzel', 'Times New Roman', serif;
  font-size: 1.45rem;
  font-weight: 700;
  color: #2c1e0f;
  margin: 0 0 1.8rem;
  line-height: 1.25;
  letter-spacing: 0.03em;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid #d4b896;
}
#journal-reader-body {
  font-family: 'Crimson Text', Georgia, 'Times New Roman', serif;
  font-size: 1.15rem;
  color: #2c1e0f;
  line-height: 1.85;
}
#journal-reader-body p {
  margin: 0 0 1.2em;
  text-indent: 1.5em;
}
#journal-reader-body p:first-child { text-indent: 0; }
#journal-reader-body em { font-style: italic; color: #4a3520; }

/* ──────────────────────────────────────────────
   BOOKS EXPLORER  (two-column: TOC + reader)
   ────────────────────────────────────────────── */
#books-panel {
  display: flex;
  height: calc(100vh - 52px);
  box-sizing: border-box;
  overflow: hidden;
}

/* ── Left column: table of contents ── */
#books-toc {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--gold-dim);
  background: var(--sidebar-bg, #10131f);
  height: 100%;
  overflow: hidden;
}
.books-toc-header {
  padding: 0.7rem 0.8rem 0.6rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.books-toc-header input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  border: 1px solid var(--gold-dim);
  background: rgba(0,0,0,0.35);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-body);
}
.books-toc-header input:focus { outline: none; border-color: var(--gold); }
.books-count {
  font-size: 0.7rem;
  color: var(--text-dim);
  padding-left: 0.2rem;
}
#books-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.4rem 0;
}
.book-list-item {
  padding: 0.5rem 1rem;
  font-size: 0.83rem;
  font-family: var(--font-body);
  color: var(--text-dim);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  line-height: 1.35;
}
.book-list-item:hover {
  background: rgba(212,168,67,0.07);
  color: var(--text);
}
.book-list-item.active {
  background: rgba(212,168,67,0.12);
  color: var(--gold);
  border-left-color: var(--gold);
  font-weight: 600;
}

/* ── Right column: ereader pane ── */
#books-reader {
  flex: 1;
  overflow-y: auto;
  background: #fdf6e3;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: 100%;
  box-sizing: border-box;
}
#books-reader-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  color: #b0a080;
  gap: 0.8rem;
}
.reader-empty-icon { font-size: 3rem; }
#books-reader-empty p {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 1.05rem;
  color: #b0a080;
  margin: 0;
}
#books-reader-content {
  width: 100%;
  max-width: 640px;
  padding: 3.5rem 2.5rem 5rem;
  box-sizing: border-box;
}
.reader-inner {
  /* subtle drop shadow to evoke a page */
}
#books-reader-title {
  font-family: 'Cinzel', 'Times New Roman', serif;
  font-size: 1.55rem;
  font-weight: 700;
  color: #2c1e0f;
  margin: 0 0 0.3rem;
  line-height: 1.25;
  letter-spacing: 0.03em;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid #d4b896;
  margin-bottom: 2rem;
}
#books-reader-body {
  font-family: 'Crimson Text', Georgia, 'Times New Roman', serif;
  font-size: 1.15rem;
  color: #2c1e0f;
  line-height: 1.8;
}
#books-reader-body p {
  margin: 0 0 1.1em;
  text-indent: 1.5em;
}
#books-reader-body p:first-child {
  text-indent: 0;
}
#books-reader-body em {
  font-style: italic;
  color: #4a3520;
}
.reader-no-text {
  font-style: italic;
  color: #998866;
}

/* ──────────────────────────────────────────────
   WALKTHROUGH VIEW
   ────────────────────────────────────────────── */
#walkthrough-view {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden;
}

/* Stage graph pane */
#wt-cy-wrap {
  position: relative;
  flex: 0 0 240px;
  border-bottom: 1px solid var(--gold-dim);
  background: var(--bg);
}
#wt-cy-container {
  width: 100%;
  height: 240px;
}
.wt-graph-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.85rem;
}
.wt-graph-legend {
  position: absolute;
  bottom: 6px;
  right: 10px;
  display: flex;
  gap: 0.8rem;
  font-size: 0.72rem;
  pointer-events: none;
}
.wt-leg { display: flex; align-items: center; gap: 0.25rem; color: var(--text-dim); }
.wt-leg.kill   { color: #cf7b7b; }
.wt-leg.dialog { color: #7bcfcf; }
.wt-leg.auto   { color: #d4a843; }

/* Sequence list pane */
#wt-sequence {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.wt-empty {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.85rem;
  padding: 1rem;
}
.wt-stage-block {
  background: rgba(18,22,48,0.7);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.wt-stage-block.wt-stage-end {
  border-color: rgba(158,90,90,0.4);
  background: rgba(30,18,18,0.6);
}
.wt-stage-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.45rem 0.75rem;
  background: rgba(0,0,0,0.2);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.wt-stage-badge {
  font-family: var(--font-title);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--gold);
  white-space: nowrap;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--gold-dim);
  border-radius: 3px;
  background: rgba(212,168,67,0.08);
}
.wt-stage-badge.wt-badge-end {
  color: #cf7b7b;
  border-color: rgba(158,90,90,0.4);
  background: rgba(158,90,90,0.1);
}
.wt-journal-line {
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.4;
  flex: 1;
  min-width: 0;
}
.wt-action-list {
  list-style: none;
  margin: 0;
  padding: 0.2rem 0;
}
.wt-action {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.3rem 0.75rem;
  font-size: 0.83rem;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.wt-action:last-child { border-bottom: none; }
.wt-icon { font-size: 0.9rem; flex-shrink: 0; }
.wt-npc {
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.wt-label {
  color: var(--text-dim);
  font-style: italic;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wt-arrow { color: var(--border-hi); flex-shrink: 0; }
.wt-to-stage {
  font-family: var(--font-title);
  font-size: 0.72rem;
  color: var(--gold);
  white-space: nowrap;
  flex-shrink: 0;
}
.wt-action.wt-action-kill   .wt-npc { color: #cf7b7b; }
.wt-action.wt-action-dialog .wt-npc { color: #7bcfcf; }
.wt-action.wt-action-auto   .wt-npc { color: #d4a843; }

/* ──────────────────────────────────────────────
   JOURNAL ENHANCEMENTS
   ────────────────────────────────────────────── */
.journal-text {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.35rem;
  line-height: 1.5;
  white-space: pre-wrap;
  border-left: 2px solid var(--gold-dim);
  padding-left: 0.5rem;
}
.journal-completed .journal-name,
.journal-name.journal-completed {
  color: #7acf98;
}

/* Journal bubble (inline in dialogue) */
.bubble-action.journal {
  background: rgba(32,52,88,0.55);
  border: 1px solid rgba(80,140,220,0.35);
  border-radius: 4px;
  padding: 0.35rem 0.7rem;
  margin-top: 0.25rem;
  cursor: pointer;
  color: #9ecaff;
}
.bubble-action.journal summary {
  font-size: 0.82rem;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.bubble-action.journal summary::marker { display: none; }
.bubble-action.journal[open] summary { margin-bottom: 0.4rem; }
.journal-bubble-text {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.55;
  white-space: pre-wrap;
  padding-top: 0.25rem;
  border-top: 1px solid rgba(80,140,220,0.15);
}
