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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #f59e0b;
  --accent-dim: #92600a;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ---- Login screen ---- */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
}

.login-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-box h1 {
  font-size: 24px;
  color: var(--accent);
}

.login-box form {
  display: flex;
  gap: 8px;
}

.login-box input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
  width: 200px;
}

.login-box input:focus {
  border-color: var(--accent);
}

.login-error {
  color: var(--red);
  font-size: 13px;
}

/* ---- Mode selection ---- */

.mode-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
}

.mode-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.mode-box h1 {
  font-size: 24px;
  color: var(--accent);
}

.mode-subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: -12px;
}

.mode-buttons {
  display: flex;
  gap: 16px;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  width: 180px;
}

.mode-btn:hover {
  border-color: var(--accent);
  background: #1f1f1f;
}

.mode-icon {
  font-size: 32px;
}

.mode-label {
  font-size: 15px;
  font-weight: 600;
}

.mode-desc {
  font-size: 12px;
  color: var(--text-dim);
}

/* ---- App layout ---- */

#app, #app-practice, #app-words {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

.practice-progress {
  font-size: 13px;
  color: var(--text-dim);
}

.stats-bar {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-dim);
}

/* ---- Back button ---- */

.btn-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-back:hover {
  border-color: var(--accent);
  color: var(--accent);
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---- Add word bar ---- */

.add-word-bar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.add-word-form {
  display: flex;
  gap: 8px;
}

.add-word-form input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.add-word-form input:focus {
  border-color: var(--accent);
}

.btn-add {
  padding: 8px 16px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: var(--surface);
  color: var(--green);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-add:hover {
  background: rgba(34, 197, 94, 0.1);
}

/* ---- Sentence / word card ---- */

.sentence-card {
  padding: 20px;
  margin: 0 20px;
  margin-top: 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}

.sentence-english {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.5;
}

.sentence-spanish {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 15px;
  font-style: italic;
}

.sentence-card.score-good { border-color: var(--green); }
.sentence-card.score-good .sentence-english { color: var(--green); }
.sentence-card.score-ok { border-color: var(--yellow); }
.sentence-card.score-ok .sentence-english { color: var(--yellow); }
.sentence-card.score-bad { border-color: var(--red); }
.sentence-card.score-bad .sentence-english { color: var(--red); }

/* ---- Transcript ---- */

#transcript, #practice-transcript, #word-transcript {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  animation: fadeIn 0.2s ease;
}

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

.message.tutor {
  background: var(--surface);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message.user {
  background: var(--accent-dim);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message.system {
  align-self: center;
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
}

.message .grade {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.grade .score { font-weight: 600; color: var(--accent); }
.grade .correction { color: var(--green); font-style: italic; }
.grade .errors { color: var(--red); }

.live-caption {
  min-height: 24px;
  padding: 0 4px;
  font-size: 13px;
  color: var(--text-dim);
  font-style: italic;
  opacity: 0.7;
}

/* ---- Footer ---- */

footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
}

.status-dot.connected { background: var(--green); }
.status-dot.speaking { background: var(--blue); animation: pulse 1s infinite; }
.status-dot.listening { background: var(--accent); animation: pulse 1.5s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.btn-group { display: flex; gap: 8px; }

.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover:not(:disabled) { background: var(--border); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) { background: #d97706; }

.btn-end { border-color: var(--red); color: var(--red); }
.btn-end:hover:not(:disabled) { background: rgba(239, 68, 68, 0.1); }
.btn.mic-on { border-color: var(--green); color: var(--green); }
.btn-clue { border-color: var(--yellow); color: var(--yellow); }
.btn-clue:hover:not(:disabled) { background: rgba(234, 179, 8, 0.1); }
.btn-next { border-color: var(--blue); color: var(--blue); }
.btn-next:hover:not(:disabled) { background: rgba(59, 130, 246, 0.1); }

/* Scrollbar */
main::-webkit-scrollbar { width: 6px; }
main::-webkit-scrollbar-track { background: transparent; }
main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Scaffolded learning phase badge */
.phase-badge {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.phase-badge.phase-echo {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.4);
}
.phase-badge.phase-translate {
  background: rgba(234, 179, 8, 0.15);
  color: #facc15;
  border: 1px solid rgba(234, 179, 8, 0.4);
}
.phase-badge.hidden { display: none; }
