/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #f6f5f8;
  --bg-elev: #ffffff;
  --bg-sunken: #eeecf2;
  --ink: #1a1725;
  --ink-soft: #5c566e;
  --ink-faint: #8b849e;
  --line: #e3e0ea;
  --brand: #5b4bdb;
  --brand-ink: #ffffff;
  --brand-soft: #ede9ff;
  --accent: #0f9b8e;
  --accent-soft: #dff5f2;
  --warn: #c2410c;
  --warn-soft: #fff0e6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(26, 23, 37, 0.06), 0 8px 24px rgba(26, 23, 37, 0.06);
  --shadow-sm: 0 1px 2px rgba(26, 23, 37, 0.07);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131120;
    --bg-elev: #1c1930;
    --bg-sunken: #100e1b;
    --ink: #f0eef7;
    --ink-soft: #b4aecb;
    --ink-faint: #837c9c;
    --line: #2c2745;
    --brand: #8b7cf6;
    --brand-ink: #14102a;
    --brand-soft: #262046;
    --accent: #3ddbc8;
    --accent-soft: #10322f;
    --warn: #fb923c;
    --warn-soft: #35210f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ----------------------------------------------------------------- screens */
.screen {
  display: none;
  height: 100dvh;
  overflow-y: auto;
  animation: rise 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.screen--active { display: block; }
.screen--chat.screen--active { display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* -------------------------------------------------------------- onboarding */
.onboard {
  max-width: 560px;
  margin: 0 auto;
  padding: clamp(32px, 7vh, 72px) 20px 64px;
}

.onboard__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.brand__mark {
  font-size: 26px;
  background: var(--brand-soft);
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
}
.brand__name {
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
}

.onboard__title {
  font-size: clamp(28px, 5vw, 40px);
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin: 0 0 14px;
  font-weight: 700;
}
.onboard__title em {
  font-style: normal;
  color: var(--brand);
}
.onboard__lede {
  color: var(--ink-soft);
  margin: 0 0 30px;
  font-size: 17px;
}

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.form { display: grid; gap: 22px; }

.field { display: grid; gap: 8px; border: 0; padding: 0; margin: 0; }
.field__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  padding: 0;
}
.field__hint {
  font-weight: 400;
  color: var(--ink-faint);
  font-size: 13px;
}

.field__input {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field__input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}

/* ------------------------------------------------------------------ levels */
.levels { display: grid; gap: 8px; }

.level {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.level:hover { border-color: var(--brand); }
.level input { position: absolute; opacity: 0; pointer-events: none; }
.level__id {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 2px 7px;
  border-radius: 6px;
  flex: none;
}
.level__label { font-weight: 600; font-size: 14px; }
.level__blurb {
  color: var(--ink-faint);
  font-size: 13px;
  display: block;
}
.level--on {
  border-color: var(--brand);
  background: var(--brand-soft);
}

/* ----------------------------------------------------------------- buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.12s, opacity 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--brand);
  color: var(--brand-ink);
  padding: 13px 20px;
  font-size: 15px;
}
.btn--full { width: 100%; }

.btn--send {
  background: var(--brand);
  color: var(--brand-ink);
  width: 44px;
  height: 44px;
  flex: none;
  font-size: 16px;
  display: grid;
  place-items: center;
  border-radius: 12px;
}

.iconbtn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 17px;
  cursor: pointer;
  flex: none;
  transition: background 0.15s;
}
.iconbtn:hover { background: var(--bg-sunken); }

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar__title { display: grid; min-width: 0; flex: 1; }
.topbar__title strong {
  font-size: 16px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__sub { font-size: 13px; color: var(--ink-faint); }

.streak {
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--bg-sunken);
  padding: 6px 11px;
  border-radius: 999px;
  white-space: nowrap;
  flex: none;
}

/* --------------------------------------------------------------- scenarios */
.scenarios {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  padding: 20px;
  max-width: 900px;
  margin: 0 auto;
}

.scenario {
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.scenario:hover {
  transform: translateY(-2px);
  border-color: var(--brand);
  box-shadow: var(--shadow);
}
.scenario__icon { font-size: 26px; display: block; margin-bottom: 10px; }
.scenario__title { font-weight: 650; font-size: 15.5px; margin-bottom: 3px; letter-spacing: -0.01em; }
.scenario__sub { color: var(--ink-faint); font-size: 13.5px; line-height: 1.4; }

/* -------------------------------------------------------------------- chat */
.chat {
  overflow-y: auto;
  padding: 24px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}
.chat__inner { max-width: 720px; margin: 0 auto; width: 100%; }

.turn {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  animation: rise 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15.5px;
  max-width: 78%;
  width: fit-content;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.turn--tutor .bubble {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.turn--user { display: flex; flex-direction: column; align-items: flex-end; }
.turn--user .bubble {
  background: var(--brand);
  color: var(--brand-ink);
  border-bottom-right-radius: 6px;
}

.speakbtn {
  background: none;
  border: 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-faint);
  padding: 4px 6px;
  margin-top: 2px;
  border-radius: 6px;
}
.speakbtn:hover { color: var(--brand); background: var(--brand-soft); }

/* --------------------------------------------------------- correction card */
.feedback {
  margin-top: 10px;
  max-width: 78%;
  margin-left: auto;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.feedback__head {
  font-size: 12.5px;
  font-weight: 600;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-bottom: 1px solid var(--line);
}
.feedback--clean .feedback__head { color: var(--accent); background: var(--accent-soft); border-bottom: 0; }
.feedback--fix .feedback__head { color: var(--warn); background: var(--warn-soft); }

.fix { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.fix:last-child { border-bottom: 0; }
.fix__line { font-size: 14.5px; margin-bottom: 5px; line-height: 1.5; }
.fix__was {
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--warn) 65%, transparent);
  color: var(--ink-faint);
}
.fix__arrow { color: var(--ink-faint); margin: 0 7px; font-size: 12px; }
.fix__now { color: var(--accent); font-weight: 650; }
.fix__why { font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; }
.fix__tag {
  display: inline-block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--ink-faint);
  background: var(--bg-sunken);
  padding: 2px 6px;
  border-radius: 5px;
  margin-left: 6px;
  vertical-align: 1px;
}

.praise {
  font-size: 13.5px;
  color: var(--accent);
  padding: 10px 14px;
  background: var(--accent-soft);
}

/* --------------------------------------------------------------- composer */
.composer {
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 12px 18px 14px;
}
.composer__row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 720px;
  margin: 0 auto;
}
.composer__input {
  flex: 1;
  font: inherit;
  font-size: 15.5px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  resize: none;
  max-height: 160px;
  line-height: 1.5;
}
.composer__input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
.composer__hint {
  max-width: 720px;
  margin: 8px auto 0;
  font-size: 11.5px;
  color: var(--ink-faint);
  text-align: center;
}
kbd {
  font-family: inherit;
  background: var(--bg-sunken);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
}

.suggestion {
  max-width: 720px;
  margin: 0 auto 10px;
  font-size: 13.5px;
  color: var(--ink-soft);
  background: var(--brand-soft);
  border-radius: 10px;
  padding: 9px 13px;
}
.suggestion strong { color: var(--brand); font-weight: 650; }

/* ---------------------------------------------------------------- thinking */
.dots { display: inline-flex; gap: 4px; padding: 4px 2px; }
.dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  animation: blink 1.3s infinite ease-in-out both;
}
.dots span:nth-child(2) { animation-delay: 0.16s; }
.dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ------------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 50;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}

/* ------------------------------------------------------------------ mobile */
@media (max-width: 560px) {
  .bubble, .feedback { max-width: 88%; }
  .scenarios { grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px; }
  .scenario { padding: 14px; }
  .scenario__icon { font-size: 22px; margin-bottom: 6px; }
  .scenario__sub { display: none; }
  .composer__hint { display: none; }
  .streak { display: none; }
}
