/* ── Telegram theme variables with browser fallbacks ── */
:root {
  --tg-theme-bg-color: #ffffff;
  --tg-theme-text-color: #222222;
  --tg-theme-hint-color: #888888;
  --tg-theme-link-color: #2678b6;
  --tg-theme-button-color: #2678b6;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-secondary-bg-color: #f4f4f5;

  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --transition: 0.2s ease;
}

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Screens ── */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: var(--gap);
  animation: fadeIn 0.2s ease;
}
.screen.active { display: flex; }

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

/* ── Loading ── */
#loading-screen {
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  color: var(--tg-theme-hint-color);
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--tg-theme-secondary-bg-color);
  border-top-color: var(--tg-theme-button-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Header ── */
.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: var(--gap);
  min-height: 44px;
}
.screen-title {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}
.back-btn {
  background: none;
  border: none;
  color: var(--tg-theme-button-color);
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* ── Part cards (home screen) ── */
.part-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color var(--transition), background var(--transition);
  text-align: left;
  width: 100%;
}
.part-card:hover, .part-card:active {
  border-color: var(--tg-theme-button-color);
  background: var(--tg-theme-bg-color);
}
.part-card-icon { font-size: 28px; flex-shrink: 0; }
.part-card-body { flex: 1; }
.part-card-title { font-size: 15px; font-weight: 600; }
.part-card-desc  { font-size: 13px; color: var(--tg-theme-hint-color); margin-top: 2px; }
.part-card-arrow { color: var(--tg-theme-hint-color); font-size: 18px; }

/* ── Topic card ── */
.topic-card {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
}
.topic-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--tg-theme-hint-color);
  margin-bottom: 6px;
}
.topic-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 10px;
}
.topic-part-desc {
  font-size: 13px;
  color: var(--tg-theme-hint-color);
  line-height: 1.5;
}
.topic-meta {
  font-size: 13px;
  color: var(--tg-theme-hint-color);
  margin-bottom: 12px;
}
.topic-questions { list-style: none; }
.topic-questions li {
  padding: 6px 0;
  border-top: 1px solid rgba(128,128,128,0.15);
  font-size: 14px;
  color: var(--tg-theme-hint-color);
}
.topic-questions li:first-child { border-top: none; }

.cue-card {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.6;
}

/* ── Buttons ── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  min-height: 52px;
  transition: opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.7; }

.btn-primary {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
}
.btn-secondary {
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
}
.btn-ghost {
  background: none;
  color: var(--tg-theme-link-color);
  font-size: 14px;
}
.btn-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.btn-row .btn { flex: 1; }

/* ── Progress dots ── */
.progress-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: var(--gap);
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--tg-theme-secondary-bg-color);
  border: 2px solid var(--tg-theme-hint-color);
  transition: background var(--transition);
}
.dot.done  { background: var(--tg-theme-button-color); border-color: var(--tg-theme-button-color); }
.dot.active { background: var(--tg-theme-text-color); border-color: var(--tg-theme-text-color); }

/* ── Question bubble ── */
.question-bubble {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
}

/* ── Recording button ── */
.record-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: auto 0;
}
.record-btn-wrap {
  position: relative;
  width: 88px; height: 88px;
}
.record-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 3px solid var(--tg-theme-button-color);
  opacity: 0;
  transform: scale(0.9);
}
.record-ring.pulsing {
  animation: pulse-ring 1.2s ease-out infinite;
}
@keyframes pulse-ring {
  0%   { transform: scale(0.9); opacity: 0.7; }
  100% { transform: scale(1.5); opacity: 0; }
}
.record-btn {
  width: 88px; height: 88px;
  border-radius: 50%;
  background: var(--tg-theme-button-color);
  border: none;
  color: var(--tg-theme-button-text-color);
  font-size: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  transition: background var(--transition), transform var(--transition);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.record-btn.recording {
  background: #e74c3c;
}
.record-btn.recording:active { transform: scale(0.95); }

.record-timer {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--tg-theme-text-color);
}
.record-hint {
  font-size: 13px;
  color: var(--tg-theme-hint-color);
  text-align: center;
}

/* ── Waveform canvas ── */
#waveform-canvas {
  width: 100%;
  height: 56px;
  border-radius: var(--radius-sm);
  background: var(--tg-theme-secondary-bg-color);
}

/* ── Replay button ── */
.replay-btn {
  background: none;
  border: 1px solid var(--tg-theme-hint-color);
  border-radius: var(--radius-sm);
  color: var(--tg-theme-hint-color);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Part 2 prep timer ── */
.prep-timer-display {
  font-size: 56px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--tg-theme-button-color);
  margin: 8px 0;
}
.prep-progress-bar {
  width: 100%;
  height: 8px;
  background: var(--tg-theme-secondary-bg-color);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: var(--gap);
}
.prep-progress-fill {
  height: 100%;
  background: var(--tg-theme-button-color);
  border-radius: 4px;
  transition: width 1s linear;
}

/* ── Assessing screen ── */
#assessing-screen {
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
}
.assessing-dots {
  display: flex;
  gap: 10px;
}
.assessing-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--tg-theme-button-color);
  animation: bounce-dot 1.2s ease-in-out infinite;
}
.assessing-dot:nth-child(2) { animation-delay: 0.2s; }
.assessing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce-dot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1.1); opacity: 1; }
}
.assessing-progress {
  width: 200px; height: 6px;
  background: var(--tg-theme-secondary-bg-color);
  border-radius: 3px;
  overflow: hidden;
}
.assessing-progress-fill {
  height: 100%;
  background: var(--tg-theme-button-color);
  border-radius: 3px;
  animation: indeterminate 2s ease-in-out infinite;
}
@keyframes indeterminate {
  0%   { width: 0%; margin-left: 0; }
  50%  { width: 70%; margin-left: 15%; }
  100% { width: 0%; margin-left: 100%; }
}

/* ── Results screen ── */
.band-badge {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  margin-bottom: var(--gap);
}
.band-number {
  font-size: 52px;
  font-weight: 800;
  color: var(--tg-theme-text-color);
  line-height: 1;
}
.band-label {
  font-size: 14px;
  color: var(--tg-theme-hint-color);
  margin-top: 4px;
}

.criteria-list { margin-bottom: var(--gap); }
.criterion {
  padding: 10px 0;
  border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
}
.criterion:last-child { border-bottom: none; }
.criterion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.criterion-name { font-size: 14px; font-weight: 500; }
.criterion-score { font-size: 14px; font-weight: 700; }
.criterion-bar {
  width: 100%; height: 6px;
  background: var(--tg-theme-secondary-bg-color);
  border-radius: 3px;
  overflow: hidden;
}
.criterion-bar-fill {
  height: 100%;
  background: var(--tg-theme-button-color);
  border-radius: 3px;
  transition: width 0.6s ease;
}

.feedback-section { margin-bottom: var(--gap); }
.feedback-item {
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--tg-theme-secondary-bg-color);
}
.feedback-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--tg-theme-secondary-bg-color);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.feedback-header .chevron {
  transition: transform var(--transition);
  color: var(--tg-theme-hint-color);
}
.feedback-header.open .chevron { transform: rotate(180deg); }
.feedback-body {
  display: none;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--tg-theme-hint-color);
}
.feedback-body.open { display: block; }
.fb-explanation {
  margin: 0 0 10px;
  color: var(--tg-theme-text-color);
}
.fb-example {
  padding: 6px 0;
  border-top: 1px solid var(--tg-theme-secondary-bg-color);
  font-size: 13px;
  line-height: 1.5;
}
.fb-example:first-of-type { border-top: none; }

/* ── Stats screen ── */
.stats-summary {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
  text-align: center;
}
.stats-row {
  display: flex;
  justify-content: space-around;
  gap: 8px;
  margin-top: 12px;
}
.stats-item { text-align: center; }
.stats-value { font-size: 24px; font-weight: 700; }
.stats-key   { font-size: 12px; color: var(--tg-theme-hint-color); }

.recent-list { flex: 1; overflow-y: auto; }
.recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
  font-size: 14px;
}
.recent-item:last-child { border-bottom: none; }
.recent-part { color: var(--tg-theme-hint-color); font-size: 13px; }
.recent-band { font-weight: 700; }

/* ── Error toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #e74c3c;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ── Utility ── */
.spacer { flex: 1; }
.text-hint { color: var(--tg-theme-hint-color); font-size: 14px; }
.mt-auto { margin-top: auto; }

/* ── Menu description ── */
.menu-description {
  font-size: 14px;
  color: var(--tg-theme-hint-color);
  text-align: center;
  padding: 8px 4px 0;
  line-height: 1.5;
}

/* ── Full Speaking / main action button ── */
.full-speaking-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  padding: 18px 20px;
  margin-bottom: 12px;
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  min-height: 72px;
  transition: opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.full-speaking-btn:active { opacity: 0.7; }
.full-speaking-sub {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.85;
}

/* ── Parts menu button (secondary on main menu) ── */
.menu-parts-btn {
  margin-bottom: 6px;
}

/* ── Stats button ── */
.stats-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
  padding: 12px;
  color: var(--tg-theme-link-color);
  font-size: 15px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

/* ── Full Speaking progress indicator ── */
.full-progress-bar {
  display: flex;
  gap: 8px;
  margin-bottom: var(--gap);
}
.full-progress-step {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--tg-theme-secondary-bg-color);
  font-size: 16px;
  opacity: 0.4;
  transition: opacity var(--transition), background var(--transition);
}
.full-progress-step.done {
  background: var(--tg-theme-button-color);
  opacity: 0.6;
}
.full-progress-step.active {
  background: var(--tg-theme-button-color);
  opacity: 1;
}

/* ── Full results panels ── */
.full-result-panel {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.full-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.full-result-part { font-size: 14px; font-weight: 600; }
.full-result-band {
  font-size: 18px;
  font-weight: 800;
  color: var(--tg-theme-button-color);
}
.criterion-compact { padding: 5px 0; }
.criterion-compact .criterion-name { font-size: 12px; }
.criterion-compact .criterion-score { font-size: 12px; }

/* ── Recording time limit indicator ── */
.record-limit {
  font-size: 12px;
  color: var(--tg-theme-hint-color);
  text-align: center;
}
