/* ============ tokens ============ */
:root {
  --sand: #f7f2e8;
  --sand-2: #ece3d3;
  --ink: #152028;
  --ink-soft: #5a6a71;
  --teal: #0e6b63;
  --teal-700: #0a524c;
  --teal-100: #dceeea;
  --teal-glow: #2aa392;
  --amber: #e2a13c;
  --amber-soft: #fbefd6;
  --amber-ink: #8a5f14;
  --code-bg: #132630;
  --code-ink: #e9f4f0;
  --ok: #1f8a70;
  --ok-soft: #e2f5ee;
  --ok-ink: #0d5c4b;
  --bad: #bf5757;
  --bad-soft: #fbe9e7;
  --bad-ink: #8f3535;
  --card: #ffffff;
  --line: #e4dbcb;
  --radius: 22px;
  --shadow: 0 1px 2px rgba(21, 32, 40, .05), 0 14px 30px -16px rgba(21, 32, 40, .35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* ============ base ============ */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

[hidden] { display: none !important; }
.is-hidden { display: none !important; }

body {
  font-family: "Tajawal", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background-color: var(--sand);
  background-image:
    radial-gradient(880px 460px at 88% -12%, rgba(226, 161, 60, .20), transparent 62%),
    radial-gradient(760px 480px at -12% 6%, rgba(14, 107, 99, .16), transparent 62%),
    radial-gradient(700px 500px at 50% 115%, rgba(14, 107, 99, .10), transparent 65%);
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; -webkit-tap-highlight-color: transparent; }

::selection { background: var(--teal-100); color: var(--teal-700); }

/* ============ layout ============ */
.app {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 22px 18px 44px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen { flex: 1 1 auto; display: flex; flex-direction: column; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.enter { animation: fadeUp .38s cubic-bezier(.22, .8, .3, 1) both; }

/* ============ home ============ */
.screen-home { justify-content: center; }

.home-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 0 4px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, .78);
  color: var(--teal-700);
  border: 1px solid rgba(14, 107, 99, .16);
  font-size: 12.5px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  line-height: 1.4;
}
.eyebrow .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(226, 161, 60, .22);
}

.logo {
  width: 78px; height: 78px;
  margin: 20px 0 16px;
  border-radius: 26px;
  display: grid;
  place-items: center;
  font-size: 40px;
  line-height: 1;
  background: linear-gradient(150deg, #149c8a, #0a524c);
  box-shadow: 0 18px 34px -16px rgba(10, 82, 76, .9), inset 0 1px 0 rgba(255, 255, 255, .35);
}

h1 {
  font-size: 33px;
  font-weight: 800;
  line-height: 1.25;
  margin: 0 0 12px;
  color: var(--ink);
}

.lead {
  margin: 0 0 24px;
  max-width: 40ch;
  font-size: 16.5px;
  line-height: 1.8;
  color: var(--ink-soft);
  font-weight: 500;
}

/* ============ buttons ============ */
.btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 17px;
  border: none;
  border-radius: 16px;
  min-height: 54px;
  padding: 0 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  transition: transform .12s ease, box-shadow .2s ease, background-color .18s ease, color .18s ease, border-color .18s ease;
}
.btn:focus-visible { outline: 3px solid rgba(14, 107, 99, .35); outline-offset: 3px; }
.btn:active { transform: translateY(1px) scale(.99); }

.btn-primary {
  background: linear-gradient(180deg, #127d73, #0a5f58);
  color: #ffffff;
  box-shadow: 0 12px 26px -12px rgba(10, 95, 88, .9);
}
.btn-primary:active { box-shadow: 0 6px 14px -8px rgba(10, 95, 88, .9); }

.btn-ghost {
  background: #ffffff;
  color: var(--teal-700);
  border: 2px solid var(--line);
}

.btn-lg { width: 100%; min-height: 58px; font-size: 18px; }
.btn-block { width: 100%; }

.best {
  margin: 14px 0 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--teal-700);
  background: rgba(255, 255, 255, .7);
  border: 1px solid rgba(14, 107, 99, .14);
  border-radius: 999px;
  padding: 6px 14px;
  line-height: 1.5;
}
.best:empty { display: none; }

/* ============ home goals teaser ============ */
.home-goals {
  width: 100%;
  margin-top: 26px;
  background: rgba(255, 255, 255, .66);
  border: 1px solid rgba(228, 219, 203, .95);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
}

.mini-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-soft);
}

.locked-goals {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.locked-goals li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 13px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-soft);
  min-height: 40px;
}

.locked-goals .lk { font-size: 13px; opacity: .8; flex: 0 0 auto; }

.locked-goals .blurtxt {
  filter: blur(4.5px);
  opacity: .62;
  user-select: none;
  flex: 1 1 auto;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
  line-height: 1.6;
}

/* ============ quiz head ============ */
.screen-quiz { justify-content: flex-start; }

.quiz-head { padding-top: 4px; }

.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-btn {
  width: 42px; height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #ffffff;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background-color .16s ease, color .16s ease;
}
.icon-btn:active { background: var(--sand-2); color: var(--ink); }
.icon-btn:focus-visible { outline: 3px solid rgba(14, 107, 99, .3); outline-offset: 2px; }

.qcount {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
}
.qcount span { color: var(--ink); font-weight: 800; }

.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  background: var(--amber-soft);
  color: var(--amber-ink);
  font-size: 15px;
  font-weight: 800;
  padding: 8px 13px;
  border-radius: 999px;
  line-height: 1;
  min-height: 38px;
}
.score-chip .star { font-size: 13px; color: #c9871f; }

.progress-track {
  height: 8px;
  margin-top: 14px;
  border-radius: 999px;
  background: var(--sand-2);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--teal-glow));
  transition: width .4s cubic-bezier(.22, .8, .3, 1);
}

.obj-dots {
  display: flex;
  justify-content: center;
  gap: 7px;
  margin-top: 12px;
}
.obj-dot {
  width: 30px; height: 30px;
  border-radius: 10px;
  border: none;
  background: var(--sand-2);
  color: #a89d88;
  font-size: 12px;
  font-weight: 800;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: default;
  transition: background-color .2s ease, color .2s ease, box-shadow .2s ease, transform .2s ease;
}
.obj-dot.on {
  background: var(--amber-soft);
  color: var(--amber-ink);
  box-shadow: inset 0 0 0 1.5px var(--amber);
  cursor: pointer;
  font-size: 14px;
}
.obj-dot.on:active { transform: scale(.92); }
.obj-dot:focus-visible { outline: 3px solid rgba(226, 161, 60, .45); outline-offset: 2px; }

/* ============ question card ============ */
.quiz-main { margin-top: 18px; }

.q-card {
  background: var(--card);
  border: 1px solid rgba(228, 219, 203, .9);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: var(--shadow);
}

.topic-chip {
  display: inline-block;
  background: var(--teal-100);
  color: var(--teal-700);
  font-size: 12.5px;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: 999px;
  line-height: 1.5;
}

.q-text {
  margin: 12px 0 0;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.7;
  color: var(--ink);
}

.code {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
  margin: 14px 0 0;
  padding: 15px 16px;
  background: var(--code-bg);
  color: var(--code-ink);
  border-radius: 16px;
  font-family: var(--mono);
  font-size: 14.5px;
  line-height: 1.95;
  white-space: pre;
  overflow-x: auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.tok-kw { color: #7fd8c7; font-weight: 600; }
.tok-str { color: #f2c67f; }

.listen-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  min-height: 44px;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--sand);
  color: var(--teal-700);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: background-color .16s ease, opacity .16s ease;
}
.listen-btn:active { background: var(--sand-2); }
.listen-btn.is-speaking { opacity: .6; }
.listen-btn:focus-visible { outline: 3px solid rgba(14, 107, 99, .3); outline-offset: 2px; }

/* ============ options ============ */
.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 12px 14px;
  text-align: right;
  background: #ffffff;
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 16px;
  font-size: 16.5px;
  font-weight: 700;
  line-height: 1.5;
  cursor: pointer;
  user-select: none;
  transition: transform .12s ease, border-color .18s ease, background-color .18s ease, opacity .18s ease;
}
.option:active:not(:disabled) { transform: scale(.985); }
.option:focus-visible { outline: 3px solid rgba(14, 107, 99, .3); outline-offset: 2px; }
.option:disabled { cursor: default; }

@media (hover: hover) {
  .option:hover:not(:disabled) { border-color: var(--teal); background: #f2fbf8; }
}

.opt-letter {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--sand-2);
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 800;
  transition: background-color .18s ease, color .18s ease;
}

.opt-label { flex: 1 1 auto; min-width: 0; }
.opt-label.is-code {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  direction: ltr;
  unicode-bidi: isolate;
  overflow-wrap: anywhere;
}

.option.is-correct {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok-ink);
}
.option.is-correct .opt-letter { background: var(--ok); color: #ffffff; }

.option.is-wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
  color: var(--bad-ink);
}
.option.is-wrong .opt-letter { background: var(--bad); color: #ffffff; }

.option.is-dim { opacity: .48; }

/* ============ feedback ============ */
.feedback {
  margin-top: 16px;
  padding: 16px;
  border-radius: 20px;
  background: #ffffff;
  border: 2px solid var(--line);
  box-shadow: 0 10px 24px -18px rgba(21, 32, 40, .5);
  animation: fadeUp .3s cubic-bezier(.22, .8, .3, 1) both;
}
.feedback.ok { border-color: #b9e7d7; background: #f3fdf9; }
.feedback.bad { border-color: #f2ccc7; background: #fdf5f4; }

.fb-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
}
.fb-head strong { font-weight: 800; }
.feedback.ok .fb-head strong { color: var(--ok-ink); }
.feedback.bad .fb-head strong { color: var(--bad-ink); }

.fb-icon {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  color: #ffffff;
}
.feedback.ok .fb-icon { background: var(--ok); }
.feedback.bad .fb-icon { background: var(--bad); }

.fb-text {
  margin: 10px 0 14px;
  font-size: 15px;
  line-height: 1.8;
  color: var(--ink-soft);
  font-weight: 500;
}
.fb-text b { color: var(--ink); font-weight: 800; }

/* ============ result ============ */
.screen-result { justify-content: flex-start; }

.result-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 14px;
}

.score-ring {
  width: 138px; height: 138px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin-bottom: 14px;
  border: 7px solid transparent;
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    linear-gradient(150deg, var(--teal), var(--teal-glow) 55%, var(--amber)) border-box;
  box-shadow: 0 18px 34px -22px rgba(21, 32, 40, .7);
}
.ring-num { font-size: 44px; font-weight: 800; line-height: 1; color: var(--teal-700); }
.ring-total { font-size: 14px; font-weight: 700; color: var(--ink-soft); }

.res-stars {
  font-size: 24px;
  letter-spacing: 3px;
  color: var(--amber);
  margin-bottom: 6px;
  line-height: 1;
}

.screen-result h1 { font-size: 27px; margin: 0 0 10px; }

.res-msg {
  margin: 0 0 22px;
  max-width: 40ch;
  font-size: 16px;
  line-height: 1.8;
  color: var(--ink-soft);
  font-weight: 500;
}

.res-goals {
  width: 100%;
  text-align: right;
  background: rgba(255, 255, 255, .72);
  border: 1px solid rgba(228, 219, 203, .95);
  border-radius: var(--radius);
  padding: 16px 14px 12px;
}
.res-goals .mini-title { margin-bottom: 12px; }

#resGoals {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.res-goal {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 12px 13px;
}
.res-goal.perfect { border-color: #bfe8da; background: #f6fdfa; }

.rg-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 6px;
}
.rg-num {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--teal-100);
  color: var(--teal-700);
  font-size: 12.5px;
  font-weight: 800;
}
.res-goal.perfect .rg-num { background: var(--ok); color: #ffffff; }

.rg-title {
  flex: 1 1 auto;
  font-size: 14.5px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.45;
  min-width: 0;
}
.rg-acc {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-soft);
  background: var(--sand);
  border-radius: 999px;
  padding: 3px 9px;
  line-height: 1.5;
}
.res-goal.perfect .rg-acc { color: var(--ok-ink); background: var(--ok-soft); }

.rg-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ink-soft);
  font-weight: 500;
}

.res-best {
  margin: 16px 0 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--teal-700);
  background: rgba(255, 255, 255, .7);
  border: 1px solid rgba(14, 107, 99, .14);
  border-radius: 999px;
  padding: 6px 14px;
  line-height: 1.5;
}
.res-best:empty { display: none; }

.res-actions {
  width: 100%;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ============ overlay ============ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(21, 32, 40, .55);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  animation: fadeIn .2s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.objective-card {
  width: 100%;
  max-width: 400px;
  max-height: calc(100dvh - 44px);
  overflow-y: auto;
  background: #ffffff;
  color: var(--ink);
  border-radius: 26px;
  padding: 26px 22px 22px;
  text-align: center;
  box-shadow: 0 30px 60px -24px rgba(0, 0, 0, .6);
  animation: popIn .34s cubic-bezier(.2, .9, .3, 1.2) both;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(16px) scale(.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.obj-icon {
  width: 66px; height: 66px;
  margin: 0 auto 12px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  font-size: 32px;
  background: var(--amber-soft);
  box-shadow: inset 0 0 0 1.5px rgba(226, 161, 60, .5);
}

.obj-kicker {
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--amber-ink);
  background: var(--amber-soft);
  border-radius: 999px;
  padding: 5px 14px;
  display: inline-block;
  line-height: 1.5;
}

.objective-card h2 {
  margin: 8px 0 10px;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.5;
  color: var(--ink);
}

.obj-text {
  margin: 0 0 20px;
  font-size: 15.5px;
  line-height: 1.85;
  color: var(--ink-soft);
  font-weight: 500;
}

/* ============ short screens ============ */
@media (max-height: 700px) {
  .logo { width: 64px; height: 64px; font-size: 32px; margin: 14px 0 12px; border-radius: 20px; }
  h1 { font-size: 28px; }
  .lead { font-size: 15.5px; margin-bottom: 18px; }
  .home-goals { margin-top: 18px; }
}

@media (max-width: 400px) {
  .app { padding: 16px 14px 34px; }
  h1 { font-size: 29px; }
  .q-text { font-size: 17.5px; }
  .option { font-size: 15.5px; padding: 11px 12px; }
  .score-ring { width: 120px; height: 120px; }
  .ring-num { font-size: 38px; }
}

/* ============ reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .enter, .feedback, .objective-card, .overlay { animation: none !important; }
}