/* ═══════════════════════════════════════════════════════════════
   NPC ENGINE — Fantasy Pixel Art Theme
   Dark RPG UI layer over NES.css v2.3.0
   ═══════════════════════════════════════════════════════════════ */

/* ── 0. CSS Variables & Dark Foundation ──────────────────────── */

:root {
  --bg-deep:    #0f0f1a;
  --bg-body:    #1a1a2e;
  --bg-surface: #16213e;
  --bg-raised:  #1e2a4a;
  --text-main:  #d4d4d8;
  --text-dim:   #8888aa;
  --text-muted: #555577;
  --gold:       #d4a017;
  --gold-glow:  #ffd700;
  --hp-green:   #22c55e;
  --hp-yellow:  #eab308;
  --hp-orange:  #f97316;
  --hp-red:     #ef4444;

  /* Location theme defaults (overridden by body.theme-*) */
  --loc-bg:      #1a1a2e;
  --loc-surface: #16213e;
  --loc-accent:  #d4a017;
  --loc-glow:    #ffd700;
}


/* ── 1. Global Dark Mode ─────────────────────────────────────── */

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

html {
  font-size: 18px;
  background: var(--bg-deep);
}

body {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 3rem;
  font-family: "IBM Plex Mono", "SF Mono", "Menlo", monospace;
  font-size: 18px;
  line-height: 1.7;
  color: var(--text-main);
  background:
    radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--loc-glow) 6%, transparent) 0%, transparent 60%),
    var(--loc-bg);
  transition: background 0.6s ease;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  image-rendering: pixelated;
}

/* Scanline overlay — very subtle CRT feel */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.03) 2px,
    rgba(0,0,0,0.03) 4px
  );
}

a { color: var(--loc-accent); transition: color 0.2s; }
a:hover { color: var(--loc-glow); text-shadow: 0 0 8px color-mix(in srgb, var(--loc-glow) 40%, transparent); }

/* Pixel font for UI chrome only */
h1, h2, h3, h4,
button, .nes-btn, .topic-btn,
.debug-badge, .npc-portrait,
.rpg-bar-label,
#attitude-label,
summary {
  font-family: "Press Start 2P", monospace;
}

h1, h2, h3, h4 {
  color: var(--loc-accent);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.5);
  margin: 0 0 0.8rem;
  line-height: 1.6;
}

h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }

p { margin: 0.4rem 0; }

small, .text-sm { font-size: 16px; }
.text-xs { font-size: 14px; }


/* ── 2. NES.css Dark Overrides ───────────────────────────────── */

/* Force all containers dark */
.nes-container {
  background: var(--loc-surface) !important;
  color: var(--text-main) !important;
  margin-bottom: 1rem;
}

/* Title inside with-title containers */
.nes-container.with-title > .title {
  background-color: var(--loc-bg) !important;
  color: var(--loc-accent) !important;
  font-size: 16px;
}

/* Buttons — dark defaults */
.nes-btn {
  font-size: 14px;
  color: var(--text-main);
  background: var(--bg-raised);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.nes-btn:hover {
  transform: translateY(-1px);
  color: #fff;
}
.nes-btn:active { transform: translateY(1px); }

.nes-btn.is-primary { background: #209cee; color: #fff; }
.nes-btn.is-success { background: #22c55e; color: #fff; }
.nes-btn.is-warning { background: #d4a017; color: #1a1a2e; }
.nes-btn.is-error   { background: #ef4444; color: #fff; }
.nes-btn.is-disabled,
.nes-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

/* Inputs & Selects — dark, readable font */
.nes-input,
.nes-textarea {
  background: var(--bg-deep) !important;
  color: var(--text-main) !important;
  font-family: "IBM Plex Mono", "SF Mono", monospace;
  font-size: 16px;
}
.nes-select select {
  background: var(--bg-deep) !important;
  color: var(--text-main) !important;
  font-family: "IBM Plex Mono", "SF Mono", monospace;
  font-size: 16px;
}


/* ── 3. Location Themes ──────────────────────────────────────── */

/* -- Gorn's Forge: Fiery embers, molten orange -- */
.theme-gorns-forge {
  --loc-bg:      #1a0d00;
  --loc-surface: #2a1500;
  --loc-accent:  #ff6b1a;
  --loc-glow:    #ff4500;
}

/* -- The Anvil Inn: Warm tavern amber -- */
.theme-anvil-inn {
  --loc-bg:      #1a1400;
  --loc-surface: #2a2200;
  --loc-accent:  #d4a017;
  --loc-glow:    #ffa500;
}

/* -- Eastern Marshes: Eerie green fog -- */
.theme-eastern-marshes {
  --loc-bg:      #001a0d;
  --loc-surface: #002a15;
  --loc-accent:  #00cc66;
  --loc-glow:    #39ff14;
}

/* -- Ironspine Mountains: Cold blue-grey stone -- */
.theme-ironspine-mountains {
  --loc-bg:      #0d1117;
  --loc-surface: #161b26;
  --loc-accent:  #6b8aad;
  --loc-glow:    #4a7ab5;
}

/* -- Default: Classic gold fantasy -- */
.theme-default {
  --loc-bg:      #1a1a2e;
  --loc-surface: #16213e;
  --loc-accent:  #d4a017;
  --loc-glow:    #ffd700;
}


/* ── 4. NPC Portraits ────────────────────────────────────────── */

.npc-portrait {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-family: "Press Start 2P", monospace;
  color: #fff;
  background: var(--bg-raised);
  border: 4px solid var(--loc-accent);
  box-shadow:
    inset 0 0 12px rgba(0,0,0,0.5),
    0 0 8px color-mix(in srgb, var(--loc-accent) 30%, transparent);
  image-rendering: pixelated;
  flex-shrink: 0;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.8);
  position: relative;
  overflow: hidden;
}

/* Subtle inner glow */
.npc-portrait::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.1) 0%, transparent 60%);
  pointer-events: none;
}

.npc-portrait.gorn {
  background: linear-gradient(135deg, #4a1500 0%, #2a0800 100%);
  border-color: #ff6b1a;
  box-shadow:
    inset 0 0 12px rgba(255,107,26,0.3),
    0 0 12px rgba(255,69,0,0.3);
}

.npc-portrait.marta {
  background: linear-gradient(135deg, #3a2800 0%, #1a1200 100%);
  border-color: #d4a017;
  box-shadow:
    inset 0 0 12px rgba(212,160,23,0.3),
    0 0 12px rgba(255,165,0,0.3);
}


/* ── 5. NPC Card Grid (Home Page) ────────────────────────────── */

.npc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.npc-card {
  cursor: pointer;
  padding: 1.5rem;
  background: var(--loc-surface);
  border: 4px solid var(--text-muted);
  box-shadow:
    4px 4px 0 rgba(0,0,0,0.4),
    inset 0 0 20px rgba(0,0,0,0.2);
  transition: transform 0.15s, border-color 0.3s, box-shadow 0.3s;
  position: relative;
}
.npc-card:hover {
  transform: translateY(-3px);
  border-color: var(--loc-accent);
  box-shadow:
    4px 6px 0 rgba(0,0,0,0.4),
    0 0 16px color-mix(in srgb, var(--loc-accent) 25%, transparent),
    inset 0 0 20px rgba(0,0,0,0.2);
}

/* Per-card theme coloring on home page */
.npc-card.theme-gorns-forge   { --loc-accent: #ff6b1a; --loc-glow: #ff4500; --loc-surface: #2a1500; background: #2a1500; }
.npc-card.theme-anvil-inn     { --loc-accent: #d4a017; --loc-glow: #ffa500; --loc-surface: #2a2200; background: #2a2200; }
.npc-card.theme-eastern-marshes     { --loc-accent: #00cc66; --loc-surface: #002a15; background: #002a15; }
.npc-card.theme-ironspine-mountains { --loc-accent: #6b8aad; --loc-surface: #161b26; background: #161b26; }

.npc-card h4 {
  color: var(--loc-accent);
  margin: 0.5rem 0 0.2rem;
  font-size: 16px;
}


/* ── 6. RPG Attitude Bar ─────────────────────────────────────── */

.rpg-bar-container {
  position: relative;
  height: 24px;
  background: var(--bg-deep);
  border: 4px solid var(--text-muted);
  box-shadow:
    inset 2px 2px 0 rgba(0,0,0,0.5),
    2px 2px 0 rgba(0,0,0,0.3);
  margin: 0.5rem 0;
  overflow: hidden;
}

.rpg-bar-fill {
  height: 100%;
  transition: width 0.6s ease, background-color 0.4s ease;
  position: relative;
  image-rendering: pixelated;
  /* Chunky pixel stepped look */
  background-image: linear-gradient(
    90deg,
    transparent 0px,
    transparent 1px,
    rgba(255,255,255,0.08) 1px,
    rgba(255,255,255,0.08) 3px,
    transparent 3px,
    transparent 4px
  );
  background-size: 4px 100%;
}

/* Shine highlight */
.rpg-bar-fill::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 2px;
  right: 2px;
  height: 4px;
  background: rgba(255,255,255,0.2);
}

.rpg-bar-label {
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.2rem;
}
.rpg-bar-label span:first-child { color: var(--text-dim); }
.rpg-bar-label span:last-child  { color: var(--loc-accent); }


/* ── 7. Topic Buttons ────────────────────────────────────────── */

.topic-btn {
  display: inline-block;
  margin: 0.3rem;
  padding: 0.6rem 1rem 0.6rem 1.6rem;
  font-family: "Press Start 2P", monospace;
  font-size: 13px;
  color: var(--text-main);
  background: var(--bg-raised);
  border: 3px solid var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.1s, box-shadow 0.2s;
  position: relative;
}

/* RPG menu cursor prefix */
.topic-btn::before {
  content: "\25B6";
  position: absolute;
  left: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--loc-accent);
  transition: color 0.2s;
}

.topic-btn:hover {
  border-color: var(--loc-accent);
  background: color-mix(in srgb, var(--loc-accent) 10%, var(--bg-raised));
  transform: translateX(2px);
  box-shadow: 0 0 8px color-mix(in srgb, var(--loc-accent) 20%, transparent);
}
.topic-btn:hover::before { color: var(--loc-glow); }

.topic-btn:active { transform: translateX(4px); }

.topic-btn.asked {
  opacity: 0.4;
  filter: saturate(0.3);
}
.topic-btn.asked::before { content: "\2713"; color: var(--text-muted); }

.topic-btn[disabled] {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none !important;
}

/* Discovery glow animation */
.topic-btn.discovered {
  animation: topic-discover 1.8s ease;
}
@keyframes topic-discover {
  0%   { box-shadow: 0 0 20px var(--loc-glow); opacity: 0; transform: scale(0.9); border-color: var(--loc-glow); }
  30%  { opacity: 1; transform: scale(1.02); }
  60%  { box-shadow: 0 0 10px var(--loc-glow); }
  100% { box-shadow: none; border-color: var(--text-muted); }
}


/* ── 8. Chat & Response Stream ───────────────────────────────── */

#response-stream {
  min-height: 60px;
  padding: 1rem;
  margin: 1rem 0;
  background: var(--bg-deep);
  border: 3px solid color-mix(in srgb, var(--loc-accent) 40%, var(--text-muted));
  box-shadow:
    inset 0 0 20px rgba(0,0,0,0.3),
    0 0 8px color-mix(in srgb, var(--loc-glow) 10%, transparent);
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 18px;
}

.chat-log {
  max-height: 500px;
  overflow-y: auto;
  margin-top: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) var(--bg-deep);
}
.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-track { background: var(--bg-deep); }
.chat-log::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border: 2px solid var(--bg-deep);
}

.chat-msg {
  padding: 0.8rem;
  margin: 0.5rem 0;
  font-size: 18px;
  line-height: 1.6;
  position: relative;
}

.chat-msg.npc {
  background: color-mix(in srgb, var(--loc-surface) 80%, var(--loc-accent) 20%);
  border-left: 4px solid var(--loc-accent);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}

.chat-msg.player {
  background: rgba(255,255,255,0.03);
  border-left: 4px solid var(--text-muted);
  opacity: 0.6;
}

.chat-msg strong {
  font-family: "Press Start 2P", monospace;
  font-size: 14px;
  color: var(--loc-accent);
}
.chat-msg.player strong { color: var(--text-dim); }


/* ── 9. Debug & GM Cards ─────────────────────────────────────── */

.debug-card {
  padding: 0.8rem;
  margin-bottom: 0.8rem;
  background: var(--bg-surface);
  border: 3px solid var(--text-muted);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}
.debug-card h4 {
  margin: 0 0 0.3rem;
  font-size: 14px;
  color: var(--loc-accent);
}

.debug-section {
  margin-bottom: 2rem;
}
details.debug-section > summary {
  font-family: "Press Start 2P", monospace;
  font-size: 16px;
  color: var(--loc-accent, #d4a017);
  border-bottom: 2px solid var(--text-muted);
  padding-bottom: 0.4rem;
  margin-bottom: 1rem;
  cursor: pointer;
  list-style: none;
}
details.debug-section > summary::-webkit-details-marker { display: none; }
details.debug-section > summary::before {
  content: "▶ ";
  font-size: 12px;
  display: inline-block;
  transition: transform 0.2s;
}
details.debug-section[open] > summary::before {
  transform: rotate(90deg);
}
.debug-section h3 {
  font-size: 16px;
  border-bottom: 2px solid var(--text-muted);
  padding-bottom: 0.4rem;
}

/* Badges */
.debug-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 11px;
  font-family: "Press Start 2P", monospace;
  margin: 0.15rem;
  border: 2px solid;
}
.debug-badge.place   { background: #0d2847; color: #7db8f0; border-color: #1e3a5f; }
.debug-badge.event   { background: #3d0d0d; color: #f07d7d; border-color: #5f1e1e; }
.debug-badge.concept { background: #0d3d1e; color: #7df0b8; border-color: #1e5f3a; }
.debug-badge.edge    { background: #2e2e0d; color: #d0d07d; border-color: #3a3a1e; }
.debug-badge.item    { background: #2e1a3d; color: #c07df0; border-color: #3f1e5f; }
.debug-badge.character { background: #3d2e0d; color: #f0c07d; border-color: #5f4a1e; }

.debug-fact {
  margin: 0.1rem 0;
  padding-left: 1rem;
  font-size: 16px;
  opacity: 0.6;
}


/* ── 10. Header & Navigation ─────────────────────────────────── */

header {
  margin-bottom: 1.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 4px double var(--text-muted);
}

header a {
  text-decoration: none;
  font-size: 16px;
}


/* ── 11. Prompt Debug Panel ──────────────────────────────────── */

#prompt-debug {
  margin-top: 1.5rem;
  opacity: 0.6;
}
#prompt-debug summary {
  cursor: pointer;
  font-size: 14px;
  color: var(--text-dim);
}
#prompt-debug pre {
  font-size: 14px;
  max-height: 500px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 0.5rem;
  padding: 0.8rem;
  background: var(--bg-deep);
  border: 2px solid var(--text-muted);
  color: var(--text-dim);
  font-family: "IBM Plex Mono", "SF Mono", monospace;
}


/* ── 12. Forms (GM page) ─────────────────────────────────────── */

input, select, textarea {
  font-family: "IBM Plex Mono", "SF Mono", monospace;
  font-size: 16px;
  color: var(--text-main);
  background: var(--bg-deep);
  border: 2px solid var(--text-muted);
  padding: 0.5rem 0.6rem;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--loc-accent);
  box-shadow: 0 0 6px color-mix(in srgb, var(--loc-accent) 20%, transparent);
}

input::placeholder {
  color: var(--text-muted);
  font-size: 14px;
}

button {
  font-size: 14px;
  cursor: pointer;
  color: var(--text-main);
  background: var(--bg-raised);
  border: 3px solid var(--text-muted);
  padding: 0.5rem 1rem;
  transition: border-color 0.2s, background 0.2s, transform 0.1s;
}
button:hover {
  border-color: var(--loc-accent);
  background: color-mix(in srgb, var(--loc-accent) 15%, var(--bg-raised));
}
button:active { transform: translateY(1px); }

button[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
}


/* ── 13. Refusal Message ─────────────────────────────────────── */

#refusal-msg p {
  color: var(--hp-red);
  font-style: italic;
  text-align: center;
  padding: 1rem;
  border: 3px solid var(--hp-red);
  background: rgba(239,68,68,0.08);
}


/* ── 14. Responsive ──────────────────────────────────────────── */

@media (max-width: 500px) {
  html { font-size: 16px; }
  body { padding: 0.8rem; max-width: 100%; }

  .npc-grid {
    grid-template-columns: 1fr;
  }

  .npc-portrait {
    width: 56px;
    height: 56px;
    font-size: 22px;
  }

  .topic-btn {
    font-size: 11px;
    padding: 0.4rem 0.8rem 0.4rem 1.4rem;
  }

  .debug-badge { font-size: 9px; }
  .rpg-bar-container { height: 20px; }

  #response-stream { font-size: 16px; }
}
