@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&display=swap');

/* ===================== DESIGN TOKENS ===================== */
:root {
  --bg: #0a0f1e;
  --surface: rgba(22, 32, 58, 0.85);
  --surface-hover: rgba(30, 45, 80, 0.9);
  --border: rgba(255,255,255,0.08);
  --primary: #3b82f6;
  --primary-glow: rgba(59, 130, 246, 0.4);
  --accent: #10b981;
  --accent-glow: rgba(16, 185, 129, 0.4);
  --danger: #ef4444;
  --text: #f0f4ff;
  --text-muted: #6b7fa3;
  --radius: 14px;
  --radius-sm: 8px;
  --header-h: 64px;
}

/* ===================== RESET ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background-image: radial-gradient(ellipse at 10% 0%, rgba(59,130,246,0.08) 0%, transparent 60%),
                    radial-gradient(ellipse at 90% 100%, rgba(16,185,129,0.06) 0%, transparent 60%);
}

/* ===================== HEADER ===================== */
header {
  height: var(--header-h);
  padding: 0 0.75rem;
  background: rgba(10, 15, 30, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  z-index: 100;
  overflow: hidden;
}

.header-left { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.logo { font-weight: 800; font-size: 0.9rem; letter-spacing: -0.02em; white-space: nowrap; color: var(--text); }

.header-center {
  display: flex; gap: 5px; align-items: center; justify-content: center;
  flex: 1; min-width: 0; overflow: hidden;
}
.stat-chip {
  display: flex; align-items: center; gap: 3px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 700; color: #94a3b8;
  white-space: nowrap; transition: 0.2s; flex-shrink: 1; min-width: 0;
}
.stat-chip span { color: var(--text); font-variant-numeric: tabular-nums; }
/* Streak chip: red/fire themed */
.streak-chip { border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.1); color: #fca5a5; }
.streak-chip span { color: #f87171; }

.header-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

/* ===================== ICON BUTTONS ===================== */
.icon-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.2s; flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); border-color: rgba(255,255,255,0.15); }
.icon-btn.accent-btn { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.3); color: var(--accent); }
.icon-btn.accent-btn:hover { background: rgba(16,185,129,0.25); border-color: var(--accent); }
.icon-btn.danger-btn { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.25); color: var(--danger); }
.icon-btn.danger-btn:hover { background: rgba(239,68,68,0.22); border-color: var(--danger); }
.icon-btn.hidden { display: none; }

/* ===================== MODEL BADGE ===================== */
.badge {
  font-size: 0.7rem; padding: 3px 8px; border-radius: 20px; font-weight: 600; white-space: nowrap;
}
.badge.groq { background: rgba(234,179,8,0.2); color: #fbbf24; border: 1px solid rgba(234,179,8,0.3); }
.badge.gemini { background: rgba(168,85,247,0.2); color: #c084fc; border: 1px solid rgba(168,85,247,0.3); }
.badge.error { background: rgba(239,68,68,0.2); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }

/* ===================== MODE SELECTOR ===================== */
.mode-selector {
  display: flex; gap: 0.35rem; padding: 0.6rem 1rem;
  background: rgba(10, 15, 30, 0.5);
  overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.mode-selector::-webkit-scrollbar { display: none; }
.mode-btn {
  background: transparent; border: 1px solid transparent;
  color: var(--text-muted); padding: 5px 12px; border-radius: 8px;
  cursor: pointer; transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1); white-space: nowrap; font-weight: 450;
  font-size: 0.82rem; letter-spacing: -0.01em;
}
.mode-btn:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.mode-btn.active {
  background: rgba(59,130,246,0.14); border-color: rgba(96,165,250,0.3); color: #93c5fd;
  box-shadow: 0 1px 6px rgba(0,0,0,0.25); font-weight: 500;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  position: fixed; top: 0; left: -300px; width: 300px; height: 100dvh;
  background: rgba(10, 15, 30, 0.97); backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  z-index: 2000; transition: left 0.3s ease;
  display: flex; flex-direction: column;
}
.sidebar.open { left: 0; box-shadow: 8px 0 40px rgba(0,0,0,0.6); }
.sidebar-header { padding: 1.25rem 1.25rem 1rem; border-bottom: 1px solid var(--border); position: relative; }
.sidebar-content { padding: 1rem; flex: 1; overflow-y: auto; }
.sidebar-content h3 { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.75rem; }
.sidebar-btn { width: 100%; padding: 10px; margin-bottom: 8px; border-radius: var(--radius-sm); border: none; cursor: pointer; font-weight: 700; font-size: 0.9rem; transition: 0.2s; }
.sidebar-btn.primary { background: var(--primary); color: white; }
.sidebar-btn.primary:hover { background: #2563eb; }
.sidebar-btn.secondary { background: rgba(255,255,255,0.07); color: white; border: 1px solid var(--border); }
.sidebar-btn.secondary:hover { background: rgba(255,255,255,0.12); }
.sidebar-btn.secondary.active { background: rgba(16,185,129,0.2); border-color: var(--accent); color: var(--accent); }

/* ===================== CHAT AREA ===================== */
#chat-area {
  flex: 1; padding: 1rem; overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.75rem;
}
#chat-area::-webkit-scrollbar { width: 4px; }
#chat-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

.msg {
  max-width: 85%; padding: 0.85rem 1.1rem; border-radius: 18px;
  line-height: 1.55; font-size: 0.95rem;
  animation: fadeIn 0.25s ease;
}
.msg.user {
  align-self: flex-end; background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-bottom-right-radius: 4px; box-shadow: 0 4px 15px rgba(59,130,246,0.25);
}
.msg.bot {
  align-self: flex-start; background: var(--surface);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.msg.bot.bot-speaking-anim {
  border-color: var(--primary); box-shadow: 0 0 16px rgba(59,130,246,0.3);
  animation: aipulse 1.5s infinite alternate;
}

/* ===================== CONTROLS ===================== */
.controls {
  padding: 0.75rem 1rem 2rem;
  background: rgba(10,15,30,0.95);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.5rem;
  flex-shrink: 0;
}
.controls-top {
  display: flex; justify-content: flex-end;
}
.toggle-container {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.75rem; color: var(--text-muted); cursor: pointer;
}
.input-wrapper {
  display: flex; gap: 8px; align-items: center;
}
#chat-input {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 0.85rem 1.2rem; border-radius: 25px;
  font-size: 0.95rem; outline: none; transition: 0.3s;
  font-family: 'Inter', sans-serif;
}
#chat-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
#chat-input::placeholder { color: var(--text-muted); }

/* Action circles */
.action-circle {
  width: 48px; height: 48px; border-radius: 50%;
  border: none; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; color: white;
}
.action-circle.hidden { display: none; }
.send-btn { background: var(--primary); box-shadow: 0 4px 15px rgba(59,130,246,0.3); }
.send-btn:hover { background: #2563eb; transform: scale(1.05); }
.record-btn { background: var(--accent); box-shadow: 0 4px 15px var(--accent-glow); }
.record-btn:hover { transform: scale(1.05); }
.record-btn.recording {
  background: var(--danger); box-shadow: 0 0 0 0 rgba(239,68,68,0.7);
  animation: ripple 1.5s infinite;
}
.stop-btn { background: var(--danger); box-shadow: 0 4px 15px rgba(239,68,68,0.3); }

/* ===================== MUSIC PLAYER ===================== */
#yt-container { padding: 0 1rem 0; flex-shrink: 0; }
.yt-player-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: var(--radius);
  padding: 10px 14px; border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.yt-player-bar button { background: none; border: none; color: var(--text); font-size: 1.1rem; cursor: pointer; flex-shrink: 0; }
.yt-player-bar span { color: var(--text-muted); font-size: 0.78rem; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.yt-player-bar input[type=range] { flex: 1; accent-color: var(--primary); height: 4px; }

/* ===================== LYRICS TABS ===================== */
.lyrics-tabs-container { background: var(--surface); border-radius: var(--radius); overflow: hidden; margin: 8px 0; border: 1px solid var(--border); }
.lyrics-tab-nav { display: flex; background: rgba(10,15,30,0.7); border-bottom: 1px solid var(--border); }
.lyric-tab-btn { flex: 1; background: none; border: none; color: var(--text-muted); padding: 10px 5px; cursor: pointer; font-size: 0.82rem; font-weight: 700; transition: 0.25s; letter-spacing: 0.02em; }
.lyric-tab-btn:hover { color: var(--text); }
.lyric-tab-btn.active { color: var(--primary); border-bottom: 2px solid var(--primary); }
.lyric-tab-content { padding: 16px; font-size: 1rem; line-height: 2; max-height: 400px; overflow-y: auto; white-space: pre-line; }
.lyric-tab-content::-webkit-scrollbar { width: 4px; }
.lyric-tab-content::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }
.lyric-pair-en { color: #e2e8f0; font-weight: 600; }
.lyric-pair-tr { color: var(--text-muted); font-style: italic; }

/* ===================== KARAOKE VIEW ===================== */
.kara-content { padding: 0 !important; }
.kara-status {
  font-size: 0.75rem; color: var(--text-muted); padding: 8px 16px;
  border-bottom: 1px solid var(--border); background: rgba(0,0,0,0.2);
}
.kara-list {
  max-height: 400px; overflow-y: auto; padding: 8px 0;
  scroll-behavior: smooth;
}
.kara-list::-webkit-scrollbar { width: 3px; }
.kara-list::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }
.kara-line {
  padding: 10px 16px; transition: all 0.35s ease;
  border-left: 3px solid transparent; margin: 2px 0;
  opacity: 0.35; transform: scale(0.97);
  transform-origin: left center;
}
.kara-line .kara-en { display: block; font-size: 1rem; font-weight: 600; color: #e2e8f0; }
.kara-line .kara-tr { display: block; font-size: 0.85rem; color: var(--text-muted); font-style: italic; margin-top: 2px; }
.kara-line.kara-active {
  opacity: 1; transform: scale(1.01);
  border-left-color: var(--primary);
  background: linear-gradient(90deg, rgba(59,130,246,0.12) 0%, transparent 100%);
}
.kara-line.kara-active .kara-en { color: #ffffff; text-shadow: 0 0 12px rgba(59,130,246,0.6); }
.kara-line.kara-active .kara-tr { color: #93c5fd; }

/* ===================== VOCAB BUTTONS ===================== */
.vocab-inline-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.3);
  color: #93c5fd; padding: 2px 8px; border-radius: 6px; font-size: 0.8rem;
  cursor: pointer; margin: 2px; font-weight: 600; transition: 0.2s;
}
.vocab-inline-btn:hover { background: rgba(59,130,246,0.25); border-color: var(--primary); }
.vocab-inline-btn.added { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.4); color: #6ee7b7; }
.vocab-inline-btn.added:hover { background: rgba(16,185,129,0.25); }

/* ===================== FLASHCARD & SRS ===================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal.hidden { display: none; }
.modal-content {
  background: linear-gradient(145deg, #111827, #0f172a);
  width: 92%; max-width: 420px;
  border-radius: 20px; padding: 2rem;
  border: 1px solid var(--border); position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
  max-height: 90dvh; overflow-y: auto;
}
.modal-close-btn {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,0.07); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: 0.2s;
}
.modal-close-btn:hover { background: rgba(255,255,255,0.12); color: white; }
.modal-content h2 { font-size: 1.2rem; margin-bottom: 0.5rem; text-align: center; }

.fc-container { width: 100%; height: 260px; perspective: 1200px; margin: 1.5rem 0; }
.flashcard { width: 100%; height: 100%; position: relative; transition: transform 0.6s; transform-style: preserve-3d; cursor: pointer; }
.flashcard.flipped { transform: rotateY(180deg); }
.fc-front, .fc-back {
  position: absolute; width: 100%; height: 100%; border-radius: var(--radius);
  backface-visibility: hidden; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 1.5rem;
  border: 1px solid var(--border);
}
.fc-front { background: var(--surface); }
.fc-back { background: linear-gradient(135deg, #1e3a5f, #0f2744); transform: rotateY(180deg); }
.fc-nav { display: flex; justify-content: space-between; gap: 8px; }
.fc-nav button { flex: 1; background: var(--surface); color: white; border: 1px solid var(--border); padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 500; font-size: 0.82rem; }
.fc-nav.hidden { display: none; }

.srs-controls { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.srs-btn { border: none; padding: 8px 6px; border-radius: 6px; cursor: pointer; font-size: 0.78rem; font-weight: 500; color: white; flex: 1; transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1); min-width: 58px; }
.srs-btn.again { background: var(--danger); }
.srs-btn.hard { background: #f59e0b; }
.srs-btn.good { background: var(--accent); }
.srs-btn.easy { background: var(--primary); }
.srs-btn:hover { filter: brightness(1.15); transform: translateY(-1px); }

.confirm-btn {
  background: var(--accent); border: none; color: white;
  padding: 10px 28px; border-radius: var(--radius-full); font-size: 0.95rem;
  cursor: pointer; font-weight: 600; transition: 0.2s; font-family: 'Inter', sans-serif;
}
.confirm-btn:hover { background: #059669; }

/* ===================== SESSION LIST ===================== */
.session-list { list-style: none; }
.session-list li {
  padding: 10px 12px; background: rgba(0,0,0,0.3); margin-bottom: 6px;
  border-radius: var(--radius-sm); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  transition: 0.2s; font-size: 0.83rem; border: 1px solid transparent;
}
.session-list li:hover { background: rgba(255,255,255,0.06); }
.session-list li.active { border-color: var(--primary); background: rgba(59,130,246,0.1); }
.session-info { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.session-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-date { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }
.session-actions { display: flex; gap: 6px; flex-shrink: 0; }
.action-btn { background: none; border: none; font-size: 0.9rem; cursor: pointer; opacity: 0.4; }
.action-btn:hover { opacity: 1; }
.action-btn.delete:hover { color: var(--danger); }
.action-btn.edit:hover { color: var(--primary); }

/* ===================== STATS ===================== */
.histogram-container { padding: 8px 0; }
.close-btn { position: absolute; top: 15px; right: 20px; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); }

/* ===================== ANIMATIONS ===================== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes aipulse { 0% { box-shadow: 0 0 8px rgba(59,130,246,0.3); } 100% { box-shadow: 0 0 20px rgba(59,130,246,0.7); } }
@keyframes ripple {
  0% { box-shadow: 0 0 0 0 rgba(239,68,68,0.6); }
  70% { box-shadow: 0 0 0 14px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
