/* ========================================
   INVINCIBLE RPG — HERO/VILLAIN GENERATOR
   Comic-Stil Redesign
   ======================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Hero Mode (Mark Grayson — Gelb/Blau) */
  --bg-primary:      #0a0e1a;
  --bg-panel:        #111827;
  --bg-panel-hover:  #1e293b;
  --accent-primary:  #facc15;
  --accent-blue:     #3b82f6;
  --accent-glow:     rgba(250, 204, 21, 0.25);
  --text-primary:    #f8fafc;
  --text-secondary:  #94a3b8;
  --text-muted:      #64748b;
  --border:          #1e293b;
  --border-panel:    #f8fafc;
  --danger:          #ef4444;
  --attr-physical:   #1e3a5f;
  --attr-mental:     #3b1f6e;
  --btn-generate-bg: #facc15;
  --btn-generate-fg: #0a0e1a;
  --toggle-hero:     #3b82f6;
  --toggle-villain:  #dc2626;
  --story-border:    rgba(250, 204, 21, 0.4);
  --story-bg:        rgba(250, 204, 21, 0.05);

  /* Transition speed for mode switch */
  --mode-transition: 0.5s ease;
}

/* Villain Mode (Omni-Man — Rot/Violett) */
body.villain-mode {
  --bg-primary:      #0a0505;
  --bg-panel:        #1a0a0a;
  --bg-panel-hover:  #2a1515;
  --accent-primary:  #dc2626;
  --accent-blue:     #9333ea;
  --accent-glow:     rgba(220, 38, 38, 0.25);
  --text-primary:    #fef2f2;
  --text-secondary:  #d4a0a0;
  --text-muted:      #8a5a5a;
  --border:          #3a1515;
  --border-panel:    #fef2f2;
  --attr-physical:   #5a1a1a;
  --attr-mental:     #3a1050;
  --btn-generate-bg: #dc2626;
  --btn-generate-fg: #ffffff;
  --story-border:    rgba(220, 38, 38, 0.4);
  --story-bg:        rgba(220, 38, 38, 0.05);
}

body {
  font-family: 'Roboto Condensed', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  transition:
    background var(--mode-transition),
    color var(--mode-transition);
}

/* Halftone dot texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.03;
  background-image: radial-gradient(circle, var(--text-primary) 1px, transparent 1px);
  background-size: 16px 16px;
}

/* ============================================================
   APP CONTAINER
   ============================================================ */

.app-container {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* ============================================================
   HEADER — Speed Lines + Impact Styling
   ============================================================ */

.app-header {
  padding: 28px 0 20px;
  margin-bottom: 28px;
  border-bottom: 3px solid var(--accent-primary);
  position: relative;
  overflow: hidden;
  transition: border-color var(--mode-transition);
}

/* Speed lines background */
.app-header::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  background: repeating-linear-gradient(
    -15deg,
    transparent,
    transparent 8px,
    var(--accent-primary) 8px,
    var(--accent-primary) 9px
  );
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  position: relative;
}

.title {
  font-family: 'Bangers', cursive;
  font-size: 2.4rem;
  letter-spacing: 3px;
  color: var(--accent-primary);
  text-shadow: 0 0 30px var(--accent-glow), 0 2px 0 rgba(0,0,0,0.3);
  transition: color var(--mode-transition), text-shadow var(--mode-transition);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-actions {
  display: flex;
  gap: 10px;
  position: relative;
}

/* ============================================================
   HERO/VILLAIN TOGGLE — Dramatic Mode Switch
   ============================================================ */

.toggle-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-label {
  font-family: 'Bangers', cursive;
  font-size: 1.1rem;
  letter-spacing: 1px;
  color: var(--text-muted);
  transition: color 0.3s, text-shadow 0.3s;
}

.toggle-label-hero {
  color: var(--accent-blue);
  text-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

body.villain-mode .toggle-label-hero {
  color: var(--text-muted);
  text-shadow: none;
}

body.villain-mode .toggle-label-villain {
  color: var(--accent-primary);
  text-shadow: 0 0 8px var(--accent-glow);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 56px;
  height: 30px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--toggle-hero);
  border-radius: 30px;
  transition: background 0.4s, box-shadow 0.4s;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.3);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--toggle-villain);
  box-shadow: 0 0 12px rgba(220, 38, 38, 0.5);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(26px);
}

/* Villain header pulse */
body.villain-mode .app-header {
  animation: villain-pulse 3s ease-in-out infinite;
}

@keyframes villain-pulse {
  0%, 100% { border-bottom-color: var(--accent-primary); }
  50% { border-bottom-color: #9333ea; }
}

/* Settings gear button */
.btn-settings {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-settings:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: rotate(30deg);
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  font-family: 'Roboto Condensed', sans-serif;
  font-weight: 700;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
  font-size: 0.9rem;
  position: relative;
  overflow: hidden;
}

.btn:hover {
  transform: translateY(-2px) scale(1.02);
  filter: brightness(1.1);
}

.btn:active {
  transform: translateY(0) scale(0.98);
}

/* Impact burst on hover */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.3) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.btn:hover::after {
  opacity: 1;
}

.btn-generate {
  background: var(--btn-generate-bg);
  color: var(--btn-generate-fg);
  padding: 12px 28px;
  font-size: 1.1rem;
  font-family: 'Bangers', cursive;
  letter-spacing: 2px;
  box-shadow: 0 0 16px var(--accent-glow), 0 4px 12px rgba(0,0,0,0.3);
  transition: all 0.2s, background var(--mode-transition), color var(--mode-transition);
}

.btn-generate:hover {
  box-shadow: 0 0 32px var(--accent-glow), 0 6px 20px rgba(0,0,0,0.4);
}

.btn-clear {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 12px 20px;
  font-family: 'Bangers', cursive;
  letter-spacing: 1px;
}

.btn-clear:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-dice {
  background: var(--bg-panel);
  color: var(--accent-primary);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 1.1rem;
  min-width: 42px;
  transition: all 0.2s, color var(--mode-transition), border-color 0.2s;
}

.btn-dice:hover {
  border-color: var(--accent-primary);
  background: var(--bg-panel-hover);
  animation: dice-wiggle 0.3s ease;
}

@keyframes dice-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-10deg); }
  75% { transform: rotate(10deg); }
}

.btn-sm {
  font-size: 0.85rem;
  padding: 3px 8px;
  min-width: 32px;
  vertical-align: middle;
}

.btn-add {
  background: transparent;
  color: var(--accent-primary);
  border: 1px dashed var(--border);
  padding: 10px 16px;
  width: 100%;
  margin-top: 8px;
  transition: all 0.2s, color var(--mode-transition);
}

.btn-add:hover {
  border-color: var(--accent-primary);
  background: var(--bg-panel-hover);
}

/* AI-specific button */
.btn-ai {
  background: linear-gradient(135deg, var(--accent-blue), #7c3aed);
  color: #fff;
  padding: 6px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.3);
}

body.villain-mode .btn-ai {
  background: linear-gradient(135deg, #9333ea, #dc2626);
  box-shadow: 0 0 12px rgba(147, 51, 234, 0.3);
}

.btn-ai:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 20px rgba(124, 58, 237, 0.5);
}

.btn-ai.loading {
  pointer-events: none;
  min-width: 200px;
  text-align: center;
  animation: ai-pulse 1.5s ease-in-out infinite;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}

@keyframes ai-pulse {
  0%, 100% { box-shadow: 0 0 12px rgba(124, 58, 237, 0.3); opacity: 0.8; }
  50% { box-shadow: 0 0 28px rgba(124, 58, 237, 0.7); opacity: 1; }
}

/* ============================================================
   COMIC PANEL GRID LAYOUT
   ============================================================ */

.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.main-grid .panel-full {
  grid-column: 1 / -1;
}

/* ============================================================
   PANELS — Comic-Panel Bordüren
   ============================================================ */

.panel {
  background: var(--bg-panel);
  border: 3px solid var(--border-panel);
  border-radius: 2px;
  overflow: hidden;
  transition:
    transform 0.2s,
    box-shadow 0.2s,
    background var(--mode-transition),
    border-color var(--mode-transition);
  /* Fade-in animation */
  animation: panel-enter 0.4s ease-out both;
}

.panel:hover {
  transform: translateY(-2px);
  box-shadow:
    0 8px 24px rgba(0,0,0,0.4),
    0 0 0 1px var(--accent-primary);
}

@keyframes panel-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger panel entrance */
.panel:nth-child(1) { animation-delay: 0.0s; }
.panel:nth-child(2) { animation-delay: 0.05s; }
.panel:nth-child(3) { animation-delay: 0.1s; }
.panel:nth-child(4) { animation-delay: 0.15s; }
.panel:nth-child(5) { animation-delay: 0.2s; }
.panel:nth-child(6) { animation-delay: 0.25s; }
.panel:nth-child(7) { animation-delay: 0.3s; }
.panel:nth-child(8) { animation-delay: 0.35s; }

.panel-title {
  font-family: 'Bangers', cursive;
  font-size: 1.3rem;
  letter-spacing: 1.5px;
  color: var(--accent-primary);
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: color var(--mode-transition);
}

.panel-title .title-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title .title-actions {
  display: flex;
  gap: 6px;
}

.panel-body {
  padding: 16px;
}

/* ============================================================
   INPUTS
   ============================================================ */

.select-input {
  font-family: 'Roboto Condensed', sans-serif;
  font-size: 1rem;
  background: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  width: 100%;
  max-width: 300px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.select-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.text-input {
  font-family: 'Roboto Condensed', sans-serif;
  font-size: 1rem;
  background: rgba(0,0,0,0.2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  width: 100%;
  transition: border-color 0.2s;
}

.text-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-glow);
}

.text-input::placeholder {
  color: var(--text-muted);
}

.textarea-input {
  font-family: 'Roboto Condensed', sans-serif;
  font-size: 1rem;
  background: rgba(0,0,0,0.2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  width: 100%;
  resize: none;
  min-height: 80px;
  transition: border-color 0.2s;
}

.textarea-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-glow);
}

.textarea-input::placeholder {
  color: var(--text-muted);
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.display-value {
  flex: 1;
  font-size: 1.05rem;
  color: var(--text-primary);
  padding: 6px 0;
  min-height: 1.5em;
}

/* ============================================================
   IDENTITY PANEL
   ============================================================ */

.identity-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.field-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
}

/* Archetype info */
.archetype-info {
  margin-top: 12px;
}

.role-badge {
  display: inline-block;
  font-family: 'Bangers', cursive;
  font-size: 0.85rem;
  letter-spacing: 1px;
  background: var(--accent-primary);
  color: var(--bg-primary);
  padding: 2px 10px;
  border-radius: 3px;
  margin-bottom: 8px;
  transition: background var(--mode-transition);
}

.archetype-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Rank info */
.rank-info {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
}

.rank-stat {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.rank-stat strong {
  color: var(--accent-primary);
  transition: color var(--mode-transition);
}

body.villain-mode .reputation-stat {
  display: none;
}

/* ============================================================
   ATTRIBUTES — Power-Meter Cards
   ============================================================ */

.attr-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.attr-card {
  background: var(--attr-physical);
  border-radius: 6px;
  padding: 14px 10px;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: background var(--mode-transition), transform 0.2s;
}

.attr-card:hover {
  transform: scale(1.03);
}

.attr-card.attr-mental {
  background: var(--attr-mental);
}

/* Power-meter bar behind the card */
.attr-card::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-primary);
  opacity: 0.6;
  transition: background var(--mode-transition);
}

.attr-card label {
  display: block;
  font-family: 'Bangers', cursive;
  font-size: 0.85rem;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 6px;
}

.attr-input {
  font-family: 'Bangers', cursive;
  font-size: 2rem;
  width: 60px;
  text-align: center;
  background: rgba(0, 0, 0, 0.4);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 4px;
  transition: border-color 0.2s;
}

.attr-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Hide spin buttons */
.attr-input::-webkit-inner-spin-button,
.attr-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.attr-input {
  -moz-appearance: textfield;
}

.attr-summary {
  text-align: center;
  margin-top: 12px;
  font-size: 1rem;
  color: var(--text-secondary);
}

.attr-summary strong {
  color: var(--accent-primary);
  font-family: 'Bangers', cursive;
  font-size: 1.2rem;
  transition: color var(--mode-transition);
}

/* Derived Values */
.derived-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.derived-card {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  text-align: center;
}

.derived-card label {
  display: block;
  font-family: 'Bangers', cursive;
  font-size: 0.8rem;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.derived-value {
  font-family: 'Bangers', cursive;
  font-size: 1.8rem;
  color: var(--accent-primary);
  transition: color var(--mode-transition);
}

/* ============================================================
   POWERS — Badges with Comic Colors per Type
   ============================================================ */

.powers-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.power-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: transform 0.15s, border-color 0.15s;
}

.power-item:hover {
  transform: translateX(4px);
  border-color: var(--accent-primary);
}

.power-name {
  flex: 1;
  font-weight: 700;
  font-size: 1rem;
}

.power-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 3px;
  color: #fff;
  white-space: nowrap;
}

/* Power type colors with icons */
.power-badge.attack     { background: #dc2626; }
.power-badge.defense    { background: #2563eb; }
.power-badge.control    { background: #16a34a; }
.power-badge.movement   { background: #0891b2; }
.power-badge.sensory    { background: #d97706; }
.power-badge.modification { background: #ea580c; }

.power-level {
  font-family: 'Bangers', cursive;
  font-size: 1rem;
  color: var(--accent-primary);
  background: rgba(0,0,0,0.3);
  padding: 2px 8px;
  border-radius: 3px;
  transition: color var(--mode-transition);
}

.placeholder {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Power source section */
.power-source-row {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.power-source-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  font-weight: 700;
}

/* ============================================================
   TALENTS & DRAWBACKS
   ============================================================ */

.talent-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.talent-field label,
.field-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
}

/* Drawbacks */
.drawback-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 6px;
}

.drawback-name {
  flex: 1;
}

.btn-remove {
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 6px;
  transition: color 0.2s;
}

.btn-remove:hover {
  color: var(--danger);
}

/* Occupation details */
.occupation-details {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
}

.occ-detail {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.occ-detail strong {
  color: var(--accent-primary);
  transition: color var(--mode-transition);
}

/* ============================================================
   PERSONAL PANEL
   ============================================================ */

.personal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.personal-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
}

/* ============================================================
   ORIGIN STORY — Speech Bubble
   ============================================================ */

.story-box {
  background: var(--story-bg);
  border: 2px solid var(--story-border);
  border-radius: 16px;
  padding: 24px 20px 20px;
  position: relative;
  transition: border-color var(--mode-transition), background var(--mode-transition);
}

/* Speech bubble tail */
.story-box::after {
  content: '';
  position: absolute;
  top: -12px;
  left: 32px;
  width: 24px;
  height: 24px;
  background: var(--story-bg);
  border-left: 2px solid var(--story-border);
  border-top: 2px solid var(--story-border);
  transform: rotate(45deg);
  transition: background var(--mode-transition), border-color var(--mode-transition);
}

/* Opening quote */
.story-box::before {
  content: '\201C';
  position: absolute;
  top: 4px;
  left: 14px;
  font-family: 'Bangers', cursive;
  font-size: 3rem;
  color: var(--accent-primary);
  opacity: 0.3;
  line-height: 1;
  transition: color var(--mode-transition);
}

.story-text {
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text-primary);
  padding-left: 8px;
}

/* ============================================================
   AI ASSISTANT PANEL
   ============================================================ */

/* AI features only visible when token is set */
.ai-only {
  display: none !important;
}

body.ai-enabled .ai-only {
  display: block !important;
}

body.ai-enabled .ai-only-block {
  display: block !important;
}

body.ai-enabled .ai-only-inline {
  display: inline-flex !important;
}

.ai-panel .panel-title {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(124, 58, 237, 0.15));
}

body.villain-mode .ai-panel .panel-title {
  background: linear-gradient(135deg, rgba(147, 51, 234, 0.15), rgba(220, 38, 38, 0.15));
}

.ai-panel .panel-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.ai-panel .textarea-input {
  flex: 1;
  min-height: 60px;
}

.ai-actions {
  display: flex;
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .ai-panel .panel-body {
    flex-direction: column;
  }

  .ai-actions {
    width: 100%;
  }

  .ai-actions .btn-ai {
    width: 100%;
  }
}

.ai-response-box {
  margin-top: 12px;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  position: relative;
  min-height: 0;
  display: none;
}

.ai-response-box.visible {
  display: block;
}

/* Speech bubble style for AI response */
.ai-response-box::after {
  content: '';
  position: absolute;
  top: -8px;
  right: 32px;
  width: 16px;
  height: 16px;
  background: rgba(0,0,0,0.2);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  transform: rotate(45deg);
}

.ai-response-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.ai-error {
  color: var(--danger);
}

.ai-response-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   ASK AI — Floating Action Button + Slide-in Drawer
   ============================================================ */

.ask-ai-fab {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 200;
  background: linear-gradient(135deg, var(--accent-blue), #7c3aed);
  color: #fff;
  border: none;
  border-radius: 12px 0 0 12px;
  padding: 16px 10px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: -4px 0 16px rgba(124, 58, 237, 0.4);
  transition: all 0.3s;
}

body.villain-mode .ask-ai-fab {
  background: linear-gradient(135deg, #9333ea, #dc2626);
  box-shadow: -4px 0 16px rgba(147, 51, 234, 0.4);
}

.ask-ai-fab:hover {
  padding-right: 16px;
  box-shadow: -6px 0 24px rgba(124, 58, 237, 0.6);
}

/* Hide FAB when drawer is open */
.ask-ai-fab.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) translateX(100%);
}

.ask-ai-drawer {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%) translateX(110%);
  z-index: 300;
  width: 380px;
  max-height: 70vh;
  background: var(--bg-panel);
  border: 3px solid var(--border-panel);
  border-right: none;
  border-radius: 12px 0 0 12px;
  display: flex;
  flex-direction: column;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), background var(--mode-transition), border-color var(--mode-transition);
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}

.ask-ai-drawer.open {
  transform: translateY(-50%) translateX(0);
}

.ask-ai-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 2px solid var(--border);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(124, 58, 237, 0.15));
}

body.villain-mode .ask-ai-drawer-header {
  background: linear-gradient(135deg, rgba(147, 51, 234, 0.15), rgba(220, 38, 38, 0.15));
}

.ask-ai-drawer-title {
  font-family: 'Bangers', cursive;
  font-size: 1.2rem;
  letter-spacing: 1px;
  color: var(--accent-primary);
}

.ask-ai-drawer-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

@media (max-width: 480px) {
  .ask-ai-drawer {
    width: 100%;
    border-radius: 12px 12px 0 0;
    top: auto;
    bottom: 0;
    transform: translateY(110%);
    max-height: 75vh;
  }

  .ask-ai-drawer.open {
    transform: translateY(0);
  }
}

/* ============================================================
   SETTINGS MODAL
   ============================================================ */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-panel);
  border: 3px solid var(--border-panel);
  border-radius: 4px;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  animation: modal-enter 0.3s ease-out;
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 2px solid var(--border);
  background: rgba(0,0,0,0.3);
}

.modal-header h2 {
  font-family: 'Bangers', cursive;
  font-size: 1.4rem;
  color: var(--accent-primary);
  letter-spacing: 1px;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 20px;
}

.modal-body .field-group {
  margin-bottom: 16px;
}

.modal-body .field-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
}

.modal-body .field-group .hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.btn-modal-save {
  background: var(--accent-primary);
  color: var(--bg-primary);
  border: none;
  padding: 8px 20px;
  border-radius: 4px;
  font-weight: 700;
  cursor: pointer;
  font-family: 'Bangers', cursive;
  letter-spacing: 1px;
  font-size: 1rem;
  transition: all 0.2s;
}

.btn-modal-save:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-modal-cancel {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 4px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-modal-cancel:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

/* ============================================================
   AI CONFIRM MODAL
   ============================================================ */

.confirm-modal .modal {
  max-width: 600px;
}

.confirm-preview {
  max-height: 300px;
  overflow-y: auto;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px;
  margin-bottom: 16px;
}

.confirm-preview-item {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.confirm-preview-item:last-child {
  border-bottom: none;
}

.confirm-preview-label {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.confirm-preview-value {
  color: var(--accent-primary);
  font-weight: 700;
  font-size: 0.9rem;
}

/* ============================================================
   IMPACT FLASH ANIMATION (Generate All)
   ============================================================ */

.impact-flash {
  position: fixed;
  inset: 0;
  background: white;
  pointer-events: none;
  z-index: 9999;
  animation: impact 0.3s ease-out forwards;
}

@keyframes impact {
  0% { opacity: 0.6; }
  100% { opacity: 0; }
}

/* ============================================================
   FOOTER
   ============================================================ */

.floating-footer {
  position: fixed;
  bottom: 12px;
  right: 12px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  color: var(--text-muted);
  font-size: 0.7rem;
  opacity: 0.5;
  transition: opacity 0.3s, background var(--mode-transition), border-color var(--mode-transition);
  backdrop-filter: blur(8px);
}

.floating-footer:hover {
  opacity: 1;
}

.floating-footer a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color 0.2s, text-shadow 0.2s;
}

.floating-footer a:hover {
  text-shadow: 0 0 8px var(--accent-glow);
}

.footer-divider {
  color: var(--border);
}

@media (max-width: 600px) {
  .floating-footer {
    left: 12px;
    right: 12px;
    justify-content: center;
    flex-wrap: wrap;
  }
}

/* ============================================================
   RESPONSIVE — Mobile: Single Column Stack
   ============================================================ */

@media (max-width: 768px) {
  .title {
    font-size: 1.5rem;
  }

  .header-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .main-grid {
    grid-template-columns: 1fr;
  }

  .attr-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .derived-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .identity-grid,
  .talent-row,
  .personal-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .attr-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .derived-grid {
    grid-template-columns: 1fr;
  }

  .title {
    font-size: 1.2rem;
  }
}
