/* ==========================================
   LinguaBase - Styles with 3 Switchable Themes
   campus (default) / kids / terminal
   ========================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&display=swap');

/* ============ THEME: Campus (default) ============ */
:root,
[data-theme="campus"] {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #93c5fd;
  --primary-bg: rgba(59, 130, 246, 0.06);
  --accent: #8b5cf6;
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.08);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.08);
  --warning: #f59e0b;
  --bg: #f8fafc;
  --bg-secondary: #f1f5f9;
  --card: #ffffff;
  --card-border: #e2e8f0;
  --text: #1e293b;
  --text-light: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --nav-bg: #ffffff;
  --nav-border: #e2e8f0;
  --radius: 4px;
  --radius-lg: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.08);
  --gap-block: 20px;
  --flashcard-front: #ffffff;
  --flashcard-back: #f0f4ff;
  --typing-current-bg: rgba(59, 130, 246, 0.12);
  --input-bg: #ffffff;
  --select-bg: #f1f5f9;
}

/* ============ THEME: Kids ============ */
[data-theme="kids"] {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --primary: #e63946;
  --primary-dark: #c1121f;
  --primary-light: #fca5a5;
  --primary-bg: rgba(230, 57, 70, 0.08);
  --accent: #f77f00;
  --success: #06d6a0;
  --success-bg: rgba(6, 214, 160, 0.12);
  --danger: #e63946;
  --danger-bg: rgba(230, 57, 70, 0.1);
  --warning: #fcbf49;
  --bg: #fffbea;
  --bg-secondary: #fef3c7;
  --card: #ffffff;
  --card-border: #fcd34d;
  --text: #292524;
  --text-light: #78716c;
  --text-muted: #a8a29e;
  --border: #fcd34d;
  --nav-bg: #e63946;
  --nav-border: #c1121f;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 2px 0 rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-hover: 0 3px 0 rgba(0,0,0,0.08), 0 6px 16px rgba(0,0,0,0.06);
  --gap-block: 24px;
  --flashcard-front: #ffffff;
  --flashcard-back: #fef3c7;
  --typing-current-bg: rgba(230, 57, 70, 0.15);
  --input-bg: #ffffff;
  --select-bg: rgba(255,255,255,0.25);
}

/* ============ THEME: Terminal ============ */
[data-theme="terminal"] {
  --font: 'Cascadia Code', 'Fira Code', 'SF Mono', 'Consolas', monospace;
  --primary: #00ff41;
  --primary-dark: #00cc33;
  --primary-light: #33ff66;
  --primary-bg: rgba(0, 255, 65, 0.06);
  --accent: #00d4ff;
  --success: #00ff41;
  --success-bg: rgba(0, 255, 65, 0.08);
  --danger: #ff3333;
  --danger-bg: rgba(255, 51, 51, 0.1);
  --warning: #ffcc00;
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --card: #161b22;
  --card-border: #30363d;
  --text: #c9d1d9;
  --text-light: #8b949e;
  --text-muted: #484f58;
  --border: #30363d;
  --nav-bg: #010409;
  --nav-border: #30363d;
  --radius: 0px;
  --radius-lg: 0px;
  --shadow: none;
  --shadow-hover: 0 0 8px rgba(0, 255, 65, 0.1);
  --gap-block: 16px;
  --flashcard-front: #161b22;
  --flashcard-back: #0d1117;
  --typing-current-bg: rgba(0, 255, 65, 0.15);
  --input-bg: #0d1117;
  --select-bg: #0d1117;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ============ NAVIGATION ============ */
.nav {
  background: var(--nav-bg);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--nav-border);
  gap: 12px;
  flex-wrap: wrap;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.nav-title {
  font-size: 1.1rem;
  font-weight: 800;
  text-decoration: none;
  color: var(--primary);
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.nav-select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--select-bg);
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--font);
  cursor: pointer;
  outline: none;
}

.nav-select:focus {
  border-color: var(--primary);
}

.nav-links {
  display: flex;
  gap: 4px;
  list-style: none;
}

.nav-links a {
  color: var(--text-light);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}

.nav-links a:hover {
  background: var(--primary-bg);
  color: var(--primary);
}

.nav-links a.active {
  background: var(--primary);
  color: #fff;
}

/* Kids theme: white text on colored nav */
[data-theme="kids"] .nav-title { color: #fff; }
[data-theme="kids"] .nav-links a { color: rgba(255,255,255,0.7); }
[data-theme="kids"] .nav-links a:hover { background: rgba(255,255,255,0.15); color: #fff; }
[data-theme="kids"] .nav-links a.active { background: #fff; color: var(--primary); }
[data-theme="kids"] .nav-select { border-color: rgba(255,255,255,0.3); color: #fff; }

/* Terminal theme: green accent nav */
[data-theme="terminal"] .nav-title { color: var(--primary); text-shadow: 0 0 6px rgba(0,255,65,0.3); }
[data-theme="terminal"] .nav-select { border-color: var(--border); color: var(--primary); }

/* ============ CONTAINER ============ */
.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 28px 20px;
}

/* ============ CARDS ============ */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: var(--gap-block);
  transition: box-shadow 0.2s;
}

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

.card-title {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 10px;
  color: var(--text);
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  text-decoration: none;
  font-family: var(--font);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  opacity: 0.9;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: #fff;
}

.btn-block {
  width: 100%;
}

/* Terminal buttons */
[data-theme="terminal"] .btn-primary {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
  text-shadow: 0 0 4px rgba(0,255,65,0.3);
}
[data-theme="terminal"] .btn-primary:hover {
  background: rgba(0,255,65,0.1);
}
[data-theme="terminal"] .btn-success {
  background: transparent;
  border: 1px solid var(--success);
  color: var(--success);
}
[data-theme="terminal"] .btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

/* ============ FORMS ============ */
.input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
  background: var(--input-bg);
  color: var(--text);
}

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

/* ============ SEARCH ============ */
.search-box {
  position: relative;
  margin-bottom: var(--gap-block);
}

.search-box .input {
  padding-left: 40px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1rem;
}

/* ============ RESULT LIST ============ */
.result-list {
  list-style: none;
}

.result-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  border-radius: var(--radius);
  margin-bottom: 2px;
}

.result-item:hover {
  background: var(--primary-bg);
}

.result-word {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.result-def {
  color: var(--text-light);
  font-size: 0.85rem;
  margin-top: 2px;
}

/* ============ FLASHCARD ============ */
.flashcard-container {
  perspective: 1000px;
  margin: 28px auto;
  max-width: 400px;
}

.flashcard {
  width: 100%;
  min-height: 240px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

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

.flashcard-face {
  position: absolute;
  width: 100%;
  min-height: 240px;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
}

.flashcard-front {
  background: var(--flashcard-front);
}

.flashcard-back {
  background: var(--flashcard-back);
  transform: rotateY(180deg);
}

.flashcard-word {
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  color: var(--text);
}

.flashcard-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 14px;
}

.flashcard-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

/* ============ PROGRESS BAR ============ */
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-secondary);
  border-radius: 2px;
  overflow: hidden;
  margin: 16px 0;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

[data-theme="kids"] .progress-fill {
  background: linear-gradient(90deg, #e63946, #f77f00, #06d6a0);
}

[data-theme="terminal"] .progress-fill {
  background: var(--primary);
  box-shadow: 0 0 6px rgba(0,255,65,0.4);
}

/* ============ STATS ============ */
.stats {
  display: flex;
  gap: 10px;
  margin-bottom: var(--gap-block);
}

.stat {
  flex: 1;
  text-align: center;
  padding: 12px 8px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 2px;
}

/* ============ TYPING STAGE ============ */
.typing-stage {
  text-align: center;
  padding: 32px 20px 24px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: text;
}

.typing-next {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  min-height: 1.2em;
}

.typing-main-word {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  transition: opacity 0.15s;
}

.typing-reading {
  font-size: 1.4rem;
  letter-spacing: 2px;
  font-family: 'Inter', monospace;
  margin-top: 4px;
  min-height: 2em;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1px;
}

.typing-reading span {
  display: inline-block;
  padding: 2px 1px;
  transition: color 0.1s;
}

.tp-pending {
  color: var(--text-muted);
}

.tp-correct {
  color: var(--success);
  font-weight: 700;
}

@keyframes tp-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.tp-current {
  color: #e63946;
  font-weight: 800;
  border-bottom: 2px solid #e63946;
  animation: tp-blink 0.9s ease-in-out infinite;
}

[data-theme="terminal"] .tp-current {
  color: #ff3333;
  border-bottom-color: #ff3333;
}

[data-theme="kids"] .tp-current {
  color: #f77f00;
  border-bottom-color: #f77f00;
}

.typing-stage-hint {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 4px;
  font-style: italic;
}

/* Hidden input for capturing keystrokes */
.typing-hidden-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* Word complete animation */
.typing-word-done {
  opacity: 0.3;
  transform: scale(0.95);
  transition: all 0.2s;
}

/* Shake on wrong key */
@keyframes typing-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.typing-shake {
  animation: typing-shake 0.3s ease;
}

/* ============ VIRTUAL KEYBOARD ============ */
.keyboard {
  max-width: 540px;
  margin: 20px auto 0;
  user-select: none;
  padding: 14px 10px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 5px;
}

/* Stagger rows like a real keyboard */
.kb-row[data-row="home"] { padding: 0 14px; }
.kb-row[data-row="bottom"] { padding: 0 34px; }
.kb-row[data-row="space"] { margin-top: 2px; }

.kb-key {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: var(--font);
  color: var(--text);
  cursor: default;

  /* 3D keycap */
  background: linear-gradient(180deg, #fafafa 0%, #e8e8e8 100%);
  border: 1px solid #ccc;
  border-bottom: 3px solid #b0b0b0;
  border-radius: 5px;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.6) inset,
    0 1px 2px rgba(0,0,0,0.08);
  transition: all 0.08s ease;
  position: relative;
}

/* Home key indicators (F and J bumps) */
.kb-home::after {
  content: '';
  position: absolute;
  bottom: 7px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 2px;
  background: var(--text-muted);
  border-radius: 1px;
}

.kb-space {
  width: 220px;
  font-size: 0.72rem;
  letter-spacing: 2px;
  color: var(--text-light);
}

/* ---- Key pressed down effect ---- */
.kb-key.kb-pressed {
  border-bottom-width: 1px;
  transform: translateY(2px);
  box-shadow:
    0 0 0 rgba(255,255,255,0.6) inset,
    0 0 1px rgba(0,0,0,0.1);
  background: linear-gradient(180deg, #e0e0e0 0%, #d4d4d4 100%);
}

/* ---- Next key to press: pulse glow ---- */
@keyframes kb-pulse {
  0%, 100% { box-shadow: 0 1px 0 rgba(255,255,255,0.6) inset, 0 0 6px rgba(59,130,246,0.3); }
  50% { box-shadow: 0 1px 0 rgba(255,255,255,0.6) inset, 0 0 14px rgba(59,130,246,0.5); }
}

.kb-key.kb-active {
  background: linear-gradient(180deg, #5b9cf6 0%, #3b82f6 100%);
  color: #fff;
  border-color: #2563eb;
  border-bottom: 3px solid #1d4ed8;
  animation: kb-pulse 1s ease-in-out infinite;
}

/* ---- Correct flash ---- */
.kb-key.kb-correct {
  background: linear-gradient(180deg, #4ade80 0%, #22c55e 100%);
  color: #fff;
  border-color: #16a34a;
  border-bottom: 1px solid #16a34a;
  transform: translateY(2px);
}

/* ---- Wrong flash ---- */
.kb-key.kb-wrong {
  background: linear-gradient(180deg, #f87171 0%, #ef4444 100%);
  color: #fff;
  border-color: #dc2626;
  border-bottom: 1px solid #dc2626;
  transform: translateY(2px);
}

/* ============ Terminal Keyboard ============ */
[data-theme="terminal"] .keyboard {
  background: #010409;
  border-color: #30363d;
}

[data-theme="terminal"] .kb-key {
  background: linear-gradient(180deg, #21262d 0%, #161b22 100%);
  border-color: #30363d;
  border-bottom: 3px solid #0d1117;
  color: #8b949e;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.03) inset,
    0 1px 2px rgba(0,0,0,0.3);
}

[data-theme="terminal"] .kb-home::after {
  background: #484f58;
}

@keyframes kb-pulse-term {
  0%, 100% { box-shadow: 0 0 6px rgba(0,255,65,0.2); }
  50% { box-shadow: 0 0 16px rgba(0,255,65,0.45); }
}

[data-theme="terminal"] .kb-key.kb-active {
  background: linear-gradient(180deg, #0a2010 0%, #051a08 100%);
  color: var(--primary);
  border-color: var(--primary);
  border-bottom: 3px solid #00aa2a;
  text-shadow: 0 0 6px rgba(0,255,65,0.5);
  animation: kb-pulse-term 1s ease-in-out infinite;
}

[data-theme="terminal"] .kb-key.kb-correct {
  background: linear-gradient(180deg, #052e10 0%, #021a08 100%);
  color: var(--primary);
  border-color: var(--primary);
  border-bottom: 1px solid var(--primary);
  transform: translateY(2px);
}

[data-theme="terminal"] .kb-key.kb-wrong {
  background: linear-gradient(180deg, #2e0505 0%, #1a0202 100%);
  color: #ff3333;
  border-color: #ff3333;
  border-bottom: 1px solid #ff3333;
  transform: translateY(2px);
}

/* ============ Kids Keyboard ============ */
[data-theme="kids"] .keyboard {
  background: #fef3c7;
  border-color: #fcd34d;
  border-width: 2px;
  border-radius: 10px;
  padding: 16px 12px 12px;
}

[data-theme="kids"] .kb-key {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 800;
  background: linear-gradient(180deg, #ffffff 0%, #f5f5f5 100%);
  border: 2px solid #ddd;
  border-bottom: 4px solid #bbb;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.8) inset,
    0 2px 4px rgba(0,0,0,0.06);
}

[data-theme="kids"] .kb-space {
  width: 230px;
}

@keyframes kb-pulse-kids {
  0%, 100% { box-shadow: 0 1px 0 rgba(255,255,255,0.6) inset, 0 0 6px rgba(230,57,70,0.25); }
  50% { box-shadow: 0 1px 0 rgba(255,255,255,0.6) inset, 0 0 14px rgba(230,57,70,0.45); }
}

[data-theme="kids"] .kb-key.kb-active {
  background: linear-gradient(180deg, #fb7185 0%, #e63946 100%);
  color: #fff;
  border-color: #c1121f;
  border-bottom: 4px solid #9b0d18;
  animation: kb-pulse-kids 1s ease-in-out infinite;
}

[data-theme="kids"] .kb-key.kb-correct {
  background: linear-gradient(180deg, #6ee7b7 0%, #06d6a0 100%);
  border-color: #059669;
  border-bottom: 2px solid #059669;
  transform: translateY(2px);
}

[data-theme="kids"] .kb-key.kb-wrong {
  background: linear-gradient(180deg, #fca5a5 0%, #e63946 100%);
  border-color: #c1121f;
  border-bottom: 2px solid #c1121f;
  transform: translateY(2px);
}

/* ============ Responsive Keyboard ============ */
@media (max-width: 520px) {
  .keyboard {
    padding: 10px 6px 8px;
  }
  .kb-key {
    width: 30px;
    height: 34px;
    font-size: 0.68rem;
    border-bottom-width: 2px;
  }
  .kb-space {
    width: 150px;
    font-size: 0.6rem;
  }
  .kb-row {
    gap: 3px;
    margin-bottom: 3px;
  }
  .kb-row[data-row="home"] { padding: 0 10px; }
  .kb-row[data-row="bottom"] { padding: 0 24px; }
  .typing-main-word {
    font-size: 2rem;
  }
  .typing-reading {
    font-size: 1.1rem;
  }
  [data-theme="kids"] .kb-key {
    width: 32px;
    height: 38px;
    border-bottom-width: 3px;
  }
  [data-theme="kids"] .kb-space {
    width: 160px;
  }
}

/* ============ HOME CARDS ============ */
.home-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap-block);
  margin-top: 24px;
}

.home-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 22px;
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.2s, transform 0.15s;
}

.home-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

[data-theme="terminal"] .home-card:hover {
  border-color: var(--primary);
}

.home-card-icon {
  font-size: 2.2rem;
  flex-shrink: 0;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--bg-secondary);
}

[data-theme="kids"] .home-card:nth-child(1) .home-card-icon { background: #fee2e2; }
[data-theme="kids"] .home-card:nth-child(2) .home-card-icon { background: #fef3c7; }
[data-theme="kids"] .home-card:nth-child(3) .home-card-icon { background: #d1fae5; }

.home-card-title {
  font-size: 1.05rem;
  font-weight: 800;
}

.home-card-desc {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 2px;
}

/* ============ BADGES ============ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.badge-new {
  background: var(--primary-bg);
  color: var(--primary);
}

.badge-review {
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
}

.badge-mastered {
  background: var(--success-bg);
  color: #15803d;
}

[data-theme="terminal"] .badge-review { color: var(--warning); }
[data-theme="terminal"] .badge-mastered { color: var(--success); }

/* ============ RESPONSIVE ============ */

/* Desktop */
@media (min-width: 600px) {
  .home-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---- Tablet (max 768px) ---- */
@media (max-width: 768px) {
  .container {
    padding: 20px 16px;
  }

  .flashcard-container {
    max-width: 340px;
  }

  .flashcard, .flashcard-face {
    min-height: 210px;
  }

  .flashcard-face {
    padding: 22px;
  }
}

/* ---- Mobile (max 520px) ---- */
@media (max-width: 520px) {

  /* --- Nav --- */
  .nav {
    padding: 8px 10px;
    gap: 6px;
  }

  .nav-left {
    gap: 4px;
    width: 100%;
    justify-content: space-between;
  }

  .nav-title {
    font-size: 0.88rem;
  }

  .nav-select {
    font-size: 0.72rem;
    padding: 3px 6px;
  }

  .nav-links {
    gap: 2px;
    width: 100%;
    justify-content: center;
  }

  .nav-links a {
    font-size: 0.72rem;
    padding: 5px 8px;
    flex: 1;
    text-align: center;
  }

  /* --- Container --- */
  .container {
    padding: 14px 10px;
  }

  /* --- Cards --- */
  .card {
    padding: 16px 14px;
  }

  /* --- Buttons --- */
  .btn {
    padding: 8px 14px;
    font-size: 0.82rem;
  }

  .flashcard-controls {
    gap: 8px;
  }

  .flashcard-controls .btn {
    flex: 1;
    padding: 12px 10px;
    font-size: 0.88rem;
  }

  /* --- Stats --- */
  .stats {
    gap: 6px;
  }

  .stat {
    padding: 8px 4px;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  .stat-label {
    font-size: 0.65rem;
  }

  /* --- Flashcard --- */
  .flashcard-container {
    max-width: 100%;
    margin: 20px auto;
  }

  .flashcard, .flashcard-face {
    min-height: 200px;
  }

  .flashcard-face {
    padding: 20px 16px;
  }

  .flashcard-word {
    font-size: 1.5rem;
  }

  .flashcard-hint {
    font-size: 0.75rem;
  }

  /* --- Home cards --- */
  .home-card {
    padding: 14px 14px;
    gap: 12px;
  }

  .home-card-icon {
    width: 42px;
    height: 42px;
    font-size: 1.8rem;
  }

  .home-card-title {
    font-size: 0.95rem;
  }

  .home-card-desc {
    font-size: 0.78rem;
  }

  /* --- Dictionary --- */
  .search-box .input {
    font-size: 0.88rem;
    padding: 9px 12px 9px 36px;
  }

  .search-icon {
    left: 11px;
    font-size: 0.9rem;
  }

  .result-item {
    padding: 10px 10px;
  }

  .result-word {
    font-size: 0.92rem;
  }

  .result-def {
    font-size: 0.8rem;
  }

  /* --- Progress bar --- */
  .progress-bar {
    margin: 10px 0;
  }

  /* --- Typing stage --- */
  .typing-stage {
    padding: 20px 12px 16px;
    min-height: 140px;
    gap: 6px;
  }

  .typing-main-word {
    font-size: 2rem;
  }

  .typing-reading {
    font-size: 1.1rem;
  }

  .typing-next {
    font-size: 0.75rem;
  }

  .typing-stage-hint {
    font-size: 0.78rem;
  }
}

/* ---- Small mobile (max 360px) ---- */
@media (max-width: 360px) {
  .nav-title {
    font-size: 0.8rem;
  }

  .nav-links a {
    font-size: 0.65rem;
    padding: 4px 5px;
  }

  .container {
    padding: 10px 8px;
  }

  .stat-value {
    font-size: 1rem;
  }

  .stat-label {
    font-size: 0.6rem;
  }

  .flashcard-word {
    font-size: 1.3rem;
  }

  .flashcard, .flashcard-face {
    min-height: 180px;
  }

  .typing-main-word {
    font-size: 1.6rem;
  }

  .typing-reading {
    font-size: 0.95rem;
  }

  .home-card {
    padding: 12px;
    gap: 10px;
  }

  .home-card-icon {
    width: 36px;
    height: 36px;
    font-size: 1.5rem;
  }
}

/* ---- Touch: bigger tap targets ---- */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 44px;
  }

  .result-item {
    min-height: 48px;
    padding: 12px;
  }

  .nav-links a {
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .nav-select {
    min-height: 36px;
  }
}

/* ---- Safe area (notch phones) ---- */
@supports (padding: env(safe-area-inset-bottom)) {
  .nav {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .container {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
}

/* ============ FOOTER ============ */
.site-footer {
  margin-top: 40px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.footer-inner {
  max-width: 600px;
  margin: 0 auto;
  padding: 24px 16px 20px;
  text-align: center;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  margin-bottom: 12px;
}

.footer-links a {
  font-size: 0.82rem;
  color: var(--text-light);
  text-decoration: none;
  transition: color 0.15s;
}

.footer-links a:hover {
  color: var(--primary);
}

.footer-copy {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Terminal footer */
[data-theme="terminal"] .site-footer {
  border-top-color: var(--border);
  background: var(--bg);
}

[data-theme="terminal"] .footer-links a:hover {
  color: var(--primary);
  text-shadow: 0 0 4px rgba(0,255,65,0.3);
}

/* Kids footer */
[data-theme="kids"] .site-footer {
  border-top: 2px solid var(--border);
}

.footer-links + .footer-links {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ============ LEGAL PAGES ============ */
.legal-page h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.legal-updated {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.legal-section {
  margin-bottom: 24px;
}

.legal-section h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.legal-section p,
.legal-section li {
  font-size: 0.9rem;
  color: var(--text-light);
  line-height: 1.7;
}

.legal-section ul {
  padding-left: 20px;
  margin: 8px 0;
}

.legal-section li {
  margin-bottom: 6px;
}

.legal-section a {
  color: var(--primary);
  text-decoration: underline;
}

/* Contact card */
.contact-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
}

.contact-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.contact-card h2 {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 2px;
}

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

.contact-card a {
  color: var(--primary);
}

.contact-note {
  margin-top: 20px;
  padding: 14px 16px;
  background: var(--primary-bg);
  border-radius: var(--radius-lg);
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.6;
}

/* ============ RTL ADJUSTMENTS ============ */
[dir="rtl"] .search-box .input {
  padding-left: 14px;
  padding-right: 40px;
}

[dir="rtl"] .search-icon {
  left: auto;
  right: 14px;
}

[dir="rtl"] .nav-links {
  direction: ltr;
}

/* ============ TERMINAL EXTRAS ============ */
[data-theme="terminal"] .typing-stage {
  border-color: var(--primary);
}

[data-theme="terminal"] a {
  color: var(--accent);
}

[data-theme="terminal"] .home-card {
  border-color: var(--border);
}

[data-theme="terminal"] ::selection {
  background: rgba(0,255,65,0.2);
  color: var(--primary);
}

/* ============ KIDS EXTRAS ============ */
[data-theme="kids"] .card {
  border-width: 2px;
}

[data-theme="kids"] .btn {
  border-radius: 6px;
  font-weight: 800;
}

[data-theme="kids"] .home-card {
  border-width: 2px;
}

[data-theme="kids"] .flashcard-face {
  border-width: 2px;
  border-color: var(--border);
}
