:root {
  --teal: #5ce0e5;
  --blue: #024caf;
  --gold: #f7c224;
  --aubergine: #2a1b30;
  --rose: #8b3e68;
  --bg: #160e1a;
  --card: #2a1b30;
  --card-2: #34233c;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f6f1f8;
  --muted: #b9a9c2;
  --good: #4fd1a5;
  --warn: #f7c224;
  --bad: #ff7a8a;
  --gradient: linear-gradient(120deg, var(--teal), var(--blue));
  --radius: 16px;
  --font-ar: "Tajawal", system-ui, sans-serif;
  --font-en: "Poppins", system-ui, sans-serif;
  --font-display: "Bebas Neue", "Poppins", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ar);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
html[lang="en"] body { font-family: var(--font-en); font-size: 15px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(22, 14, 26, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.wordmark {
  font-family: var(--font-display);
  font-size: 32px; letter-spacing: 1px; line-height: 1;
  text-decoration: none;
  background: var(--gradient);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.lang-toggle {
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: 14px; color: var(--muted);
}
.lang-toggle:hover { color: var(--text); border-color: var(--teal); }

main { max-width: 720px; margin: 0 auto; padding: 20px 16px 40px; }

/* ---------- shared ---------- */
h1, h2, h3 { margin: 0; line-height: 1.25; }
.hero h1 {
  font-size: 28px; font-weight: 700;
}
html[lang="en"] .hero h1 { font-family: var(--font-display); font-size: 40px; font-weight: 400; letter-spacing: 0.5px; }
.hero p { color: var(--muted); margin: 8px 0 0; }
.section { margin-top: 24px; }
.label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); font-size: 14px; margin-top: 8px; }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 14px 22px; font-weight: 600;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: #24170a; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--teal); }
.btn-block { width: 100%; }

/* ---------- setup ---------- */
.scenarios { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 480px) { .scenarios { grid-template-columns: 1fr; } }
.scenario {
  text-align: start; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 6px;
}
.scenario[aria-pressed="true"] { border-color: var(--teal); background: var(--card-2); }
.scenario .title { font-weight: 700; font-size: 17px; }
.scenario .who { color: var(--muted); font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--gradient) border-box; border-color: transparent; color: #fff; font-weight: 600; }

.toggle { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: var(--muted); font-size: 14px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--teal); }

textarea.goal, .composer textarea, .retry textarea {
  width: 100%; resize: vertical; min-height: 64px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}
textarea:focus { border-color: var(--teal); outline: none; }

.start-row { margin-top: 28px; }

/* ---------- chat ---------- */
.chat-head {
  position: sticky; top: 57px; z-index: 4;
  display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.avatar {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--gradient);
}
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .name { font-weight: 700; }
.chat-head .meta { color: var(--muted); font-size: 13px; }

.messages { display: flex; flex-direction: column; gap: 10px; padding: 16px 0 140px; }
.msg {
  max-width: 85%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word;
}
.msg.persona { align-self: flex-start; background: var(--card-2); border-start-start-radius: 4px; }
.msg.learner { align-self: flex-end; background: var(--rose); border-start-end-radius: 4px; }
.typing { align-self: flex-start; display: flex; gap: 4px; padding: 14px; background: var(--card-2); border-radius: 18px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.composer {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  background: rgba(22, 14, 26, 0.95); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.composer-inner { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 48px; max-height: 140px; resize: none; }
.composer .send { flex: none; padding: 12px 18px; }
.closed-banner { max-width: 720px; margin: 0 auto; display: flex; gap: 12px; align-items: center; justify-content: space-between; }

/* ---------- scoring ---------- */
.scoring { text-align: center; padding: 60px 0; }
.spinner {
  width: 64px; height: 64px; margin: 0 auto 20px; border-radius: 50%;
  border: 4px solid var(--card-2); border-top-color: var(--teal); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- scorecard ---------- */
.score-hero { display: flex; gap: 20px; align-items: center; }
.ring { width: 112px; height: 112px; flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .value {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--font-display); font-size: 40px; letter-spacing: 1px;
}
.ring .value small { font-family: var(--font-en); font-size: 12px; color: var(--muted); display: block; margin-top: -6px; }
.score-hero .summary { flex: 1; }
@media (max-width: 480px) { .score-hero { flex-direction: column; text-align: center; } }

.criteria { display: flex; flex-direction: column; gap: 14px; }
.criterion .row { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.bar { height: 8px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--gradient); }
.criterion details { margin-top: 6px; }
.criterion summary { color: var(--teal); font-size: 14px; cursor: pointer; }
.criterion p { margin: 6px 0 0; color: var(--muted); font-size: 15px; }

.moment { display: flex; flex-direction: column; gap: 10px; }
.quote { border-inline-start: 3px solid var(--rose); padding-inline-start: 12px; font-style: normal; }
.issue { color: var(--muted); }
.better { background: rgba(92, 224, 229, 0.08); border: 1px solid rgba(92, 224, 229, 0.25); border-radius: 12px; padding: 10px 12px; }
.better .tag, .quote .tag { display: block; font-size: 12px; color: var(--teal); margin-bottom: 2px; }
.quote .tag { color: #e3a3c6; }

.strengths { margin: 0; padding-inline-start: 20px; }
.strengths li { margin: 4px 0; }

.retry { border: 2px solid var(--gold); }
.retry h3 { color: var(--gold); }
.verdict { margin-top: 12px; padding: 12px; border-radius: 12px; }
.verdict.good { background: rgba(79, 209, 165, 0.12); border: 1px solid rgba(79, 209, 165, 0.4); }
.verdict.bad { background: rgba(247, 194, 36, 0.1); border: 1px solid rgba(247, 194, 36, 0.4); }

.stack > * + * { margin-top: 16px; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 28px; }
.actions .btn { flex: 1; min-width: 160px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
