/* ══════════════════════════════════════════════════════
   RAiC — Role AI Character
   Дизайн-система: ASCII/TUI терминал с неоновой подсветкой
   ══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,300;0,400;0,700;0,800;1,400&display=swap');

:root {
  /* Цвета фона (тёплые, глубокие терминальные оттенки) */
  --bg-primary: #0a0808;
  --bg-secondary: #120e0e;
  --bg-card: #181313;
  --bg-input: #1d1717;
  --bg-hover: #271f1f;

  /* Неоновые акцентные цвета */
  --accent-cyan: #00f3ff;
  --accent-cyan-dim: #00b8c4;
  --accent-cyan-glow: rgba(0, 243, 255, 0.45);

  /* Розовый брендовый с ярким неоновым свечением */
  --accent-pink: #FFA3A3;
  --accent-pink-dim: #ff8585;
  --accent-pink-glow: rgba(255, 163, 163, 0.55);

  /* Теплый сепийно-белый основной текст */
  --text-sepia: #f6efe2;
  --text: var(--text-sepia);
  --text-dim: #a49989;
  
  /* Контуры и разделители */
  --border: #4f4337;

  --red: #ff5555;
  --red-dim: #cc3333;
  --gray: #6e6051;
  --gray-light: #9e8e7c;
  --gray-dark: #372f27;

  /* Шрифты строго моноширинные для TUI-стилистики */
  --font-display: 'JetBrains Mono', monospace;
  --font-body: 'JetBrains Mono', monospace;
  
  /* КРУПНЫЙ ИНТЕРФЕЙС И ШРИФТЫ */
  --font-size-xs: 0.9rem;
  --font-size-sm: 1.05rem;
  --font-size-md: 1.25rem;
  --font-size-lg: 1.45rem;
  --font-size-xl: 1.85rem;
  --font-size-xxl: 2.5rem;

  /* Отступы */
  --space-xs: 0.35rem;
  --space-sm: 0.65rem;
  --space-md: 1.25rem;
  --space-lg: 1.85rem;
  --space-xl: 2.5rem;
  --space-xxl: 3.5rem;

  /* Радиусы скругления строго 0 для аутентичного TUI терминала */
  --radius-sm: 0px;
  --radius-md: 0px;
  --radius-lg: 0px;

  /* Тени и неоновое свечение */
  --shadow-cyan: 0 0 15px var(--accent-cyan-glow);
  --shadow-pink: 0 0 15px var(--accent-pink-glow);
  --shadow-card: 0 4px 30px rgba(0,0,0,0.9);

  /* Анимации */
  --transition-fast: 120ms ease;
  --transition-normal: 200ms ease;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  background: var(--bg-primary);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--font-size-md);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent-cyan); text-decoration: none; }
a:hover { color: var(--accent-pink); }

/* ─── Скроллбар (Решает баг перекрытия обводки) ─── */
* {
  --scrollbar-thumb: var(--border);
  --scrollbar-track: transparent;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  scrollbar-width: thin;
}

/* Резервирование стабильного места для скроллбара, чтобы избежать наездов на рамки */
.modal-overlay, .chat-messages {
  scrollbar-gutter: stable;
}

/* Legacy WebKit-скроллбар с прозрачным треком и внутренними отступами */
@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border: 3px solid transparent;
    background-clip: padding-box;
  }
  ::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent-cyan);
  }
}

/* ─── Контейнеры и Терминальные Рамки ─────────────── */
.terminal-box {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  box-shadow: var(--shadow-card);
  position: relative;
}

/* TUI-уголки на рамке, жестко привязанные к границе и не съезжающие */
.terminal-box::before {
  content: '';
  position: absolute;
  top: -2px; left: -2px; width: 14px; height: 14px;
  border-top: 3px solid var(--accent-cyan);
  border-left: 3px solid var(--accent-cyan);
  pointer-events: none;
}
.terminal-box::after {
  content: '';
  position: absolute;
  bottom: -2px; right: -2px; width: 14px; height: 14px;
  border-bottom: 3px solid var(--accent-cyan);
  border-right: 3px solid var(--accent-cyan);
  pointer-events: none;
}

.terminal-box--glow {
  border-color: var(--accent-cyan);
  box-shadow: var(--shadow-cyan), var(--shadow-card);
}
.terminal-box--glow::before {
  border-color: var(--accent-pink);
  filter: drop-shadow(0 0 2px var(--accent-pink));
}
.terminal-box--glow::after {
  border-color: var(--accent-pink);
  filter: drop-shadow(0 0 2px var(--accent-pink));
}

/* ─── Кнопки ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  font-weight: 700;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent-pink);
  color: #0a0808;
  border-color: var(--accent-pink);
  box-shadow: var(--shadow-pink);
}
.btn-primary:hover:not(:disabled) {
  background: #ffc2c2;
  border-color: #ffc2c2;
  box-shadow: 0 0 25px var(--accent-pink);
}

.btn-secondary {
  background: transparent;
  color: var(--accent-cyan);
  border-color: var(--accent-cyan-dim);
}
.btn-secondary:hover:not(:disabled) {
  background: rgba(0, 243, 255, 0.08);
  border-color: var(--accent-cyan);
  box-shadow: var(--shadow-cyan);
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red-dim);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(255, 85, 85, 0.08);
  border-color: var(--red);
  box-shadow: 0 0 12px rgba(255, 85, 85, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--gray-light);
}

.btn-sm { padding: var(--space-xs) var(--space-md); font-size: var(--font-size-xs); border-width: 1px; }
.btn-lg { padding: var(--space-md) var(--space-xl); font-size: var(--font-size-md); }
.btn-icon { padding: var(--space-sm); aspect-ratio: 1; }

/* ─── Поля ввода ──────────────────────────────────── */
.input-field {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--font-size-md);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
.input-field:focus {
  border-color: var(--accent-cyan);
  box-shadow: var(--shadow-cyan);
}
.input-field::placeholder { color: #5a4e41; }

textarea.input-field { resize: vertical; min-height: 100px; line-height: 1.5; }

.input-label {
  display: block;
  margin-bottom: var(--space-xs);
  font-size: var(--font-size-sm);
  color: var(--accent-cyan);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.input-group { margin-bottom: var(--space-md); }

/* ─── Сетка НПС (Библиотека) ───────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-lg);
}

.npc-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  cursor: pointer;
  transition: all var(--transition-normal);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-sm);
  position: relative;
}
.npc-card::before {
  content: '';
  position: absolute;
  top: -2px; left: -2px; width: 12px; height: 12px;
  border-top: 3px solid var(--accent-pink-dim);
  border-left: 3px solid var(--accent-pink-dim);
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}
.npc-card::after {
  content: '';
  position: absolute;
  bottom: -2px; right: -2px; width: 12px; height: 12px;
  border-bottom: 3px solid var(--accent-pink-dim);
  border-right: 3px solid var(--accent-pink-dim);
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}
.npc-card:hover {
  border-color: var(--accent-pink-dim);
  box-shadow: var(--shadow-pink);
  transform: translateY(-3px);
}
.npc-card:hover::before, .npc-card:hover::after {
  opacity: 1;
}

.npc-card__avatar {
  width: 90px;
  height: 90px;
  border-radius: 0;
  object-fit: cover;
  border: 2px solid var(--border);
  background: var(--bg-secondary);
  /* Перекрашиваем противного зеленого дефолтного человечка в красивую циановую гамму */
  filter: grayscale(100%) brightness(0.9) sepia(1) saturate(2) hue-rotate(145deg);
  transition: filter var(--transition-normal);
}

.npc-card:hover .npc-card__avatar {
  /* При наведении аватарка становится розовой */
  filter: grayscale(100%) brightness(1) sepia(1) saturate(1.8) hue-rotate(295deg);
}

.npc-card__avatar--large {
  width: 140px;
  height: 140px;
  filter: grayscale(100%) brightness(0.95) sepia(1) saturate(1.8) hue-rotate(145deg);
}

.npc-card__name {
  font-family: var(--font-display);
  font-size: var(--font-size-md);
  color: var(--accent-pink);
  font-weight: 800;
  text-shadow: 0 0 5px rgba(255, 163, 163, 0.4);
}
.npc-card__info {
  font-size: var(--font-size-xs);
  color: var(--text-dim);
}

/* ─── Вкладки (Tabs) ──────────────────────────────── */
.tab-bar {
  display: flex;
  gap: var(--space-sm);
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--space-lg);
}

.tab {
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-size-sm);
  color: var(--text-dim);
  cursor: pointer;
  border: 2px solid transparent;
  border-bottom: none;
  border-radius: 0;
  transition: all var(--transition-fast);
  background: none;
  font-family: var(--font-body);
  font-weight: 700;
}
.tab:hover { color: var(--text); }
.tab-active {
  color: var(--accent-cyan);
  border-color: var(--border);
  background: var(--bg-card);
  position: relative;
  text-shadow: 0 0 4px var(--accent-cyan-glow);
}
.tab-active::after {
  content: '';
  position: absolute;
  bottom: -2px; left: 0; right: 0;
  height: 3px;
  background: var(--bg-card);
}

/* ─── Адаптивный Макет Профиля НПС ────────────────── */
.npc-profile-layout {
  display: flex;
  gap: var(--space-xl);
  align-items: flex-start;
}

.npc-profile-sidebar {
  flex-shrink: 0;
  width: 180px;
  text-align: center;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  padding: var(--space-md);
  position: relative;
}
.npc-profile-sidebar::before {
  content: '';
  position: absolute;
  top: -2px; left: -2px; width: 10px; height: 10px;
  border-top: 3px solid var(--accent-cyan);
  border-left: 3px solid var(--accent-cyan);
}
.npc-profile-sidebar::after {
  content: '';
  position: absolute;
  bottom: -2px; right: -2px; width: 10px; height: 10px;
  border-bottom: 3px solid var(--accent-cyan);
  border-right: 3px solid var(--accent-cyan);
}

.npc-profile-main {
  flex: 1;
}

/* Сетка полей ввода (крупная и двухколоночная) */
.npc-fields-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

/* ─── Чат ─────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.chat-message {
  max-width: 75%;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  animation: fadeSlideIn 0.2s ease;
}

.chat-message--player {
  align-self: flex-end;
  background: rgba(0, 243, 255, 0.05);
  border: 2px solid var(--accent-cyan-dim);
  color: var(--text);
  position: relative;
}
.chat-message--player::before {
  content: '>';
  position: absolute;
  left: -20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent-cyan);
  font-weight: bold;
}

.chat-message--npc {
  align-self: flex-start;
  background: rgba(255, 163, 163, 0.05);
  border: 2px solid var(--accent-pink-dim);
  color: var(--text);
  position: relative;
}
.chat-message--npc::before {
  content: '<';
  position: absolute;
  right: -20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent-pink);
  font-weight: bold;
}

.chat-message--system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-style: italic;
  font-size: var(--font-size-xs);
  border: none;
  max-width: 100%;
}

.chat-input-bar {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-top: 2px solid var(--border);
  background: var(--bg-secondary);
}

/* ─── Layout ──────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xl);
  border-bottom: 2px solid var(--border);
  background: var(--bg-secondary);
}

.app-header__logo {
  font-family: var(--font-display);
  font-size: var(--font-size-lg);
  color: var(--accent-cyan);
  letter-spacing: 0.12em;
  font-weight: 800;
  text-shadow: 0 0 8px var(--accent-cyan-glow);
}

.app-header__user {
  font-size: var(--font-size-sm);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.app-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-xl);
}

.page-title {
  font-family: var(--font-display);
  font-size: var(--font-size-xl);
  color: var(--accent-cyan);
  margin-bottom: var(--space-xl);
  border-bottom: 2px dashed var(--border);
  padding-bottom: var(--space-sm);
  text-shadow: 0 0 5px var(--accent-cyan-glow);
}

/* ─── Модальное окно ──────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
  overflow-y: auto;
  padding: var(--space-xl) var(--space-md);
}

.modal {
  background: var(--bg-card);
  border: 3px double var(--accent-cyan); /* Эффектная двойная рамка в стиле TUI */
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  width: min(90vw, 680px);
  box-shadow: var(--shadow-cyan), var(--shadow-card);
  position: relative;
  margin: auto;
}

/* Крупные угловые накладки для модалок, которые никогда не съедут */
.modal::before {
  content: '';
  position: absolute;
  top: -3px; left: -3px; width: 22px; height: 22px;
  border-top: 4px solid var(--accent-pink);
  border-left: 4px solid var(--accent-pink);
  pointer-events: none;
  filter: drop-shadow(0 0 2px var(--accent-pink));
}
.modal::after {
  content: '';
  position: absolute;
  bottom: -3px; right: -3px; width: 22px; height: 22px;
  border-bottom: 4px solid var(--accent-pink);
  border-right: 4px solid var(--accent-pink);
  pointer-events: none;
  filter: drop-shadow(0 0 2px var(--accent-pink));
}

.modal__title {
  font-family: var(--font-display);
  font-size: var(--font-size-lg);
  color: var(--accent-pink);
  margin-bottom: var(--space-lg);
  border-bottom: 2px dashed var(--border);
  padding-bottom: var(--space-sm);
  text-shadow: 0 0 8px rgba(255, 163, 163, 0.8), 0 0 20px rgba(255, 163, 163, 0.3);
  font-weight: 800;
  text-transform: uppercase;
}

.modal__actions {
  display: flex;
  gap: var(--space-md);
  justify-content: flex-end;
  margin-top: var(--space-xl);
}

/* ─── Утилиты ─────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.text-green { color: #55ff55; text-shadow: 0 0 5px rgba(85, 255, 85, 0.4); }
.text-amber { color: var(--accent-cyan); text-shadow: 0 0 5px rgba(0, 243, 255, 0.4); }
.text-purple { color: var(--accent-pink); text-shadow: 0 0 5px rgba(255, 163, 163, 0.4); }
.text-dim { color: var(--text-dim); }
.text-center { text-align: center; }
.mt-md { margin-top: var(--space-md); }
.mb-md { margin-bottom: var(--space-md); }
.hidden { display: none !important; }

/* ─── Спиннер загрузки ────────────────────────────── */
.spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─── Мигающий курсор ─────────────────────────────── */
.cursor-blink::after {
  content: '_';
  animation: blink 1s step-end infinite;
  color: var(--accent-cyan);
}

/* ─── Анимации ────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Эффект ЭЛТ scanline для фона */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 243, 255, 0.012) 2px,
    rgba(0, 243, 255, 0.012) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* ─── Адаптивность и Мобильная Верстка ────────────── */
@media (max-width: 992px) {
  .app-content { padding: var(--space-md); }
  .npc-profile-layout {
    flex-direction: column;
    align-items: center;
  }
  .npc-profile-sidebar {
    width: 100%;
    max-width: 320px;
    margin-bottom: var(--space-md);
  }
}

@media (max-width: 768px) {
  .npc-fields-grid {
    grid-template-columns: 1fr; /* Поля выстраиваются строго в одну колонку на мобилках */
  }
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-md);
  }
  .chat-message { max-width: 88%; }
  .modal { padding: var(--space-lg); width: 95vw; }
  .tab { padding: var(--space-sm) var(--space-md); font-size: var(--font-size-xs); }
}

@media (max-width: 480px) {
  .card-grid { grid-template-columns: 1fr; }
  .app-header { padding: var(--space-sm) var(--space-md); flex-direction: column; gap: var(--space-xs); text-align: center; }
  .app-header__logo { font-size: var(--font-size-md); }
  .tab-bar { flex-wrap: wrap; }
}
