:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2ff;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --accent: #0ea5e9;
  --emerald: #10b981;
  --emerald-light: #d1fae5;
  --amber: #f59e0b;
  --amber-light: #fef3c7;
  --rose: #e11d48;
  --rose-light: #ffe4e6;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 16px 36px rgba(79, 70, 229, 0.12);
  --radius: 14px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Header & Navigation */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.28);
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.nav-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.18s ease;
}

.nav-btn:hover {
  background: var(--surface-3);
  color: var(--primary);
}

.nav-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 3px 10px rgba(79, 70, 229, 0.25);
}

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

/* Buttons & Inputs */
button, .btn {
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: all 0.15s ease;
  text-decoration: none;
}

button:hover, .btn:hover {
  border-color: #cbd5e1;
  background: var(--surface-2);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

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

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

.btn-success:hover {
  background: #059669;
  border-color: #059669;
}

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

.btn-danger:hover {
  background: #be123c;
  border-color: #be123c;
}

.btn-soft {
  background: var(--surface-3);
  color: var(--primary);
  border-color: var(--primary-light);
}

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

.btn-lg {
  padding: 12px 22px;
  font-size: 15px;
  border-radius: 11px;
}

.btn-sm {
  padding: 5px 11px;
  font-size: 12px;
  border-radius: 7px;
}

input, select, textarea {
  font: inherit;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

/* Cards & Grid */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 960px) {
  .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 680px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .container { padding: 16px 14px 48px; }
}

/* Mode Selector Cards */
.mode-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.mode-card:hover {
  border-color: #a5b4fc;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.mode-card.selected {
  border-color: var(--primary);
  background: linear-gradient(180deg, #f5f7ff 0%, #ffffff 100%);
  box-shadow: var(--shadow-lg);
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--primary);
  width: fit-content;
  margin-bottom: 10px;
}

.mode-card.selected .mode-badge {
  background: var(--primary);
  color: #fff;
}

.mode-title {
  font-size: 17px;
  font-weight: 800;
  margin: 0 0 6px;
  color: var(--text);
}

.mode-desc {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 12px;
}

.mode-meta {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: flex;
  justify-content: space-between;
}

/* Badges & Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--primary);
}

.pill-green {
  background: var(--emerald-light);
  color: #065f46;
}

.pill-amber {
  background: var(--amber-light);
  color: #92400e;
}

.pill-rose {
  background: var(--rose-light);
  color: #9f1239;
}

/* Live Exam Room */
.exam-header {
  background: linear-gradient(135deg, #1e1b4b, #312e81, #4338ca);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-md);
}

.exam-steps {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.exam-step {
  font-size: 12px;
  font-weight: 700;
  padding: 6px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.75);
}

.exam-step.active {
  background: #fff;
  color: #1e1b4b;
}

.exam-step.done {
  background: rgba(16, 185, 129, 0.28);
  color: #a7f3d0;
}

.exam-layout {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 920px) {
  .exam-layout {
    grid-template-columns: 1fr;
  }
}

.question-box {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border: 2px solid var(--primary-light);
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 16px;
  position: relative;
}

.examiner-bubble {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.examiner-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.examiner-avatar.speaking {
  background: var(--primary);
  color: #fff;
  animation: pulse-ring 1.4s infinite;
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.45); }
  70% { box-shadow: 0 0 0 12px rgba(79, 70, 229, 0); }
  100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); }
}

.q-prompt {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.38;
  margin: 8px 0 14px;
}

/* Cue Card */
.cue-card {
  background: #fffbeb;
  border: 2px solid #fcd34d;
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 12px 0;
}

.cue-card h3 {
  margin: 0 0 10px;
  font-size: 19px;
  color: #78350f;
}

.cue-card ul {
  margin: 8px 0 0;
  padding-left: 20px;
  color: #92400e;
  font-weight: 600;
}

.cue-card li {
  margin-bottom: 6px;
}

/* Timer Display */
.timer-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
}

.timer-digits {
  font-size: 32px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
}

.timer-digits.warn {
  color: var(--amber);
}

.timer-digits.danger {
  color: var(--rose);
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s linear;
}

/* Audio Recorder & Waveform */
.recorder-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.rec-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--rose);
  display: inline-block;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

canvas.waveform {
  width: 100%;
  height: 54px;
  background: #0f172a;
  border-radius: 8px;
  display: block;
  margin: 10px 0;
}

/* Phrase Bank Grid */
.phrase-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.phrase-chip {
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.phrase-chip:hover {
  border-color: var(--primary);
  background: var(--surface-3);
  color: var(--primary);
}

.phrase-chip.used {
  background: var(--emerald-light);
  border-color: #6ee7b7;
  color: #065f46;
}

/* Model Answer Comparison */
.band-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 10px;
}

@media (max-width: 720px) {
  .band-compare {
    grid-template-columns: 1fr;
  }
}

.band-box {
  border-radius: 11px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.band-box.b65 {
  border-left: 4px solid var(--accent);
  background: #f0f9ff;
}

.band-box.b80 {
  border-left: 4px solid var(--emerald);
  background: #ecfdf5;
}

/* Topic Cards in Bank */
.topic-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.16s ease;
}

.topic-card:hover {
  border-color: #a5b4fc;
  box-shadow: var(--shadow-md);
}

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

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

.muted {
  color: var(--muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-content {
  background: var(--surface);
  border-radius: 16px;
  width: min(920px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.22);
}

.hist-row {
  cursor: pointer;
  transition: background 0.15s ease;
}
.hist-row:hover, .stu-row:hover {
  background: var(--surface-2) !important;
}


/* --- Grammar Specific Extensions --- */
.tenses-grid {
  display: grid;
  grid-template-columns: 120px repeat(4, 1fr);
  gap: 12px;
  overflow-x: auto;
}
@media (max-width: 900px) {
  .tenses-grid {
    grid-template-columns: 100px repeat(4, 240px);
  }
}
.tense-header-cell {
  background: var(--surface-2);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tense-card-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.tense-card-cell:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.tense-cell-name {
  font-weight: 700;
  color: var(--primary);
  font-size: 14px;
  margin-bottom: 6px;
}
.tense-cell-formula {
  font-size: 11.5px;
  font-family: monospace;
  background: var(--surface-2);
  padding: 4px 6px;
  border-radius: 4px;
  margin-bottom: 8px;
  color: var(--text-2);
}
.tense-cell-sig {
  font-size: 11px;
  color: var(--muted);
}
.timeline-box {
  background: #0f172a;
  color: #f8fafc;
  border-radius: var(--radius);
  padding: 24px;
  margin: 18px 0;
  font-family: ui-monospace, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  overflow-x: auto;
}
.callout {
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 14px 0;
  border-left: 4px solid var(--primary);
  background: var(--surface-3);
  font-size: 14px;
}
.callout-title {
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.callout-trap {
  border-left-color: var(--rose);
  background: var(--rose-light);
  color: #991b1b;
}
.callout-idea {
  border-left-color: var(--primary);
  background: var(--primary-light);
  color: #1e3a8a;
}
.callout-tip {
  border-left-color: var(--emerald);
  background: var(--emerald-light);
  color: #065f46;
}
.callout-amber {
  border-left-color: var(--amber);
  background: var(--amber-light);
  color: #92400e;
}
.err-correction-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.err-wrong-badge {
  color: var(--rose);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.err-right-badge {
  color: var(--emerald);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.table-wrap {
  width: 100%;
  overflow-x: auto;
}
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table-wrap th,
.table-wrap td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.table-wrap th {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--text-2);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary);
}
.badge-green { background: var(--emerald-light); color: #065f46; }
.badge-red { background: var(--rose-light); color: #9f1239; }
.badge-amber { background: var(--amber-light); color: #92400e; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--surface);
  border-radius: 16px;
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.3);
}

/* Vocab-specific styles */
.ipa-tag {
  font-family: "Lucida Sans Unicode", "DejaVu Sans", Arial, sans-serif;
  color: #4f46e5;
  background: #eef2ff;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
}
.level-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.lvl-A1 { background: #dcfce7; color: #166534; }
.lvl-A2 { background: #d1fae5; color: #065f46; }
.lvl-B1 { background: #e0e7ff; color: #3730a3; }
.lvl-B2 { background: #fef3c7; color: #92400e; }
.lvl-C1 { background: #ffe4e6; color: #9f1239; }
.lvl-EXT { background: #f1f5f9; color: #334155; }

.srs-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
}
.srs-P { background: #f1f5f9; color: #475569; }
.srs-R1, .srs-R2, .srs-R3 { background: #fef3c7; color: #92400e; }
.srs-R4, .srs-R5, .srs-R6 { background: #e0e7ff; color: #3730a3; }
.srs-A { background: #d1fae5; color: #065f46; }

.word-box-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  margin-bottom: 14px;
}
.word-pill {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.word-pill:hover { border-color: var(--primary); color: var(--primary); background: var(--surface-3); }

.flashcard-stage {
  background: linear-gradient(135deg, #ffffff, #f8fafc);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow-md);
  margin: 16px 0;
}
.flashcard-word {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}
.blurred-recall {
  filter: blur(6px);
  user-select: none;
  transition: filter 0.2s;
}
.blurred-recall:hover { filter: blur(0); }
