:root {
  /* 60-30-10 Warm Editorial Literacy Palette (Petrol Teal + Alabaster Paper) */
  --bg: #f6f2e8;
  --surface: #ffffff;
  --paper: #fbf8f1;
  --subtle: #eee9dc;
  --ink: #18202c;
  --muted: #5a6475;
  --border: #e5dfd1;

  --primary: #0e5a6f;
  --primary-hover: #0a4657;
  --primary-soft: #e9f3f6;

  --ok: #166534;
  --ok-soft: #eaf7ef;
  --warn: #b45309;
  --warn-soft: #fef6e6;
  --err: #b42318;
  --err-soft: #fef2f2;

  --shadow-card: 0 1px 2px rgba(24, 32, 44, 0.04), 0 12px 30px rgba(24, 32, 44, 0.05);
  --shadow-cta: 0 4px 14px rgba(14, 90, 111, 0.22);
  --radius-card: 20px;
  --radius-inner: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  font-family: "IBM Plex Sans Arabic", "Noto Sans Arabic", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 80% 0%, #fcfaf5 0%, var(--bg) 65%);
  color: var(--ink);
  line-height: 1.65;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* شريط علوي رشيق */
.topbar {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 860px;
  margin-inline: auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
}

.brand-title {
  font-size: clamp(0.92rem, 2.5vw, 1.06rem);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions,
.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.compact-select {
  width: auto;
  min-height: 40px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.nav-pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.nav-pill-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* مساحة العمل الرئيسية */
.stage {
  max-width: 820px;
  margin: 20px auto 48px;
  padding-inline: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* شريط التقدم المرقّم (أفقي دائم بدون التفاف مشوّه) */
.stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: var(--subtle);
  padding: 5px;
  border-radius: 14px;
}

.step-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  border: none;
  background: transparent;
  padding: 6px 8px;
  border-radius: 10px;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  font-weight: 700;
}

.step-tab.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(24, 32, 44, 0.06);
}

.step-tab.active .step-num {
  background: var(--primary);
  color: #fff;
}

.step-tab.done {
  color: var(--ok);
}

.step-tab.done .step-num {
  background: var(--ok-soft);
  color: var(--ok);
}

/* البطاقة المركزية (بدون تداخل حدود مزدوجة) */
.surface-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: clamp(18px, 3.5vw, 32px);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.surface-card.child-focus {
  max-width: 660px;
  width: 100%;
  margin-inline: auto;
}

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

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--subtle);
  padding: 4px;
  border-radius: 12px;
  max-width: 100%;
}

.segmented.scrollable-x {
  overflow-x: auto;
  scrollbar-width: none;
}

.segmented.scrollable-x::-webkit-scrollbar {
  display: none;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 9px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* مساحة القراءة الدافئة (بلا حدود مزعجة وفق BDA + Refactoring UI) */
.reading-zone {
  background: var(--paper);
  border-radius: var(--radius-inner);
  padding: clamp(22px, 5vw, 44px) clamp(16px, 4vw, 32px);
}

.reading-zone.compact {
  padding: clamp(14px, 3vw, 22px) clamp(12px, 3vw, 20px);
}

.reading-display {
  text-align: center;
  font-size: clamp(1.45rem, 4.2vw, 2.15rem);
  font-weight: 600;
  line-height: 2.2;
  word-spacing: 0.22em;
  letter-spacing: 0.015em;
  color: var(--ink);
}

.reading-display .trouble-highlight {
  color: var(--primary-hover);
  background: var(--primary-soft);
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 700;
}

/* شريط الإجراءات (يتحوّل إلى شريط إبهام ثابت على الهاتف) */
.thumb-dock {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.center-dock {
  justify-content: center;
}

.split-dock {
  justify-content: space-between;
}

button {
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 10px 26px;
  border-radius: 999px;
  font-size: 0.98rem;
  font-weight: 700;
  box-shadow: var(--shadow-cta);
}

.primary-cta:hover:not(:disabled) {
  background: var(--primary-hover);
}

.mic-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 48px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
}

.mic-pill.is-live {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.mic-pill.is-offline {
  color: var(--muted);
  background: var(--subtle);
  border-color: transparent;
}

.mic-pill.recording,
.danger-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: none;
  background: var(--err);
  color: #fff;
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
}

.quiet-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
}

.quiet-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.ghost-link {
  border: none;
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 600;
}

.ghost-link:hover {
  background: var(--subtle);
  color: var(--ink);
}

.status-text {
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
}

/* 2. مراجعة المعلم */
.stat-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--subtle);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.86rem;
  color: var(--muted);
}

.stat-chip strong {
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-chip.accent {
  background: var(--primary-soft);
  color: var(--primary);
}

.stat-chip.accent strong {
  color: var(--primary);
}

.word-map {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.word-chip {
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 12px;
  font-size: clamp(1.18rem, 3.2vw, 1.45rem);
  font-weight: 600;
  border: 1.5px solid transparent;
  background: var(--surface);
  color: var(--ink);
}

.word-chip.ok {
  color: var(--ok);
  background: var(--ok-soft);
}

.word-chip.mismatch_or_disfluent {
  border-color: #fca5a5;
  background: var(--err-soft);
  color: var(--err);
}

.word-chip.hesitation_or_repeat {
  border-style: dashed;
  border-color: #fcd34d;
  background: var(--warn-soft);
  color: var(--warn);
}

.word-chip.omitted {
  background: var(--subtle);
  color: var(--muted);
  opacity: 0.72;
}

.word-chip.is-dismissed {
  border-color: var(--border);
  background: var(--surface);
  color: var(--muted);
  opacity: 0.7;
}

.word-chip.is-playing {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.diag-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diag-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--paper);
}

.diag-item.confirmed {
  background: var(--primary-soft);
}

.diag-item.rejected {
  background: var(--subtle);
  opacity: 0.68;
}

.diag-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.diag-word {
  font-size: 1.2rem;
  font-weight: 700;
}

.tag-pill,
.counter-pill,
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--subtle);
  color: var(--muted);
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.listen-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 40px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
}

.listen-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.triage-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.decision-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
}

.decision-btn.confirm-active {
  background: var(--primary);
  color: #fff;
}

.decision-btn.reject-active {
  background: var(--ok);
  color: #fff;
}

/* 3. التدريب */
.progress-track {
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  height: 5px;
  background: var(--subtle);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.28s ease;
}

.practice-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.sentence-hint {
  font-size: clamp(1.05rem, 3vw, 1.25rem);
  color: var(--muted);
  text-align: center;
  line-height: 1.9;
}

.sentence-hint strong {
  color: var(--primary);
  font-weight: 700;
}

.word-hero {
  width: 100%;
  background: var(--paper);
  border-radius: 18px;
  padding: clamp(20px, 4vw, 30px) 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.hero-word {
  font-size: clamp(2.15rem, 8vw, 3.2rem);
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
}

.sound-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  border: 1px solid var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
}

.choice-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.drill-opt {
  min-height: 78px;
  padding: 16px;
  font-size: clamp(1.55rem, 5vw, 1.95rem);
  font-weight: 700;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 3px 10px rgba(24, 32, 44, 0.03);
}

.drill-opt:hover {
  border-color: var(--primary);
}

.drill-opt.correct-hit {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.drill-opt.retry-hit {
  background: var(--warn-soft);
  border-color: var(--warn);
}

/* Color ONLY without horizontal padding/underline so Arabic cursive joining stays intact */
.drill-opt .focus-char {
  color: var(--warn);
  font-weight: 800;
}

.empty-state,
.done-state {
  padding: 28px;
  text-align: center;
  background: var(--paper);
  border-radius: var(--radius-inner);
  font-weight: 600;
}

.done-stats {
  display: flex;
  justify-content: center;
  gap: 36px;
}

.done-metric span {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
}

.done-metric strong {
  font-size: 1.5rem;
  color: var(--ok);
}

/* 4. النتيجة */
.result-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.result-metric {
  background: var(--paper);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
}

.result-metric span {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}

.result-metric strong {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.result-metric.highlight {
  background: var(--ok-soft);
  color: var(--ok);
}

/* النوافذ المنبثقة (تتحول لبطاقة سفلية Bottom Sheet على الهاتف) */
dialog {
  border: none;
  border-radius: 20px;
  padding: 22px;
  max-width: 580px;
  width: 92%;
  max-height: 85dvh;
  overflow-y: auto;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.16);
}

dialog::backdrop {
  background: rgba(24, 32, 44, 0.4);
  backdrop-filter: blur(2px);
}

.modal-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.modal-head h2,
.modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 14px;
}

.form-row {
  display: flex;
  gap: 8px;
}

textarea {
  width: 100%;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--paper);
}

.adapted-box {
  background: var(--paper);
  border-radius: 12px;
  padding: 14px;
  font-size: 1.3rem;
  margin: 8px 0;
}

.skill-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skill-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.skill-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 600;
}

.bar {
  height: 8px;
  background: var(--subtle);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--primary);
}

.code-box {
  background: var(--paper);
  border-radius: 10px;
  padding: 10px;
  direction: ltr;
  text-align: left;
  overflow-x: auto;
  max-height: 180px;
  font-size: 0.8rem;
}

.hidden {
  display: none !important;
}

/* استجابة الهاتف الاحترافية: منطقة الإبهام (Thumb Zone) وشريط الخطوات الأفقي الرشيق */
@media (max-width: 640px) {
  .hide-xs {
    display: none;
  }

  .topbar-inner {
    padding: 8px 12px;
    gap: 6px;
  }

  .brand {
    gap: 6px;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
  }

  .brand-title {
    font-size: 0.88rem;
  }

  .topbar-actions {
    gap: 6px;
    flex-shrink: 0;
  }

  #skillsBtn svg {
    display: none;
  }

  .compact-select,
  .nav-pill-btn {
    min-height: 36px;
    padding: 4px 10px;
    font-size: 0.8rem;
  }

  .stage {
    margin: 12px auto 0;
    padding-inline: 10px;
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    gap: 12px;
  }

  /* شريط الخطوات بقي أفقياً بترتيب RTL واضح دون كسر إلى 2x2 */
  .step-tab {
    flex-direction: column;
    gap: 3px;
    padding: 7px 4px;
    min-height: 48px;
    font-size: 0.76rem;
  }

  .surface-card {
    padding: 16px 14px;
    border-radius: 18px;
    gap: 14px;
  }

  .thumb-dock {
    position: fixed;
    inset-inline: 0;
    inset-block-end: 0;
    z-index: 30;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(24, 32, 44, 0.07);
    justify-content: space-between;
  }

  .thumb-dock.center-dock {
    justify-content: stretch;
  }

  .thumb-dock .primary-cta {
    flex: 1 1 auto;
  }

  .dock-primary-pair {
    flex: 1 1 auto;
    justify-content: flex-end;
  }

  /* بطاقات التمييز على الهاتف بعرض كامل سهل النقر */
  .choice-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .drill-opt {
    min-height: 64px;
  }

  .diag-item {
    flex-direction: column;
    align-items: stretch;
  }

  .diag-item .btn-row {
    justify-content: space-between;
    width: 100%;
  }

  .result-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-row {
    flex-direction: column;
  }

  /* Bottom Sheet للنوافذ على الهاتف */
  dialog.sheet-dialog {
    position: fixed;
    inset-block-start: auto;
    inset-block-end: 0;
    inset-inline: 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 22px 22px 0 0;
    padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
  }

  dialog.sheet-dialog::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    margin: 0 auto 12px;
    border-radius: 999px;
    background: var(--border);
  }
}
