:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 10px 25px -5px rgb(0 0 0 / 0.4);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

.screen { display: none; animation: fadeIn 0.3s ease; }
.screen.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Hero */
.hero { text-align: center; margin-bottom: 1.75rem; }
.hero.small { margin-bottom: 1.25rem; }
.logo { font-size: 1.25rem; font-weight: 700; color: var(--primary); margin-bottom: 0.4rem; }
.logo.small { font-size: 1rem; margin-bottom: 0.2rem; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 700; margin-bottom: 0.4rem; }
.subtitle { color: var(--text-muted); max-width: 560px; margin: 0 auto; font-size: 0.95rem; }
.muted { color: var(--text-muted); }
.muted.small { font-size: 0.85rem; margin-bottom: 1rem; }

/* Tabs */
.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  justify-content: center;
}
.tab {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  color: var(--text-muted);
  padding: 0.5rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  font-size: 0.9rem;
}
.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--surface-2);
}
.auth-card { max-width: 420px; margin: 0 auto; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.card h2 { font-size: 1.15rem; margin-bottom: 0.75rem; }

/* Forms */
.form-row { margin-bottom: 1rem; }
.form-row label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
input[type="text"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.25);
}
.role-toggle {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}
.role-toggle label { cursor: pointer; display: flex; align-items: center; gap: 0.4rem; }
.hint { font-size: 0.8rem; color: var(--text-muted); margin-top: -0.5rem; margin-bottom: 1rem; }
.note { margin-top: 1rem; font-size: 0.8rem; color: var(--text-muted); }
.error { color: var(--danger); font-size: 0.9rem; margin-top: 0.75rem; }
.msg { margin-top: 0.75rem; font-size: 0.9rem; }
.msg.success { color: var(--accent); }
.msg.error { color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.65rem 1.15rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.full { width: 100%; }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.secondary:hover:not(:disabled) { background: #475569; }
.btn.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--surface-2);
}
.btn.ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn.record { background: var(--danger); color: white; min-width: 110px; }
.btn.record:hover { background: #dc2626; }
.btn.stop { background: var(--warning); color: #111; }
.btn.danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
}

/* Dashboard */
.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.dash-header h1 { font-size: 1.5rem; }
.dash-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 720px) {
  .dash-grid { grid-template-columns: 1fr; }
}

.badge {
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
}

.student-list {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.student-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.student-item:hover { border-color: var(--primary); }
.student-item .info { flex: 1; min-width: 0; }
.student-item .name { font-weight: 600; }
.student-item .meta { font-size: 0.8rem; color: var(--text-muted); }
.student-item .actions { display: flex; gap: 0.4rem; }

.session-list { display: flex; flex-direction: column; gap: 0.6rem; }
.session-item {
  background: var(--bg);
  padding: 0.85rem 1rem;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.session-item .meta { font-size: 0.85rem; color: var(--text-muted); }

/* Test header */
.test-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.student-badge { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.progress-wrap {
  flex: 1;
  min-width: 140px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  background: var(--accent);
  width: 20%;
  transition: width 0.3s ease;
  border-radius: 999px;
}
#progress-text { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }

/* Task */
.task-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--surface-2);
  box-shadow: var(--shadow);
}
.task-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.task-type-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: rgb(59 130 246 / 0.15);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
}
.timer { font-size: 0.9rem; font-weight: 600; color: var(--warning); font-variant-numeric: tabular-nums; }
#task-title { font-size: 1.3rem; margin-bottom: 1rem; }
.prompt {
  background: var(--bg);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
  font-size: 1.02rem;
  border-left: 4px solid var(--primary);
}
.prompt p { margin-bottom: 0.55rem; }
.prompt p:last-child { margin-bottom: 0; }
.prompt .instruction { color: var(--text-muted); font-size: 0.9rem; }
.prompt ol, .prompt ul { padding-left: 1.3rem; margin: 0.5rem 0; }
.prompt li { margin-bottom: 0.3rem; }

.visual { margin-bottom: 1.25rem; border-radius: 10px; overflow: hidden; background: var(--bg); }
.visual:empty { display: none; }
.scene-box { padding: 1.25rem; text-align: center; }
.scene-illustration {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  max-width: 400px;
  margin: 0 auto 0.75rem;
}
.scene-item {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.85rem 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.scene-item strong { display: block; color: var(--text); font-size: 1.3rem; margin-bottom: 0.2rem; }
.chart-box { padding: 1.1rem; }
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.9rem;
  height: 150px;
  margin-top: 1rem;
}
.bar {
  flex: 1;
  background: var(--primary);
  border-radius: 6px 6px 0 0;
  position: relative;
  min-height: 6px;
}
.bar span {
  position: absolute;
  bottom: -1.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.bar .value {
  position: absolute;
  top: -1.3rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
}

/* Recorder */
.recorder {
  background: var(--bg);
  border-radius: 10px;
  padding: 1.15rem;
  margin-bottom: 1.35rem;
}
.rec-controls { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.65rem; }
.rec-icon {
  width: 10px; height: 10px;
  background: white;
  border-radius: 50%;
  display: inline-block;
}
.btn.record.recording .rec-icon { animation: pulse 1s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.status { font-size: 0.85rem; color: var(--text-muted); }
.status.recording { color: var(--danger); font-weight: 600; }
#playback { width: 100%; margin-top: 0.65rem; border-radius: 6px; }
.nav-buttons { display: flex; justify-content: space-between; gap: 1rem; }

/* Results */
.results-card { margin-bottom: 2rem; }
#results-list { display: flex; flex-direction: column; gap: 0.85rem; margin-bottom: 1.35rem; }
.result-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  justify-content: space-between;
}
.result-item h4 { font-size: 0.9rem; flex: 1; min-width: 160px; }
.result-item audio { max-width: 260px; width: 100%; }
.results-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-bottom: 1.5rem; }
.rubric-note {
  border-top: 1px solid var(--surface-2);
  padding-top: 1.1rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.rubric-note h3 { color: var(--text); font-size: 0.95rem; margin-bottom: 0.4rem; }

.hidden { display: none !important; }

@media (max-width: 600px) {
  #app { padding: 1rem; }
  .task-card, .card { padding: 1.15rem; }
  .nav-buttons { flex-direction: column-reverse; }
  .nav-buttons .btn { width: 100%; }
  .test-header { flex-direction: column; align-items: flex-start; }
  .progress-wrap { width: 100%; }
}
