/* ═══════════════════════════════════════════════════════════════
   FLUENCIFY — Design System & Styles
   Premium AI English Tutor | Portfolio Project
   ═══════════════════════════════════════════════════════════════ */

/* ─── DESIGN TOKENS ─── */
:root {
  --bg: #EEF2EF;
  --card: #0D1B2A;
  --teal: #00C9A7;
  --teal-dark: #00A896;
  --teal-glow: rgba(0, 201, 167, 0.18);
  --bubble-ai: #1A2E3B;
  --bubble-user: #00C9A7;
  --text: #F4F7F5;
  --muted: #8A9BAE;
  --danger: #ff6b6b;
  --font-display: 'Syne', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
  --radius-card: 28px;
  --radius-bubble-ai: 18px 18px 18px 4px;
  --radius-bubble-user: 18px 18px 4px 18px;
  --shadow-card:
    0 24px 64px rgba(13, 27, 42, 0.35),
    0 0 48px rgba(0, 201, 167, 0.08);
  --ease-out-expo: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  position: relative;
  overflow-x: hidden;
}

/* Grain Texture Overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.035'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ─── KEYFRAME ANIMATIONS ─── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(32px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulseRing {
  0% {
    transform: scale(1);
    opacity: 0.35;
  }
  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

@keyframes wave {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
}

@keyframes typingBounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes micPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 20px rgba(0,201,167,0.3), 0 0 40px rgba(0,201,167,0.1); }
  50% { box-shadow: 0 0 30px rgba(0,201,167,0.5), 0 0 60px rgba(0,201,167,0.2); }
}

@keyframes floatSubtle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes gradientShift {
  0%, 100% { opacity: 0.12; }
  50% { opacity: 0.18; }
}

/* ─── DECORATIVE BACKGROUND ─── */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  will-change: transform;
}

.bg-glow--teal {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, var(--teal), transparent 70%);
  top: 8%;
  right: -5%;
  opacity: 0.14;
  animation: gradientShift 8s ease-in-out infinite;
}

.bg-glow--blue {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle, #0D1B2A, transparent 70%);
  bottom: 3%;
  left: -8%;
  opacity: 0.08;
  animation: gradientShift 10s ease-in-out 2s infinite;
}

.bg-glow--accent {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(0, 168, 150, 0.5), transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.06;
  animation: gradientShift 6s ease-in-out 1s infinite;
}

/* ─── PAGE HEADER ─── */
.page-header {
  text-align: center;
  margin-bottom: 40px;
  animation: fadeUp 0.8s var(--ease-out-expo) both;
  z-index: 1;
}

.page-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.5rem, 5vw, 3.5rem);
  color: var(--card);
  letter-spacing: -1.5px;
  line-height: 1.1;
  background: linear-gradient(135deg, #0D1B2A 0%, #1a3a4f 50%, #0D1B2A 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-subtitle {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  color: var(--muted);
  margin-top: 8px;
  letter-spacing: 0.3px;
}

/* ─── MAIN CARD ─── */
.card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: var(--radius-card);
  border: 1px solid var(--teal-glow);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  animation: fadeUp 0.8s var(--ease-out-expo) 0.15s both;
  z-index: 1;
  position: relative;
}

/* Card inner top glow */
.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(0, 201, 167, 0.4),
    transparent
  );
  z-index: 10;
}

/* ─── CARD HEADER ─── */
.card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  position: relative;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 16px rgba(0, 201, 167, 0.25);
  position: relative;
}

/* Avatar glow ring */
.avatar::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 201, 167, 0.2);
}

.avatar svg {
  width: 22px;
  height: 22px;
  fill: white;
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ai-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.3px;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--teal);
  animation: statusPulse 2s ease-in-out infinite;
  box-shadow: 0 0 6px rgba(0, 201, 167, 0.5);
}

/* ─── CHAT AREA ─── */
.chat-area {
  height: 320px;
  overflow-y: auto;
  padding: 20px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Custom Scrollbar — WebKit */
.chat-area::-webkit-scrollbar {
  width: 4px;
}

.chat-area::-webkit-scrollbar-track {
  background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
  background: rgba(0, 201, 167, 0.3);
  border-radius: 4px;
}

/* Custom Scrollbar — Firefox */
.chat-area {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 201, 167, 0.3) transparent;
}

/* ─── MESSAGE BUBBLES ─── */
.message {
  display: flex;
  gap: 10px;
  max-width: 88%;
  animation: bubbleIn 0.4s var(--ease-out-expo) both;
}

.message--ai {
  align-self: flex-start;
}

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

.message__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.message__avatar svg {
  width: 14px;
  height: 14px;
  fill: white;
}

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

.message__bubble {
  padding: 12px 16px;
  font-size: 0.875rem;
  line-height: 1.55;
  font-weight: 400;
}

.message--ai .message__bubble {
  background: var(--bubble-ai);
  color: var(--text);
  border-radius: var(--radius-bubble-ai);
}

.message--user .message__bubble {
  background: linear-gradient(135deg, var(--bubble-user), var(--teal-dark));
  color: var(--card);
  border-radius: var(--radius-bubble-user);
  font-weight: 500;
}

/* Correction Tag */
.message__correction {
  background: rgba(0, 201, 167, 0.10);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.78rem;
  color: var(--teal);
  line-height: 1.45;
  border-left: 3px solid rgba(0, 201, 167, 0.4);
  backdrop-filter: blur(4px);
}

.message__correction strong {
  font-weight: 600;
  color: var(--teal);
}

/* ─── TYPING INDICATOR ─── */
.typing-indicator {
  display: none;
  align-self: flex-start;
  gap: 10px;
  max-width: 88%;
  animation: bubbleIn 0.3s var(--ease-out-expo) both;
}

.typing-indicator.visible {
  display: flex;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  background: var(--bubble-ai);
  border-radius: var(--radius-bubble-ai);
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

/* ─── MIC SECTION ─── */
.mic-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 24px 28px;
  gap: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  position: relative;
}

/* Section gradient glow */
.mic-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(0, 201, 167, 0.15),
    transparent
  );
}

/* Waveform Visualizer */
.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 32px;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.waveform.active {
  opacity: 1;
}

.waveform__bar {
  width: 3px;
  height: 100%;
  background: linear-gradient(to top, var(--teal-dark), var(--teal));
  border-radius: 3px;
  animation: wave 1.2s ease-in-out infinite;
  transform: scaleY(0.3);
}

.waveform__bar:nth-child(1)  { animation-delay: 0.00s; height: 16px; }
.waveform__bar:nth-child(2)  { animation-delay: 0.08s; height: 22px; }
.waveform__bar:nth-child(3)  { animation-delay: 0.16s; height: 28px; }
.waveform__bar:nth-child(4)  { animation-delay: 0.24s; height: 18px; }
.waveform__bar:nth-child(5)  { animation-delay: 0.32s; height: 32px; }
.waveform__bar:nth-child(6)  { animation-delay: 0.40s; height: 24px; }
.waveform__bar:nth-child(7)  { animation-delay: 0.48s; height: 30px; }
.waveform__bar:nth-child(8)  { animation-delay: 0.56s; height: 20px; }
.waveform__bar:nth-child(9)  { animation-delay: 0.64s; height: 26px; }
.waveform__bar:nth-child(10) { animation-delay: 0.72s; height: 32px; }
.waveform__bar:nth-child(11) { animation-delay: 0.80s; height: 22px; }
.waveform__bar:nth-child(12) { animation-delay: 0.88s; height: 28px; }
.waveform__bar:nth-child(13) { animation-delay: 0.96s; height: 18px; }

/* Mic Wrapper */
.mic-wrapper {
  width: 80px;
  height: 80px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Pulse Rings */
.pulse-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--teal);
  opacity: 0;
  pointer-events: none;
}

.mic-wrapper.recording .pulse-ring {
  animation: pulseRing 2s var(--ease-out-expo) infinite;
}

.mic-wrapper.recording .pulse-ring:nth-child(1) {
  animation-delay: 0s;
  border-color: var(--teal);
}

.mic-wrapper.recording .pulse-ring:nth-child(2) {
  animation-delay: 0.5s;
  border-color: rgba(0, 201, 167, 0.6);
}

.mic-wrapper.recording .pulse-ring:nth-child(3) {
  animation-delay: 1s;
  border-color: rgba(0, 201, 167, 0.3);
}

/* Mic Button */
.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
  transition: all 0.35s var(--ease-out-expo);
  box-shadow:
    0 8px 24px rgba(0, 201, 167, 0.35),
    0 0 0 0 rgba(0, 201, 167, 0);
  outline: none;
}

.mic-btn:hover {
  transform: scale(1.06);
  box-shadow:
    0 12px 32px rgba(0, 201, 167, 0.45),
    0 0 20px rgba(0, 201, 167, 0.15);
}

.mic-btn:active {
  transform: scale(0.97);
}

.mic-btn.recording {
  background: linear-gradient(135deg, var(--danger), #e55555);
  box-shadow:
    0 8px 24px rgba(255, 107, 107, 0.35),
    0 0 0 0 rgba(255, 107, 107, 0);
  animation: micPulse 1.5s ease-in-out infinite;
}

.mic-btn svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: transform 0.3s ease;
}

.mic-btn:hover svg {
  transform: scale(1.08);
}

/* Mic Label */
.mic-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.3px;
  transition: color 0.3s ease;
}

.mic-label.recording {
  color: var(--danger);
}

/* ─── FOOTER ─── */
.page-footer {
  margin-top: 32px;
  text-align: center;
  z-index: 1;
  animation: fadeUp 0.8s var(--ease-out-expo) 0.3s both;
}

.page-footer p {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 400;
  opacity: 0.6;
  letter-spacing: 0.2px;
}

/* ─── ACCESSIBILITY: Focus Visible ─── */
.mic-btn:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 4px;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 480px) {
  body {
    padding: 24px 16px;
    justify-content: flex-start;
    padding-top: 48px;
  }

  .card {
    max-width: 100%;
    border-radius: 22px;
  }

  .page-header {
    margin-bottom: 28px;
  }

  .chat-area {
    height: 280px;
    padding: 16px 16px 10px;
  }

  .mic-section {
    padding: 16px 20px 24px;
  }

  .card-header {
    padding: 18px 20px 14px;
  }

  .bg-glow--teal {
    width: 250px;
    height: 250px;
  }

  .bg-glow--blue {
    width: 300px;
    height: 300px;
  }
}

@media (max-width: 360px) {
  .chat-area {
    height: 240px;
  }
}

/* ─── REDUCED MOTION ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
