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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3e;
  --accent: #6c63ff;
  --accent-hover: #574fd6;
  --text: #e8eaf0;
  --muted: #7b7f9a;
  --success: #4caf82;
  --error: #e05c5c;
  --radius: 12px;
  --font: 'Inter', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Layout ── */
#app { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

.screen { display: none; flex: 1; }
.screen.active { display: flex; }

/* ── Auth screen ── */
#screen-auth {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.auth-box h1 {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.auth-box .subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 28px;
}

.ui-lang-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}
.ui-lang-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-family: var(--font);
  padding: 5px 28px 5px 10px;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%237b7f9a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.ui-lang-select:focus { border-color: var(--accent); }
.ui-lang-select option { background: var(--surface); }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 24px;
}

.tab-btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all .2s;
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color .2s;
}

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

.form-select {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  cursor: pointer;
  transition: border-color .2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%237b7f9a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.form-select:focus { border-color: var(--accent); }
.form-select option { background: var(--surface); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.msg {
  font-size: 0.85rem;
  padding: 10px 14px;
  border-radius: 8px;
  margin-top: 14px;
  display: none;
}
.msg.error { background: #3d1a1a; color: var(--error); display: block; }
.msg.success { background: #1a3d2e; color: var(--success); display: block; }

/* ── Dashboard ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.topbar .logo { font-weight: 700; font-size: 1.1rem; color: var(--accent); }

.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--muted);
}

.level-badge {
  background: var(--accent);
  color: #fff;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
}

.lang-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}

.btn-settings {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: all .2s;
  display: flex; align-items: center; justify-content: center;
}
.btn-settings:hover { border-color: var(--accent); color: var(--accent); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 90%; max-width: 340px;
}
.modal-card h3 { font-size: 1.1rem; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn-cancel {
  flex: 1; padding: 10px; border: 1px solid var(--border);
  border-radius: 8px; background: transparent; color: var(--muted);
  font-size: 0.9rem; cursor: pointer; transition: all .2s;
}
.btn-cancel:hover { border-color: var(--text); color: var(--text); }
.btn-save {
  flex: 1; padding: 10px; border: none;
  border-radius: 8px; background: var(--accent); color: #fff;
  font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: background .2s;
}
.btn-save:hover { background: var(--accent-hover); }
.btn-save:disabled { opacity: .5; cursor: not-allowed; }

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all .2s;
}
.btn-logout:hover { border-color: var(--error); color: var(--error); }

#screen-dashboard { height: 100vh; height: 100dvh; overflow: hidden; flex-direction: column; }

.dashboard-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 24px;
  min-height: 0;
  overflow-y: auto;
}

.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  text-align: center;
  max-width: 520px;
  width: 100%;
}

.welcome-card h2 { font-size: 1.25rem; margin-bottom: 4px; }
.welcome-card p { color: var(--muted); margin-bottom: 14px; line-height: 1.5; font-size: 0.9rem; }

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

.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  text-align: center;
  min-width: 80px;
}

.stat .val { font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.stat .lbl { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

.level-section {
  margin-bottom: 16px;
  text-align: left;
}
.level-buttons {
  display: flex;
  gap: 8px;
}
.level-btn {
  flex: 1;
  padding: 7px 0;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.level-btn:hover { border-color: var(--accent); color: var(--accent); }
.level-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.topic-section {
  margin-bottom: 16px;
  text-align: left;
}
.topic-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 8px 0;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.topic-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.topic-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all .15s;
}
.topic-btn:hover { border-color: var(--accent); color: var(--accent); }
.topic-btn.selected { background: var(--accent); color: #fff; border-color: var(--accent); }
.topic-icon { font-size: 0.85rem; }

.start-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-start {
  flex: 1;
  background: var(--accent);
  color: #fff;
  padding: 11px 28px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all .2s;
}
.btn-start:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-history {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all .2s;
  flex-shrink: 0;
}
.btn-history:hover { border-color: var(--accent); color: var(--accent); }

/* ── History screen ── */
#screen-history { flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.history-list::-webkit-scrollbar { display: none; }
.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .15s;
  display: flex;
  align-items: center;
  gap: 14px;
}
.history-card:hover { border-color: var(--accent); }
.history-card-info { flex: 1; min-width: 0; }
.history-card-topic {
  font-weight: 600;
  font-size: 0.93rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-card-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 3px;
}
.history-card-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.history-accuracy {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
}
.history-msgs {
  font-size: 0.75rem;
  color: var(--muted);
}
.history-empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 60px 20px;
}

/* ── Paywall ── */
.paywall-card { max-width: 520px; text-align: center; }
.paywall-sub { color: var(--muted); margin: 6px 0 24px; font-size: 0.92rem; }
.plans-grid { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.plan-card {
  flex: 1;
  min-width: 130px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 14px;
  position: relative;
}
.plan-card.plan-featured { border-color: var(--accent); }
.plan-badge {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.plan-name { font-weight: 700; font-size: 1rem; margin-bottom: 6px; }
.plan-price { font-size: 1.6rem; font-weight: 700; color: var(--accent); line-height: 1.1; }
.plan-price span { font-size: 0.75rem; color: var(--muted); font-weight: 400; }
.plan-desc { font-size: 0.78rem; color: var(--muted); margin: 6px 0 14px; }
.btn-plan {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background .2s;
}
.btn-plan:hover { background: var(--accent-hover); }

/* ── Chat screen ── */
#screen-chat { flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.btn-back {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all .2s;
}
.btn-back:hover { border-color: var(--accent); color: var(--accent); }

.chat-topic { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; }
.chat-topic-label { color: var(--muted); }
#chat-topic-text { color: var(--text); font-weight: 600; }

.btn-end-session {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all .2s;
}
.btn-end-session:hover { border-color: var(--error); color: var(--error); }

.chat-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.chat-body::-webkit-scrollbar { display: none; }

.chat-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex: 1;
  color: var(--muted);
  font-size: 0.9rem;
}

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bubble {
  max-width: min(72%, calc(100vw - 48px));
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.93rem;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: break-word;
}

.bubble.ai {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.btn-play {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 0.73rem;
  cursor: pointer;
  transition: all .2s;
  line-height: 1.7;
  white-space: nowrap;
}
.btn-play:hover, .btn-play.speaking { border-color: var(--accent); color: var(--accent); }

.bubble-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-reply {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 3px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.btn-reply:hover { background: var(--accent-hover); }

.kword { border-radius: 3px; transition: background .1s, color .1s; }
.k-active { background: var(--accent); color: #fff; padding: 0 2px; margin: 0 -2px; }
.bubble.user .k-active { background: #fff; color: var(--accent); border-radius: 3px; }

.bubble.user {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.bubble.user .btn-play {
  border-color: rgba(255,255,255,.5);
  color: rgba(255,255,255,.9);
}
.bubble.user .btn-play:hover,
.bubble.user .btn-play.speaking {
  border-color: #fff;
  color: #fff;
}

.bubble-typing {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  padding: 14px 18px;
}
.typing-dots { display: flex; gap: 5px; }
.typing-dots span {
  width: 7px; height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce .9s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .30s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

.chat-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.btn-mic {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 44px; height: 44px;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all .2s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-mic:hover:not(:disabled) { border-color: var(--accent); }
.btn-mic.recording { border-color: #e53e3e; background: #e53e3e; animation: pulse-mic .8s infinite; }
.btn-mic:disabled { opacity: .4; cursor: not-allowed; }
@keyframes pulse-mic { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }

.feedback-bar {
  min-height: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  font-size: 0.82rem;
  color: #f0b429;
  transition: max-height .2s ease, opacity .2s ease, padding .2s ease;
}
.feedback-bar.visible {
  padding: 8px 16px;
  max-height: 60px;
  opacity: 1;
  background: #2a220a;
  border-bottom: 1px solid #3d3010;
}

.voice-transcript {
  padding: 10px 16px 8px;
  min-height: 40px;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}
.vword { display: inline; }
.vword.interim { color: var(--muted); font-style: italic; }
.vword.error { color: #e53e3e; font-weight: 600; }

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
}

#chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.93rem;
  padding: 10px 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color .2s;
}
#chat-input:focus { border-color: var(--accent); }
#chat-input:disabled { opacity: .4; cursor: not-allowed; }

.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 44px; height: 44px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all .2s;
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--accent-hover); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; }

/* ── Session end overlay ── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.overlay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  text-align: center;
  max-width: 360px;
  width: 90%;
}
.overlay-card h3 { font-size: 1.3rem; margin-bottom: 8px; }
.overlay-card p { color: var(--muted); margin-bottom: 24px; font-size: 0.9rem; }
.overlay-stats { display: flex; gap: 16px; justify-content: center; margin-bottom: 28px; }
.overlay-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 28px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.overlay-btn:hover { background: var(--accent-hover); }

/* ── Mobile ── */
@media (max-width: 480px) {
  .topbar { padding: 8px 14px; }
  .welcome-card { padding: 16px 14px; }
  .stats-row { gap: 6px; }
  .stat { padding: 8px 10px; min-width: 64px; }
  .stat .val { font-size: 1rem; }
  .chat-topbar { padding: 8px 12px; }
  .chat-footer { padding: 0; }
  .bubble { max-width: calc(100vw - 36px); }
  .plans-grid { flex-direction: column; }
}
