:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #1f2933;
  --muted: #66727e;
  --primary: #2563a8;
  --primary-dark: #1d4f87;
  --primary-soft: #eaf2fb;
  --ok: #2e7d4f;
  --ok-bg: #e7f5ec;
  --warn: #8a5d00;
  --warn-bg: #fff5d9;
  --bad: #b03a2e;
  --bad-bg: #fdecea;
  --neutral: #5f6b76;
  --neutral-bg: #eef1f4;
  --star: #e0a800;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Tajawal", Tahoma, Arial, sans-serif;
  font-size: 18px;
  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.2rem; }

.container { max-width: 1000px; 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; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; padding: 8px 32px; gap: 12px; flex-wrap: wrap; }
.brand { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.nav a { padding: 6px 12px; border-radius: 20px; }
.nav a:hover { background: var(--primary-soft); text-decoration: none; }
.nav a.active { background: var(--primary-soft); font-weight: 700; }
.nav .who { font-weight: 500; margin-inline-end: 6px; }

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

/* 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; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h1, .card-head h2 { margin: 0; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form label, .form .label { font-weight: 500; }
input[type="text"], input[type="password"] {
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.pin-input { text-align: center; font-size: 1.4rem; letter-spacing: 8px; }

.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: 52px; height: 52px; font-size: 1.7rem;
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer; background: #fff;
}
.avatar-pick input:checked + span { border: 3px solid var(--primary); background: var(--primary-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
}
.btn:hover { background: #f0f3f6; 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 28px; font-size: 1.1rem; min-height: 52px; }
.btn-xl { padding: 14px 48px; font-size: 1.4rem; font-weight: 700; min-height: 64px; border-radius: 16px; }
.btn-big { flex-direction: column; gap: 2px; min-width: 110px; min-height: 84px; font-size: 1.05rem; font-weight: 500; border-width: 2px; }
.btn-big .ico { font-size: 1.8rem; line-height: 1; }

.alert {
  background: var(--bad-bg);
  color: var(--bad);
  border: 1px solid #f3c7c2;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 12px 0;
}
.narrow-alert { max-width: 520px; margin-inline: auto; }

/* 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: 136px; padding: 18px 8px;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius);
}
.profile-card:hover { border-color: var(--primary); text-decoration: none; }
.profile-card .avatar { font-size: 2.8rem; }
.profile-card .name { font-weight: 700; }

/* Lessons */
.level { margin-bottom: 32px; }
.level-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.level-head h2 { margin: 0; }
.level-head p { margin: 2px 0 0; }
.level-num { display: inline-block; background: var(--primary); color: #fff; font-size: .85rem; padding: 2px 10px; border-radius: 12px; margin-inline-end: 6px; vertical-align: middle; }
.level-stars { color: var(--muted); white-space: nowrap; font-size: .95rem; }
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.lesson-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
}
.lesson-card:hover { border-color: var(--primary); text-decoration: none; }
.lesson-icon { font-size: 2.4rem; width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; background: var(--bg); border-radius: 12px; font-weight: 700; color: var(--primary); flex-shrink: 0; }
.lesson-body { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.lesson-body strong { font-size: 1.15rem; }
.lesson-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .9rem; }
.stars span { color: #cfd5db; }
.stars span.on { color: var(--star); }

/* Practice */
.practice-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.score-box { background: var(--surface); border: 2px solid var(--star); border-radius: 20px; padding: 4px 16px; white-space: nowrap; font-size: 1.2rem; }
.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.3); } }
.progress { height: 10px; background: #e3e7eb; border-radius: 5px; overflow: hidden; margin-top: 12px; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .3s; }
#progress-text { margin: 6px 0 16px; }

.steps { display: flex; justify-content: center; gap: 12px; margin: 8px 0 24px; flex-wrap: wrap; }
.step { display: flex; flex-direction: column; align-items: center; width: 110px; padding: 12px 6px; background: var(--bg); border-radius: 12px; font-weight: 500; }
.step span { font-size: 2.2rem; }

.picture { font-size: 5.5rem; line-height: 1.2; min-height: 6.5rem; font-weight: 700; color: var(--primary); }
.target, .ar-text { font-family: "Noto Naskh Arabic", "Traditional Arabic", serif; }
.target { font-size: 3.6rem; font-weight: 700; line-height: 1.8; margin-bottom: 12px; }
.target.sentence { font-size: 2.4rem; }
.ar-text { font-size: 1.25rem; }
.listen-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; }
.instruction { margin: 16px 0 14px; font-weight: 700; font-size: 1.15rem; }

.record-btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 132px; height: 132px;
  font: inherit; font-size: 1.05rem; font-weight: 700;
  border-radius: 50%;
  border: 4px solid var(--bad);
  background: #fff; color: var(--bad);
  cursor: pointer;
}
.record-btn .mic { font-size: 2.6rem; line-height: 1; }
.record-btn.recording { background: var(--bad); color: #fff; animation: pulse 1.2s infinite; }
.record-btn:disabled { opacity: .45; cursor: not-allowed; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(176, 58, 46, .45); } 100% { box-shadow: 0 0 0 18px rgba(176, 58, 46, 0); } }

.meter { width: 220px; height: 8px; margin: 14px auto 0; background: #e3e7eb; border-radius: 4px; 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; font-weight: 500; }

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

.feedback { border-radius: var(--radius); padding: 14px 18px; margin: 0 auto 16px; max-width: 540px; text-align: center; animation: pop .3s ease; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.feedback p { margin: 4px 0; }
.feedback-icon { font-size: 2.6rem; line-height: 1.2; }
.feedback-msg { font-weight: 700; font-size: 1.35rem; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); }
.feedback.retry { background: var(--warn-bg); color: var(--warn); }
.feedback.skip { background: var(--neutral-bg); color: var(--neutral); }
.letter-badge { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: 50%; background: #fff; border: 3px solid var(--warn); font-family: "Noto Naskh Arabic", serif; font-size: 2.2rem; font-weight: 700; }
.heard { color: var(--muted); font-size: .9rem; }
.tip { color: var(--text); }

/* Summary */
.big-stars { font-size: 3.4rem; letter-spacing: 6px; }
.big-stars span { color: #cfd5db; }
.big-stars span.on { color: var(--star); }
.result-line { font-size: 1.2rem; }
.cheer { font-size: 1.25rem; font-weight: 700; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: start; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: .9rem; white-space: nowrap; }
.table .pic { font-size: 1.5rem; width: 40px; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: .85rem; white-space: nowrap; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.ar-letters { font-family: "Noto Naskh Arabic", serif; font-size: 1.2rem; font-weight: 700; }

/* Progress */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.tile-ico { font-size: 1.8rem; }
.tile-num { font-size: 2rem; font-weight: 700; line-height: 1.3; }
.tile-label { color: var(--muted); font-size: .9rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.two-col .card { margin-bottom: 20px; }

.imp { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 14px; font-weight: 700; font-size: .95rem; }
.imp-good { background: var(--ok-bg); color: var(--ok); }
.imp-neutral, .imp-none { background: var(--neutral-bg); color: var(--neutral); }
.imp-bad { background: var(--bad-bg); color: var(--bad); }

.letters { display: flex; flex-wrap: wrap; gap: 10px; }
.letter-chip { display: flex; flex-direction: column; align-items: center; width: 84px; padding: 8px; border: 1px solid var(--border); border-radius: 12px; }
.letter-chip .letter { font-family: "Noto Naskh Arabic", serif; font-size: 2rem; font-weight: 700; line-height: 1.4; }
.letter-chip .count { color: var(--muted); font-size: .85rem; }
.word-list { list-style: none; margin: 0; padding: 0; }
.word-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.word-list li:last-child { border-bottom: 0; }
.word-list .pic { font-size: 1.4rem; }
.word-list .ar-text { flex: 1; }

/* Chart: one series (success % per session), plain bars */
.chart { margin: 8px 0 0; }
.chart-title { font-weight: 500; color: var(--muted); font-size: .95rem; margin-bottom: 8px; }
.chart-plot { position: relative; height: 200px; margin: 0 40px 30px 0; }
.chart-grid { position: absolute; inset: 0; border-bottom: 1px solid #c9d1d9; }
.chart-grid span { position: absolute; right: -40px; transform: translateY(50%); font-size: .75rem; color: var(--muted); width: 34px; text-align: left; }
.chart-grid .gl { position: absolute; left: 0; right: 0; border-top: 1px dashed #e3e8ed; }
.chart-bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 6px; padding: 0 6px; }
.bar-col { position: relative; flex: 1; max-width: 44px; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline: none; cursor: default; }
.bar { width: 100%; max-width: 28px; background: var(--primary); border-radius: 4px 4px 0 0; }
.bar-col:hover .bar, .bar-col:focus .bar { background: var(--primary-dark); }
.bar-label { position: absolute; bottom: -24px; font-size: .72rem; color: var(--muted); white-space: nowrap; }
.bar-tip { display: none; position: absolute; bottom: calc(100% + 6px); z-index: 2; background: var(--text); color: #fff; font-size: .8rem; line-height: 1.5; padding: 6px 10px; border-radius: 8px; white-space: nowrap; text-align: center; }
.bar-col:hover .bar-tip, .bar-col:focus .bar-tip { display: block; }
.bar-col:hover { z-index: 3; }

@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 600px) {
  body { font-size: 17px; }
  .topbar-inner { padding: 8px 16px; }
  .nav { font-size: .9rem; gap: 2px; }
  .nav a { padding: 4px 8px; }
  .card { padding: 18px 14px; }
  .target { font-size: 2.8rem; }
  .target.sentence { font-size: 1.8rem; }
  .picture { font-size: 4.5rem; min-height: 5.5rem; }
  .record-btn { width: 116px; height: 116px; }
  .btn-big { min-width: 96px; min-height: 76px; }
  .tile-num { font-size: 1.6rem; }
  .bar-label { font-size: .65rem; }
  .bar-col:nth-child(even) .bar-label { display: none; }
  .level-head { flex-direction: column; gap: 4px; }
}
