/* اللغة الصينية — المرحلة المتوسطة | تصميم عربي RTL خفيف بلا مكتبات */
:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #1d2433;
  --muted: #5d6779;
  --line: #e2e8f0;
  --brand: #c8102e;      /* أحمر صيني */
  --brand-2: #0f766e;    /* فيروزي */
  --gold: #f5b301;
  --ok: #15803d;
  --bad: #b91c1c;
  --soon: #8a94a6;
  --space: #0b1026;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(16, 24, 40, .08);
  --ar: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Noto Sans Arabic", "Geeza Pro", Arial, sans-serif;
  --zh: "Noto Sans SC", "Noto Sans CJK SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--ar); font-size: 17px; line-height: 1.7;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--brand-2); }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
.zh { font-family: var(--zh); unicode-bidi: isolate; direction: ltr; }
.py { font-family: "Segoe UI", Arial, sans-serif; unicode-bidi: isolate; direction: ltr; color: var(--brand-2); }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.hidden { display: none !important; }

/* ===== رأس الصفحة ===== */
.topbar {
  background: linear-gradient(135deg, #b10f2a, #e0313f);
  color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar .in { max-width: 1000px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.topbar a { color: #fff; text-decoration: none; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.logo .seal {
  width: 38px; height: 38px; border-radius: 10px; background: #fff; color: var(--brand);
  display: grid; place-items: center; font-family: var(--zh); font-size: 1.4rem; font-weight: 700;
}
.topbar .spacer { flex: 1; }
.topbar .nav a { background: rgba(255,255,255,.18); padding: 6px 12px; border-radius: 999px; font-size: .9rem; white-space: nowrap; }

main { flex: 1; width: 100%; max-width: 1000px; margin: 0 auto; padding: 16px; }

/* ===== مسار التنقل ===== */
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; font-size: .88rem; color: var(--muted); margin: 4px 0 14px; }
.crumbs a { color: var(--brand-2); text-decoration: none; }
.crumbs span.sep { opacity: .6; }

/* ===== بطاقات عامة ===== */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card h2, .card h3 { margin-top: 0; }
h1 { font-size: 1.55rem; margin: 6px 0 10px; line-height: 1.4; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.08rem; }
.badge { display: inline-block; font-size: .78rem; padding: 2px 10px; border-radius: 999px; background: #e6f4f1; color: var(--brand-2); font-weight: 700; vertical-align: middle; }
.badge.soon { background: #eef0f4; color: var(--soon); }
.badge.gold { background: #fff6d6; color: #8a6200; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 10px 16px; background: var(--brand-2); color: #fff;
  font-weight: 700; text-decoration: none; min-height: 44px;
}
.btn.red { background: var(--brand); }
.btn.ghost { background: #fff; color: var(--brand-2); border: 2px solid var(--brand-2); }
.btn.gold { background: var(--gold); color: #3b2a00; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ===== الصفحة الرئيسية: اختيار الصف ===== */
.hero { text-align: center; padding: 18px 8px 6px; }
.hero .big-zh { font-family: var(--zh); font-size: 3rem; color: var(--brand); line-height: 1.2; }
.grades { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-top: 16px; }
.grade-card {
  display: block; text-decoration: none; color: inherit; background: #fff; border-radius: 20px; padding: 20px;
  box-shadow: var(--shadow); border: 2px solid transparent; transition: transform .15s, border-color .15s;
}
.grade-card:hover, .grade-card:focus { transform: translateY(-2px); border-color: var(--brand-2); }
.grade-card .num { font-size: 2.4rem; font-weight: 800; color: var(--brand); }
.grade-card h2 { margin: 4px 0; }

/* ===== صفحة الصف ===== */
.term-tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.term-tabs button { border: 2px solid var(--brand-2); background: #fff; color: var(--brand-2); border-radius: 999px; padding: 8px 16px; font-weight: 700; }
.term-tabs button.on { background: var(--brand-2); color: #fff; }
.unit { padding: 0; overflow: hidden; }
.unit-head { display: flex; gap: 12px; align-items: center; padding: 14px 16px; background: linear-gradient(90deg, #fff, #f1f8f7); border-bottom: 1px solid var(--line); }
.unit-num { min-width: 52px; height: 52px; border-radius: 14px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; line-height: 1.1; text-align: center; font-size: .78rem; }
.unit-num b { font-size: 1.35rem; display: block; }
.unit-title .zh { font-size: 1.2rem; font-weight: 700; }
.unit-title .en { direction: ltr; unicode-bidi: isolate; color: var(--muted); font-size: .9rem; }
.lessons { list-style: none; margin: 0; padding: 6px 10px 10px; }
.lesson-link {
  display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 12px; text-decoration: none; color: inherit;
}
.lesson-link:hover { background: #f5f8fc; }
.lesson-link.soon { opacity: .75; cursor: default; }
.lesson-no { width: 40px; height: 40px; border-radius: 50%; background: #e6f4f1; color: var(--brand-2); display: grid; place-items: center; font-weight: 800; flex: none; }
.lesson-link.soon .lesson-no { background: #eef0f4; color: var(--soon); }
.lesson-meta { flex: 1; min-width: 0; }
.lesson-meta .zh { font-size: 1.15rem; font-weight: 700; }
.lesson-stars { color: var(--gold); white-space: nowrap; font-size: .95rem; letter-spacing: 1px; }
.unit-foot { padding: 0 16px 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===== صفحة الدرس ===== */
.lesson-hero { display: flex; gap: 14px; align-items: center; }
.lesson-hero .n { width: 64px; height: 64px; flex: none; border-radius: 18px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 1.8rem; font-weight: 800; }
.lesson-hero .zh { font-size: 1.8rem; font-weight: 700; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; position: sticky; top: 58px; z-index: 10; background: var(--bg); padding: 8px 0; }
.tabs a { text-align: center; text-decoration: none; padding: 10px 4px; border-radius: 12px; background: #fff; color: var(--ink); font-weight: 700; border: 2px solid var(--line); font-size: .95rem; }
.tabs a .ic { display: block; font-size: 1.3rem; line-height: 1.2; }
.tabs a.on { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }

.vocab-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.vcard { border: 2px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; background: #fff; position: relative; }
.vcard .zh { font-size: 2.1rem; line-height: 1.3; }
.vcard .py { font-size: 1.1rem; font-weight: 700; }
.vcard .mean { font-weight: 700; margin-top: 2px; }
.vcard .approx { font-size: .82rem; color: var(--muted); }
.vcard .en { font-size: .78rem; color: var(--muted); direction: ltr; unicode-bidi: isolate; }
.vcard.extra { border-style: dashed; background: #fbfbfd; }
.say { border: 0; background: #e6f4f1; color: var(--brand-2); border-radius: 999px; width: 38px; height: 38px; font-size: 1.05rem; display: inline-grid; place-items: center; vertical-align: middle; flex: none; }
.say:hover { background: #cdebe6; }
body.no-tts .say, body.no-tts .saybtn { display: none !important; }
.vocab-grid.quiz-mode .vcard:not(.peek) .mean,
.vocab-grid.quiz-mode .vcard:not(.peek) .en,
.vocab-grid.quiz-mode .vcard:not(.peek) .approx { visibility: hidden; }
.vocab-grid.quiz-mode .vcard { cursor: pointer; }
.qshow.long { font-size: 1.7rem; }
details summary { cursor: pointer; }
.note { background: #fff8e6; border-right: 4px solid var(--gold); padding: 10px 12px; border-radius: 10px; font-size: .93rem; }
.note.info { background: #eef6ff; border-color: #3b82f6; }

.dialogue { border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 10px; }
.dialogue h4 { margin: 0 0 6px; }
.dline { display: flex; gap: 10px; align-items: flex-start; padding: 8px 4px; border-bottom: 1px dashed var(--line); }
.dline:last-child { border-bottom: 0; }
.spk { flex: none; min-width: 36px; height: 36px; padding: 0 6px; border-radius: 18px; background: #fde8eb; color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: .85rem; font-family: var(--zh); }
.dline .txt { flex: 1; }
.dline .zh { font-size: 1.3rem; display: block; }
.dline .py { display: block; font-size: .95rem; }
.dline .tr { display: block; color: var(--muted); font-size: .95rem; }
.toggles { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.toggles label { background: #f1f5f9; border-radius: 999px; padding: 4px 12px; font-size: .88rem; cursor: pointer; }
body.hide-py .dline .py { visibility: hidden; }
body.hide-tr .dline .tr { display: none; }

.tone-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.tone-box { border-radius: 12px; padding: 10px; text-align: center; color: #fff; }
.tone-box .mk { font-size: 1.9rem; font-weight: 800; line-height: 1.1; direction: ltr; }
.t1 { background: #2563eb; } .t2 { background: #16a34a; } .t3 { background: #d97706; } .t4 { background: #dc2626; } .t0 { background: #64748b; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #f1f5f9; border-radius: 999px; padding: 3px 12px; font-family: "Segoe UI", Arial, sans-serif; direction: ltr; unicode-bidi: isolate; font-weight: 700; }
button.chip { border: 0; }

.write-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.wcard { border: 2px solid var(--line); border-radius: 14px; padding: 12px; }
.wcard .head { display: flex; gap: 12px; align-items: center; }
.wcard .bigzh { font-family: var(--zh); font-size: 3.2rem; line-height: 1; width: 72px; height: 72px; display: grid; place-items: center; background: #fff7f7; border-radius: 12px; color: var(--brand); }
.pad-wrap { position: relative; width: 100%; max-width: 240px; aspect-ratio: 1; margin: 10px auto 4px; }
.pad-wrap .ghost { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--zh); font-size: min(170px, 46vw); color: rgba(200,16,46,.13); pointer-events: none; line-height: 1; }
.pad-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; border-radius: 12px; border: 2px dashed #f0b4bd;
  background-image: linear-gradient(rgba(200,16,46,.12) 1px, transparent 1px), linear-gradient(90deg, rgba(200,16,46,.12) 1px, transparent 1px);
  background-size: 50% 50%; background-position: center; }

/* ===== المجرّة ===== */
.galaxy {
  position: relative; border-radius: 20px; padding: 18px 12px 24px; color: #fff; overflow: hidden;
  background: radial-gradient(ellipse at 20% 10%, #2b2f77 0%, transparent 55%), radial-gradient(ellipse at 80% 90%, #5b1d5e 0%, transparent 50%), var(--space);
}
.galaxy::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .7;
  background-image: radial-gradient(1px 1px at 10% 20%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 30% 70%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 60% 30%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 85% 60%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 45% 90%, #fff 50%, transparent 51%), radial-gradient(1.5px 1.5px at 75% 12%, #fff 50%, transparent 51%);
}
.galaxy h2, .galaxy p { position: relative; }
.planets { position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px 10px; margin-top: 12px; }
.planet { text-align: center; text-decoration: none; color: #fff; display: block; }
.planet .orb {
  width: 92px; height: 92px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center; position: relative;
  font-family: var(--zh); font-size: 1.6rem; font-weight: 700; box-shadow: inset -12px -12px 24px rgba(0,0,0,.35), 0 0 22px rgba(255,255,255,.18);
}
.planet .orb::after { content: ""; position: absolute; width: 130%; height: 22%; border: 2px solid rgba(255,255,255,.45); border-radius: 50%; transform: rotate(-18deg); }
.planet.soon { opacity: .45; cursor: default; }
.planet .pstars { color: var(--gold); font-size: .9rem; letter-spacing: 1px; }
.planet .plabel { font-size: .85rem; }
.p1 { background: radial-gradient(circle at 30% 30%, #ffb3b3, #c8102e); }
.p2 { background: radial-gradient(circle at 30% 30%, #b3f0e6, #0f766e); }
.p3 { background: radial-gradient(circle at 30% 30%, #ffe9a8, #c58a00); }
.p4 { background: radial-gradient(circle at 30% 30%, #c9d7ff, #3046c2); }
.p5 { background: radial-gradient(circle at 30% 30%, #f3c2ff, #8a2bb0); }
.p6 { background: radial-gradient(circle at 30% 30%, #c4f5b8, #2f8a1d); }
.p7 { background: radial-gradient(circle at 30% 30%, #ffd2b0, #d0560b); }

.star-path { position: relative; display: flex; flex-direction: column; gap: 14px; align-items: center; padding: 10px 0; }
.star-node {
  position: relative; width: 100%; max-width: 420px; display: flex; gap: 12px; align-items: center; padding: 10px 14px;
  border-radius: 16px; background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.2); text-align: right;
}
.star-node:nth-child(even) { transform: translateX(-18px); }
.star-node:nth-child(odd) { transform: translateX(18px); }
.star-node .s {
  width: 54px; height: 54px; flex: none; display: grid; place-items: center; font-size: 1.7rem;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background: #6b7280;
}
.star-node.open .s { background: var(--gold); }
.star-node.done .s { background: linear-gradient(#ffe066, #f59f00); }
.star-node.locked { opacity: .5; cursor: not-allowed; }
.star-node .info { flex: 1; }
.star-node .info b { display: block; }
.star-node .got { color: var(--gold); letter-spacing: 2px; }

/* ===== الأسئلة ===== */
.qbox { text-align: center; }
.qprog { height: 10px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-bottom: 12px; }
.qprog i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-2), #22c3a6); width: 0; transition: width .3s; }
.qshow { font-family: var(--zh); font-size: 2.6rem; margin: 6px 0; line-height: 1.3; }
.qshow.pyshow { font-family: "Segoe UI", Arial, sans-serif; color: var(--brand-2); direction: ltr; unicode-bidi: isolate; }
.qprompt { font-size: 1.12rem; font-weight: 700; margin-bottom: 10px; }
.choices { display: grid; gap: 10px; grid-template-columns: 1fr; max-width: 520px; margin: 0 auto; }
@media (min-width: 560px) { .choices.two { grid-template-columns: 1fr 1fr; } }
.choice {
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 12px; font-size: 1.1rem; min-height: 52px; font-weight: 600;
}
.choice:hover:not(:disabled) { border-color: var(--brand-2); }
.choice.ok { background: #dcfce7; border-color: var(--ok); color: #064e1f; }
.choice.no { background: #fee2e2; border-color: var(--bad); color: #7f1d1d; }
.choice .zh { font-size: 1.4rem; }
.feedback { min-height: 28px; margin-top: 10px; font-weight: 700; }
.feedback.ok { color: var(--ok); } .feedback.no { color: var(--bad); }
.result { text-align: center; padding: 10px; }
.result .score { font-size: 3rem; font-weight: 800; color: var(--brand-2); line-height: 1.2; }
.result .stars { font-size: 2.2rem; color: var(--gold); letter-spacing: 4px; }
.review-list { text-align: right; margin-top: 12px; }
.review-list li { margin-bottom: 6px; }

/* ===== الألعاب ===== */
.game-menu { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.game-tile { border: 0; border-radius: 18px; padding: 18px; text-align: center; color: #fff; font-weight: 800; font-size: 1.1rem; box-shadow: var(--shadow); }
.game-tile .ic { display: block; font-size: 2.2rem; }
.game-tile small { display: block; font-weight: 500; opacity: .9; font-size: .82rem; margin-top: 4px; }
.gt1 { background: linear-gradient(135deg, #7c3aed, #a855f7); }
.gt2 { background: linear-gradient(135deg, #ea580c, #f59e0b); }
.gt3 { background: linear-gradient(135deg, #0f766e, #14b8a6); }
.mem-grid { display: grid; gap: 8px; grid-template-columns: repeat(4, 1fr); max-width: 560px; margin: 10px auto; }
.mem-card {
  aspect-ratio: 3 / 4; border-radius: 12px; border: 0; background: linear-gradient(135deg, var(--brand), #ff5a6e); color: #fff;
  font-size: 1.6rem; display: grid; place-items: center; padding: 4px; line-height: 1.25; overflow: hidden; word-break: break-word;
}
.mem-card.up { background: #fff; color: var(--ink); border: 2px solid var(--brand-2); font-size: 1rem; }
.mem-card.up.zhc { font-family: var(--zh); font-size: 1.6rem; }
.mem-card.done { background: #dcfce7; border: 2px solid var(--ok); color: #064e1f; }
.hud { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; margin-bottom: 8px; flex-wrap: wrap; }
.tone-btns { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; max-width: 520px; margin: 10px auto; }
.tone-btns button { border: 0; border-radius: 12px; color: #fff; padding: 10px 2px; font-weight: 800; font-size: 1.4rem; min-height: 64px; line-height: 1.1; }
.tone-btns button small { display: block; font-size: .7rem; font-weight: 600; }
.match-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 560px; margin: 0 auto; }
.match-cols button { width: 100%; margin-bottom: 8px; border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 6px; min-height: 52px; font-weight: 700; }
.match-cols button.zhb { font-family: var(--zh); font-size: 1.35rem; }
.match-cols button.sel { border-color: var(--brand-2); background: #e6f4f1; }
.match-cols button.gone { visibility: hidden; }
.match-cols button.wrong { border-color: var(--bad); background: #fee2e2; }

/* ===== قريبًا ===== */
.soon-box { text-align: center; padding: 28px 16px; }
.soon-box .ic { font-size: 3rem; }

/* ===== التذييل ===== */
.review-banner {
  background: #fff3cd; color: #6b4e00; border-top: 3px solid var(--gold); text-align: center; padding: 12px 16px; font-weight: 700;
}
footer.site { background: #1d2433; color: #cbd5e1; text-align: center; padding: 14px 16px 18px; font-size: .85rem; }
footer.site a { color: #fff; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  h1 { font-size: 1.3rem; }
  .lesson-hero .zh { font-size: 1.45rem; }
  .tabs { top: 54px; }
  .tabs a { font-size: .82rem; padding: 8px 2px; }
  .mem-grid { grid-template-columns: repeat(3, 1fr); }
  .star-node:nth-child(even), .star-node:nth-child(odd) { transform: none; }
  .logo .t { font-size: .92rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
