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

:root {
  --primary: #2d6a4f;
  --primary-light: #40916c;
  --primary-dark: #1b4332;
  --accent: #52b788;
  --bg: #f8f9fa;
  --card-bg: #ffffff;
  --text: #212529;
  --text-light: #6c757d;
  --border: #dee2e6;
  --success: #2d6a4f;
  --error: #dc3545;
  --warning: #fd7e14;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 2rem;
}

/* Header */
#app-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
  padding: 1.5rem 1rem;
  text-align: center;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.logo-img {
  width: 40px;
  height: 40px;
}

.logo {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}

.help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.6);
  color: white;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.help-btn:hover {
  background: rgba(255,255,255,0.2);
  border-color: white;
}

.tagline {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-top: 0.25rem;
}

.voice-label {
  font-size: 0.8rem;
  opacity: 0.8;
}

.voice-btn {
  padding: 0.25rem 0.75rem;
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: 20px;
  background: transparent;
  color: rgba(255,255,255,0.7);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.voice-btn.active {
  background: rgba(255,255,255,0.2);
  border-color: white;
  color: white;
  font-weight: 600;
}

/* Auth area */
.auth-area {
  margin-top: 0.6rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

#auth-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.auth-pic {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.5);
}

.auth-name {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.9);
}

/* Login gate */
#login-gate {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
  padding: 2rem;
}

.login-gate-content {
  text-align: center;
  max-width: 400px;
}

.gate-logo {
  width: 100px;
  height: 100px;
  margin-bottom: 1rem;
}

.login-gate-content h2 {
  color: var(--primary-dark);
  margin-bottom: 0.75rem;
  font-size: 1.5rem;
}

.login-gate-content p {
  color: var(--text-light);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

#google-signin-btn-gate {
  display: inline-block;
  margin-bottom: 1.5rem;
}

.help-link {
  display: block;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
}

.help-link:hover {
  text-decoration: underline;
}

/* Voice toggle (moved below nav) */
.voice-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem;
  background: var(--primary-dark);
}

/* Navigation */
#app-nav {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav-btn {
  flex: 1;
  padding: 0.75rem;
  border: none;
  background: none;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}

.nav-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Main */
#app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
}

/* Views */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* Back button */
.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0.5rem 0;
  margin-bottom: 1rem;
  font-weight: 500;
}

/* Cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border-left: 4px solid var(--accent);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.card.locked {
  opacity: 0.55;
  cursor: default;
}

.card.locked:hover {
  transform: none;
  box-shadow: var(--shadow);
}

.card.admin-access {
  border-left-color: var(--warning);
  cursor: pointer;
}

.card h3 {
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
  color: var(--primary-dark);
}

.card p {
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.5;
}

.card .badge {
  display: inline-block;
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  margin-top: 0.5rem;
  font-weight: 600;
}

.card .badge.locked {
  background: var(--text-light);
}

/* Scenario body */
.context-text {
  font-size: 0.85rem;
  color: var(--text-light);
  font-style: italic;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: #e8f5e9;
  border-radius: 8px;
}

.scenario-body {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  line-height: 1.8;
  font-size: 1rem;
  white-space: pre-line;
  margin-bottom: 1rem;
}

.scenario-body .glossary-word {
  background: #d8f3dc;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  cursor: pointer;
  border-bottom: 2px dotted var(--primary);
  transition: background 0.2s;
}

.scenario-body .glossary-word:hover {
  background: #b7e4c7;
}

.scenario-body .dict-word {
  cursor: pointer;
  border-bottom: 1px dotted #adb5bd;
  transition: border-color 0.2s;
}

.scenario-body .dict-word:hover {
  border-bottom-color: var(--primary);
  color: var(--primary);
}

/* Action buttons */
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 0.5rem;
}

.action-btn:hover {
  background: var(--primary-light);
}

/* Quiz */
#quiz-section {
  margin-top: 2rem;
}

#quiz-section h3 {
  margin-bottom: 1rem;
  color: var(--primary-dark);
}

.quiz-question {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.quiz-question-text {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.quiz-option {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
  text-align: left;
}

.quiz-option:hover {
  border-color: var(--primary-light);
  background: #f0faf4;
}

.quiz-option.selected {
  border-color: var(--primary);
  background: #d8f3dc;
}

.quiz-option.correct {
  border-color: var(--success);
  background: #d4edda;
}

.quiz-option.incorrect {
  border-color: var(--error);
  background: #f8d7da;
}

.quiz-option.disabled {
  cursor: default;
  opacity: 0.85;
}

.quiz-explanation {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #fff3cd;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #856404;
}

#quiz-result {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  margin-top: 1rem;
}

#quiz-result .score {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

#quiz-result .score-label {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-top: 0.25rem;
}

/* Glossary */
.glossary-header {
  margin-bottom: 1rem;
}

.glossary-header .action-btn {
  margin-top: 0.75rem;
  width: 100%;
}

.search-bar {
  margin-bottom: 0;
}

.search-bar input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-bar input:focus {
  border-color: var(--primary);
}

.glossary-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.glossary-item {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.glossary-item .term {
  font-weight: 600;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.glossary-item .definition {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 0.25rem;
}

/* Speak button */
.speak-btn {
  background: none;
  border: 2px solid var(--primary);
  color: var(--primary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.speak-btn:hover {
  background: var(--primary);
  color: white;
}

/* Popup */
.popup {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-radius: 16px 16px 0 0;
  padding: 1.5rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
  z-index: 100;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.popup.visible {
  transform: translateY(0);
}

.popup-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
}

.popup h4 {
  font-size: 1.3rem;
  color: var(--primary-dark);
  margin-bottom: 0.25rem;
}

.popup .translation {
  color: var(--primary);
  font-weight: 600;
  font-size: 1.1rem;
  direction: rtl;
  text-align: right;
}

.popup .phonetic {
  color: var(--text-light);
  font-style: italic;
  font-size: 0.9rem;
}

.popup .example {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: #f0faf4;
  border-radius: 6px;
  font-size: 0.85rem;
  font-style: italic;
}

/* Phrases */
.phrase-category {
  margin-bottom: 1.5rem;
}

.phrase-category h3 {
  text-transform: capitalize;
  color: var(--primary-dark);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
}

.phrase-item {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow);
}

.phrase-text {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.phrase-explanation {
  font-size: 0.85rem;
  color: var(--text-light);
}

.phrase-translation {
  font-size: 0.9rem;
  color: var(--primary);
  direction: rtl;
  text-align: right;
  margin-top: 0.35rem;
  font-weight: 500;
}

/* Filters */
#phrases-filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 0.4rem 0.8rem;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: white;
  font-size: 0.8rem;
  cursor: pointer;
  text-transform: capitalize;
  transition: all 0.2s;
}

.filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Utility */
.hidden {
  display: none !important;
}

/* Loading overlay */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-content {
  text-align: center;
}

.loading-logo {
  width: 80px;
  height: 80px;
  margin-bottom: 1.5rem;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 1rem;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  color: var(--text-light);
  font-size: 0.95rem;
}

/* Loading state (inline) */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-light);
}

/* Footer */
#app-footer {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

.footer-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.85rem;
}

.footer-link:hover {
  text-decoration: underline;
}

.version {
  font-size: 0.75rem;
  color: var(--text-light);
  opacity: 0.6;
  margin-top: 0.5rem;
}

/* Responsive */
@media (min-width: 768px) {
  #app-main {
    padding: 2rem;
  }
}
