/* ── Telegram theme variables ───────────────────────────────── */
:root {
  --tg-bg:           var(--tg-theme-bg-color, #ffffff);
  --tg-text:         var(--tg-theme-text-color, #000000);
  --tg-hint:         var(--tg-theme-hint-color, #707579);
  --tg-link:         var(--tg-theme-link-color, #2481cc);
  --tg-btn:          var(--tg-theme-button-color, #2481cc);
  --tg-btn-text:     var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f1);

  --radius:    16px;
  --radius-sm: 10px;
  --shadow:    0 2px 12px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  min-height: 100vh;
  overscroll-behavior: none;
}

/* ── Screens ─────────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  padding: 16px;
  padding-bottom: 28px;
}
.screen.active { display: flex; }

/* Chat-style screen (study): fixed height, scrollable body */
.screen-chat {
  height: 100vh;
  min-height: unset;
  overflow: hidden;
  padding: 16px 16px 0;
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-shrink: 0;
}
.header-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--tg-btn);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.header-info { flex: 1; min-width: 0; }
.header-title { font-size: 17px; font-weight: 700; }
.header-sub   { font-size: 13px; color: var(--tg-hint); }

.btn-back {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--tg-btn);
  cursor: pointer;
  padding: 4px 8px 4px 0;
  flex-shrink: 0;
  border-radius: 8px;
  transition: background 0.15s;
}
.btn-back:active { background: rgba(0,0,0,0.06); }

/* ── Progress bar ─────────────────────────────────────────────── */
.progress-bar-wrap {
  height: 3px;
  background: var(--tg-secondary-bg);
  border-radius: 2px;
  margin: -10px 0 14px;
  overflow: hidden;
  flex-shrink: 0;
}
.progress-bar-fill {
  height: 100%;
  background: var(--tg-btn);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

/* ── Section label ────────────────────────────────────────────── */
.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--tg-hint);
  margin-bottom: 10px;
}

/* ── Deck list ────────────────────────────────────────────────── */
#screen-decks { gap: 6px; }

.deck-item {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.1s;
}
.deck-item:active { background: rgba(0,0,0,0.07); }
.deck-icon   { font-size: 24px; flex-shrink: 0; }
.deck-body   { flex: 1; min-width: 0; }
.deck-name   { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.deck-meta   { font-size: 13px; color: var(--tg-hint); }
.deck-arrow  { font-size: 18px; color: var(--tg-hint); flex-shrink: 0; }

/* ── Mode selection ───────────────────────────────────────────── */
.mode-list { display: flex; flex-direction: column; gap: 6px; }

.mode-card {
  background: var(--tg-secondary-bg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  width: 100%;
  transition: background 0.1s;
}
.mode-card:active { background: rgba(0,0,0,0.07); }
.mode-icon  { font-size: 22px; flex-shrink: 0; }
.mode-body  { flex: 1; }
.mode-title { font-size: 15px; font-weight: 600; color: var(--tg-text); margin-bottom: 2px; }
.mode-desc  { font-size: 13px; color: var(--tg-hint); line-height: 1.3; }
.mode-arrow { font-size: 20px; color: var(--tg-hint); flex-shrink: 0; }

/* ── Study screen (chat layout) ───────────────────────────────── */
.chat-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 10px;
}

/* Task card (question) */
.task-card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 16px;
  flex-shrink: 0;
}
.task-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--tg-hint);
  margin-bottom: 8px;
}
.task-text {
  font-size: 16px;
  line-height: 1.5;
  font-weight: 500;
}

/* Chat message bubbles */
.msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}
.msg-user {
  align-self: flex-end;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border-bottom-right-radius: 4px;
}
.msg-bot {
  align-self: flex-start;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border-bottom-left-radius: 4px;
}
.msg-thinking {
  align-self: flex-start;
  background: var(--tg-secondary-bg);
  color: var(--tg-hint);
  font-style: italic;
  border-bottom-left-radius: 4px;
}

.score-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.score-num-big { font-size: 22px; font-weight: 700; }
.score-good    { color: #2dc55e; }
.score-ok      { color: #ff9800; }
.score-bad     { color: #e53935; }
.score-label   { font-size: 13px; color: var(--tg-hint); }

.correct-answer-block {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0,0,0,0.08);
  font-size: 13px;
  color: var(--tg-hint);
}
.correct-answer-block strong { color: var(--tg-text); font-size: 14px; }

/* ── Input area ───────────────────────────────────────────────── */
.input-area {
  border-top: 1px solid rgba(0,0,0,0.07);
  padding: 12px 0 max(16px, env(safe-area-inset-bottom, 16px));
  flex-shrink: 0;
  background: var(--tg-bg);
}

.input-mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  width: 100%;
}
.input-mode-tabs-sm { margin-bottom: 8px; }

.tab-btn {
  flex: 1;
  padding: 10px;
  border: 1.5px solid rgba(0,0,0,0.12);
  border-radius: var(--radius-sm);
  background: var(--tg-secondary-bg);
  color: var(--tg-hint);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.tab-btn.tab-active {
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border-color: var(--tg-btn);
}

.voice-confirm-box {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
  display: none;
}
.voice-confirm-box.visible { display: block; }
.voice-confirm-label {
  font-size: 12px;
  color: var(--tg-hint);
  margin-bottom: 6px;
}
.voice-text-edit {
  width: 100%;
  background: var(--tg-bg);
  border: 1.5px solid var(--tg-btn);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  color: var(--tg-text);
  resize: none;
  min-height: 64px;
  font-family: inherit;
  outline: none;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.btn-confirm {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-confirm:active { opacity: 0.75; }
.btn-send     { background: var(--tg-btn); color: var(--tg-btn-text); }
.btn-rerecord { background: var(--tg-secondary-bg); color: var(--tg-text);
                border: 1.5px solid rgba(0,0,0,0.12); }

/* Microphone button */
.mic-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.btn-mic {
  width: 62px; height: 62px;
  border-radius: 50%;
  border: none;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  font-size: 28px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn-mic:active { transform: scale(0.94); }
.btn-mic.recording {
  background: #e53935;
  animation: pulse 1.2s infinite;
}
.btn-mic.disabled { background: var(--tg-hint); cursor: not-allowed; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(229,57,53,0.5); }
  70%  { box-shadow: 0 0 0 14px rgba(229,57,53,0); }
  100% { box-shadow: 0 0 0 0 rgba(229,57,53,0); }
}
.mic-hint { font-size: 14px; color: var(--tg-hint); line-height: 1.4; }

/* Text input row */
.text-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-text-area {
  flex: 1;
  background: var(--tg-secondary-bg);
  border: 1.5px solid var(--tg-btn);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  color: var(--tg-text);
  resize: none;
  min-height: 48px;
  max-height: 120px;
  font-family: inherit;
  outline: none;
}
.btn-send-text {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s;
}
.btn-send-text:active { opacity: 0.75; }

/* ── Primary / secondary buttons ─────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 15px;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:active   { opacity: 0.8; }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  padding: 14px;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border: 1.5px solid rgba(0,0,0,0.12);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:active { background: rgba(0,0,0,0.06); }

/* ── Match mode ───────────────────────────────────────────────── */
#screen-match { gap: 0; }
.match-instructions {
  font-size: 14px;
  color: var(--tg-hint);
  margin-bottom: 12px;
  text-align: center;
}
.match-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex: 1;
  align-content: start;
  margin-bottom: 16px;
}
.match-col { display: flex; flex-direction: column; gap: 6px; }
.match-card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.12s;
  text-align: center;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-word;
}
.match-card.selected      { border-color: var(--tg-btn); background: rgba(36,129,204,0.1); }
.match-card.match-correct { background: rgba(45,197,94,0.15); border-color: #2dc55e; }
.match-card.match-wrong   { background: rgba(229,57,53,0.15); border-color: #e53935; }
.pair-0 { border-color: #2481cc; background: rgba(36,129,204,0.12); }
.pair-1 { border-color: #e67e22; background: rgba(230,126,34,0.12); }
.pair-2 { border-color: #8e44ad; background: rgba(142,68,173,0.12); }
.pair-3 { border-color: #27ae60; background: rgba(39,174,96,0.12); }
.match-actions { display: flex; flex-direction: column; gap: 8px; }

/* ── Results ──────────────────────────────────────────────────── */
.results-hero {
  text-align: center;
  padding: 16px 0 12px;
}
.results-score-big {
  font-size: 52px;
  font-weight: 700;
  color: var(--tg-btn);
  line-height: 1;
  margin-bottom: 4px;
}
.results-score-label { font-size: 14px; color: var(--tg-hint); margin-bottom: 6px; }
.results-pts         { font-size: 15px; font-weight: 600; }

.results-list { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.result-icon    { font-size: 18px; flex-shrink: 0; }
.result-body    { flex: 1; min-width: 0; }
.result-concept { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.score-bar-wrap { display: flex; align-items: center; gap: 8px; }
.score-bar      { flex: 1; height: 6px; background: rgba(0,0,0,0.08); border-radius: 3px; overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 3px; }
.score-bar-fill.good { background: #2dc55e; }
.score-bar-fill.ok   { background: #ff9800; }
.score-bar-fill.bad  { background: #e53935; }
.score-num      { font-size: 12px; color: var(--tg-hint); white-space: nowrap; }
.results-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

/* ── Stats ────────────────────────────────────────────────────── */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}
.stats-cat {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
}
.stats-cat-num   { font-size: 22px; font-weight: 700; }
.stats-cat-label { font-size: 11px; color: var(--tg-hint); margin-top: 2px; }
.cat-bad  .stats-cat-num { color: #e53935; }
.cat-ok   .stats-cat-num { color: #ff9800; }
.cat-good .stats-cat-num { color: #2dc55e; }
.cat-new  .stats-cat-num { color: var(--tg-hint); }

.stats-cards-list { display: flex; flex-direction: column; gap: 6px; }
.stat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.stat-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stat-dot-good { background: #2dc55e; }
.stat-dot-ok   { background: #ff9800; }
.stat-dot-bad  { background: #e53935; }
.stat-dot-new  { background: var(--tg-hint); }
.stat-body    { flex: 1; min-width: 0; }
.stat-concept { font-size: 14px; font-weight: 500; }
.stat-meta    { font-size: 12px; color: var(--tg-hint); margin-top: 2px; }
.stat-last    { font-size: 16px; flex-shrink: 0; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  color: var(--tg-hint);
}
.empty-state .big-emoji { font-size: 48px; }
.empty-state p          { font-size: 15px; line-height: 1.5; }

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

.hidden { display: none !important; }
