@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg:       #0d0d1a;
  --panel:    #12121f;
  --border:   #2a2a42;
  --text:     #e2e2f0;
  --dim:      #8888aa;
  --accent:   #aa66dd;   /* eldritch purple */
  --dread:    #ee55ee;   /* dread pink */
  --kaos:     #ff8833;   /* chaos orange */
  --safe:     #44bb66;   /* hemlighet green */
  --danger:   #ee4444;   /* investigator red */
  --ritual:   #66aaff;   /* ritual blue */
  --win:      #00e87a;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 13px;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  gap: 0;
  filter: hue-rotate(calc(var(--dread-intensity, 0) * -35deg)) saturate(calc(1 + var(--dread-intensity, 0) * 0.7));
  transition: filter 2s ease;
}

#app.kaos-glitch { animation: kaos-glitch-shake 0.4s steps(2, end) 2; }

@keyframes kaos-glitch-shake {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-2px, 1px); filter: hue-rotate(20deg); }
  40%  { transform: translate(2px, -1px); filter: hue-rotate(-15deg); }
  60%  { transform: translate(-1px, 2px); filter: hue-rotate(10deg); }
  80%  { transform: translate(1px, -2px); }
  100% { transform: translate(0, 0); }
}

#danger-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999; /* below modals (1000/1001), above map/log */
  background: radial-gradient(ellipse at center, transparent 55%, var(--danger) 150%);
  opacity: var(--hemlighet-danger, 0);
  transition: opacity 1.5s ease;
}

/* ── Header ── */
#header {
  grid-column: 1 / -1;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 24px;
}

.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--dread);
  text-shadow: 0 0 20px rgba(204, 68, 204, 0.4);
}

.brand-sub {
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ── Panels ── */
.panel {
  padding: 16px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.panel:last-child { border-right: none; border-left: 1px solid var(--border); }

.panel-title {
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ── Resources ── */
.resource {
  margin-bottom: 10px;
}

.resource-label {
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 3px;
}

.resource-value {
  font-size: 16px;
  font-weight: 700;
}

.resource-bar {
  height: 3px;
  background: var(--border);
  margin-top: 4px;
  border-radius: 2px;
  overflow: hidden;
}

.resource-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.bar-hemlighet .resource-bar-fill { background: var(--safe); }
.bar-kaos      .resource-bar-fill { background: var(--kaos); }
.bar-ritual    .resource-bar-fill { background: var(--ritual); }

/* ── Map ── */
#map-container {
  background: var(--panel);
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 400px;
}

/* Leaflet overrides */
.leaflet-container { background: #06060e !important; }
.map-tooltip {
  background: var(--panel) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  font-family: inherit !important;
  font-size: 11px !important;
  padding: 3px 8px !important;
  border-radius: 2px !important;
  box-shadow: none !important;
}
.map-tooltip::before { display: none !important; }

/* ── Upgrades ── */
.upgrade-btn {
  display: block;
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: border-color 0.15s, color 0.15s;
  line-height: 1.4;
}

.upgrade-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--dread);
}

.upgrade-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.upgrade-btn .up-name {
  font-weight: 700;
  display: block;
  margin-bottom: 2px;
  color: var(--accent);
}

.upgrade-btn .up-desc {
  color: #aaaacc;
  font-size: 10px;
  display: block;
  margin-bottom: 4px;
}

.upgrade-btn .up-cost { font-size: 10px; color: #9999bb; }

/* ── Log ── */
#log {
  padding: 0;
  font-size: 11px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.log-entry {
  padding: 8px 16px;
  border-bottom: 1px solid #1a1a2e;
  color: var(--text);
}

.log-entry.kaos   { color: var(--kaos); border-left: 2px solid var(--kaos); }
.log-entry.system { color: var(--dim); font-style: italic; }
.log-entry.upgrade { color: var(--accent); }

/* ── Intro screen ── */
#intro-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1002; /* above help modal and overlay */
  background-size: cover;
  background-position: center;
  background-color: var(--bg);
  align-items: center;
  justify-content: flex-end;
}

#intro-screen.visible { display: flex; }

.intro-scrim {
  background: linear-gradient(180deg, rgba(6,6,14,0) 0%, rgba(6,6,14,0.75) 35%, rgba(6,6,14,0.97) 100%);
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 18vh 20px 8vh;
  text-align: center;
  gap: 12px;
}

.intro-title {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 8px;
  color: var(--dread);
  text-shadow: 0 0 30px rgba(204, 68, 204, 0.5);
}

.intro-sub {
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
}

.intro-flavor {
  max-width: 480px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.9;
  margin: 8px 20px 4px;
}

/* ── Overlays ── */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: var(--bg);
  background-size: cover;
  background-position: center;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

#overlay.visible { display: flex; }

.overlay-scrim {
  background: radial-gradient(ellipse 55% 42% at center, rgba(6,6,14,0.8) 0%, rgba(6,6,14,0.5) 55%, rgba(6,6,14,0.12) 80%, transparent 100%);
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 20px;
}

.overlay-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.overlay-title.won  { color: var(--win); text-shadow: 0 0 30px rgba(0,232,122,0.5); }
.overlay-title.lost { color: var(--danger); }

.overlay-body {
  max-width: 480px;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.8;
}

.overlay-btn {
  background: none;
  border: 1px solid var(--dim);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 8px 24px;
  cursor: pointer;
  margin-top: 8px;
  transition: border-color 0.15s, color 0.15s;
}

.overlay-btn:hover { border-color: var(--accent); color: var(--dread); }

/* ── Phase label ── */
.phase-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 2px 8px;
  border: 1px solid;
}

.phase-tag.early  { color: var(--dim); border-color: var(--dim); }
.phase-tag.mid    { color: var(--accent); border-color: var(--accent); }
.phase-tag.late   { color: var(--dread); border-color: var(--dread); }

.pause-tag {
  margin-left: 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--kaos);
}

/* Dim the world a touch while paused, so it reads as "held" rather than "broken" */
#app.paused #map-container,
#app.paused #panel-left,
#app.paused #panel-right {
  filter: grayscale(0.5) brightness(0.75);
  transition: filter 0.3s ease;
}

/* ── Help / header buttons ── */
.header-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.help-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--dim);
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.help-btn:hover { border-color: var(--accent); color: var(--accent); }
#abandon-btn:hover { border-color: var(--danger); color: var(--danger); }

/* ── Help modal ── */
.help-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6, 6, 14, 0.88);
  z-index: 1001; /* above Leaflet's z-index 400-1000 range */
  align-items: center;
  justify-content: center;
}
.help-modal.visible { display: flex; }

.help-modal-inner {
  background: var(--panel);
  border: 1px solid var(--border);
  width: min(640px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.help-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.help-modal-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.help-close {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}
.help-close:hover { color: var(--text); }

.help-modal-body {
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.event-modal-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

.event-modal-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-section { display: flex; flex-direction: column; gap: 8px; }

.help-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--dim);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.help-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text);
}
.help-list li::before { content: '—  '; color: var(--dim); }
.help-list strong { color: var(--accent); }
.help-list em { color: var(--dread); font-style: normal; }

.help-flavor {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.8;
  font-style: italic;
}

#characters-modal-inner { width: min(860px, 94vw); }

.characters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.character-card {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.character-portrait {
  width: 100%;
  aspect-ratio: 4 / 5;
  background: #08080f;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.character-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(0.15) contrast(1.05);
}

.character-portrait-fallback,
.locked-portrait {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--dim);
  letter-spacing: 0.05em;
}

.character-card.locked .character-portrait.locked-portrait {
  background: repeating-linear-gradient(135deg, #08080f, #08080f 6px, #0d0d1a 6px, #0d0d1a 12px);
  border-style: dashed;
}

.character-card.locked .character-name,
.character-card.locked .character-role {
  color: var(--dim);
}

.character-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.character-role {
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.character-bio {
  font-size: 11px;
  line-height: 1.6;
  color: var(--text);
}

.help-changelog-entry {
  margin-bottom: 14px;
}

.help-changelog-version {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 5px;
}

.help-changelog-date {
  font-weight: 400;
  color: var(--dim);
  margin-left: 6px;
}

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .panel { border-right: none; border-bottom: 1px solid var(--border); }
  #map { min-height: 250px; }
}
