:root {
  --bg: #f5f2ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1d2b27;
  --muted: #5f6f6a;
  --line: #e4ded1;
  --brand: #0f5c4d;
  --brand-2: #157a66;
  --brand-soft: #e3f1ec;
  --accent: #f0a033;
  --accent-soft: #fdf0dc;
  --ok: #1e8a4c;
  --ok-soft: #e2f5e9;
  --bad: #c0392b;
  --bad-soft: #fbe7e4;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20,40,35,.06), 0 8px 24px rgba(20,40,35,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Arabic", "Tajawal", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .5em; }
.hidden { display: none !important; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.topbar {
  background: var(--brand);
  color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: #fff; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px; background: var(--accent);
  display: grid; place-items: center; color: var(--brand); font-size: 1.3rem;
}
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: .95rem; }
.points-pill { background: rgba(255,255,255,.15); padding: 4px 12px; border-radius: 99px; font-weight: 600; white-space: nowrap; }

/* ---------- Cards & layout ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.grid { display: grid; gap: 16px; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.section { padding: 28px 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Hero ---------- */
.hero { padding: 36px 0 12px; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
.hero p { color: var(--muted); max-width: 560px; }
.hero-grid { display: grid; gap: 24px; align-items: start; }
@media (min-width: 820px) { .hero-grid { grid-template-columns: 1.1fr .9fr; } }
.feature-list { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 12px; }
.feature-list li { display: flex; gap: 12px; align-items: flex-start; }
.feature-list .ic { width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--brand-soft); display: grid; place-items: center; font-size: 1.1rem; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; margin: 0 0 6px; font-size: .95rem; }
.field { margin-bottom: 14px; }
input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 11px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); background: #fff; box-shadow: 0 0 0 3px var(--brand-soft); }
input.ltr { direction: ltr; text-align: right; letter-spacing: .5px; }
.dob { display: grid; grid-template-columns: 1fr 1.4fr 1.2fr; gap: 8px; }
.hint { font-size: .85rem; color: var(--muted); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700;
  padding: 11px 20px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  background: var(--brand); color: #fff;
  cursor: pointer; text-decoration: none;
  transition: transform .05s, background .15s;
}
.btn:hover { background: var(--brand-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.accent { background: var(--accent); color: #3b2604; }
.btn.accent:hover { background: #e8932a; }
.btn.ghost { background: transparent; color: var(--brand); border-color: var(--line); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.danger { background: transparent; color: var(--bad); border-color: #f0c9c3; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 6px 12px; font-size: .88rem; border-radius: 10px; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.topbar .btn.ghost:hover { background: rgba(255,255,255,.12); }

.tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); padding: 4px; border-radius: 14px; margin-bottom: 18px; overflow-x: auto; }
.tab { flex: 1; white-space: nowrap; background: none; border: 0; font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 10px; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--surface); color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: .95rem; }
.alert.err { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--accent-soft); color: #7a4b07; }

/* ---------- Competitions ---------- */
.comp {
  display: flex; gap: 14px; align-items: center;
  padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.comp + .comp { margin-top: 10px; }
.comp .ic { width: 48px; height: 48px; flex: none; border-radius: 14px; display: grid; place-items: center; font-size: 1.4rem; background: var(--accent-soft); }
.comp.done .ic { background: var(--ok-soft); }
.comp h3 { font-size: 1.05rem; margin: 0; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .82rem; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--accent-soft); color: #8a5408; }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 1.6rem; color: var(--brand); line-height: 1.2; }
.stat span { font-size: .85rem; color: var(--muted); }

/* ---------- Quiz ---------- */
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 18px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .25s; }
.q-text { font-size: 1.2rem; font-weight: 600; margin-bottom: 18px; }
.options { display: grid; gap: 10px; }
.opt {
  display: flex; gap: 12px; align-items: center; text-align: right;
  font: inherit; padding: 14px 16px;
  border: 2px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink); cursor: pointer;
}
.opt:hover { border-color: var(--brand-2); }
.opt .l { width: 32px; height: 32px; flex: none; border-radius: 10px; display: grid; place-items: center; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.sel .l { background: var(--brand); color: #fff; border-color: var(--brand); }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.qnav button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font: inherit; font-size: .85rem; cursor: pointer; }
.qnav button.answered { background: var(--brand-soft); border-color: var(--brand-2); color: var(--brand); font-weight: 700; }
.qnav button.current { outline: 2px solid var(--accent); }

/* ---------- Result ---------- */
.score-ring { width: 150px; height: 150px; margin: 6px auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); }
.score-ring > div { width: 118px; height: 118px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: 1.8rem; font-weight: 700; color: var(--brand); }
.review { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-top: 10px; background: var(--surface); }
.review.right { border-inline-start: 5px solid var(--ok); }
.review.wrong { border-inline-start: 5px solid var(--bad); }
.review .ans { font-size: .95rem; margin-top: 6px; }
.review .exp { font-size: .9rem; color: var(--muted); margin-top: 6px; background: var(--surface-2); padding: 8px 10px; border-radius: 10px; }

/* ---------- Leaderboard ---------- */
.lb-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; }
.lb-row + .lb-row { border-top: 1px solid var(--line); }
.lb-row.me { background: var(--accent-soft); }
.lb-rank { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); }
.lb-rank.r1 { background: #f7c948; border-color: #e5b52e; }
.lb-rank.r2 { background: #dfe3e6; border-color: #c8cdd1; }
.lb-rank.r3 { background: #e7b288; border-color: #d39a6c; }
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--brand-2); }

/* ---------- Tables (admin) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.drop {
  border: 2px dashed var(--line); border-radius: 14px; padding: 22px; text-align: center; background: var(--surface-2); cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--brand-2); background: var(--brand-soft); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

footer { padding: 30px 0; text-align: center; color: var(--muted); font-size: .88rem; }

/* منع تمدد عناصر الشبكة على الشاشات الصغيرة */
.grid > *, .hero-grid > * { min-width: 0; }
#authCard .tab { white-space: normal; line-height: 1.4; }
.who { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }

/* ---------- العداد ---------- */
.timer { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; }
.timer-num { min-width: 64px; text-align: center; font-weight: 700; font-size: 1.6rem; color: var(--brand); line-height: 1; }
.timer-num small { display: block; font-size: .7rem; font-weight: 600; color: var(--muted); margin-top: 2px; }
.timer-bar { flex: 1; height: 12px; background: var(--line); border-radius: 99px; overflow: hidden; }
.timer-bar > div { height: 100%; background: var(--brand-2); width: 100%; transition: width .2s linear; }
.timer.warn .timer-num { color: var(--bad); }
.timer.warn .timer-bar > div { background: var(--bad); }
.no-copy { -webkit-user-select: none; user-select: none; }
.rules { text-align: right; padding-inline-start: 20px; margin: 14px 0; display: grid; gap: 6px; }
.opt:disabled { cursor: default; opacity: .75; }
.overall { font-weight: 700; font-size: .95rem; padding: 3px 12px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; direction: ltr; }
.overall.warn { background: var(--bad-soft); color: var(--bad); }
.qnav button.later { background: var(--accent-soft); border-color: var(--accent); color: #8a5408; font-weight: 700; }
.pw-rules { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 2px; font-size: .85rem; color: var(--muted); }
.pw-rules li::before { content: "○ "; }
.pw-rules li.ok { color: var(--ok); }
.pw-rules li.ok::before { content: "✓ "; }
.kb-warn { font-size: .85rem; color: var(--bad); margin-top: 4px; font-weight: 600; }
.modal { position: fixed; inset: 0; background: rgba(20,30,28,.45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-card { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; }
.board-card h3 { margin-bottom: 8px; padding-bottom: 8px; border-bottom: 2px solid var(--accent-soft); }
.nowrap { white-space: nowrap; }
.board-name { flex: 1; min-width: 0; font-size: .9rem; font-weight: 700; line-height: 1.45; white-space: nowrap; }
.board-name.wrap { white-space: normal; }
/* لوحة الشرف في الرئيسية: مساحة أكبر للأسماء */
#homeBoard { width: min(1180px, calc(100vw - 32px)); margin-inline: auto; position: relative; inset-inline-start: 50%; transform: translateX(50%); }
.board-card { padding: 18px 16px; }
.board-card .lb-row { gap: 8px; padding: 10px 6px; }
.board-card .lb-rank { width: 30px; height: 30px; font-size: .9rem; }
.board-grid { grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); }

/* ================= لوحة الشرف (الرئيسية) ================= */
.hof-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.hof-head h2 { margin: 0; font-size: 1.5rem; }
.hof-head p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.hof-trophy { width: 56px; height: 56px; flex: none; border-radius: 18px; display: grid; place-items: center; font-size: 1.8rem;
  background: linear-gradient(145deg, #ffd978, #f0a033); box-shadow: 0 8px 20px rgba(240,160,51,.35); }

.hof-card { --c1: #0f5c4d; --c2: #1e8a73; --soft: #e3f1ec;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(20,40,35,.05), 0 12px 32px rgba(20,40,35,.08); display: flex; flex-direction: column; }
.hof-card.g4 { --c1: #0f5c4d; --c2: #21977d; --soft: #e3f3ee; }
.hof-card.g5 { --c1: #b35a12; --c2: #e8902f; --soft: #fdf0dc; }
.hof-card.g6 { --c1: #2c4a8f; --c2: #4f74c9; --soft: #e8eefb; }
.hof-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 14px 18px; color: #fff; background: linear-gradient(120deg, var(--c1), var(--c2)); }
.hof-grade { font-weight: 700; font-size: 1.15rem; }
.hof-sub { font-size: .8rem; opacity: .85; }

.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 8px; padding: 22px 14px 0;
  background: linear-gradient(180deg, var(--soft), transparent 75%); }
.pod { display: flex; flex-direction: column; align-items: center; text-align: center; min-width: 0; }
.pod-crown { font-size: 1.3rem; line-height: 1; margin-bottom: 2px; animation: hof-bob 2.6s ease-in-out infinite; }
@keyframes hof-bob { 50% { transform: translateY(-3px); } }
.pod-avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 1.15rem;
  color: var(--c1); background: #fff; border: 3px solid var(--ring, #cfd5d3); box-shadow: 0 4px 10px rgba(0,0,0,.08); }
.pod-1 .pod-avatar { width: 58px; height: 58px; font-size: 1.4rem; }
.pod-1 { --ring: #f2c13b; --base: linear-gradient(180deg, #ffd978, #f0b429); --bh: 74px; }
.pod-2 { --ring: #c3cad1; --base: linear-gradient(180deg, #eef1f4, #c9d0d6); --bh: 54px; }
.pod-3 { --ring: #e0a46f; --base: linear-gradient(180deg, #f6cfa8, #dc9a5f); --bh: 40px; }
.pod-name { margin-top: 8px; font-weight: 700; font-size: .8rem; line-height: 1.4; color: var(--ink); word-break: break-word; }
.pod-1 .pod-name { font-size: .88rem; }
.pod-points { margin: 4px 0 8px; font-weight: 700; font-size: .85rem; color: var(--c1); }
.pod-points span { font-weight: 400; font-size: .72rem; color: var(--muted); }
.pod-base { width: 100%; height: var(--bh); border-radius: 12px 12px 0 0; background: var(--base);
  display: grid; place-items: start center; padding-top: 6px; box-shadow: inset 0 -6px 0 rgba(0,0,0,.06); }
.pod-base span { font-weight: 800; font-size: 1.3rem; color: rgba(0,0,0,.45); }
.pod-empty .pod-base { opacity: .35; }
.pod-empty { opacity: .9; }

.hof-rest { padding: 6px 14px 14px; border-top: 1px solid var(--line); }
.hof-row { display: flex; align-items: center; gap: 10px; padding: 9px 6px; }
.hof-row + .hof-row { border-top: 1px dashed var(--line); }
.hof-rank { width: 28px; height: 28px; flex: none; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: .85rem;
  background: var(--soft); color: var(--c1); }
.hof-pts { font-weight: 700; font-size: .85rem; color: var(--c1); white-space: nowrap; }

.hof-empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 30px 16px; color: var(--muted);
  background: linear-gradient(180deg, var(--soft), transparent 80%); }
.hof-empty div { font-size: 2.2rem; filter: grayscale(.3); opacity: .8; }
.hof-empty p { margin: 6px 0 0; font-size: .9rem; }
@media (prefers-reduced-motion: reduce) { .pod-crown { animation: none; } }

/* ---------- بطاقة المعلم ---------- */
.tcard { position: relative; display: flex; align-items: center; gap: 18px; padding: 22px 20px 18px; margin-bottom: 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(20,40,35,.05), 0 14px 34px rgba(20,40,35,.09); max-width: 520px; }
.tcard::before { content: ""; position: absolute; inset-inline: 0; top: 0; height: 5px;
  background: linear-gradient(90deg, var(--brand-2), var(--accent)); }
.tcard-photo-wrap { position: relative; flex: none; }
.tcard-photo { width: 104px; height: 104px; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 700; font-size: 1.6rem;
  border: 4px solid #fff; box-shadow: 0 0 0 3px var(--accent), 0 10px 22px rgba(15,92,77,.25); }
.tcard-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tcard-badge { position: absolute; bottom: 2px; inset-inline-start: 0; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1rem; background: var(--accent); border: 3px solid #fff; box-shadow: 0 4px 10px rgba(0,0,0,.15); }
.tcard-info { position: relative; z-index: 1; min-width: 0; }
.tcard-role { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .2px; color: var(--brand);
  background: var(--brand-soft); padding: 3px 10px; border-radius: 99px; }
.tcard-name { font-size: 1.3rem; font-weight: 700; margin: 0 0 4px; line-height: 1.35; }
.tcard-school { color: var(--muted); font-size: .9rem; }
.tcard-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tcard-chips span { font-size: .75rem; font-weight: 600; padding: 3px 10px; border-radius: 99px;
  background: var(--accent-soft); color: #8a5408; border: 1px solid #f6dcae; }
@media (max-width: 480px) {
  .tcard { gap: 14px; padding: 16px; }
  .tcard-photo { width: 84px; height: 84px; }
  .tcard-badge { width: 28px; height: 28px; font-size: .85rem; }
  .tcard-name { font-size: 1.1rem; }
}

/* ---------- أزرار الدخول ونافذة دخول الطالب ---------- */
.top-actions { display: flex; gap: 8px; align-items: center; }
.topbar .btn.accent { color: #3b2604; }
.hero-cta { margin-top: 6px; padding: 13px 26px; font-size: 1.05rem; box-shadow: 0 8px 20px rgba(240,160,51,.35); }
.features-card { align-self: center; }
.modal { position: fixed; inset: 0; background: rgba(20,30,28,.5); display: grid; place-items: center; z-index: 40; padding: 16px; backdrop-filter: blur(2px); }
.login-card { position: relative; max-width: 440px; padding-top: 26px; animation: pop .18s ease-out; }
.modal-x { position: absolute; top: 10px; inset-inline-end: 10px; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--muted); font-size: 1rem; cursor: pointer; }
.modal-x:hover { background: var(--bad-soft); color: var(--bad); }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
@media (max-width: 480px) {
  .top-actions .btn { padding: 6px 10px; font-size: .8rem; }
  .brand span:last-child { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) { .login-card { animation: none; } }
.top-actions .btn { white-space: nowrap; }
@media (max-width: 480px) {
  .top-actions { gap: 6px; }
  .top-actions .em { display: none; }
  .topbar .wrap { gap: 8px; }
  .brand { gap: 8px; font-size: 1rem; white-space: nowrap; }
  .brand-mark { width: 32px; height: 32px; font-size: 1.1rem; }
}
