/* --- CSS Design Tokens (Harmonious Curated HSL Palette) --- */
:root {
  --bg-deep: hsl(222, 24%, 7%);
  --panel-bg: hsla(222, 24%, 12%, 0.65);
  --border-light: hsla(222, 20%, 25%, 0.4);
  --border-active: hsla(43, 85%, 55%, 0.55);
  
  --primary-gold: hsl(43, 85%, 55%);
  --primary-gold-glow: hsla(43, 85%, 55%, 0.25);
  
  --hp-green: hsl(145, 80%, 45%);
  --threat-red: hsl(355, 85%, 55%);
  
  --text-primary: hsl(220, 20%, 94%);
  --text-muted: hsl(220, 10%, 65%);
  
  --transition-smooth: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  --shadow-premium: 0 12px 40px -10px rgba(0, 0, 0, 0.6);
}

/* --- Base Framework Resets --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  overflow: hidden;
  height: 100vh;
  position: relative;
}

.title-font {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* --- Ambient Backdrops Glows --- */
.ambient-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  opacity: 0.15;
}
.glow-1 {
  width: 400px;
  height: 400px;
  background: var(--primary-gold);
  top: -100px;
  left: 10%;
}
.glow-2 {
  width: 500px;
  height: 500px;
  background: var(--threat-red);
  bottom: -150px;
  right: 15%;
}

/* --- Premium Glassmorphism Panels --- */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: var(--shadow-premium);
  transition: var(--transition-smooth);
}

.glass-panel:hover {
  border-color: hsla(220, 20%, 35%, 0.4);
}

/* --- Main Layout Grid --- */
.game-container {
  display: grid;
  grid-template-columns: 280px 1fr 400px;
  gap: 16px;
  padding: 16px;
  height: 100vh;
  max-width: 1800px;
  margin: 0 auto;
}

/* --- Sidebar HUD & widgets --- */
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
  gap: 16px;
}

.sidebar-header {
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.sidebar-header h2 {
  font-size: 1.25rem;
  color: var(--primary-gold);
}

.character-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 12px;
}

.character-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.char-avatar {
  font-size: 2rem;
  background: rgba(255, 255, 255, 0.05);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.character-meta h3 {
  font-size: 1.1rem;
}

.badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.07);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
}

.badge.friendly {
  background: rgba(145, 80, 45, 0.15);
  color: var(--hp-green);
  border: 1px solid rgba(145, 80, 45, 0.3);
}

.badge.active-combat {
  background: rgba(355, 85, 55, 0.15);
  color: var(--threat-red);
  border: 1px solid rgba(355, 85, 55, 0.3);
}

/* HP Progress Bars */
.stat-group {
  margin-bottom: 12px;
}

.stat-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.progress-bar-bg {
  background: rgba(255, 255, 255, 0.05);
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.progress-hp {
  background: var(--hp-green);
  box-shadow: 0 0 8px var(--hp-green);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.mini-stat {
  background: rgba(0, 0, 0, 0.2);
  padding: 6px;
  border-radius: 8px;
  text-align: center;
  font-size: 0.8rem;
}

.mini-stat .label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.sub-section {
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
  margin-top: 12px;
}

.sub-section h4 {
  font-size: 0.85rem;
  color: var(--primary-gold);
  margin-bottom: 6px;
}

.inventory-items, .quest-items {
  list-style: none;
  font-size: 0.8rem;
}

.inventory-items li, .quest-items li {
  padding: 4px 0;
  color: var(--text-muted);
}

.quest-active {
  color: var(--primary-gold) !important;
  font-weight: 500;
}

.relations-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
}

.relation-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* --- Center Section: Narrative Chat Terminal --- */
.chat-terminal {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.terminal-header {
  display: flex;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  gap: 12px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  background: var(--primary-gold);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--primary-gold);
}

.terminal-header h1 {
  font-size: 1.35rem;
  flex: 1;
}

.campaign-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.message-feed {
  flex: 1 1 0;
  /* min-height: 0 is required for overflow to trigger on a flex child;
     without it the column flex parent grows to fit content and the scrollbar
     never appears. */
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 85%;
  border-radius: 12px;
  padding: 12px 16px;
  line-height: 1.5;
  font-size: 0.95rem;
  animation: messageSlideIn 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.system-msg {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-light);
  align-self: flex-start;
  color: var(--text-muted);
}

.dm-msg {
  background: rgba(43, 85, 55, 0.03);
  border: 1px solid hsla(43, 85, 55, 0.15);
  border-left: 4px solid var(--primary-gold);
  align-self: flex-start;
  color: var(--text-primary);
}

.player-msg {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-light);
  align-self: flex-end;
  color: var(--text-primary);
}

.msg-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  color: var(--primary-gold);
}

.input-area {
  padding: 16px;
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 12px;
}

.input-area input {
  flex: 1;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 12px;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  transition: var(--transition-smooth);
}

.input-area input:focus {
  outline: none;
  border-color: var(--primary-gold);
  box-shadow: 0 0 10px var(--primary-gold-glow);
}

/* --- Buttons Styles --- */
.btn-primary {
  background: linear-gradient(135deg, var(--primary-gold), hsl(43, 85%, 45%));
  color: #000;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  padding: 12px 24px;
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition-smooth);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px var(--primary-gold-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition-smooth);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--primary-gold);
}

/* --- Tactical Board Sidebar --- */
.tactical-board {
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
}

.board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 8px;
}

.board-header h2 {
  font-size: 1.25rem;
}

.canvas-container {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

#battlefield-canvas {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.board-instructions {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

.action-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

/* --- Setup Modal Overlay --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
}

.modal-card {
  width: 500px;
  max-width: 90%;
  padding: 24px;
}

.modal-card h2 {
  font-size: 1.75rem;
  color: var(--primary-gold);
  margin-bottom: 8px;
}

.modal-card .description {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.setup-section h3 {
  font-size: 1.1rem;
  margin-bottom: 12px;
}

.campaign-cards-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.concept-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.concept-card:hover {
  border-color: var(--primary-gold);
  background: rgba(255, 255, 255, 0.04);
}

.concept-card.active {
  border-color: var(--primary-gold);
  background: rgba(43, 85, 55, 0.04);
  box-shadow: 0 0 12px rgba(43, 85, 55, 0.2);
}

.concept-card h4 {
  margin-bottom: 4px;
}

.concept-card p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.form-row input, .form-row select {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px;
  color: #fff;
  font-family: inherit;
}

.form-row input:focus, .form-row select:focus {
  outline: none;
  border-color: var(--primary-gold);
}

.mt-2 {
  margin-top: 16px;
}

.hidden {
  display: none !important;
}

/* --- Dice Roll Spinner Overlay --- */
.dice-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.dice-card {
  width: 280px;
  padding: 24px;
  text-align: center;
}

.dice-wrapper {
  margin: 32px 0;
  perspective: 1000px;
}

.d20-visual {
  width: 90px;
  height: 90px;
  margin: 0 auto;
  background: radial-gradient(circle, var(--threat-red), hsl(355, 85%, 35%));
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  color: #fff;
  border: 2px solid var(--primary-gold);
  box-shadow: 0 0 30px hsla(355, 85%, 55%, 0.4);
  animation: d20RollSpin 1.8s ease-out;
}

.dice-formula {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.dice-outcome {
  font-size: 1.35rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  color: var(--primary-gold);
}

/* --- CSS3 Animations --- */
@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes d20RollSpin {
  0% {
    transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scale(0.6);
  }
  50% {
    transform: rotateX(720deg) rotateY(360deg) rotateZ(180deg) scale(1.2);
  }
  100% {
    transform: rotateX(1440deg) rotateY(720deg) rotateZ(360deg) scale(1);
  }
}

/* --- Campaign Creator Extras --- */
.w-full {
  width: 100%;
}

.flex-row {
  display: flex;
  gap: 12px;
}

.flex-grow {
  flex: 1;
}

.section-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.architect-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(145, 80, 45, 0.08);
  border: 1px dashed rgba(145, 80, 45, 0.3);
  border-radius: 8px;
  padding: 10px;
  color: var(--primary-gold);
  font-size: 0.85rem;
  font-weight: 500;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(212, 175, 55, 0.2);
  border-top-color: var(--primary-gold);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
  to { transform: rotate(360deg); }
}

/* --- Ability Edit Grid and Edit Button --- */
.ability-edit-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  text-align: center;
}

.ability-edit-grid label {
  font-size: 0.7rem;
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.ability-edit-grid input {
  width: 100%;
  padding: 6px;
  text-align: center;
}

.mini-btn {
  font-size: 0.7rem;
  padding: 4px 8px;
  margin-left: 8px;
  border-radius: 4px;
}

/* --- Overworld Map / Grid navigation tabs --- */
.tab-navigation {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 3px;
  margin-bottom: 12px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: rgba(145, 80, 45, 0.18);
  color: var(--primary-gold);
  border: 1px solid rgba(212, 175, 55, 0.35);
}

.tab-btn:hover:not(.active) {
  color: var(--text-light);
  background: rgba(255, 255, 255, 0.04);
}

/* --- Asymmetric Private Whisper bubble --- */
.private-whisper-msg {
  background: rgba(212, 175, 55, 0.08);
  border: 1px solid rgba(212, 175, 55, 0.35);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.1);
  border-left: 4px solid var(--primary-gold);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
  animation: privateWhisperPulse 2.5s infinite alternate ease-in-out;
}

.private-whisper-msg .msg-header {
  color: var(--primary-gold);
  font-weight: bold;
  font-size: 0.85rem;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

@keyframes privateWhisperPulse {
  0% {
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.08);
    background: rgba(212, 175, 55, 0.06);
  }
  100% {
    box-shadow: 0 0 14px rgba(212, 175, 55, 0.22);
    background: rgba(212, 175, 55, 0.11);
  }
}
