/* ============================================================
   Prompt Injection Training Game — Main Stylesheet
   Google Material 3 inspired, dark-capable, modern UI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Google+Sans:wght@400;500;700&display=swap');

/* ── CSS Variables ── */
:root {
  --primary: #6750A4;
  --primary-container: #EADDFF;
  --on-primary: #FFFFFF;
  --secondary: #625B71;
  --tertiary: #7D5260;
  --surface: #FFFBFE;
  --surface-variant: #E7E0EC;
  --surface-2: #F4EFF4;
  --on-surface: #1C1B1F;
  --on-surface-variant: #49454F;
  --outline: #79747E;
  --outline-variant: #CAC4D0;
  --error: #B3261E;
  --error-container: #F9DEDC;
  --success: #146C2E;
  --success-container: #C8F0D4;
  --warning: #7A5800;
  --warning-container: #FFDEA9;
  --shadow: rgba(0,0,0,0.08);
  --shadow-md: rgba(0,0,0,0.14);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --transition: 0.2s cubic-bezier(0.2, 0, 0, 1);
  --font: 'Inter', 'Google Sans', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--surface);
  color: var(--on-surface);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--outline); }

/* ── Layout ── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Top Bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 64px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--shadow-md);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-logo {
  width: 36px; height: 36px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.topbar-subtitle {
  font-size: 12px;
  opacity: 0.75;
  font-weight: 400;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-user {
  font-size: 13px;
  opacity: 0.9;
  font-weight: 500;
  padding: 4px 12px;
  background: rgba(255,255,255,0.12);
  border-radius: 20px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: #7965AF; box-shadow: 0 2px 8px rgba(103,80,164,0.35); }

.btn-surface {
  background: var(--surface-2);
  color: var(--on-surface);
  border: 1px solid var(--outline-variant);
}
.btn-surface:hover { background: var(--surface-variant); }

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
}
.btn-danger:hover { background: var(--error-container); }

.btn-ghost {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
}
.btn-ghost:hover { background: rgba(255,255,255,0.22); }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-icon { padding: 8px; border-radius: 50%; }

/* ── Stage Progress Bar ── */
.stage-progress-bar {
  background: var(--surface-2);
  border-bottom: 1px solid var(--outline-variant);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.stage-steps {
  display: flex;
  gap: 6px;
  flex: 1;
}

.stage-step {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: var(--outline-variant);
  transition: all 0.4s ease;
  position: relative;
}

.stage-step.completed { background: var(--success); }
.stage-step.current {
  background: var(--primary);
  box-shadow: 0 0 8px rgba(103,80,164,0.4);
}

.stage-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--on-surface-variant);
  white-space: nowrap;
}

/* ── Main Content ── */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ── Left Pane — Chat ── */
.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--outline-variant);
  overflow: hidden;
}

.chat-pane-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--outline-variant);
  background: var(--surface);
  flex-shrink: 0;
}

.pane-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--on-surface);
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane-subtitle {
  font-size: 12px;
  color: var(--on-surface-variant);
  margin-top: 2px;
}

.difficulty-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.3px;
}

/* ── Messages ── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  gap: 10px;
  animation: msg-in 0.25s ease both;
  max-width: 85%;
}

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

.message.user { flex-direction: row-reverse; align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.message-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .message-avatar { background: var(--primary); color: #fff; }
.message.assistant .message-avatar { background: var(--surface-variant); }

.message-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  max-width: 100%;
  word-break: break-word;
}

.message.user .message-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--surface-2);
  color: var(--on-surface);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--outline-variant);
}

.message-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

.filter-notice {
  font-size: 11px;
  color: var(--warning);
  background: var(--warning-container);
  padding: 4px 10px;
  border-radius: 6px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* System / info messages */
.message-system {
  align-self: center;
  background: var(--surface-variant);
  color: var(--on-surface-variant);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 20px;
  text-align: center;
  max-width: 80%;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--outline-variant);
  width: fit-content;
}

.typing-dot {
  width: 7px; height: 7px;
  background: var(--outline);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ── Chat Input ── */
.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--outline-variant);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--surface-2);
  border: 1.5px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--on-surface);
  resize: none;
  max-height: 120px;
  min-height: 44px;
  transition: border-color var(--transition);
  outline: none;
}

.chat-input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.chat-input::placeholder { color: var(--on-surface-variant); }

.send-btn {
  width: 44px; height: 44px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.send-btn:hover { background: #7965AF; transform: scale(1.05); }
.send-btn:disabled { opacity: 0.5; pointer-events: none; }

/* ── Right Pane — Password Check ── */
.password-pane {
  width: 340px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow-y: auto;
  flex-shrink: 0;
}

.stage-card {
  margin: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, #9C89C9 100%);
  border-radius: var(--radius-xl);
  padding: 24px;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.stage-card::before {
  content: '';
  position: absolute;
  top: -30px; right: -30px;
  width: 120px; height: 120px;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
}

.stage-card-number {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.8;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.stage-card-title {
  font-size: 26px;
  font-weight: 700;
  margin: 4px 0 8px;
}

.stage-card-desc {
  font-size: 13px;
  opacity: 0.85;
  line-height: 1.5;
}

.stage-card-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  background: rgba(255,255,255,0.18);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
}

.hint-card {
  margin: 0 20px 16px;
  background: var(--warning-container);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border-left: 4px solid #F29900;
}

.hint-card-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--warning);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.hint-card-text {
  font-size: 13px;
  color: var(--on-surface);
  line-height: 1.5;
}

/* Password Submit */
.password-submit-section {
  margin: 0 20px;
  padding: 20px;
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--outline-variant);
}

.password-submit-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--on-surface);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.password-input-row {
  display: flex;
  gap: 8px;
}

.password-input {
  flex: 1;
  background: var(--surface);
  border: 1.5px solid var(--outline-variant);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--on-surface);
  text-transform: uppercase;
  outline: none;
  transition: border-color var(--transition);
}

.password-input:focus { border-color: var(--primary); }
.password-input::placeholder { letter-spacing: 0; font-weight: 400; text-transform: none; }

.submit-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}
.submit-btn:hover { background: #7965AF; }
.submit-btn:disabled { opacity: 0.5; }

.password-result {
  margin-top: 10px;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  display: none;
  align-items: center;
  gap: 6px;
}
.password-result.success {
  display: flex;
  background: var(--success-container);
  color: var(--success);
}
.password-result.error {
  display: flex;
  background: var(--error-container);
  color: var(--error);
}

/* Completed stages panel */
.completed-stages-section {
  margin: 16px 20px 20px;
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.completed-stage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--success-container);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--success);
  font-weight: 500;
  animation: slide-in 0.3s ease both;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateX(10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Reset button */
.reset-section {
  margin: 0 20px 20px;
  padding-top: 16px;
  border-top: 1px solid var(--outline-variant);
}

/* ── Overlay / Modal ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fade-in 0.2s ease;
  backdrop-filter: blur(4px);
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 420px;
  max-width: 95vw;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
  animation: modal-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  text-align: center;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-icon {
  font-size: 56px;
  margin-bottom: 16px;
  display: block;
}

.modal-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--on-surface);
  margin-bottom: 8px;
}

.modal-body {
  font-size: 15px;
  color: var(--on-surface-variant);
  margin-bottom: 28px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Name modal specific */
.name-input {
  width: 100%;
  border: 1.5px solid var(--outline-variant);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--on-surface);
  background: var(--surface-2);
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 16px;
}

.name-input:focus { border-color: var(--primary); }
.name-input.error-shake { animation: shake 0.4s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* ── Win Screen ── */
.win-screen {
  background: linear-gradient(135deg, var(--primary) 0%, #9C89C9 100%);
  color: #fff;
}

.confetti-emoji {
  font-size: 40px;
  display: block;
  animation: float 2s ease-in-out infinite alternate;
}

@keyframes float {
  from { transform: translateY(0) rotate(-5deg); }
  to   { transform: translateY(-10px) rotate(5deg); }
}

/* ── Stage Advance Celebration ── */
.celebration-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.celebration-badge {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-xl);
  padding: 20px 36px;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 16px 48px rgba(103,80,164,0.5);
  animation: badge-pop 2.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  text-align: center;
}

@keyframes badge-pop {
  0%   { opacity: 0; transform: scale(0.5); }
  15%  { opacity: 1; transform: scale(1.1); }
  25%  { transform: scale(1); }
  75%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.9) translateY(-30px); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .main-content { flex-direction: column; }
  .password-pane { width: 100%; border-top: 1px solid var(--outline-variant); max-height: 50vh; }
  .chat-pane { min-height: 50vh; border-right: none; }
  .topbar-subtitle { display: none; }
  .stage-card { margin: 12px; }
  .password-submit-section, .hint-card, .completed-stages-section, .reset-section { margin-left: 12px; margin-right: 12px; }
}
