:root {
  --sand: #f4efec;
  --page: #ffffff;
  --ink: #251f21;
  --ink2: #585254;
  --ink4: #c0bebf;
  --hairline: #eae9ea;
  --teal: #0d9488;
  --teal-soft: #d9efec;
  --red: #ed313e;
  --amber: #f59e0b;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", Arial, sans-serif;
  background: var(--sand); color: var(--ink); min-height: 100vh;
  display: flex; justify-content: center;
}
#app { width: 100%; max-width: 480px; background: var(--page); min-height: 100vh; padding-bottom: 76px; position: relative; box-shadow: 0 0 24px rgba(0,0,0,.06); }
[dir="ltr"] #app { text-align: left; }

header.top {
  position: sticky; top: 0; background: var(--page); z-index: 5;
  padding: 14px 18px; border-bottom: 1px solid var(--hairline);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
header.top h1 { font-size: 1.15rem; font-weight: 700; }
header.top .gear { font-size: 1.3rem; background: none; border: none; cursor: pointer; padding: 6px; }

main { padding: 18px; }

.card {
  background: var(--page); border: 1px solid var(--hairline); border-radius: 16px;
  padding: 16px; margin-bottom: 14px;
}
.card.tinted { background: var(--teal-soft); border-color: transparent; }
.card.warn { background: #fdf3e4; border-color: transparent; }

.big-title { font-size: 1.6rem; font-weight: 800; margin-bottom: 8px; }
.sub { color: var(--ink2); margin-bottom: 18px; line-height: 1.6; }

.btn {
  display: block; width: 100%; border: none; border-radius: 12px; cursor: pointer;
  background: var(--teal); color: #fff; font-size: 1.05rem; font-weight: 700;
  padding: 14px; font-family: inherit; text-align: center;
}
.btn.secondary { background: var(--sand); color: var(--ink); }
.btn.ghost { background: none; color: var(--teal); padding: 8px; font-size: .95rem; }
.btn:disabled { opacity: .45; }
.btn + .btn { margin-top: 10px; }

.opt {
  display: block; width: 100%; text-align: start; font-family: inherit;
  background: var(--page); border: 1.5px solid var(--hairline); border-radius: 12px;
  padding: 13px 14px; font-size: 1rem; margin-bottom: 10px; cursor: pointer; color: var(--ink);
}
.opt:active { border-color: var(--teal); }
.opt.picked { border-color: var(--teal); background: var(--teal-soft); }
.opt.correct { border-color: var(--teal); background: var(--teal-soft); }
.opt.wrong { border-color: var(--red); background: #fdecec; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.stat-grid { display: flex; gap: 10px; margin-bottom: 14px; }
.stat {
  flex: 1; background: var(--sand); border-radius: 12px; padding: 10px;
  text-align: center;
}
.stat .num { font-size: 1.3rem; font-weight: 800; color: var(--teal); }
.stat .lbl { font-size: .8rem; color: var(--ink2); }

.chunk-face { font-size: 1.35rem; font-weight: 800; text-align: center; padding: 26px 10px 10px; direction: ltr; }
.chunk-sub { text-align: center; color: var(--ink2); padding-bottom: 18px; }
.play-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--teal);
  background: #fff; color: var(--teal); border-radius: 999px; padding: 7px 16px;
  font-size: .95rem; font-weight: 700; cursor: pointer; font-family: inherit;
}
.center { text-align: center; }

.grade-row { display: flex; gap: 8px; }
.grade-row .btn { padding: 12px 6px; font-size: .95rem; }
.btn.again { background: var(--red); }
.btn.hard { background: var(--amber); }
.btn.good { background: var(--teal); }
.btn.easy { background: #2563eb; }

.story-text { direction: ltr; text-align: left; font-size: 1.08rem; line-height: 2; }
.story-text .g { border-bottom: 2px dotted var(--teal); cursor: pointer; font-weight: 600; }
.gloss-pop {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 20;
  background: var(--ink); color: #fff; border-radius: 12px; padding: 12px 18px;
  max-width: 320px; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.gloss-pop .w { direction: ltr; font-weight: 800; font-size: 1.1rem; }
.gloss-pop button { background: var(--teal); color: #fff; border: none; border-radius: 8px; padding: 6px 14px; margin-top: 8px; cursor: pointer; font-family: inherit; }

.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 14px; line-height: 1.55; direction: ltr; text-align: left; }
.bubble.bot { background: var(--sand); align-self: flex-start; border-end-start-radius: 4px; }
.bubble.me { background: var(--teal); color: #fff; align-self: flex-end; border-end-end-radius: 4px; }
.bubble.sys { background: var(--teal-soft); align-self: stretch; max-width: 100%; direction: inherit; text-align: start; font-size: .9rem; color: var(--ink2); }

textarea.writing {
  width: 100%; min-height: 130px; border: 1.5px solid var(--hairline); border-radius: 12px;
  padding: 12px; font-family: inherit; font-size: 1rem; direction: ltr; resize: vertical;
}
.model-answer { direction: ltr; text-align: left; background: var(--sand); border-radius: 12px; padding: 12px; line-height: 1.7; margin-top: 10px; }

.mistake-item { border-inline-start: 3px solid var(--red); padding: 8px 12px; margin-bottom: 10px; background: var(--sand); border-radius: 8px; }
.mistake-item .cat { font-size: .75rem; color: var(--ink2); }

nav.bottom {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; background: var(--page); border-top: 1px solid var(--hairline);
  display: flex; z-index: 10;
}
nav.bottom button {
  flex: 1; background: none; border: none; padding: 8px 2px 10px; cursor: pointer;
  font-family: inherit; font-size: .72rem; color: var(--ink2);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
nav.bottom button .ico { font-size: 1.25rem; }
nav.bottom button.active { color: var(--teal); font-weight: 700; }

.progress-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 16px; }
.progress-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--ink4); }
.progress-dots span.on { background: var(--teal); }

.badge-level {
  display: inline-block; background: var(--teal); color: #fff; border-radius: 999px;
  font-weight: 800; padding: 6px 18px; font-size: 1.2rem; direction: ltr;
}
.hint-box { background: #fdf3e4; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: .92rem; }
.strike-flame { color: var(--amber); }
