@font-face { font-family: "Thmanyah Sans"; src: url(assets/fonts/thmanyahsans-Regular.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Thmanyah Sans"; src: url(assets/fonts/thmanyahsans-Medium.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Thmanyah Sans"; src: url(assets/fonts/thmanyahsans-Bold.woff2) format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Thmanyah Serif Display"; src: url(assets/fonts/thmanyahserifdisplay-Bold.woff2) format("woff2"); font-weight: 700; font-display: swap; }

:root {
  /* ألوان الهوية */
  --olive: #3b4b12;
  --gold: #b9a344;
  --ivory: #ffffea;
  --white: #ffffff;

  --olive-900: #2a360b;
  --olive-50: #f3f5e8;
  --gold-50: #f7f2dc;
  --ink: #1f260a;
  --muted: #6e7353;
  --line: #e7e6c9;
  --bg: #fbfbef;
  --danger: #a3361f;

  --radius: 18px;
  --shadow: 0 1px 2px rgba(42, 54, 11, .06), 0 4px 16px rgba(42, 54, 11, .06);
  --font: "Thmanyah Sans", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --font-display: "Thmanyah Serif Display", var(--font);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { display: block; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--gold) 70%, transparent); outline-offset: 2px; }

/* ===== أزرار ===== */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--olive); color: var(--ivory);
  min-height: 52px; padding: 0 24px; border-radius: 14px;
  font-weight: 700; font-size: 17px;
  transition: background .15s, transform .1s;
}
.btn-primary:active { transform: scale(.98); background: var(--olive-900); }
.btn-primary svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-ghost { min-height: 48px; padding: 0 20px; border-radius: 14px; color: var(--muted); font-weight: 500; }
.btn-link { color: var(--olive); font-weight: 700; font-size: 14px; padding: 6px 10px; border-radius: 10px; background: var(--olive-50); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--olive-50); flex: none; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--olive); stroke-width: 2.2; stroke-linecap: round; }

/* ===== الدخول ===== */
.login {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 20px calc(32px + var(--safe-b)); gap: 32px;
  background:
    radial-gradient(120% 60% at 50% 0%, var(--ivory) 0%, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--white); border-radius: 28px;
  padding: 36px 28px 28px; box-shadow: var(--shadow); text-align: center;
  border: 1px solid var(--line);
}
.login-logo { width: 190px; height: auto; margin: 0 auto 8px; }
.login-title { font-family: var(--font-display); color: var(--gold); font-size: 26px; margin: 8px 0 24px; font-weight: 700; }
.login form { display: grid; gap: 12px; }
.login input {
  min-height: 52px; border-radius: 14px; border: 1.5px solid var(--line); padding: 0 16px;
  background: var(--bg); font-size: 17px; text-align: center;
}
.login input:focus { outline: none; border-color: var(--gold); background: var(--white); }
.form-error { color: var(--danger); margin: 0; min-height: 1.5em; font-size: 14px; }
.login-nokhab { width: 96px; opacity: .85; }

/* ===== الشريط العلوي ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--white); border-bottom: 1px solid var(--line);
}
.brand { height: 44px; width: auto; }
.topbar-end { display: flex; align-items: center; gap: 12px; }
.brand-nokhab { height: 40px; width: auto; }
.sync { display: none; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.sync i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sync.is-busy { display: inline-flex; background: var(--gold-50); color: #7a6a1f; }
.sync.is-busy i { background: var(--gold); animation: pulse 1s infinite; }
.sync.is-error { display: inline-flex; background: #f6e9e4; color: var(--danger); }
.sync.is-error i { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

/* ===== الواجهة الرئيسة ===== */
.hero { position: relative; background: var(--olive); color: var(--ivory); overflow: hidden; }
.hero-pattern {
  position: absolute; inset: 0; opacity: .14; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='64' viewBox='0 0 56 64'%3E%3Cg fill='none' stroke='%23b9a344' stroke-width='1.4'%3E%3Cpath d='M4 30c0-9 8-14 13-17 4-2.4 6-4 7-6 1 2 3 3.6 7 6 5 3 13 8 13 17v2'/%3E%3Cpath d='M-24 62c0-9 8-14 13-17 4-2.4 6-4 7-6 1 2 3 3.6 7 6 5 3 13 8 13 17'/%3E%3Cpath d='M32 62c0-9 8-14 13-17 4-2.4 6-4 7-6 1 2 3 3.6 7 6 5 3 13 8 13 17'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 56px 64px;
  -webkit-mask-image: linear-gradient(to left, #000 0%, transparent 75%);
          mask-image: linear-gradient(to left, #000 0%, transparent 75%);
}
.hero-inner {
  position: relative; max-width: 960px; margin: 0 auto; padding: 22px 20px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.hero-title { font-family: var(--font-display); font-size: clamp(28px, 7vw, 40px); margin: 0; line-height: 1.15; }
.hero-sub { margin: 2px 0 0; color: var(--gold); font-size: 17px; }
.hero-progress { display: flex; align-items: center; gap: 12px; }
.hero-progress-text { font-size: 15px; line-height: 1.35; }
.hero-progress-text b { font-size: 22px; }
.hero-progress-text small { color: color-mix(in srgb, var(--ivory) 70%, transparent); }
.ring {
  --p: 0; width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--gold) calc(var(--p) * 1%), rgba(255,255,234,.14) 0);
  position: relative; font-weight: 700; font-size: 14px;
}
.ring::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--olive); }
.ring span { position: relative; }
.ring span::after { content: "٪"; font-size: 11px; margin-inline-start: 1px; }

.tabs { position: relative; display: flex; gap: 4px; max-width: 960px; margin: 0 auto; padding: 0 16px; }
.tab {
  padding: 12px 18px 14px; color: color-mix(in srgb, var(--ivory) 70%, transparent); font-weight: 500;
  border-radius: 14px 14px 0 0; transition: color .15s;
}
.tab.is-active { background: var(--bg); color: var(--olive); font-weight: 700; }

.view { max-width: 960px; margin: 0 auto; padding: 16px 16px 24px; }

/* ===== أدوات القائمة ===== */
.toolbar { display: flex; gap: 10px; }
.search { flex: 1; position: relative; }
.search svg { position: absolute; inset-inline-start: 14px; top: 50%; translate: 0 -50%; width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input, .group-filter {
  width: 100%; min-height: 48px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--white);
  padding: 0 44px 0 14px; font-size: 16px;
}
.search input:focus, .group-filter:focus { outline: none; border-color: var(--gold); }
.group-filter {
  width: auto; max-width: 42%; padding: 0 14px 0 32px; color: var(--muted); appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236e7353' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center;
}
.chips { display: flex; gap: 8px; margin: 12px 0 14px; overflow-x: auto; scrollbar-width: none; }
.chip {
  flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; background: var(--white);
  border: 1.5px solid var(--line); font-size: 15px; font-weight: 500; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip span { font-size: 13px; opacity: .8; }
.chip.is-active { background: var(--olive); border-color: var(--olive); color: var(--ivory); }

/* ===== بطاقة الطالب ===== */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
@media (min-width: 720px) { .list { grid-template-columns: 1fr 1fr; } }
.card {
  width: 100%; text-align: start; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: grid; gap: 10px; box-shadow: 0 1px 0 rgba(42,54,11,.03);
  transition: transform .1s, border-color .15s;
}
.card:active { transform: scale(.99); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-name { font-weight: 700; font-size: 17px; }
.badge { flex: none; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.badge.done { background: var(--olive); color: var(--ivory); }
.badge.progress { background: var(--gold-50); color: #7a6a1f; }
.badge.todo { background: #f1f1e4; color: var(--muted); }
.card.is-done { background: linear-gradient(to left, var(--olive-50), var(--white) 60%); border-color: #d9dfbf; }
.metrics { display: grid; grid-template-columns: 1.4fr 1fr .8fr; gap: 10px; align-items: end; }
.metric small { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; white-space: nowrap; }
.metric b { font-size: 14px; font-weight: 700; }
.metric .na { color: #b4b59b; font-weight: 500; }
.mini-bar { display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px; height: 8px; margin-top: 4px; }
.mini-bar i { border-radius: 2px; background: #ecebd3; }
.mini-bar i.on { background: var(--gold); }
.mini-bar.full i.on { background: var(--olive); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 5px; vertical-align: 1px; }
.dot.none { background: var(--danger); opacity: .7; } .dot.partial { background: var(--gold); } .dot.full { background: var(--olive); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ===== لوحة الرصد ===== */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(31, 38, 10, .45); z-index: 20; animation: fade .2s; }
.sheet {
  position: fixed; z-index: 21; inset-inline: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  background: var(--white); border-radius: 26px 26px 0 0; max-height: 92dvh; overflow-y: auto;
  padding: 8px 20px calc(24px + var(--safe-b)); box-shadow: 0 -8px 40px rgba(31,38,10,.2);
  animation: up .25s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 720px) {
  .sheet { bottom: auto; top: 50%; translate: 0 -50%; border-radius: 26px; animation: pop .2s; }
  .sheet-grip { display: none; }
}
@keyframes up { from { transform: translateY(100%); } }
@keyframes pop { from { opacity: 0; scale: .97; } }
@keyframes fade { from { opacity: 0; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 6px 0 14px; }
.sheet-head h2 { margin: 0; font-size: 22px; line-height: 1.3; }
.sheet-status { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.locked {
  display: flex; align-items: center; gap: 12px; background: var(--olive); color: var(--ivory);
  padding: 12px 14px; border-radius: 16px; margin-bottom: 14px;
}
.locked > svg { width: 28px; height: 28px; flex: none; fill: none; stroke: var(--gold); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.locked div { flex: 1; display: grid; }
.locked small { opacity: .75; }
.locked .btn-link { background: rgba(255,255,234,.14); color: var(--ivory); }
.sheet-body.is-locked { opacity: .5; pointer-events: none; filter: saturate(.6); }

.field { padding: 16px 0; border-top: 1px solid var(--line); }
.field:first-child { border-top: 0; padding-top: 4px; }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.field-head h3 { margin: 0; font-size: 17px; color: var(--olive); }
.field-val { color: var(--muted); font-size: 15px; }
.field-val b { color: var(--ink); font-size: 20px; }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

/* شريط الأبيات */
.verses { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; }
.verse {
  min-height: 56px; border-radius: 12px; background: var(--bg); border: 1.5px solid var(--line);
  display: grid; place-items: center; align-content: center; gap: 0;
  font-size: 11px; color: var(--muted); line-height: 1.2; transition: background .12s, border-color .12s, color .12s;
  position: relative;
}
.verse b { font-size: 15px; color: var(--ink); }
.verse.on { background: var(--gold); border-color: var(--gold); color: rgba(255,255,255,.85); }
.verse.on b { color: var(--white); }
.verses.full .verse.on { background: var(--olive); border-color: var(--olive); }
.verse.last::after {
  content: ""; position: absolute; bottom: -6px; left: 50%; translate: -50% 0; width: 6px; height: 6px; border-radius: 50%;
  background: var(--olive);
}
@media (max-width: 380px) { .verse { min-height: 50px; } .verse b { font-size: 13px; } .verse small { display: none; } }

/* اختيار ثلاثي */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg button {
  min-height: 56px; border-radius: 14px; background: var(--bg); border: 1.5px solid var(--line);
  font-weight: 500; font-size: 15px; transition: all .12s;
}
.seg button[aria-checked="true"][data-v="full"] { background: var(--olive); border-color: var(--olive); color: var(--ivory); font-weight: 700; }
.seg button[aria-checked="true"][data-v="partial"] { background: var(--gold); border-color: var(--gold); color: var(--white); font-weight: 700; }
.seg button[aria-checked="true"][data-v="none"] { background: #f6e9e4; border-color: #e3c2b8; color: var(--danger); font-weight: 700; }

/* الدرجة */
.score { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; align-items: stretch; }
.step { min-height: 64px; border-radius: 16px; background: var(--olive-50); color: var(--olive); font-weight: 700; font-size: 18px; }
.step:active { background: #e4e9cf; }
.score-input {
  display: flex; align-items: center; justify-content: center; gap: 6px; border-radius: 16px;
  border: 1.5px solid var(--line); background: var(--bg);
}
.score-input:focus-within { border-color: var(--gold); background: var(--white); }
.score-input input {
  width: 3.2ch; border: 0; background: transparent; text-align: center; font-size: 32px; font-weight: 700; padding: 0;
  font-variant-numeric: tabular-nums;
}
.score-input input:focus { outline: none; }
.score-input span { color: var(--muted); font-size: 16px; }

/* ===== الإحصاءات ===== */
.stats { display: grid; gap: 12px; }
@media (min-width: 720px) { .stats { grid-template-columns: 1fr 1fr; } .stats .wide { grid-column: 1 / -1; } }
.stat-card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat-card h3 { margin: 0 0 12px; font-size: 16px; color: var(--olive); display: flex; justify-content: space-between; align-items: baseline; }
.stat-card h3 small { color: var(--muted); font-weight: 400; font-size: 14px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { border-radius: 14px; padding: 12px; background: var(--bg); text-align: center; }
.kpi b { display: block; font-size: 26px; line-height: 1.2; }
.kpi small { color: var(--muted); font-size: 13px; }
.kpi.done { background: var(--olive); color: var(--ivory); } .kpi.done small { color: color-mix(in srgb, var(--ivory) 75%, transparent); }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: #ecebd3; margin-bottom: 10px; gap: 2px; }
.stack i { display: block; height: 100%; }
.c-full { background: var(--olive); } .c-partial { background: var(--gold); } .c-none { background: #d9a596; } .c-empty { background: #ecebd3; }
.legend { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend li .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend li b { margin-inline-start: auto; font-variant-numeric: tabular-nums; }
.big-num { font-size: 40px; font-weight: 700; line-height: 1; color: var(--olive); }
.big-num small { font-size: 16px; color: var(--muted); font-weight: 400; }
.sub-nums { display: flex; gap: 18px; margin-top: 10px; color: var(--muted); font-size: 14px; }
.sub-nums b { color: var(--ink); }
.group-rows { display: grid; gap: 10px; }
.group-row { display: grid; grid-template-columns: 90px 1fr 48px; gap: 10px; align-items: center; font-size: 14px; }
.group-row .bar { height: 8px; border-radius: 4px; background: #ecebd3; overflow: hidden; }
.group-row .bar i { display: block; height: 100%; background: var(--olive); border-radius: 4px; }
.group-row b { text-align: left; font-variant-numeric: tabular-nums; }
.stats-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; margin-top: 16px; }
.stats-actions .btn-primary { flex: 1; max-width: 320px; }

/* ===== تذييل وتنبيه ===== */
.foot { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 12px 16px calc(24px + var(--safe-b)); }
.foot-dome { width: 14px; height: 14px; color: var(--gold); }
.toast {
  position: fixed; bottom: calc(24px + var(--safe-b)); left: 50%; translate: -50% 20px; z-index: 40;
  background: var(--ink); color: var(--ivory); padding: 10px 18px; border-radius: 999px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s, translate .2s; white-space: nowrap;
}
.toast.show { opacity: 1; translate: -50% 0; }
.toast.error { background: var(--danger); }

@media (max-width: 420px) {
  .brand { height: 36px; } .brand-nokhab { height: 32px; }
  .hero-progress-text { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
