:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --border: #262b35;
  --text: #e8eaed;
  --text-dim: #8a90a0;
  --accent: #4f7cff;
  --accent-dim: #2c3a66;
  --user-bubble: #1f2937;
  --ai-bubble: #17233d;
  --correction: #ffb454;
  --danger: #ff5f5f;
  --success: #4ade80;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 8px;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.nav-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 14px 0 12px;
  flex-shrink: 0;
}

.avatar {
  position: relative;
  width: 108px;
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, var(--accent-dim), transparent 70%);
  border: 2px solid var(--border);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.talk-btn {
  position: relative;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(160deg, var(--accent), #345bd6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(79, 124, 255, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.3s ease, opacity 0.2s ease;
}

.talk-btn[hidden] {
  display: none;
}

.talk-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.talk-btn:active:not(:disabled) {
  transform: scale(0.96);
}

/* Listening state — user is talking */
.avatar.listening .avatar-ring {
  border-color: var(--accent);
  box-shadow: 0 0 0 8px rgba(79, 124, 255, 0.12);
}

.avatar.listening .talk-btn {
  background: linear-gradient(160deg, #ff5f5f, #d63b3b);
  box-shadow: 0 6px 24px rgba(255, 95, 95, 0.4);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Thinking state — waiting on Claude/TTS/STT */
.avatar.thinking .talk-btn {
  opacity: 0.5;
}

.avatar.thinking .avatar-ring {
  animation: spin 1.6s linear infinite;
  border-color: transparent;
  border-top-color: var(--accent);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Speaking state — Аня's voice playing */
.avatar.speaking .avatar-ring {
  border-color: var(--accent);
  animation: speak-pulse 1s ease-in-out infinite;
}

@keyframes speak-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79, 124, 255, 0.35); }
  50% { box-shadow: 0 0 0 14px rgba(79, 124, 255, 0); }
}

.status-text {
  color: var(--text-dim);
  font-size: 0.9rem;
  min-height: 1.2em;
  text-align: center;
  padding: 0 20px;
}

.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Welcome / last-session blurb */
.blurb {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.5;
  max-width: 380px;
  margin: 0 auto;
}

/* Topic chips */
.chip-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.chip:hover, .chip:active {
  border-color: var(--accent);
}

.chip .chip-name {
  font-weight: 600;
}

.chip .chip-desc {
  display: block;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 400;
  margin-top: 2px;
}

.chip .chip-progress {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

/* Lesson phrase card */
.lesson-progress {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.phrase-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 20px;
  text-align: center;
}

.phrase-ru {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 8px;
  line-height: 1.3;
}

.phrase-en {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin: 0;
}

.example-card {
  background: var(--ai-bubble);
  border-radius: 14px;
  padding: 16px 18px;
  text-align: center;
}

.example-card .example-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.example-card .example-text {
  font-size: 1.1rem;
  font-weight: 500;
  white-space: pre-line;
  line-height: 1.4;
}

.feedback-line {
  text-align: center;
  font-size: 0.9rem;
  min-height: 1.3em;
}

.feedback-line.good { color: var(--success); }
.feedback-line.retry { color: var(--correction); }

/* Free conversation bubbles */
.bubble-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.bubble.ai {
  align-self: flex-start;
  background: var(--ai-bubble);
  border-bottom-left-radius: 4px;
}

.bubble .correction {
  display: block;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(255, 180, 84, 0.4);
  color: var(--correction);
  font-size: 0.85rem;
  font-style: italic;
}

.bubble.error {
  background: rgba(255, 95, 95, 0.12);
  color: var(--danger);
  align-self: center;
  font-size: 0.85rem;
}

/* Recap */
.recap-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recap-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.recap-item .recap-phrase {
  font-weight: 600;
}

.recap-item .recap-en {
  display: block;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 400;
}

.status-badge {
  flex-shrink: 0;
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-badge.learned {
  color: var(--success);
  background: rgba(74, 222, 128, 0.12);
}

.status-badge.learning {
  color: var(--correction);
  background: rgba(255, 180, 84, 0.12);
}

.recap-summary {
  color: var(--text-dim);
  font-size: 0.88rem;
  text-align: center;
  line-height: 1.5;
}

/* Primary action dock (Begin / Finish / recap choices) */
.primary-action {
  display: flex;
  gap: 10px;
  padding: 10px 20px calc(env(safe-area-inset-bottom, 0px) + 18px);
  flex-shrink: 0;
}

.primary-action:empty {
  display: none;
}

.btn {
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(160deg, var(--accent), #345bd6);
  color: white;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.error-banner {
  background: rgba(255, 95, 95, 0.12);
  color: var(--danger);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.85rem;
  text-align: center;
}
