/* Reset & Global Tokens */
:root {
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  --card-bg: rgba(30, 41, 59, 0.85);
  --card-border: rgba(255, 255, 255, 0.1);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --accent: #38bdf8;
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
  --radius: 16px;
}

body.light-theme {
  --bg-gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --card-border: rgba(0, 0, 0, 0.08);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
}

body {
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* APP HEADER */
.app-header {
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 12px 24px;
}

.header-container {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-icon {
  font-size: 2rem;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.brand-info h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-info .sub-title {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* NAVIGATION TABS */
.nav-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.nav-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.icon-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
}

/* FILTER SECTION */
.filter-section {
  margin-bottom: 24px;
}

.filter-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.category-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chip:hover, .chip.active {
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.3);
}

.search-box {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 6px 14px;
  width: 260px;
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  margin-left: 8px;
  width: 100%;
  font-size: 0.85rem;
}

/* TAB PANES */
.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* FLASHCARD SECTION */
.flashcard-wrapper {
  max-width: 700px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.progress-bar-container {
  width: 100%;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.progress-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6366f1, #10b981);
  transition: width 0.3s ease;
}

/* 3D FLIP CARD */
.card-container {
  perspective: 1000px;
  width: 100%;
  height: 380px;
  cursor: pointer;
}

.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card-back {
  transform: rotateY(180deg);
  background: rgba(15, 23, 42, 0.95);
  border-color: rgba(99, 102, 241, 0.3);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.badge {
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.success {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.flip-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--accent);
}

.card-question {
  font-size: 1rem;
  line-height: 1.6;
}

.card-answer {
  font-size: 0.95rem;
  line-height: 1.7;
  white-space: pre-line;
}

.ref-tag {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.speak-btn {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.speak-btn:hover {
  background: var(--accent);
  color: #0f172a;
}

/* CARD CONTROLS */
.card-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.ctrl-btn {
  border: none;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-btn.primary { background: var(--primary); color: #fff; }
.ctrl-btn.secondary { background: rgba(255, 255, 255, 0.1); color: var(--text-main); }
.ctrl-btn.success { background: var(--success); color: #fff; }
.ctrl-btn.danger { background: var(--danger); color: #fff; }

.ctrl-btn:hover { transform: translateY(-2px); opacity: 0.9; }

/* AUDIO PLAYER SECTION */
.audio-player-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
}

.audio-playlist {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  height: calc(100vh - 220px);
  overflow-y: auto;
}

.audio-playlist h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--accent);
}

.playlist-item {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--card-border);
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.playlist-item:hover, .playlist-item.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.15);
}

.playlist-item .item-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.playlist-item .item-source {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* AUDIO PLAYER CARD */
.audio-player-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.now-playing-header {
  display: flex;
  align-items: center;
  gap: 20px;
}

.disc-icon {
  font-size: 3rem;
  background: linear-gradient(135deg, #1e1b4b, #312e81);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--primary);
}

.disc-icon.spinning {
  animation: spin 8s linear infinite;
}

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

.now-playing-info h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 4px 0;
}

.status-badge {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}

.speech-controls {
  display: flex;
  gap: 24px;
  background: rgba(0, 0, 0, 0.2);
  padding: 14px;
  border-radius: 12px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.speed-options {
  display: flex;
  gap: 4px;
}

.speed-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}

.speed-btn.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.voice-select {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
}

.player-main-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.player-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-btn.play-main {
  width: 64px;
  height: 64px;
  background: var(--primary);
  font-size: 1.6rem;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.5);
}

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

.article-text-container h4 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.article-content {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px;
  font-size: 0.95rem;
  line-height: 1.8;
  white-space: pre-line;
  max-height: 300px;
  overflow-y: auto;
}

/* QUIZ SECTION */
.quiz-wrapper {
  max-width: 750px;
  margin: 0 auto;
}

.quiz-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.quiz-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.quiz-question {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.6;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.option-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
}

.option-btn.correct {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--success);
  color: #34d399;
  font-weight: 600;
}

.option-btn.wrong {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--danger);
  color: #f87171;
}

.quiz-explanation {
  background: rgba(15, 23, 42, 0.8);
  border-left: 4px solid var(--primary);
  padding: 16px;
  border-radius: 0 8px 8px 0;

}

.quiz-explanation.hidden { display: none; }

.expl-header { font-weight: 700; margin-bottom: 6px; }

/* BROWSER GRID */
.articles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.article-card-item {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--card-border);
  background: rgba(15, 23, 42, 0.9);
}

@media (max-width: 768px) {
  .audio-player-layout { grid-template-columns: 1fr; }
  .header-container { flex-direction: column; }
}
