:root {
  --bg: #0f0f14;
  --surface: #1a1a24;
  --surface-hover: #252535;
  --primary: #7c3aed;
  --primary-light: #a78bfa;
  --text: #e4e4eb;
  --text-muted: #8888a0;
  --danger: #ef4444;
  --success: #22c55e;
  --border: #2a2a3a;
  --radius: 10px;
  --radius-sm: 6px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 600px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}
html { -webkit-tap-highlight-color: transparent; }

header {
  padding: 16px 20px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
header h1 {
  font-size: 24px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
#stats {
  font-size: 13px;
  color: var(--text-muted);
}

nav {
  display: flex;
  padding: 0 12px;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  overflow-x: auto;
}
nav button {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
nav button.active {
  color: var(--primary-light);
  border-bottom-color: var(--primary);
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 16px 16px;
}
main > .tab { display: none; flex: 1; min-height: 0; }
main > .tab.active { display: block; }
#tab-phrasebook.active, #tab-flashcards.active, #tab-quiz.active {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Categories grid */
#categories {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.cat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  text-transform: capitalize;
  transition: all 0.15s;
}
.cat-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Phrase cards */
.phrase-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.15s;
}
.phrase-card:hover { background: var(--surface-hover); }
.phrase-card .hinglish {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}
.phrase-card .english {
  font-size: 13px;
  color: var(--text-muted);
}
.phrase-card .play-btn {
  width: 36px; height: 36px;
  background: var(--primary);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.phrase-card .play-btn:active { transform: scale(0.9); }

/* Flashcards */
#flashcard-view {
  text-align: center;
  padding: 20px 0;
}
.flashcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  margin-bottom: 16px;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.flashcard .front { font-size: 24px; font-weight: 700; }
.flashcard .back { font-size: 18px; color: var(--primary-light); margin-top: 10px; }
.flashcard .hint { font-size: 13px; color: var(--text-muted); margin-top: 20px; }
.flashcard.revealed .front { font-size: 18px; color: var(--text-muted); }
.flashcard.revealed .back { display: block; }
.flashcard .back { display: none; }

.rating-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.rating-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.rating-btn:hover { background: var(--surface-hover); }
.rating-btn:nth-child(1) { color: var(--danger); }
.rating-btn:nth-child(2) { color: #f59e0b; }
.rating-btn:nth-child(3) { color: #3b82f6; }
.rating-btn:nth-child(4) { color: var(--success); }

/* Quiz */
#start-quiz {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 14px 40px;
  border-radius: var(--radius);
  font-size: 16px;
  cursor: pointer;
  margin: 40px auto;
  display: block;
}
.quiz-q {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  padding: 24px 0 16px;
}
.quiz-choices { display: flex; flex-direction: column; gap: 8px; }
.quiz-choice {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.quiz-choice:hover { background: var(--surface-hover); }
.quiz-choice.correct { background: #064e3b; border-color: var(--success); }
.quiz-choice.wrong { background: #4c0519; border-color: var(--danger); }
.quiz-score { text-align: center; font-size: 18px; margin: 12px 0; }
.quiz-next {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 30px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  margin: 16px auto;
  display: block;
}

/* Tutor Chat */
#tab-tutor.active {
  display: flex !important;
  flex-direction: column;
  min-height: 0;
}
#chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}
.chat-msg {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  max-width: 85%;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg.user {
  background: var(--primary);
  color: #fff;
  margin-left: auto;
}
.chat-msg.tutor {
  background: var(--surface);
  border: 1px solid var(--border);
}
.chat-msg.error { background: #4c0519; color: #fca5a5; margin: 0 auto; }
#chat-input {
  display: flex;
  gap: 8px;
  padding: 8px 0 calc(8px + var(--safe-bottom));
  background: var(--bg);
}
#chat-input input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
}
#chat-input input:focus { border-color: var(--primary); }
#chat-input button {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state h2 { font-size: 20px; margin-bottom: 8px; }
.hidden { display: none !important; }

/* Audio loading */
.audio-loading { opacity: 0.6; pointer-events: none; }

@media (max-width: 400px) {
  nav button { padding: 8px 10px; font-size: 12px; }
  .flashcard { padding: 30px 16px; min-height: 140px; }
  .flashcard .front { font-size: 20px; }
}
