:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #dde2e7;
  --text: #1f2933;
  --muted: #6b7680;
  --primary: #2563a8;
  --primary-dark: #1d4f87;
  --ok: #2e7d4f;
  --ok-bg: #e8f5ec;
  --warn: #9a6a00;
  --warn-bg: #fff6df;
  --bad: #b03a2e;
  --bad-bg: #fdecea;
  --star: #e0a800;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Tajawal", Tahoma, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0 0 12px; font-weight: 700; }
h2 { font-size: 1.15rem; }

.container { max-width: 960px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 24px; padding-bottom: 48px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.center { text-align: center; }
.en { color: var(--muted); font-weight: 400; font-size: .85em; margin-inline-start: 6px; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; padding: 0 32px; }
.brand { font-size: 1.3rem; font-weight: 700; color: var(--text); }
.brand span { color: var(--muted); font-weight: 400; font-size: .95rem; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 18px; align-items: center; }
.nav .who { font-weight: 500; }

.page-title { font-size: 1.5rem; }

/* Cards & forms */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}
.card.narrow { max-width: 520px; margin-inline: auto; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form label, .form .label { font-weight: 500; }
input[type="text"] {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
input[type="text"]:focus { outline: 2px solid var(--primary); border-color: transparent; }

.avatar-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.avatar-pick input { display: none; }
.avatar-pick span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; font-size: 1.6rem;
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer; background: #fff;
}
.avatar-pick input:checked + span { border: 2px solid var(--primary); background: #eef4fb; }

.btn {
  display: inline-block;
  font: inherit;
  padding: 9px 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: #f0f2f4; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-lg { padding: 12px 32px; font-size: 1.1rem; }

.alert {
  background: var(--bad-bg);
  color: var(--bad);
  border: 1px solid #f3c7c2;
  border-radius: 6px;
  padding: 10px 14px;
  margin: 12px 0;
}

/* Profiles */
.profiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 24px; }
.profiles-page > .page-title, .profiles-page > .muted { text-align: center; }
.profile-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 130px; padding: 16px 8px;
  font: inherit; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.profile-card:hover { border-color: var(--primary); }
.profile-card .avatar { font-size: 2.4rem; }
.profile-card .name { font-weight: 500; }

/* Lessons */
.level { margin-bottom: 28px; }
.level h2 { color: var(--muted); font-weight: 500; }
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.lesson-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--text);
}
.lesson-card:hover { border-color: var(--primary); text-decoration: none; }
.lesson-head { margin-bottom: 10px; }
.lesson-head strong { font-size: 1.1rem; }
.lesson-head .en { display: block; margin: 0; }
.lesson-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .92rem; }
.stars span { color: #cfd5db; }
.stars span.on { color: var(--star); }

/* Practice */
.practice-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.score-box { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 14px; white-space: nowrap; }
.progress { height: 8px; background: #e3e7eb; border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .3s; }
#progress-text { margin: 6px 0 16px; }

.picture { font-size: 5rem; line-height: 1.2; min-height: 6rem; font-weight: 700; color: var(--primary); }
.target { font-family: Arial, Helvetica, sans-serif; font-size: 3rem; font-weight: 700; letter-spacing: .5px; }
.target.sentence { font-size: 2rem; }
.meaning { font-size: 1.3rem; color: var(--muted); margin-bottom: 16px; }
.listen-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.instruction { margin: 16px 0 12px; font-weight: 500; }
.instruction bdi { font-family: Arial, Helvetica, sans-serif; font-weight: 700; }

.record-btn {
  display: inline-flex; align-items: center; gap: 10px;
  font: inherit; font-size: 1.1rem; font-weight: 500;
  padding: 14px 28px;
  border-radius: 40px;
  border: 2px solid var(--bad);
  background: #fff; color: var(--bad);
  cursor: pointer;
}
.record-btn .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--bad); }
.record-btn.recording { background: var(--bad); color: #fff; }
.record-btn.recording .dot { background: #fff; animation: blink 1s infinite; }
.record-btn:disabled { opacity: .45; cursor: not-allowed; }
@keyframes blink { 50% { opacity: .3; } }

.meter { width: 220px; height: 6px; margin: 12px auto 0; background: #e3e7eb; border-radius: 3px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--ok); transition: width .08s; }
.status { min-height: 1.6em; color: var(--muted); margin: 8px 0 0; }

.tries { display: flex; justify-content: center; gap: 6px; margin: 6px 0 12px; }
.tries span { width: 12px; height: 12px; border-radius: 50%; background: #dfe4e8; }
.tries span.used { background: #e8a29a; }
.tries span.ok { background: var(--ok); }

.feedback { border-radius: 6px; padding: 12px 16px; margin: 0 auto 16px; max-width: 520px; text-align: center; }
.feedback p { margin: 4px 0; }
.feedback-msg { font-weight: 700; font-size: 1.15rem; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); }
.feedback.retry { background: var(--warn-bg); color: var(--warn); }
.feedback.skip { background: var(--bad-bg); color: var(--bad); }
.heard { color: var(--text); }
.tip { color: var(--text); font-size: .95rem; }

/* Summary */
.big-stars { font-size: 3rem; letter-spacing: 6px; }
.big-stars span { color: #cfd5db; }
.big-stars span.on { color: var(--star); }
.result-line { font-size: 1.15rem; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: start; }
.table th { color: var(--muted); font-weight: 500; font-size: .92rem; }
.table .pic { font-size: 1.5rem; width: 40px; }
.en-cell { text-align: left; font-family: Arial, Helvetica, sans-serif; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: .85rem; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.actions { display: flex; gap: 10px; }

@media (max-width: 600px) {
  .topbar-inner { padding: 0 16px; }
  .target { font-size: 2.3rem; }
  .target.sentence { font-size: 1.5rem; }
  .nav { gap: 10px; font-size: .9rem; }
  .table th:nth-child(6), .table td:nth-child(6) { display: none; }
}
