/* =============================================
   Pokemon Lifeline — Playtest UI
   Theme: Dark, Pokémon-inspired, chat/messaging
   ============================================= */

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

:root {
  --bg-primary: #0f1923;
  --bg-secondary: #1a2733;
  --bg-tertiary: #243442;
  --text-primary: #e8edf2;
  --text-secondary: #8899a6;
  --text-muted: #556677;
  --accent-red: #e3350d;
  --accent-blue: #3b82f6;
  --accent-yellow: #f5c518;
  --accent-green: #22c55e;
  --accent-purple: #a855f7;
  --bubble-april: #1e3a5f;
  --bubble-april-border: #2d5a8a;
  --bubble-system: transparent;
  --bubble-player: #2d4a22;
  --bubble-player-border: #4a7a3a;
  --sidebar-width: 320px;
  --header-height: 56px;
  --choices-max-height: 260px;
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-tertiary);
  flex-shrink: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-red), var(--accent-yellow));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.header-info h1 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
}

.header-status {
  font-size: 0.75rem;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
}

.header-status.busy {
  color: var(--accent-yellow);
}

.header-status.busy::before {
  background: var(--accent-yellow);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.2s, color 0.2s;
}

.btn-icon:hover {
  background: var(--accent-blue);
  color: #fff;
}

.btn-icon.danger:hover {
  background: var(--accent-red);
}

/* --- Main Layout --- */
.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* --- Chat Panel --- */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

/* --- Message Bubbles --- */
.message {
  max-width: 85%;
  animation: message-in 0.35s ease-out;
  display: flex;
  flex-direction: column;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* April messages — left aligned */
.message.april {
  align-self: flex-start;
}

.message.april .bubble {
  background: var(--bubble-april);
  border: 1px solid var(--bubble-april-border);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.925rem;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

.message.april .bubble .speaker-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent-blue);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

/* System messages — center, muted */
.message.system {
  align-self: center;
  max-width: 90%;
}

.message.system .bubble {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  text-align: center;
  padding: 6px 12px;
  border: 1px dashed var(--bg-tertiary);
  border-radius: var(--radius-sm);
}

/* Player messages — right aligned */
.message.player {
  align-self: flex-end;
}

.message.player .bubble {
  background: var(--bubble-player);
  border: 1px solid var(--bubble-player-border);
  border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.925rem;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

/* Message grouping — tighten consecutive same-speaker */
.message.april + .message.april,
.message.system + .message.system {
  margin-top: -2px;
}

.message.april + .message.april .speaker-label {
  display: none;
}

/* Typing indicator */
.message.typing .bubble {
  display: flex;
  gap: 4px;
  padding: 12px 18px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* --- Busy Overlay --- */
.busy-overlay {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.875rem;
  gap: 10px;
}

.busy-overlay.visible {
  display: flex;
}

.busy-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--bg-tertiary);
  border-top-color: var(--accent-yellow);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* --- Choices Panel --- */
.choices-panel {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: var(--choices-max-height);
  overflow-y: auto;
  flex-shrink: 0;
}

.choices-panel:empty {
  display: none;
}

.choice-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid #3a4f5f;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-main);
  line-height: 1.4;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}

.choice-btn:hover {
  background: #2d4a5f;
  border-color: var(--accent-blue);
}

.choice-btn:active {
  transform: scale(0.98);
}

.choice-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.choice-btn .choice-condition-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--accent-yellow);
  margin-top: 4px;
  font-style: italic;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--bg-tertiary);
  overflow-y: auto;
  padding: 20px 16px;
  flex-shrink: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 90;
}

.sidebar.hidden {
  transform: translateX(100%);
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-section h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--bg-tertiary);
}

/* Team */
.team-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.team-member {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.team-member .pkmn-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.team-member .pkmn-icon.type-Normal { background: #a8a878; color: #fff; }
.team-member .pkmn-icon.type-Combat { background: #c03028; color: #fff; }
.team-member .pkmn-icon.type-Spectre { background: #705898; color: #fff; }
.team-member .pkmn-icon.type-Feu { background: #f08030; color: #fff; }
.team-member .pkmn-icon.type-Eau { background: #6890f0; color: #fff; }
.team-member .pkmn-icon.type-Plante { background: #78c850; color: #fff; }
.team-member .pkmn-icon.type-Electrik { background: #f8d030; color: #333; }
.team-member .pkmn-icon.type-Psy { background: #f85888; color: #fff; }
.team-member .pkmn-icon.type-Poison { background: #a040a0; color: #fff; }
.team-member .pkmn-icon.type-Vol { background: #a890f0; color: #fff; }

.team-member.dead {
  opacity: 0.4;
}

.team-member.dead .pkmn-name::after {
  content: ' (K.O.)';
  color: var(--accent-red);
  font-size: 0.75rem;
}

.team-member .pkmn-name {
  font-weight: 500;
}

.team-member .pkmn-type {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: auto;
}

.team-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  padding: 8px 0;
}

/* Profile Bars */
.profile-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-stat .stat-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
}

.profile-stat .stat-name {
  color: var(--text-secondary);
  font-weight: 500;
}

.profile-stat .stat-value {
  color: var(--text-primary);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.stat-bar {
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
  min-width: 2px;
}

.stat-bar-fill.compassion { background: var(--accent-green); }
.stat-bar-fill.strategie { background: var(--accent-blue); }
.stat-bar-fill.audace { background: var(--accent-red); }
.stat-bar-fill.prudence { background: var(--accent-yellow); }

/* Affinity */
.affinity-gauge {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.affinity-bar-container {
  height: 10px;
  background: var(--bg-primary);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.affinity-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-red), var(--accent-yellow), var(--accent-green));
  border-radius: 5px;
  transition: width 0.5s ease;
}

.affinity-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Missions */
.missions-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mission-item {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mission-item::before {
  content: '\2713';
  color: var(--accent-green);
  font-weight: 700;
}

.missions-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  padding: 8px 0;
}

/* Flags debug */
.flags-debug {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 8px;
  border-radius: var(--radius-sm);
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* --- Loading Screen --- */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 20px;
  transition: opacity 0.5s ease;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-title {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-red), var(--accent-yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.loading-subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.loading-bar {
  width: 200px;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  width: 30%;
  background: var(--accent-red);
  border-radius: 2px;
  animation: loading-slide 1.5s ease-in-out infinite;
}

@keyframes loading-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(700%); }
}

/* --- Error --- */
.error-banner {
  display: none;
  padding: 10px 16px;
  background: rgba(227, 53, 13, 0.15);
  border: 1px solid var(--accent-red);
  border-radius: var(--radius-sm);
  color: var(--accent-red);
  font-size: 0.8rem;
  margin: 8px 16px;
}

.error-banner.visible {
  display: block;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    right: 0;
    top: var(--header-height);
    bottom: 0;
    width: 85vw;
    max-width: var(--sidebar-width);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.hidden {
    transform: translateX(100%);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0,0,0,0.5);
    z-index: 80;
  }

  .sidebar-backdrop.visible {
    display: block;
  }

  .message {
    max-width: 92%;
  }
}

@media (max-width: 400px) {
  .header-info h1 {
    font-size: 0.9rem;
  }

  .choice-btn {
    font-size: 0.85rem;
    padding: 10px 14px;
  }
}
