/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:    #0d0a06;
  --bg-dark:    #1a1108;
  --bg-panel:   #130f08;
  --bg-card:    #1e1810;
  --bg-hover:   #2a2014;
  --gold:       #c9a84c;
  --gold-light: #e8c97e;
  --gold-dim:   #7a6030;
  --cream:      #e8dfc8;
  --cream-dim:  #9c9070;
  --red-dark:   #8b2020;
  --red-bright: #d44040;
  --green-dark: #1a4020;
  --green-bright: #3a8050;
  --blue-dark:  #1a2840;
  --blue-bright:#4080b0;
  --border:     #3a2e18;
  --border-gold:#5a4820;
  --shadow:     0 4px 20px rgba(0,0,0,0.7);
  --font-body:  'Georgia', 'Times New Roman', serif;
  --font-ui:    'Arial', 'Helvetica', sans-serif;
  --font-title: 'Georgia', serif;
  --transition: 0.25s ease;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--cream);
  font-family: var(--font-body);
}

/* ===== LAYOUT ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
  border-bottom: 2px solid var(--border-gold);
  padding: 0 20px;
  height: 52px;
  flex-shrink: 0;
  z-index: 10;
}

#topbar-title {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--gold-light);
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 10px;
}

#topbar-title .skull { font-size: 1.3rem; }

#topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

#main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== LEFT PANEL ===== */
#left-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-dark);
  position: relative;
}

#breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  min-height: 38px;
  flex-shrink: 0;
  flex-wrap: wrap;
  overflow-x: auto;
}

.crumb {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--cream-dim);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  transition: color var(--transition), background var(--transition);
}
.crumb:hover { color: var(--gold-light); background: var(--bg-hover); }
.crumb.active { color: var(--gold); }
.crumb-sep { color: var(--border-gold); font-size: 0.7rem; }

#chapter-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px 48px 24px;
  scroll-behavior: smooth;
}

#chapter-area::-webkit-scrollbar { width: 6px; }
#chapter-area::-webkit-scrollbar-track { background: var(--bg-dark); }
#chapter-area::-webkit-scrollbar-thumb { background: var(--border-gold); border-radius: 3px; }

#chapter-label {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--gold-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

#chapter-title {
  font-family: var(--font-title);
  font-size: 1.6rem;
  color: var(--gold-light);
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-gold);
}

/* Chapter content typography */
#chapter-body { font-size: 1.02rem; line-height: 1.85; }
#chapter-body p { margin-bottom: 1.1em; color: var(--cream); }
#chapter-body strong { color: var(--gold-light); }
#chapter-body em { color: var(--cream-dim); font-style: italic; }
#chapter-body h3, #chapter-body h4 {
  font-family: var(--font-title);
  color: var(--gold);
  margin: 1.2em 0 0.6em;
  font-size: 1rem;
}
#chapter-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.9rem;
}
#chapter-body th {
  background: var(--bg-card);
  color: var(--gold);
  border: 1px solid var(--border-gold);
  padding: 8px 12px;
  text-align: left;
}
#chapter-body td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  color: var(--cream-dim);
}
#chapter-body tr:nth-child(even) td { background: rgba(255,255,255,0.03); }
#chapter-body blockquote {
  border-left: 3px solid var(--gold-dim);
  margin: 1em 0;
  padding: 8px 16px;
  color: var(--cream-dim);
  font-style: italic;
  background: rgba(201,168,76,0.05);
}
#chapter-body code {
  background: var(--bg-card);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.88em;
  color: var(--gold-light);
}

/* Choices area */
#choices-area {
  padding: 16px 48px 24px;
  flex-shrink: 0;
  background: linear-gradient(to top, var(--bg-dark) 60%, transparent);
}

.choice-btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-left: 3px solid var(--gold-dim);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
  border-radius: 3px;
  position: relative;
}
.choice-btn::before {
  content: '▸';
  color: var(--gold-dim);
  margin-right: 10px;
  transition: color var(--transition), transform var(--transition);
  display: inline-block;
}
.choice-btn:hover {
  background: var(--bg-hover);
  border-color: var(--gold);
  border-left-color: var(--gold-light);
  color: var(--gold-light);
  transform: translateX(4px);
}
.choice-btn:hover::before { color: var(--gold-light); }
.choice-btn.game-end {
  border-color: var(--red-dark);
  border-left-color: var(--red-bright);
  color: var(--red-bright);
}

/* Inline choice button (inside chapter body text) */
.choice-inline {
  background: rgba(201,168,76,0.1);
  border: 1px solid var(--gold-dim);
  color: var(--gold-light);
  padding: 1px 7px;
  border-radius: 3px;
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  transition: all 0.2s;
  display: inline;
}
.choice-inline:hover {
  background: rgba(201,168,76,0.25);
  border-color: var(--gold-light);
}

/* Chapter transition */
#chapter-area.fade-out { opacity: 0; transform: translateX(-8px); transition: opacity 0.18s, transform 0.18s; }
#chapter-area.fade-in { opacity: 1; transform: translateX(0); transition: opacity 0.18s 0.05s, transform 0.18s 0.05s; }

/* Bottom nav */
#bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-btn {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--cream-dim);
  background: none;
  border: 1px solid var(--border);
  padding: 5px 14px;
  border-radius: 3px;
  cursor: pointer;
  transition: all var(--transition);
}
.nav-btn:hover { color: var(--gold-light); border-color: var(--gold-dim); background: var(--bg-hover); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

#chapter-progress {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: var(--gold-dim);
}

/* ===== RIGHT PANEL ===== */
#right-panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-left: 2px solid var(--border-gold);
  overflow-y: auto;
  overflow-x: hidden;
}
#right-panel::-webkit-scrollbar { width: 4px; }
#right-panel::-webkit-scrollbar-track { background: var(--bg-panel); }
#right-panel::-webkit-scrollbar-thumb { background: var(--border-gold); }

.panel-section {
  border-bottom: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--bg-card);
  transition: background var(--transition);
  user-select: none;
}
.panel-header:hover { background: var(--bg-hover); }

.panel-header-title {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: bold;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

.panel-toggle { color: var(--gold-dim); font-size: 0.7rem; transition: transform var(--transition); }
.panel-section.collapsed .panel-toggle { transform: rotate(-90deg); }
.panel-section.collapsed .panel-body { display: none; }

.panel-body { padding: 12px 14px; }

/* Investigator selector */
#inv-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.inv-tab {
  flex: 1;
  padding: 6px 4px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--cream-dim);
  font-family: var(--font-ui);
  font-size: 0.68rem;
  text-align: center;
  cursor: pointer;
  border-radius: 3px;
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inv-tab:hover { border-color: var(--gold-dim); color: var(--cream); }
.inv-tab.active { background: var(--bg-card); border-color: var(--gold); color: var(--gold-light); }

#inv-portrait {
  text-align: center;
  padding: 4px 0 8px;
}
#inv-name {
  font-family: var(--font-title);
  font-size: 1rem;
  color: var(--gold-light);
}
#inv-title-text {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--cream-dim);
  letter-spacing: 0.08em;
}

/* Stats row */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.stat-block {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 4px;
  text-align: center;
}
.stat-label {
  font-family: var(--font-ui);
  font-size: 0.58rem;
  color: var(--cream-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 3px;
}
.stat-value-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.stat-val {
  font-family: var(--font-title);
  font-size: 1.2rem;
  color: var(--gold-light);
  min-width: 24px;
  text-align: center;
}
.stat-val.penalty { color: var(--red-bright); }
.stat-base {
  font-size: 0.6rem;
  color: var(--cream-dim);
}

/* Counter blocks (HP/SAN/RES/CLUE/DOOM) */
.counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 5px 0;
  gap: 6px;
}
.counter-label {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--cream-dim);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  flex: 1;
}
.counter-sub {
  font-size: 0.55rem;
  color: var(--red-bright);
  display: block;
}
.counter-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.counter-btn {
  width: 22px;
  height: 22px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--cream-dim);
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
}
.counter-btn:hover { border-color: var(--gold-dim); color: var(--gold-light); background: var(--bg-hover); }
.counter-num {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--gold-light);
  min-width: 28px;
  text-align: center;
}
.counter-num.low { color: var(--red-bright); }
.counter-num.doom { color: #c05050; }

/* HP/SAN bar */
.bar-track {
  height: 5px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin: 2px 0 6px;
}
.bar-fill-hp { height: 100%; background: var(--green-bright); transition: width 0.3s; }
.bar-fill-san { height: 100%; background: var(--blue-bright); transition: width 0.3s; }
.bar-fill-doom { height: 100%; background: var(--red-bright); transition: width 0.3s; }

/* Items list */
.item-list { max-height: 160px; overflow-y: auto; margin-bottom: 6px; }
.item-list::-webkit-scrollbar { width: 3px; }
.item-list::-webkit-scrollbar-thumb { background: var(--border-gold); }

.item-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 3px;
  transition: background var(--transition);
}
.item-entry:hover { background: var(--bg-hover); }
.item-entry input[type=checkbox] { accent-color: var(--gold); cursor: pointer; }
.item-entry label { font-size: 0.8rem; color: var(--cream); cursor: pointer; flex: 1; }
.item-entry label.crossed { text-decoration: line-through; color: var(--cream-dim); }
.item-del {
  background: none;
  border: none;
  color: var(--red-dark);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 3px;
  opacity: 0.5;
  transition: opacity var(--transition);
}
.item-del:hover { opacity: 1; color: var(--red-bright); }

.add-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.add-input {
  flex: 1;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--cream);
  padding: 5px 8px;
  font-size: 0.78rem;
  border-radius: 3px;
  outline: none;
}
.add-input:focus { border-color: var(--gold-dim); }
.add-btn {
  background: var(--bg-dark);
  border: 1px solid var(--border-gold);
  color: var(--gold);
  padding: 5px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: 3px;
  transition: all var(--transition);
}
.add-btn:hover { background: var(--bg-hover); border-color: var(--gold); }

/* Tags (abilities/weaknesses) */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tag {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  cursor: default;
}
.tag-ability { background: rgba(58,128,80,0.25); border: 1px solid var(--green-dark); color: #88d4a0; }
.tag-weakness { background: rgba(139,32,32,0.25); border: 1px solid var(--red-dark); color: #e08080; }
.tag-del { cursor: pointer; opacity: 0.5; font-size: 0.65rem; }
.tag-del:hover { opacity: 1; }

/* Dice section */
/* ===== 3D DICE ===== */
#dice-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 90px;
  margin: 10px 0 6px;
}
.dice-scene {
  width: 64px;
  height: 64px;
  perspective: 240px;
  flex-shrink: 0;
}
.dice-cube {
  width: 64px;
  height: 64px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-24deg) rotateY(36deg);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
/* filter on .dice-scene (not .dice-cube) — applying filter directly to a
   preserve-3d element collapses it to a flat 2D plane in all browsers */
.dice-scene:hover { filter: brightness(1.2); }
.face {
  position: absolute;
  width: 64px;
  height: 64px;
  background: linear-gradient(145deg, #2a2015 0%, #0e0b07 100%);
  border: 2px solid var(--border-gold);
  border-radius: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  padding: 9px;
  gap: 3px;
  box-shadow:
    inset 0 1px 6px rgba(255,220,120,0.08),
    inset 0 0 14px rgba(0,0,0,0.7);
  backface-visibility: hidden;
  pointer-events: none;
}
/* Face transforms — half-size = 32px */
.face-front  { transform: translateZ(32px); }
.face-back   { transform: rotateY(180deg) translateZ(32px); }
.face-right  { transform: rotateY( 90deg) translateZ(32px); }
.face-left   { transform: rotateY(-90deg) translateZ(32px); }
.face-top    { transform: rotateX( 90deg) translateZ(32px); }
.face-bottom { transform: rotateX(-90deg) translateZ(32px); }
/* Dots — explicit sizing so grid cells render perfect circles */
.d {
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: transparent;
}
.d.on {
  background: var(--gold-light);
  box-shadow: 0 0 5px rgba(212,175,55,0.7), 0 0 2px rgba(255,220,120,0.4);
}

#dice-result {
  font-family: var(--font-title);
  font-size: 0.88rem;
  color: var(--gold);
  margin: 4px 0 8px;
  min-height: 26px;
  text-align: center;
  line-height: 1.5;
  transition: all 0.3s ease;
}
#dice-modifier-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 0.72rem;
  color: var(--cream-dim);
  flex-wrap: wrap;
}
#dice-modifier-row select, #dice-modifier-row input[type=number] {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--cream);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 0.72rem;
  outline: none;
}
#skill-mod-val { width: 46px; }

.dice-btns { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }
.dice-roll-btn {
  background: var(--bg-dark);
  border: 1px solid var(--border-gold);
  color: var(--gold);
  padding: 7px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
  font-family: var(--font-ui);
}
.dice-roll-btn:hover { background: var(--bg-hover); border-color: var(--gold-light); color: var(--gold-light); }

#dice-history {
  max-height: 72px;
  overflow-y: auto;
  margin-top: 8px;
  padding: 4px 6px;
  background: var(--bg-dark);
  border-radius: 3px;
  border: 1px solid var(--border);
}
#dice-history::-webkit-scrollbar { width: 3px; }
#dice-history::-webkit-scrollbar-thumb { background: var(--border-gold); }
.dice-hist-entry {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  color: var(--cream-dim);
  padding: 1px 0;
  border-bottom: 1px solid var(--border);
}
.dice-hist-entry:last-child { border: none; }

/* Secrets checklist */
.secret-list { max-height: 160px; overflow-y: auto; }
.secret-list::-webkit-scrollbar { width: 3px; }
.secret-list::-webkit-scrollbar-thumb { background: var(--border-gold); }
.secret-item {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  padding: 3px 4px;
  border-radius: 2px;
}
.secret-item:hover { background: var(--bg-hover); }
.secret-item input { accent-color: var(--gold); margin-top: 2px; cursor: pointer; }
.secret-item label { font-size: 0.72rem; color: var(--cream-dim); cursor: pointer; line-height: 1.4; }
.secret-item label.unlocked { color: var(--gold); }

/* Action buttons (global) */
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--cream-dim);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  cursor: pointer;
  border-radius: 3px;
  transition: all var(--transition);
  white-space: nowrap;
}
.action-btn:hover { border-color: var(--gold-dim); color: var(--gold-light); background: var(--bg-hover); }
.action-btn.danger { border-color: var(--red-dark); color: #c07070; }
.action-btn.danger:hover { border-color: var(--red-bright); color: var(--red-bright); }
.action-btn.primary { border-color: var(--gold-dim); color: var(--gold); }
.action-btn.primary:hover { border-color: var(--gold-light); background: rgba(201,168,76,0.1); }

/* Loading / Error state */
#loading-screen {
  position: fixed; inset: 0;
  background: var(--bg-deep);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  flex-direction: column; gap: 16px;
}
#loading-screen .skull-anim { font-size: 3rem; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }
#loading-screen p { color: var(--gold); font-family: var(--font-title); font-size: 1rem; }

/* Responsive: collapse right panel on small screens */
@media (max-width: 768px) {
  #right-panel { width: 260px; }
  #chapter-area { padding: 20px 20px 16px; }
  #choices-area { padding: 12px 20px 16px; }
}

/* Jump-to input */
#jump-form { display: flex; gap: 6px; align-items: center; }
#jump-input {
  width: 60px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--cream);
  padding: 4px 8px;
  border-radius: 3px;
  font-size: 0.78rem;
  outline: none;
  text-align: center;
}
#jump-input:focus { border-color: var(--gold-dim); }

/* Tooltip helper */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; bottom: 110%; left: 50%; transform: translateX(-50%);
  background: #2a2014; border: 1px solid var(--border-gold);
  color: var(--cream); font-size: 0.68rem; padding: 4px 8px; border-radius: 3px;
  white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity 0.2s;
  z-index: 50;
}
[data-tip]:hover::after { opacity: 1; }

/* Section note */
.section-note {
  font-size: 0.72rem;
  color: var(--cream-dim);
  font-style: italic;
  margin-bottom: 8px;
  padding: 4px 6px;
  background: rgba(201,168,76,0.05);
  border-left: 2px solid var(--gold-dim);
  border-radius: 2px;
}

/* Penalty warning */
.penalty-note {
  font-size: 0.7rem;
  color: var(--red-bright);
  margin: 2px 0;
  padding: 2px 5px;
  background: rgba(139,32,32,0.15);
  border-radius: 2px;
}

/* ── Help button & modal ── */
.panel-right-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}
.help-btn {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid var(--gold-dim);
  background: transparent;
  color: var(--gold-dim);
  font-size: 0.62rem;
  font-weight: bold;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.help-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}
#help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 900;
  align-items: center;
  justify-content: center;
}
#help-overlay.open { display: flex; }
#help-dialog {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: 6px;
  max-width: 460px;
  width: calc(100vw - 48px);
  max-height: 72vh;
  overflow-y: auto;
  padding: 20px 22px 18px;
  box-shadow: 0 10px 48px rgba(0,0,0,0.85);
}
#help-dialog h3 {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold-light);
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-gold);
}
#help-dialog p {
  font-size: 0.78rem;
  color: var(--cream-dim);
  line-height: 1.75;
  margin: 0 0 8px;
}
#help-dialog p:last-child { margin-bottom: 0; }
#help-close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--gold-dim);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}
#help-close-btn:hover { color: var(--gold-light); }

/* ── Cover screen ── */
#cover-screen, #inv-select-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}
#cover-screen {
  background:
    linear-gradient(to bottom, rgba(13,10,6,0.45) 0%, rgba(13,10,6,0.72) 100%),
    url('img/indexBg.png') center center / cover no-repeat;
}
.cover-inner {
  max-width: 560px;
  width: calc(100% - 48px);
  text-align: center;
  padding: 48px 0;
}
.cover-skull {
  font-size: 2.4rem;
  margin-bottom: 20px;
  opacity: 0.7;
}
.cover-title {
  font-family: var(--font-title);
  font-size: 1.9rem;
  color: var(--gold-light);
  letter-spacing: 0.1em;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9), 0 0 32px rgba(184,134,11,0.5);
  margin-bottom: 8px;
  line-height: 1.3;
}
.cover-subtitle {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: var(--gold-dim);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  margin-bottom: 36px;
}
.cover-divider {
  width: 80px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border-gold), transparent);
  margin: 0 auto 28px;
}
.cover-author {
  font-size: 0.72rem;
  color: var(--cream-dim);
  font-style: italic;
  margin-bottom: 28px;
  letter-spacing: 0.05em;
}
.cover-intro {
  font-size: 0.88rem;
  color: var(--cream-dim);
  line-height: 1.95;
  text-align: justify;
}
.cover-next-btn {
  display: inline-block;
  margin-top: 44px;
  padding: 11px 38px;
  background: transparent;
  border: 1px solid var(--border-gold);
  color: var(--gold);
  font-family: var(--font-ui);
  font-size: 0.74rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.cover-next-btn:hover {
  background: rgba(184,134,11,0.1);
  border-color: var(--gold);
  color: var(--gold-light);
}

/* ── Investigator select screen ── */
#inv-select-screen {
  justify-content: flex-start;
  padding: 32px 24px 48px;
}
.inv-sel-header {
  text-align: center;
  margin-bottom: 28px;
  flex-shrink: 0;
}
.inv-sel-header h2 {
  font-family: var(--font-title);
  font-size: 1.3rem;
  color: var(--gold);
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}
.inv-sel-header p {
  font-size: 0.8rem;
  color: var(--cream-dim);
  line-height: 1.6;
}
.inv-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
  max-width: 860px;
  width: 100%;
}
.inv-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 18px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.inv-card:hover {
  border-color: var(--border-gold);
  box-shadow: 0 6px 28px rgba(0,0,0,0.5);
  transform: translateY(-2px);
}
/* Investigator card portrait */
.inv-card-portrait {
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 4px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  position: relative;
}
.inv-card-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
  transition: transform 0.3s ease;
}
.inv-card:hover .inv-card-portrait img {
  transform: scale(1.04);
}

.inv-card-header { text-align: center; }
.inv-card-name {
  font-family: var(--font-title);
  font-size: 1.05rem;
  color: var(--gold-light);
  margin-bottom: 3px;
}
.inv-card-role {
  font-family: var(--font-ui);
  font-size: 0.62rem;
  color: var(--gold-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.inv-card-sep {
  height: 1px;
  background: var(--border);
}
.inv-card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  text-align: center;
}
.inv-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.inv-stat-val {
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--gold);
  line-height: 1;
}
.inv-stat-lbl {
  font-size: 0.56rem;
  color: var(--cream-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.inv-card-hpsp {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  text-align: center;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.inv-hpsp-block { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.inv-hpsp-val { font-size: 1.1rem; font-weight: bold; line-height: 1; }
.inv-hpsp-val.hp { color: var(--red-bright); }
.inv-hpsp-val.sp { color: #6ba3d0; }
.inv-hpsp-lbl { font-size: 0.56rem; color: var(--cream-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.inv-card-item {
  font-size: 0.72rem;
  color: var(--cream-dim);
  line-height: 1.55;
}
.inv-card-item-lbl {
  font-family: var(--font-ui);
  font-size: 0.6rem;
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: block;
  margin-bottom: 3px;
}
.inv-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.inv-tag {
  font-size: 0.58rem;
  padding: 2px 6px;
  border-radius: 2px;
  border: 1px solid;
  line-height: 1.4;
}
.inv-tag.ab { border-color: var(--green-bright); color: var(--green-bright); }
.inv-tag.wk { border-color: var(--red-bright); color: var(--red-bright); }
.inv-card-choose-btn {
  width: 100%;
  padding: 9px;
  background: transparent;
  border: 1px solid var(--border-gold);
  color: var(--gold);
  font-family: var(--font-ui);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.15s, color 0.15s;
  margin-top: auto;
}
.inv-card-choose-btn:hover { background: rgba(184,134,11,0.12); color: var(--gold-light); }

/* ── Investigator confirm modal ── */
#inv-confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 600;
  align-items: center;
  justify-content: center;
}
#inv-confirm-overlay.open { display: flex; }
#inv-confirm-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: 6px;
  max-width: 360px;
  width: calc(100% - 40px);
  padding: 28px 22px 20px;
  text-align: center;
  box-shadow: 0 12px 48px rgba(0,0,0,0.9);
}
#inv-confirm-dialog .cdlg-name {
  font-family: var(--font-title);
  font-size: 1.2rem;
  color: var(--gold-light);
  margin-bottom: 3px;
}
#inv-confirm-dialog .cdlg-role {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  color: var(--gold-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 16px;
}
#inv-confirm-dialog .cdlg-body {
  font-size: 0.78rem;
  color: var(--cream-dim);
  line-height: 1.7;
  margin-bottom: 22px;
}
.cdlg-btns { display: flex; gap: 10px; justify-content: center; }
.cdlg-btn-cancel {
  padding: 8px 20px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--cream-dim);
  font-family: var(--font-ui);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
  transition: border-color 0.15s;
}
.cdlg-btn-cancel:hover { border-color: var(--cream-dim); }
.cdlg-btn-ok {
  padding: 8px 20px;
  background: rgba(184,134,11,0.1);
  border: 1px solid var(--border-gold);
  color: var(--gold);
  font-family: var(--font-ui);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.15s;
}
.cdlg-btn-ok:hover { background: rgba(184,134,11,0.22); }

/* ── Locked investigator in sidebar ── */
#inv-locked-display {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}
.inv-locked-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  background: rgba(184,134,11,0.06);
}
#inv-locked-name {
  font-family: var(--font-title);
  font-size: 0.9rem;
  color: var(--gold-light);
}
#inv-locked-title {
  font-size: 0.62rem;
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
}

/* ============================================================
   SETTLEMENT SCREEN
   ============================================================ */
#settlement-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-darker);
  z-index: 300;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 48px;
}
.settlement-inner {
  max-width: 720px;
  width: 100%;
  animation: fadeInUp 0.5s ease both;
}
.sett-top {
  text-align: center;
  padding: 36px 0 20px;
}
.sett-skull {
  font-size: 2.8rem;
  color: var(--gold-dim);
  display: block;
  margin-bottom: 14px;
  line-height: 1;
}
.sett-title {
  font-family: var(--font-title);
  font-size: 1.9rem;
  color: var(--red-bright);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.sett-title.star-ending {
  color: var(--gold-light);
}
.sett-subtitle {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.sett-divider {
  height: 1px;
  background: linear-gradient(to right, transparent, var(--gold-dim), transparent);
  margin: 20px 0 24px;
}
.sett-body {
  padding: 0 4px;
}
.sett-narrative-wrap {
  margin-bottom: 20px;
}
.sett-narrative-wrap > .sett-section-title {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--gold-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.sett-narrative {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  border-left: 3px solid var(--red-dark);
  border-radius: 4px;
  padding: 16px 20px;
  font-size: 0.87rem;
  color: var(--text-body);
  line-height: 1.75;
  max-height: 280px;
  overflow-y: auto;
}
.sett-section {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.sett-section-title {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  color: var(--gold-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.sett-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.sett-two-col .sett-section {
  margin-bottom: 0;
}
.sett-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.sett-stat-item {
  text-align: center;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 4px 8px;
}
.sett-stat-val {
  font-family: var(--font-title);
  font-size: 1.5rem;
  color: var(--gold-light);
  line-height: 1;
  margin-bottom: 4px;
}
.sett-stat-label {
  font-size: 0.62rem;
  color: var(--text-dim);
  font-family: var(--font-ui);
  letter-spacing: 0.05em;
}
.sett-tag {
  display: inline-block;
  background: rgba(201,168,76,0.08);
  border: 1px solid var(--gold-dim);
  color: var(--text-body);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.74rem;
  margin: 2px 3px 2px 0;
}
.sett-tag.secret {
  background: rgba(100,60,140,0.15);
  border-color: #7a5aaa;
  color: #c4a0e8;
}
.sett-tag.ability {
  background: rgba(60,120,90,0.15);
  border-color: #3a7060;
  color: #80b898;
}
.sett-tag.weakness {
  background: rgba(139,32,32,0.15);
  border-color: var(--red-dark);
  color: var(--red-bright);
}
.sett-empty {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-style: italic;
}
.sett-achievements {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.sett-achiev {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 3px;
  font-size: 0.8rem;
  border: 1px solid transparent;
}
.sett-achiev.earned {
  background: rgba(60,120,80,0.12);
  border-color: #3a7050;
}
.sett-achiev.missed {
  background: rgba(40,35,30,0.4);
  border-color: var(--border);
  opacity: 0.65;
}
.sett-achiev-icon {
  font-size: 0.85rem;
  color: var(--text-dim);
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  margin-top: 1px;
}
.sett-achiev.earned .sett-achiev-icon {
  color: #80c090;
}
.sett-achiev-name {
  font-weight: 600;
  color: var(--text-body);
  margin-bottom: 2px;
}
.sett-achiev.earned .sett-achiev-name {
  color: #90c8a0;
}
.sett-achiev-desc {
  color: var(--text-dim);
  font-size: 0.7rem;
}
.sett-footer {
  text-align: center;
  padding: 24px 0 12px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.sett-hint {
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-bottom: 16px;
  letter-spacing: 0.03em;
}
.sett-btn-new {
  background: linear-gradient(135deg, rgba(100,20,20,0.4) 0%, rgba(60,15,15,0.6) 100%);
  border: 1px solid var(--red-dark);
  color: var(--gold-light);
  font-family: var(--font-title);
  font-size: 1rem;
  letter-spacing: 0.06em;
  padding: 12px 36px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}
.sett-btn-new:hover {
  background: linear-gradient(135deg, rgba(160,30,30,0.45) 0%, rgba(120,20,20,0.7) 100%);
  border-color: var(--gold-dim);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (max-width: 540px) {
  .sett-two-col { grid-template-columns: 1fr; }
  .sett-stats-grid { grid-template-columns: repeat(4, 1fr); }
}
