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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242736;
  --border: #2e3247;
  --accent: #6c8eff;
  --accent-dim: rgba(108, 142, 255, 0.15);
  --danger: #ff5f57;
  --success: #30d158;
  --text: #e8eaf0;
  --text-dim: #8b90a7;
  --text-muted: #555a72;
  --radius: 14px;
  --radius-sm: 8px;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app {
  width: 100%;
  max-width: 560px;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 4px;
}

.header h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }
.header h1 span { color: var(--accent); }

.level-selector { display: flex; gap: 6px; }

.level-btn {
  padding: 5px 11px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.level-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Screens ── */
.screen { display: none; flex-direction: column; gap: 16px; }
.screen.active { display: flex; }

/* ── Topic grid ── */
.topic-intro { text-align: center; padding: 8px 0 4px; }
.topic-intro p { color: var(--text-dim); font-size: 14px; line-height: 1.5; }

.topic-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.topic-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}

.topic-card:hover, .topic-card:active {
  background: var(--surface2);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.topic-icon { font-size: 24px; margin-bottom: 8px; }
.topic-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.topic-card p { font-size: 12px; color: var(--text-muted); }

/* ── Practice screen ── */
.progress-bar-wrap { display: flex; align-items: center; gap: 10px; }

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

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

.progress-text { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.topic-badge { display: flex; align-items: center; gap: 8px; }

.topic-badge button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  padding: 2px 0;
  transition: color 0.15s;
}

.topic-badge button:hover { color: var(--text); }
.topic-badge span { font-size: 13px; color: var(--text-dim); }

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.question-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.question-text { font-size: 17px; font-weight: 500; line-height: 1.5; }

.speak-btn {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.speak-btn:hover { border-color: var(--accent); color: var(--accent); }
.speak-btn.speaking { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }

/* ── Record area ── */
.record-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.record-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background: var(--surface2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  transition: all 0.2s;
  position: relative;
}

.record-btn::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: all 0.2s;
}

.record-btn:hover::before { border-color: var(--accent); inset: -6px; }

.record-btn.recording {
  background: rgba(255, 95, 87, 0.15);
  animation: pulse 1.5s ease-in-out infinite;
}

.record-btn.recording::before { border-color: var(--danger); inset: -6px; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 95, 87, 0.4); }
  50% { box-shadow: 0 0 0 14px rgba(255, 95, 87, 0); }
}

.record-hint { font-size: 13px; color: var(--text-muted); text-align: center; }

/* ── Transcript ── */
.transcript-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 80px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  position: relative;
}

.transcript-box.empty::after {
  content: 'Hier erscheint dein gesprochener Text...';
  color: var(--text-muted);
  font-size: 14px;
}

.transcript-box[contenteditable="true"] { outline: none; cursor: text; border-color: var(--accent); }

/* ── Buttons ── */
.actions { display: flex; gap: 10px; }

.btn {
  flex: 1;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

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

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { filter: none; }

.btn-download { border-color: var(--success); display: flex; align-items: center; justify-content: center; gap: 4px; }
.btn-download:not(:disabled):hover { background: rgba(48, 209, 88, 0.12); }
.dl-arrow { color: var(--success); font-size: 22px; font-weight: 900; line-height: 1; }
.dl-label { color: var(--text-dim); font-size: 13px; }
.dl-icon  { color: var(--accent); font-size: 15px; }

/* ── Feedback ── */
.feedback-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: none;
  flex-direction: column;
  gap: 12px;
}

.feedback-box.visible { display: flex; }

.feedback-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
}

.feedback-content { font-size: 14px; line-height: 1.7; color: var(--text-dim); }
.feedback-content strong { color: var(--text); }
.feedback-content h3 { font-size: 13px; color: var(--text); margin: 10px 0 4px; }
.feedback-content ul { padding-left: 18px; }
.feedback-content li { margin-bottom: 4px; }
.feedback-content code { background: var(--surface2); padding: 1px 6px; border-radius: 4px; font-size: 13px; }

.loading-dots { display: flex; gap: 5px; align-items: center; }

.loading-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-bounce 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── History ── */
.history-section { display: none; flex-direction: column; gap: 10px; }
.history-section.has-items { display: flex; }

.history-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.history-list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.history-item:hover { border-color: var(--accent); }
.history-item .hi-q { color: var(--text-dim); margin-bottom: 4px; }
.history-item .hi-a { color: var(--text); }

/* ── Done screen ── */
.done-screen { text-align: center; padding: 40px 0; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.done-screen .big-icon { font-size: 56px; }
.done-screen h2 { font-size: 22px; font-weight: 600; }
.done-screen p { color: var(--text-dim); font-size: 15px; line-height: 1.5; }

.stats-row { display: flex; gap: 16px; justify-content: center; }

.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px; text-align: center; }
.stat-box .stat-val { font-size: 24px; font-weight: 600; color: var(--accent); }
.stat-box .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
