/* ===== Anki AI Review — Global Styles ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #4a3aff;
  --primary-dark: #3a2ae0;
  --primary-light: #f0f0ff;
  --primary-glow: rgba(74,58,255,0.3);
  --bg: #f5f6f8;
  --card-bg: #fff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --again: #dc2626;
  --again-bg: #fee2e2;
  --hard: #d97706;
  --hard-bg: #fef3c7;
  --good: #059669;
  --good-bg: #d1fae5;
  --easy: #2563eb;
  --easy-bg: #dbeafe;
  --danger: #ef4444;
  --success: #10b981;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ===== Top Nav ===== */
.topbar {
  background: #fff;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.topbar .logo { font-size: 20px; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 8px; }
.topbar .logo .icon { font-size: 24px; }
.topbar nav { display: flex; gap: 24px; align-items: center; }
.topbar nav a { color: var(--text-muted); text-decoration: none; font-size: 14px; font-weight: 500; }
.topbar nav a.active { color: var(--primary); }

/* ===== Container ===== */
.container { max-width: 800px; margin: 40px auto; padding: 0 24px; }
.container h1 { font-size: 28px; margin-bottom: 6px; }
.container .sub { color: var(--text-muted); font-size: 15px; margin-bottom: 32px; }

/* ===== Stats Bar ===== */
.stats-bar { display: flex; gap: 24px; margin-bottom: 32px; }
.stat { background: #fff; border-radius: 12px; padding: 16px 20px; flex: 1; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.stat .num { font-size: 28px; font-weight: 700; }
.stat .label { font-size: 12px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }
.stat.due .num { color: var(--primary); }
.stat.new .num { color: var(--success); }
.stat.done .num { color: var(--text-muted); }

/* ===== Deck List ===== */
.deck-list { display: flex; flex-direction: column; gap: 14px; }
.deck-card {
  background: #fff;
  border-radius: 14px;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid transparent;
  text-decoration: none;
  color: var(--text);
}
.deck-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(74,58,255,0.12); }
.deck-info { display: flex; flex-direction: column; gap: 4px; }
.deck-name { font-size: 17px; font-weight: 600; }
.deck-meta { display: flex; gap: 16px; font-size: 13px; color: var(--text-light); }
.deck-meta .due { color: var(--primary); font-weight: 600; }
.deck-meta .new { color: var(--success); font-weight: 600; }
.deck-meta .learn { color: var(--hard); font-weight: 600; }
.arrow { font-size: 20px; color: #d1d5db; transition: all 0.2s; }
.deck-card:hover .arrow { color: var(--primary); transform: translateX(4px); }
.loading { text-align: center; padding: 40px; color: var(--text-light); }

/* ===== Review Layout ===== */
.app { display: flex; height: 100vh; overflow: hidden; }
.main-area { flex: 1; display: flex; flex-direction: column; padding: 20px; position: relative; overflow: hidden; }
.chat-panel { width: 320px; background: #fff; border-left: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }

/* ===== Review Header ===== */
.review-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-shrink: 0; }
.back-link { color: var(--text-muted); text-decoration: none; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.back-link:hover { color: var(--primary); }
.progress-info { font-size: 14px; color: var(--text-muted); }
.progress-info b { color: var(--text); }

/* ===== Toggles ===== */
.toggles { display: flex; gap: 12px; align-items: center; }
.toggle-group {
  display: flex; align-items: center; gap: 8px;
  background: #fff; padding: 6px 14px; border-radius: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  font-size: 13px; color: #4b5563;
}
.toggle {
  width: 36px; height: 20px; background: #d1d5db;
  border-radius: 10px; position: relative; cursor: pointer;
  transition: background 0.2s; flex-shrink: 0;
}
.toggle.on { background: var(--primary); }
.toggle .knob {
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  position: absolute; top: 2px; left: 2px;
  transition: transform 0.2s;
}
.toggle.on .knob { transform: translateX(16px); }

/* ===== Progress Bar ===== */
.progress-bar { width: 100%; height: 4px; background: var(--border); border-radius: 2px; margin-bottom: 24px; overflow: hidden; flex-shrink: 0; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), #7c5fff); border-radius: 2px; transition: width 0.4s ease; }

/* ===== Card Flip ===== */
.card-container {
  flex: 1; display: flex; align-items: center; justify-content: center;
  perspective: 1200px; min-height: 0;
}
.card-flipper {
  width: 100%; max-width: 620px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}
.card-flipper.flipped { transform: rotateY(180deg); }
.card {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.08);
  padding: 48px 40px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card-front { }
.card-back {
  position: absolute;
  top: 0; left: 0; width: 100%;
  transform: rotateY(180deg);
  text-align: left;
  align-items: stretch;
  justify-content: flex-start;
}
.card-tag { position: absolute; top: 16px; left: 20px; font-size: 11px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; }
.card-chapter { position: absolute; top: 16px; right: 20px; font-size: 11px; color: var(--primary); font-weight: 600; background: var(--primary-light); padding: 3px 10px; border-radius: 10px; }
.card-question { font-size: 24px; font-weight: 600; line-height: 1.5; color: var(--text); max-width: 480px; }
.card-hint { margin-top: 24px; font-size: 13px; color: var(--text-light); }
.card-q-label { font-size: 13px; color: var(--text-light); margin-bottom: 6px; margin-top: 20px; }
.card-question-text { font-size: 16px; font-weight: 500; color: var(--text-muted); margin-bottom: 20px; line-height: 1.5; }
.card-a-label { font-size: 13px; color: var(--primary); font-weight: 600; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.card-answer { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.5; margin-bottom: 24px; }
.transpose-badge { position: absolute; bottom: 16px; right: 20px; font-size: 11px; color: var(--hard); display: flex; align-items: center; gap: 4px; }

/* Card entrance animation */
.card-flipper.entering {
  animation: cardEnter 0.4s ease-out;
}
@keyframes cardEnter {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.card-flipper.entering.flipped {
  animation: cardEnterFlipped 0.4s ease-out;
}
@keyframes cardEnterFlipped {
  from { opacity: 0; transform: rotateY(180deg) translateY(20px); }
  to { opacity: 1; transform: rotateY(180deg) translateY(0); }
}

/* Card exit animation */
.card-flipper.exiting {
  animation: cardExit 0.3s ease-in forwards;
}
@keyframes cardExit {
  to { opacity: 0; transform: translateX(-30px); }
}

/* ===== Coaching Banner ===== */
.coaching-banner {
  background: linear-gradient(135deg, var(--primary-light), #e8e8ff);
  border: 1px solid #d0d0ff;
  border-radius: 12px;
  padding: 16px 20px;
  margin-top: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-shrink: 0;
  animation: slideUp 0.3s ease-out;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.coaching-banner .icon { font-size: 20px; flex-shrink: 0; }
.coaching-banner .text { font-size: 14px; line-height: 1.5; color: var(--primary); }
.coaching-banner .text b { color: var(--primary-dark); }

/* ===== Grade Buttons ===== */
.grade-row { display: flex; gap: 12px; justify-content: center; margin-top: 20px; flex-shrink: 0; }
.grade-btn {
  padding: 16px 28px; border-radius: 14px; border: none;
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: all 0.15s; display: flex; flex-direction: column;
  align-items: center; gap: 4px; min-width: 110px;
}
.grade-btn .interval { font-size: 11px; font-weight: 400; opacity: 0.8; }
.grade-again { background: var(--again-bg); color: var(--again); }
.grade-again:hover { background: #fecaca; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(220,38,38,0.2); }
.grade-hard { background: var(--hard-bg); color: var(--hard); }
.grade-hard:hover { background: #fde68a; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(217,119,6,0.2); }
.grade-good { background: var(--good-bg); color: var(--good); }
.grade-good:hover { background: #a7f3d0; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(5,150,105,0.2); }
.grade-easy { background: var(--easy-bg); color: var(--easy); }
.grade-easy:hover { background: #bfdbfe; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(37,99,235,0.2); }

/* Grade button press animation */
.grade-btn.pressed { animation: gradePress 0.5s ease-out; }
@keyframes gradePress {
  0% { transform: scale(1); }
  30% { transform: scale(1.15); }
  60% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* ===== Buttons ===== */
.controls { display: flex; gap: 12px; justify-content: center; margin-top: 20px; flex-shrink: 0; }
.btn { padding: 14px 32px; border-radius: 12px; border: none; font-size: 15px; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.btn-flip { background: var(--primary); color: #fff; box-shadow: 0 4px 14px var(--primary-glow); }
.btn-flip:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: #f3f4f6; color: #4b5563; }
.btn-secondary:hover { background: var(--border); }

/* ===== Chat Panel ===== */
.chat-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; flex-shrink: 0; }
.chat-header .ai-dot { width: 8px; height: 8px; background: var(--success); border-radius: 50%; }
.chat-messages { flex: 1; padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.chat-msg {
  max-width: 85%; padding: 10px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.5;
  animation: msgEnter 0.2s ease-out;
}
@keyframes msgEnter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.chat-msg.ai { background: var(--primary-light); color: var(--primary); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg.user { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg.system { background: #f3f4f6; color: var(--text-muted); align-self: center; font-size: 12px; text-align: center; max-width: 100%; }
.chat-input-area { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-shrink: 0; }
.chat-input {
  flex: 1; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; font-size: 14px; outline: none; font-family: inherit;
}
.chat-input:focus { border-color: var(--primary); }
.chat-send { background: var(--primary); border: none; border-radius: 10px; padding: 10px 16px; color: #fff; cursor: pointer; font-size: 14px; font-weight: 500; }
.chat-send:hover { background: var(--primary-dark); }

/* Typing indicator */
.typing { display: flex; gap: 4px; padding: 8px 14px; background: var(--primary-light); border-radius: 14px; align-self: flex-start; border-bottom-left-radius: 4px; }
.typing span { width: 6px; height: 6px; background: var(--primary); border-radius: 50%; animation: bounce 1s infinite; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

/* ===== Voice FAB ===== */
.voice-fab {
  position: absolute; bottom: 80px; right: 20px;
  width: 48px; height: 48px; background: var(--primary);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px; cursor: pointer;
  box-shadow: 0 4px 16px var(--primary-glow); border: none;
  z-index: 10;
}
.voice-fab:hover { transform: scale(1.1); }

/* ===== Grade Overlay ===== */
.grade-overlay {
  position: fixed; inset: 0; background: rgba(15,17,23,0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.grade-overlay.fade-out { animation: fadeOut 0.3s ease-out forwards; }
@keyframes fadeOut { to { opacity: 0; } }
.grade-result { text-align: center; padding: 40px; }
.grade-result .emoji { font-size: 64px; margin-bottom: 12px; animation: emojiBounce 0.5s ease-out; }
@keyframes emojiBounce { 0% { transform: scale(0); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }
.grade-result .title { font-size: 28px; font-weight: 700; margin-bottom: 8px; color: #fff; }
.grade-result .detail { font-size: 16px; color: #9ca3af; max-width: 400px; line-height: 1.5; }
.grade-result.again .title { color: var(--again); }
.grade-result.hard .title { color: var(--hard); }
.grade-result.good .title { color: var(--good); }
.grade-result.easy .title { color: var(--easy); }

/* ===== Voice Mode Overlay ===== */
.voice-overlay {
  position: fixed; inset: 0; background: #0f1117; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.3s ease-out;
}
.voice-app {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; width: 100%; max-width: 700px; padding: 40px; gap: 28px;
}
.voice-card {
  width: 100%; max-width: 560px; background: #1a1d27; border-radius: 20px;
  border: 1px solid #2d303d; padding: 40px; min-height: 200px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; position: relative; box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.voice-card .card-tag { color: #6b7280; }
.voice-text { font-size: 22px; font-weight: 600; line-height: 1.5; color: #fff; max-width: 440px; }
.voice-subtext { margin-top: 16px; font-size: 14px; color: #6b7280; }

/* AI speaking indicator */
.speaking-indicator { display: flex; align-items: center; gap: 10px; color: #7c5fff; font-size: 14px; }
.speaking-bars { display: flex; gap: 3px; align-items: center; }
.speaking-bars span { width: 3px; background: #7c5fff; border-radius: 2px; animation: pulse 0.8s infinite ease-in-out; }
.speaking-bars span:nth-child(1) { height: 12px; animation-delay: 0s; }
.speaking-bars span:nth-child(2) { height: 20px; animation-delay: 0.1s; }
.speaking-bars span:nth-child(3) { height: 16px; animation-delay: 0.2s; }
.speaking-bars span:nth-child(4) { height: 24px; animation-delay: 0.3s; }
.speaking-bars span:nth-child(5) { height: 14px; animation-delay: 0.4s; }
@keyframes pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* Mic button */
.mic-container { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.mic-button {
  width: 80px; height: 80px; border-radius: 50%; background: var(--primary);
  border: 4px solid rgba(74,58,255,0.3); display: flex; align-items: center; justify-content: center;
  font-size: 32px; cursor: pointer; transition: all 0.2s; position: relative;
}
.mic-button.listening { background: var(--danger); border-color: rgba(239,68,68,0.3); animation: micPulse 1.5s infinite; }
@keyframes micPulse { 0% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); } 100% { box-shadow: 0 0 0 24px rgba(239,68,68,0); } }
.mic-label { font-size: 13px; color: #6b7280; }
.mic-label.listening { color: var(--danger); font-weight: 600; }

/* Transcript */
.transcript {
  width: 100%; max-width: 560px; background: #1a1d27; border-radius: 14px;
  border: 1px solid #2d303d; padding: 16px 20px; min-height: 60px;
}
.transcript .label { font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.transcript .text { font-size: 15px; color: #fff; }

/* Voice command hints */
.command-hints { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.cmd-hint { background: #1a1d27; border: 1px solid #2d303d; border-radius: 8px; padding: 6px 12px; font-size: 12px; color: #6b7280; }
.cmd-hint b { color: #7c5fff; }
.btn-exit-voice {
  background: transparent; border: 1px solid #ef4444; color: #ef4444;
  padding: 8px 20px; border-radius: 8px; cursor: pointer; font-size: 13px;
}

/* ===== Settings Page ===== */
.section { background: #fff; border-radius: 14px; padding: 28px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.section-title { font-size: 17px; font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.section-desc { font-size: 13px; color: var(--text-light); margin-bottom: 20px; }
.section-divider { height: 1px; background: #f0f0f0; margin: 24px 0; }
.field-group { margin-bottom: 16px; }
.field-label { font-size: 13px; font-weight: 600; color: #4b5563; margin-bottom: 6px; display: block; }
.field-hint { font-size: 12px; color: var(--text-light); margin-top: 4px; }
input, select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; font-size: 14px; outline: none; transition: border 0.2s;
  font-family: inherit; background: #fff;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,58,255,0.1); }
input[type="password"] { font-family: monospace; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; }
.toggle-row .label { font-size: 14px; font-weight: 500; }
.toggle-row .desc { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.provider-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.provider-card {
  border: 2px solid var(--border); border-radius: 10px; padding: 12px 8px;
  text-align: center; cursor: pointer; transition: all 0.2s;
}
.provider-card.selected { border-color: var(--primary); background: var(--primary-light); }
.provider-card .name { font-size: 12px; font-weight: 600; margin-top: 4px; }
.provider-card .icon { font-size: 20px; }
.btn-row { display: flex; gap: 12px; margin-top: 8px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #f3f4f6; color: #4b5563; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 10px; }
.status-badge.ok { background: var(--good-bg); color: var(--good); }
.status-badge.warn { background: var(--hard-bg); color: var(--hard); }
.status-badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.status-badge.ok .dot { background: var(--good); }
.status-badge.warn .dot { background: var(--hard); }
.anki-status { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; background: #f8f9ff; border-radius: 10px; margin-bottom: 16px; border: 1px solid #e0e7ff; }
.anki-status .info { display: flex; flex-direction: column; gap: 2px; }
.anki-status .url { font-size: 14px; font-weight: 500; }
.anki-status .desc { font-size: 12px; color: var(--text-light); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 12px 24px;
  border-radius: 10px; font-size: 14px; z-index: 300;
  animation: toastIn 0.3s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast.success { background: var(--good); }
.toast.error { background: var(--danger); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .chat-panel { display: none; }
  .main-area { padding: 12px; }
  .card { padding: 32px 20px; }
  .card-question { font-size: 20px; }
  .grade-btn { padding: 14px 16px; min-width: 70px; font-size: 13px; }
  .toggles { flex-direction: column; gap: 6px; }
}
