/* =========================================================
   لعبة كلمة — واجهة اللعب والتقارير
   ========================================================= */
.kg-app,
.kg-report,
.kg-cert-wrap,
.kg-login-box,
.kg-cert-locked {
    --kg-ink: #142c3f;
    --kg-ink-soft: #5b7383;
    --kg-teal: #12a5a0;
    --kg-teal-dark: #0b7a76;
    --kg-teal-soft: #d8f2f0;
    --kg-mango: #ffb020;
    --kg-mango-dark: #d98c00;
    --kg-coral: #ff5f57;
    --kg-coral-soft: #ffe3e1;
    --kg-grape: #6c5ce7;
    --kg-paper: #eef6f7;
    --kg-surface: #ffffff;
    --kg-line: #d5e5e7;
    --kg-radius: 18px;

    font-family: "Segoe UI", "Noto Sans Arabic", "Cairo", Tahoma, system-ui, sans-serif;
    color: var(--kg-ink);
    /* الاتجاه يتبع خاصية dir على العنصر — لا يُفرض هنا */
    text-align: right;
    box-sizing: border-box;
}

.kg-app *,
.kg-report *,
.kg-cert-wrap *,
.kg-login-box * { box-sizing: border-box; }

/* ---------- الهيكل ---------- */
.kg-app {
    max-width: 560px;
    margin: 20px auto;
    background: var(--kg-paper);
    border-radius: 26px;
    padding: 16px 16px 20px;
    box-shadow: 0 18px 40px rgba(20, 44, 63, .12);
}
@media (max-width: 560px) {
    .kg-app { margin: 0; border-radius: 0; min-height: 100vh; min-height: 100dvh;
              padding: 14px 13px calc(20px + env(safe-area-inset-bottom, 0px)); }
}

.kg-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 2px 16px;
}

/* منطقة الطفل: وجهه واسمه */
.kg-who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.kg-avatar {
    width: 38px; height: 38px; flex: 0 0 38px;
    display: grid; place-items: center;
    background: var(--kg-surface); border-radius: 50%; font-size: 20px;
    box-shadow: 0 2px 0 var(--kg-line);
}
.kg-who-name {
    font-weight: 800; font-size: 16px; color: var(--kg-ink);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* النجوم: حبّة واحدة تنبض عند الزيادة */
.kg-score {
    margin-inline-start: auto;
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--kg-surface); border-radius: 999px;
    padding: 7px 14px 7px 11px;
    font-weight: 800; font-size: 16px; color: var(--kg-ink);
    font-variant-numeric: tabular-nums;
    box-shadow: 0 3px 0 var(--kg-line);
    transition: transform .18s cubic-bezier(.2,1.7,.5,1);
}
.kg-score.is-up { transform: scale(1.14); }
.kg-score-star { font-size: 15px; line-height: 1; }

/* زر القائمة: النقاط الثلاث */
.kg-menu-btn {
    flex: 0 0 auto;
    width: 40px; height: 40px; padding: 0;
    border: 0; border-radius: 13px; cursor: pointer;
    background: var(--kg-surface);
    box-shadow: 0 3px 0 var(--kg-line);
    display: grid; place-items: center;
    transition: transform .12s, box-shadow .12s;
}
.kg-menu-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--kg-line); }
.kg-menu-btn span, .kg-menu-btn span::before, .kg-menu-btn span::after {
    content: ""; display: block;
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--kg-ink-soft);
}
.kg-menu-btn span { position: relative; }
.kg-menu-btn span::before { position: absolute; inset-inline-start: -9px; top: 0; }
.kg-menu-btn span::after  { position: absolute; inset-inline-start: 9px;  top: 0; }

/* ---------- لوح القائمة ---------- */
/* خاصية hidden يجب أن تغلب أي قاعدة display لدينا */
.kg-app [hidden], .kg-sheet[hidden], .kg-win[hidden],
.kg-overlay[hidden], .kg-listen-modal[hidden], .kg-write[hidden] { display: none !important; }
.kg-sheet {
    position: fixed; inset: 0; z-index: 9998;
    background: rgba(20, 44, 63, .55);
    display: flex; align-items: flex-end; justify-content: center;
    animation: kg-veil .2s ease;
}
@keyframes kg-veil { from { opacity: 0; } to { opacity: 1; } }

.kg-sheet-panel {
    width: 100%; max-width: 560px;
    background: var(--kg-paper);
    border-radius: 26px 26px 0 0;
    padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -12px 40px rgba(20, 44, 63, .25);
    animation: kg-rise .26s cubic-bezier(.2, .9, .3, 1);
}
@keyframes kg-rise { from { transform: translateY(100%); } to { transform: none; } }

.kg-sheet-grip {
    width: 42px; height: 5px; border-radius: 3px;
    background: var(--kg-line); margin: 0 auto 14px;
}

.kg-sheet-links { display: grid; gap: 8px; }
.kg-sheet-links a {
    display: flex; align-items: center; gap: 12px;
    background: var(--kg-surface);
    border-radius: 15px; padding: 14px 16px;
    font-weight: 700; font-size: 16px; color: var(--kg-ink);
    text-decoration: none;
    box-shadow: 0 3px 0 var(--kg-line);
    transition: transform .12s, box-shadow .12s;
}
.kg-sheet-links a:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--kg-line); }
.kg-sheet-ico { font-size: 20px; line-height: 1; }

.kg-sheet-lang {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-top: 16px; padding: 4px 4px 0;
    font-weight: 700; font-size: 14px; color: var(--kg-ink-soft);
}

.kg-sheet-close {
    width: 100%; margin-top: 16px; padding: 14px;
    border: 0; border-radius: 15px; cursor: pointer;
    background: var(--kg-teal); color: #fff;
    font-family: inherit; font-weight: 800; font-size: 16px;
    box-shadow: 0 3px 0 var(--kg-teal-dark);
}
.kg-sheet-close:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--kg-teal-dark); }

@media (min-width: 620px) {
    .kg-sheet { align-items: center; }
    .kg-sheet-panel { border-radius: 24px; max-width: 420px; animation: kg-pop .22s ease; }
    @keyframes kg-pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) {
    .kg-sheet, .kg-sheet-panel { animation: none; }
    .kg-score { transition: none; }
}

.kg-screen { display: none; }
.kg-screen.is-active { display: block; animation: kg-fade .25s ease; }
@keyframes kg-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.kg-screen-title { font-size: 20px; font-weight: 800; margin: 0 4px 12px; }

/* ---------- خريطة المستويات: أحجار على مسار ---------- */
.kg-stones { position: relative; padding: 6px 0 10px; }
.kg-stones::before {
    content: ""; position: absolute; top: 0; bottom: 0; right: 50%;
    width: 0; border-right: 4px dotted #c3dde0; transform: translateX(50%);
}
.kg-stone {
    position: relative;
    display: flex; align-items: center; gap: 14px;
    width: 84%;
    margin: 0 0 14px;
    padding: 14px 16px;
    background: var(--kg-surface);
    border: 0; border-radius: var(--kg-radius);
    box-shadow: 0 4px 0 var(--kg-line);
    cursor: pointer;
    text-align: right;
    font: inherit;
    transition: transform .12s ease, box-shadow .12s ease;
}
.kg-stone:nth-child(even) { margin-inline-start: 16%; }
.kg-stone:not(.is-locked):hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--kg-line); }
.kg-stone:not(.is-locked):active { transform: translateY(2px); box-shadow: 0 1px 0 var(--kg-line); }
.kg-stone.is-locked { cursor: not-allowed; opacity: .72; background: #e8eff0; }
.kg-stone.is-passed { border: 2px solid var(--kg-teal); }

.kg-stone-badge {
    width: 52px; height: 52px; flex: none;
    display: grid; place-items: center;
    border-radius: 16px;
    background: var(--kg-teal-soft);
    color: var(--kg-teal-dark);
    font-size: 22px; font-weight: 800;
}
.kg-stone.is-locked .kg-stone-badge { background: #dbe4e6; color: #8fa3a8; }
.kg-stone.is-passed .kg-stone-badge { background: var(--kg-teal); color: #fff; }

.kg-stone-body { flex: 1; min-width: 0; }
.kg-stone-name { font-weight: 800; font-size: 16px; display: block; margin-bottom: 6px; }
.kg-stone-meta { font-size: 13px; color: var(--kg-ink-soft); display: flex; gap: 10px; margin-top: 6px; }

.kg-bar { height: 9px; background: #e3edee; border-radius: 999px; overflow: hidden; flex: 1; }
.kg-bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--kg-teal), #35c8b6); border-radius: 999px; transition: width .4s ease; }

/* ---------- المواضيع ---------- */
.kg-topics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kg-topic {
    background: var(--kg-surface); border: 0; border-radius: var(--kg-radius);
    padding: 16px 12px; cursor: pointer; font: inherit; text-align: center;
    box-shadow: 0 4px 0 var(--kg-line); transition: transform .12s ease;
}
.kg-topic:hover { transform: translateY(-2px); }
.kg-topic:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--kg-line); }
.kg-topic-icon { font-size: 32px; display: block; margin-bottom: 6px; }
.kg-topic-name { font-weight: 800; display: block; }
.kg-topic-meta { font-size: 12px; color: var(--kg-ink-soft); }
.kg-topic.is-done { background: var(--kg-teal-soft); }

.kg-back {
    background: none; border: 0; font: inherit; color: var(--kg-ink-soft);
    cursor: pointer; padding: 6px 4px; margin-bottom: 6px;
}
.kg-back:hover { color: var(--kg-teal-dark); }

/* ---------- شاشة اللعب ---------- */
.kg-play-head { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.kg-round-count { font-size: 13px; color: var(--kg-ink-soft); font-variant-numeric: tabular-nums; }

.kg-icon-btn {
    width: 42px; height: 42px; flex: none;
    border: 0; border-radius: 14px;
    background: var(--kg-surface);
    box-shadow: 0 3px 0 var(--kg-line);
    font-size: 19px; cursor: pointer;
    display: grid; place-items: center;
    color: var(--kg-ink);
}
.kg-icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--kg-line); }
/* الأيقونات جوّا الزر SVG (لون currentColor) بدل الإيموجي النصي، عشان تنعرض
   بشكل موحّد على كل الأجهزة والمتصفحات مهما كانت الخطوط المثبّتة عندها. */
.kg-icon-btn svg { display: block; }

.kg-picture {
    background: var(--kg-surface);
    border-radius: 22px;
    height: clamp(150px, 30vh, 220px);
    display: grid; place-items: center;
    overflow: hidden;
    box-shadow: inset 0 0 0 3px #fff, 0 4px 0 var(--kg-line);
    margin-bottom: 12px;
}
.kg-picture img { width: 100%; height: 100%; object-fit: cover; }
.kg-picture svg { width: 62%; height: 62%; }
.kg-picture .kg-emoji { font-size: clamp(64px, 16vh, 96px); line-height: 1; }

.kg-hint { text-align: center; color: var(--kg-ink-soft); font-size: 14.5px;
    min-height: 22px; margin: 0 0 14px; line-height: 1.5; }

/* خانات الحروف */
.kg-slots {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
    margin-bottom: 20px; min-height: 66px;
}
.kg-slot {
    width: 56px; height: 62px;
    border-radius: 14px;
    border: 3px dashed #bcd5d8;
    display: grid; place-items: center;
    font-size: 30px; font-weight: 800;
    background: rgba(255, 255, 255, .5);
}
.kg-slot.is-space { border: 0; width: 18px; background: none; }
.kg-slot.is-filled {
    border: 0;
    background: var(--kg-teal);
    color: #fff;
    box-shadow: 0 4px 0 var(--kg-teal-dark);
    animation: kg-pop .28s cubic-bezier(.2, 1.5, .5, 1);
}
@keyframes kg-pop { 0% { transform: scale(.5); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* حروف مبعثرة */
.kg-pool { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; min-height: 70px; }
.kg-tile {
    width: 58px; height: 62px;
    border: 0; border-radius: 16px;
    background: var(--kg-surface);
    color: var(--kg-ink);
    font-family: inherit; font-size: 30px; font-weight: 800;
    cursor: pointer;
    box-shadow: 0 5px 0 #cfe0e2;
    transition: transform .1s ease, box-shadow .1s ease, background .15s ease;
}
.kg-tile:hover { background: #fbfeff; }
.kg-tile:active { transform: translateY(3px); box-shadow: 0 2px 0 #cfe0e2; }
.kg-tile:focus-visible { outline: 3px solid var(--kg-grape); outline-offset: 3px; }
.kg-tile.is-used { visibility: hidden; }
.kg-tile.is-wrong {
    background: var(--kg-coral-soft);
    color: var(--kg-coral);
    box-shadow: 0 5px 0 #f3b6b2;
    animation: kg-shake .4s ease;
}
@keyframes kg-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}
.kg-tile.is-nudge { animation: kg-nudge 1s ease infinite; }
@keyframes kg-nudge { 0%, 100% { transform: none; } 50% { transform: translateY(-5px); } }

/* الحرف موجود بالكلمة بس بمكان غلط */
.kg-tile.is-near {
    background: #fff6d8;
    color: #9a7b00;
    box-shadow: 0 5px 0 #f0dd9b;
    animation: kg-near-shake .4s ease;
}
@keyframes kg-near-shake {
    0%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
    60% { transform: translateY(2px); }
}

/* رسالة خفيفة تظهر وقت "موجود بس مو هون" */
.kg-hint-toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translate(-50%, 12px);
    background: #3a3a3a;
    color: #fff;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(0,0,0,.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    z-index: 9999;
    max-width: 90vw;
    text-align: center;
}
.kg-hint-toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

.kg-actions { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }

/* بطاقة الترويج للعبة "رتّب الجملة" بمنيو المستويات */
.kg-sentence-promo {
    display: flex; align-items: center; gap: 12px;
    margin-top: 14px; padding: 14px 16px;
    background: linear-gradient(135deg, #fff6d8, #ffe9c2);
    border-radius: 18px; text-decoration: none; color: var(--kg-ink);
    box-shadow: 0 4px 0 #f0dd9b;
    transition: transform .1s ease;
}
.kg-sentence-promo:active { transform: translateY(2px); }
.kg-sentence-promo-icon { font-size: 30px; line-height: 1; }
.kg-sentence-promo-body { display: flex; flex-direction: column; flex: 1; text-align: start; }
.kg-sentence-promo-name { font-weight: 800; font-size: 16px; }
.kg-sentence-promo-sub { font-size: 13px; color: var(--kg-ink-soft); }
.kg-sentence-promo-go { font-size: 20px; opacity: .6; }

/* لوحة النجاح */
.kg-win {
    margin-top: 14px; padding: 16px;
    background: var(--kg-surface); border-radius: 20px;
    text-align: center; box-shadow: 0 4px 0 var(--kg-line);
}
.kg-win-stars { font-size: 30px; letter-spacing: 4px; }
.kg-win-stars span { display: inline-block; animation: kg-star .5s backwards cubic-bezier(.2, 1.6, .4, 1); }
.kg-win-stars span:nth-child(2) { animation-delay: .12s; }
.kg-win-stars span:nth-child(3) { animation-delay: .24s; }
@keyframes kg-star { from { transform: scale(0) rotate(-40deg); opacity: 0; } to { transform: none; opacity: 1; } }
.kg-win-word { font-size: 30px; font-weight: 800; margin: 6px 0 12px; }

.kg-btn {
    display: inline-block;
    border: 0; border-radius: 14px;
    background: var(--kg-surface);
    box-shadow: 0 4px 0 var(--kg-line);
    padding: 11px 20px;
    font: inherit; font-weight: 700; color: var(--kg-ink);
    cursor: pointer; text-decoration: none;
}
.kg-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--kg-line); }
.kg-btn-primary { background: var(--kg-teal); color: #fff; box-shadow: 0 4px 0 var(--kg-teal-dark); }
.kg-btn-primary:active { box-shadow: 0 2px 0 var(--kg-teal-dark); }
.kg-btn-ghost { background: transparent; box-shadow: none; text-decoration: underline; }

/* ---------- نافذة منبثقة ---------- */
.kg-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(20, 44, 63, .55);
    display: grid; place-items: center; padding: 20px;
}
.kg-overlay[hidden] { display: none; }
.kg-modal {
    background: var(--kg-surface); border-radius: 24px;
    padding: 26px 22px; max-width: 420px; width: 100%;
    text-align: center;
    animation: kg-pop .3s cubic-bezier(.2, 1.4, .5, 1);
    font-family: "Segoe UI", "Noto Sans Arabic", "Cairo", Tahoma, system-ui, sans-serif;
    color: var(--kg-ink);
}
.kg-modal h3 { margin: 8px 0 6px; font-size: 22px; }
.kg-modal p { color: var(--kg-ink-soft); margin: 0 0 16px; }
.kg-modal-emoji { font-size: 54px; }
.kg-modal .kg-btn { margin: 4px; }

/* ---------- التقرير ---------- */
.kg-report {
    max-width: 860px; margin: 24px auto; padding: 22px;
    background: var(--kg-surface); border-radius: 22px;
    box-shadow: 0 10px 30px rgba(20, 44, 63, .08);
}
.kg-report-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.kg-report h2 { margin: 0; font-size: 22px; }
.kg-report h3 { margin: 26px 0 10px; font-size: 17px; }

.kg-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-top: 16px; }
.kg-stat { background: var(--kg-paper); border-radius: 16px; padding: 14px; text-align: center; }
.kg-stat-num { display: block; font-size: 22px; font-weight: 800; }
.kg-stat-lab { display: block; font-size: 13px; color: var(--kg-ink-soft); margin-top: 2px; }

.kg-today { margin-top: 14px; padding: 14px 16px; border-radius: 16px; display: flex; flex-direction: column; gap: 3px; }
.kg-today.is-yes { background: var(--kg-teal-soft); }
.kg-today.is-no { background: #fff3e6; }
.kg-today span { font-size: 14px; color: var(--kg-ink-soft); }

.kg-heat { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; max-width: 340px; }
.kg-heat-cell { aspect-ratio: 1; border-radius: 6px; background: #e8eef0; display: block; }
.kg-heat-1 { background: #cfeae8; }
.kg-heat-2 { background: #8ed9d2; }
.kg-heat-3 { background: #38b3ab; }
.kg-heat-4 { background: var(--kg-teal-dark); }
.kg-heat-legend { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--kg-ink-soft); }
.kg-heat-legend .kg-heat-cell { width: 14px; height: 14px; }

.kg-levels-progress { display: grid; gap: 12px; }
.kg-lp-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px; }

.kg-report-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.kg-weak, .kg-hard { list-style: none; margin: 0; padding: 0; }
.kg-weak li { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.kg-weak-letter {
    width: 40px; height: 40px; flex: none; display: grid; place-items: center;
    background: var(--kg-coral-soft); color: var(--kg-coral);
    border-radius: 12px; font-size: 21px; font-weight: 800;
}
.kg-weak-bar { flex: 1; height: 10px; background: #f0f4f5; border-radius: 999px; overflow: hidden; }
.kg-weak-bar span { display: block; height: 100%; background: var(--kg-coral); border-radius: 999px; }
.kg-weak-num { font-size: 13px; color: var(--kg-ink-soft); min-width: 22px; }
.kg-hard li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--kg-line); }
.kg-hard-word { font-weight: 700; }
.kg-muted { color: var(--kg-ink-soft); font-size: 14px; }

.kg-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.kg-chip { background: var(--kg-paper); border-radius: 999px; padding: 7px 14px; font-weight: 700; }
.kg-chip em { font-style: normal; font-size: 11px; }

/* سجلّ الاستخدام التفصيلي */
.kg-log-wrap { overflow-x: auto; margin-bottom: 6px; }
.kg-log { width: 100%; border-collapse: collapse; font-size: 14px; }
.kg-log th, .kg-log td { padding: 8px 10px; text-align: start; border-bottom: 1px solid var(--kg-line); white-space: nowrap; }
.kg-log th { color: var(--kg-ink-soft); font-weight: 700; font-size: 13px; }
.kg-log tbody tr:hover { background: var(--kg-paper); }

.kg-picker { margin: 18px auto; max-width: 860px; }
.kg-cert-note { margin-top: 22px; padding: 16px; background: #fff8e8; border-radius: 16px; }

/* ---------- الشهادة ---------- */
.kg-cert-wrap { max-width: 860px; margin: 24px auto; }
.kg-cert {
    background: var(--kg-surface);
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(20, 44, 63, .12);
}
.kg-cert-frame {
    border: 4px double var(--kg-teal);
    border-radius: 4px;
    padding: 40px 34px;
    text-align: center;
    position: relative;
    background:
        radial-gradient(circle at 12% 12%, rgba(255, 176, 32, .14), transparent 24%),
        radial-gradient(circle at 88% 88%, rgba(18, 165, 160, .14), transparent 24%);
}
.kg-cert-star { font-size: 40px; color: var(--kg-mango); line-height: 1; }
.kg-cert-kicker { letter-spacing: 6px; font-size: 13px; color: var(--kg-ink-soft); margin: 6px 0 0; }
.kg-cert-title { font-size: 30px; margin: 4px 0 18px; }
.kg-cert-line { color: var(--kg-ink-soft); margin: 0; }
.kg-cert-name {
    font-size: 38px; font-weight: 800; margin: 6px 0 14px;
    border-bottom: 3px solid var(--kg-mango); display: inline-block; padding: 0 26px 6px;
}
.kg-cert-body { max-width: 480px; margin: 0 auto 30px; line-height: 1.9; }
.kg-cert-foot { display: flex; justify-content: space-around; gap: 20px; margin-top: 26px; }
.kg-cert-foot > div { border-top: 2px dotted var(--kg-line); padding-top: 8px; min-width: 150px; }
.kg-cert-val { display: block; font-weight: 700; }
.kg-cert-lab { display: block; font-size: 12px; color: var(--kg-ink-soft); }
.kg-cert-school { margin-top: 18px; font-weight: 700; color: var(--kg-teal-dark); }
.kg-cert-actions { text-align: center; margin-top: 18px; }

.kg-cert-locked {
    max-width: 560px; margin: 24px auto; padding: 30px 24px; text-align: center;
    background: var(--kg-surface); border-radius: 22px; box-shadow: 0 10px 30px rgba(20, 44, 63, .08);
}
.kg-cert-lock-icon { font-size: 54px; }

/* ---------- الدخول ---------- */
.kg-login-box {
    max-width: 420px; margin: 24px auto; padding: 26px;
    background: var(--kg-surface); border-radius: 22px;
    box-shadow: 0 10px 30px rgba(20, 44, 63, .08);
}
.kg-login-box input[type="text"],
.kg-login-box input[type="password"] {
    width: 100%; padding: 12px; border: 2px solid var(--kg-line);
    border-radius: 12px; font: inherit; margin-top: 4px;
}
.kg-login-box .login-submit input,
.kg-login-box #wp-submit {
    background: var(--kg-teal); color: #fff; border: 0; border-radius: 14px;
    padding: 12px 22px; font: inherit; font-weight: 700; cursor: pointer;
    box-shadow: 0 4px 0 var(--kg-teal-dark);
}
.kg-login-msg { font-weight: 700; }
.kg-empty { padding: 30px; text-align: center; }

/* ---------- استجابة ---------- */
@media (max-width: 480px) {
    .kg-app { margin: 10px; padding: 10px; border-radius: 20px; }
    .kg-picture { height: 170px; }
    .kg-tile, .kg-slot { width: 50px; height: 56px; font-size: 26px; }
    .kg-report-cols { grid-template-columns: 1fr; }
    .kg-cert-frame { padding: 24px 16px; }
    .kg-cert-name { font-size: 28px; }
    .kg-cert-foot { flex-direction: column; align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
    .kg-app *, .kg-report * { animation: none !important; transition: none !important; }
}

/* ---------- الطباعة ---------- */
@media print {
    body * { visibility: hidden !important; }
    .kg-cert, .kg-cert *,
    .kg-report, .kg-report * { visibility: visible !important; }
    .kg-cert { position: absolute; inset: 0; box-shadow: none; }
    .kg-report { position: absolute; inset: 0; box-shadow: none; max-width: none; }
    .kg-print, .kg-cert-actions, .kg-picker { display: none !important; }
}

/* مستوى مفتوح للمشرف بغرض المعاينة فقط */
.kg-stone.is-preview { outline: 2px dashed var(--kg-grape); outline-offset: 2px; }
.kg-stone.is-preview .kg-stone-badge { background: var(--kg-grape); color: #fff; }

/* ============ شاشة الكتابة بخط اليد ============ */
.kg-write{position:fixed;inset:0;z-index:99999;background:rgba(20,44,63,.72);
  display:grid;place-items:center;padding:14px;overflow:auto}
.kg-write-card{background:var(--kg-paper);border-radius:22px;padding:16px;width:100%;
  max-width:620px;box-shadow:0 20px 50px rgba(20,44,63,.35)}
.kg-write-head{display:flex;align-items:baseline;gap:10px;justify-content:center;
  flex-wrap:wrap;margin-bottom:12px}
.kg-write-title{font-weight:700;color:var(--kg-ink);font-size:17px}
.kg-write-word{font-size:30px;font-weight:800;color:var(--kg-teal)}
.kg-write-pad{position:relative;background:#fff;border-radius:16px;touch-action:none;
  overflow:hidden;width:100%;box-shadow:inset 0 0 0 3px #d7e7ea}
.kg-write-pad canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
.kg-write-base{position:absolute;left:6%;right:6%;top:64%;height:2px;
  background:repeating-linear-gradient(90deg,#c8dde1 0 8px,transparent 8px 16px)}
.kg-write-letters{display:flex;gap:6px;margin-top:10px}
.kg-wl{flex:1;background:#fff;border-radius:10px;padding:7px 3px 5px;text-align:center;
  box-shadow:0 2px 0 var(--kg-line)}
.kg-wl-g{font-size:23px;font-weight:800;color:var(--kg-ink);display:block;line-height:1.25}
.kg-wl{position:relative}
.kg-wl i{display:block;height:5px;border-radius:3px;background:var(--kg-line);
  margin-top:5px;width:0;transition:width .3s ease}
.kg-wl.is-good i{background:var(--kg-teal)}
.kg-wl.is-mid  i{background:var(--kg-mango)}
.kg-wl.is-bad  i{background:var(--kg-coral)}
.kg-write-msg{min-height:26px;text-align:center;margin-top:11px;font-weight:700;font-size:15px;color:var(--kg-ink)}
.kg-write-msg.is-ok{color:var(--kg-teal)}
.kg-write-msg.is-mid{color:#a97400}
.kg-write-msg.is-no{color:var(--kg-coral)}
.kg-write-actions{display:flex;gap:8px;margin-top:8px;flex-wrap:wrap}
.kg-write-actions .kg-btn{flex:1;min-width:110px}
@media (max-width:480px){
  .kg-write-card{padding:12px;border-radius:18px}
  .kg-write-word{font-size:25px}
  .kg-wl-g{font-size:19px}
}

/* الكتابة داخل تقرير الأهل */
.kg-write-gallery{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:10px;margin-top:10px}
.kg-write-shot{background:#fff;border-radius:10px;padding:8px;box-shadow:0 2px 0 var(--kg-line);text-align:center}
.kg-write-shot img{width:100%;display:block;border-radius:6px}
.kg-write-shot span{display:block;font-size:12px;color:#5d7683;margin-top:5px}
@media print{.kg-write-gallery{grid-template-columns:repeat(4,1fr)}}

/* زر النطق لما ما في صوت متاح */
.kg-listen.is-mute, #kg-listen.is-mute{opacity:.45;position:relative}
.kg-listen.is-mute::after, #kg-listen.is-mute::after{content:"✕";position:absolute;top:-2px;left:-2px;font-size:12px;color:var(--kg-coral)}

/* شارة المراجعة */
.kg-review-badge{position:absolute;top:8px;inset-inline-start:8px;background:var(--kg-surface);
  border-radius:50%;width:30px;height:30px;display:grid;place-items:center;font-size:15px;
  box-shadow:0 2px 0 var(--kg-line)}
#kg-picture{position:relative}

/* ---------- ألبوم كلماتي ---------- */
.kg-album { max-width: 720px; }
.kg-album-head { text-align: center; margin-bottom: 18px; }
.kg-album-head h2 { margin: 0 0 4px; color: var(--kg-ink); font-size: 20px; }
.kg-album .kg-bar {
    height: 10px; border-radius: 6px; background: var(--kg-line);
    overflow: hidden; margin-top: 10px;
}
.kg-album .kg-bar i { display: block; height: 100%; background: var(--kg-teal); border-radius: 6px; }

.kg-album-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: 12px;
    align-items: stretch;
}
.kg-card-word {
    background: var(--kg-surface); border-radius: 16px;
    padding: 10px 9px 12px; text-align: center;
    box-shadow: 0 3px 0 var(--kg-line);
    display: flex; flex-direction: column; gap: 6px;
    min-width: 0;
}
.kg-card-word.is-mastered { box-shadow: 0 3px 0 var(--kg-teal); }

.kg-card-pic {
    position: relative; aspect-ratio: 4 / 3; width: 100%;
    display: grid; place-items: center;
    overflow: hidden; border-radius: 11px;
    background: var(--kg-paper);
}
.kg-card-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kg-card-pic svg { width: 58%; height: 58%; }
.kg-card-pic .kg-emoji { font-size: clamp(28px, 8vw, 40px); line-height: 1; }
.kg-card-seal { position: absolute; top: 4px; inset-inline-end: 4px; font-size: 15px; }

.kg-card-name {
    font-weight: 800; color: var(--kg-ink); font-size: 15px; line-height: 1.35;
    overflow-wrap: anywhere; hyphens: auto;
}
.kg-card-word .kg-de {
    font-size: 12.5px; font-weight: 600; color: var(--kg-ink-soft);
    line-height: 1.3; overflow-wrap: anywhere; margin: 0;
}
.kg-card-stars { font-size: 11px; letter-spacing: 1px; margin-top: auto; }

@media (max-width: 420px) {
    .kg-album-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 9px; }
    .kg-card-name { font-size: 14px; }
}

/* ============ صفحة الكتابة المستقلة ============ */
.kg-write.is-inline{position:static;inset:auto;background:none;padding:0;display:block;z-index:auto}
.kg-write.is-inline .kg-write-card{max-width:none;box-shadow:none;padding:0;background:none}
.kg-write.is-inline .kg-write-head{display:none}

.kg-write-page{padding:4px 2px 8px}
.kg-write-top{display:flex;align-items:center;justify-content:space-between;
  font-weight:700;color:var(--kg-ink-soft);font-size:14px;margin-bottom:10px}
.kg-write-count{font-variant-numeric:tabular-nums}
.kg-write-cue{display:flex;align-items:center;gap:12px;background:var(--kg-surface);
  border-radius:16px;padding:10px 12px;margin-bottom:12px;box-shadow:0 3px 0 var(--kg-line)}
.kg-write-pic{width:64px;height:64px;flex:0 0 64px;display:grid;place-items:center;
  border-radius:12px;overflow:hidden;background:var(--kg-paper)}
.kg-write-pic img{width:100%;height:100%;object-fit:cover}
.kg-write-pic svg{width:48px;height:48px}
.kg-write-pic .kg-emoji{font-size:36px}
.kg-write-target{display:flex;align-items:center;gap:10px;flex:1;justify-content:center}
.kg-write-say{font-size:32px;font-weight:800;color:var(--kg-teal)}

.kg-write-end{text-align:center;padding:26px 12px}
.kg-write-end h2{margin:6px 0 10px;color:var(--kg-ink)}
.kg-write-big{font-size:44px;font-weight:800;color:var(--kg-teal);margin:0;line-height:1.1}
.kg-write-stars-big{font-size:22px;letter-spacing:2px;margin:12px 0;word-break:break-all}
.kg-write-endbtns{display:flex;gap:8px;justify-content:center;flex-wrap:wrap;margin-top:14px}
.kg-write-endbtns .kg-btn{min-width:140px;text-decoration:none;display:inline-grid;place-items:center}
@media (max-width:480px){
  .kg-write-say{font-size:26px}
  .kg-write-pic{width:54px;height:54px;flex-basis:54px}
}
.kg-topbar-write{background:var(--kg-mango);color:#3b2600 !important;border-radius:10px;
  padding:5px 11px;font-weight:800;text-decoration:none}
.kg-lang-btn{background:var(--kg-surface);border:1px solid var(--kg-line);border-radius:9px;
  padding:5px 11px;font-weight:800;cursor:pointer;color:var(--kg-ink);font-size:13px;min-width:38px}
.kg-lang-btn:hover{background:var(--kg-teal-soft)}
.kg-de{display:block;font-size:14px;font-weight:600;color:var(--kg-ink-soft);
  margin-top:3px;direction:ltr}

/* ============ مبدّل اللغة ============ */
.kg-langbar{display:inline-flex;background:var(--kg-paper);border-radius:999px;padding:3px;
  gap:2px;box-shadow:inset 0 0 0 1px var(--kg-line);flex:0 0 auto}
.kg-langopt{display:inline-block;padding:6px 15px;border-radius:999px;font-size:13.5px;
  font-weight:700;color:var(--kg-ink-soft);text-decoration:none;line-height:1.4;
  white-space:nowrap;transition:background .15s,color .15s}
.kg-langopt:hover{color:var(--kg-ink);background:var(--kg-surface)}
.kg-langopt.is-on{background:var(--kg-teal);color:#fff;box-shadow:0 1px 3px rgba(18,165,160,.4)}
.kg-langopt.is-on:hover{background:var(--kg-teal);color:#fff}
.kg-langrow{display:flex;justify-content:flex-end;margin-bottom:12px}
.kg-topbar .kg-langbar{margin-inline-start:8px}
@media (max-width:520px){
  .kg-langopt{padding:6px 11px;font-size:12.5px}
  .kg-topbar{flex-wrap:wrap;row-gap:8px}
}
@media print{.kg-noprint{display:none !important}}

/* اتجاه صفوف الحروف يتبع لغة اللعب عبر خاصية dir */
.kg-slots[dir="ltr"], .kg-pool[dir="ltr"], .kg-write-letters[dir="ltr"] { direction: ltr; }
.kg-slots[dir="rtl"], .kg-pool[dir="rtl"], .kg-write-letters[dir="rtl"] { direction: rtl; }

/* رسائل الدخول داخل التطبيق */
.kg-login-msg{margin-top:10px;font-weight:700;font-size:14px;min-height:20px}
.kg-login-msg.is-ok{color:var(--kg-teal)}
.kg-login-msg.is-bad{color:var(--kg-coral)}

/* ============ شاشة النطق ============ */
.kg-listen-modal{position:fixed;inset:0;z-index:99999;background:rgba(20,44,63,.72);
  display:grid;place-items:center;padding:16px}
.kg-listen-card{background:var(--kg-paper);border-radius:22px;padding:26px 20px;width:100%;
  max-width:420px;text-align:center;box-shadow:0 20px 50px rgba(20,44,63,.35)}
.kg-listen-title{font-weight:700;color:var(--kg-ink-soft);font-size:15px}
.kg-listen-word{font-size:38px;font-weight:800;color:var(--kg-teal);margin:6px 0 18px;line-height:1.3}
.kg-mic{width:96px;height:96px;border-radius:50%;border:0;cursor:pointer;font-size:40px;
  background:var(--kg-surface);color:var(--kg-ink);box-shadow:0 5px 0 var(--kg-line);
  transition:transform .12s,box-shadow .12s}
.kg-mic:active{transform:translateY(3px);box-shadow:0 2px 0 var(--kg-line)}
.kg-mic:disabled{opacity:.4;cursor:default}
.kg-mic.is-live{background:var(--kg-coral);color:#fff;box-shadow:0 0 0 0 rgba(255,95,87,.6);
  animation:kgPulse 1.3s infinite}
@keyframes kgPulse{
  0%{box-shadow:0 0 0 0 rgba(255,95,87,.55)}
  70%{box-shadow:0 0 0 22px rgba(255,95,87,0)}
  100%{box-shadow:0 0 0 0 rgba(255,95,87,0)}
}
.kg-listen-msg{min-height:44px;margin-top:16px;font-weight:700;font-size:15px;
  color:var(--kg-ink);line-height:1.5}
.kg-listen-msg.is-ok{color:var(--kg-teal)}
.kg-listen-msg.is-mid{color:#a97400}
.kg-listen-msg.is-no{color:var(--kg-coral)}
.kg-listen-actions{margin-top:12px}
@media (prefers-reduced-motion:reduce){.kg-mic.is-live{animation:none}}

/* ---------- تحسينات إمكانية الوصول والتفاصيل ---------- */
.kg-app :focus-visible,
.kg-sheet :focus-visible {
    outline: 3px solid var(--kg-mango);
    outline-offset: 2px;
    border-radius: 8px;
}
.kg-tile:focus-visible { outline-offset: 3px; }

/* الشاشات القصيرة جداً: نضغط الصورة لا الحروف */
@media (max-height: 620px) {
    .kg-picture { height: clamp(110px, 22vh, 150px); }
    .kg-topbar { padding-bottom: 10px; }
}

/* رابط الرجوع في الصفحات الفرعية */
.kg-back-link {
    margin-inline-start: auto;
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--kg-surface); border-radius: 999px;
    padding: 8px 15px; font-weight: 700; font-size: 14px;
    color: var(--kg-ink); text-decoration: none;
    box-shadow: 0 3px 0 var(--kg-line);
}
.kg-back-link:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--kg-line); }
[dir="ltr"] .kg-back-link span[aria-hidden] { transform: scaleX(-1); }

/* صفوف اللغة في الصفحات الفرعية */
.kg-langrow { margin-bottom: 14px; }

/* ============================================================
   شاشة الرقم السري
   ============================================================ */
.kg-pin {
    max-width: 420px; margin: 24px auto; padding: 0 14px;
    font-family: "Segoe UI", "Noto Sans Arabic", "Cairo", Tahoma, system-ui, sans-serif;
    color: var(--kg-ink);
    --kg-ink: #142c3f;
    --kg-ink-soft: #5b7383;
    --kg-teal: #12a5a0;
    --kg-coral: #ff5f57;
    --kg-paper: #eef6f7;
    --kg-line: #d5e5e7;
    /* شكل نجمة بسيط كقناع CSS — يلوّن بـ background-color مباشرة */
    --kg-star-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 1.8l2.9 6.6 7.2.7-5.4 4.8 1.6 7.1-6.3-3.8-6.3 3.8 1.6-7.1L2 9.1l7.2-.7z'/></svg>");
}
.kg-pin-card {
    background: var(--kg-paper); border-radius: 26px;
    padding: 26px 20px 24px; text-align: center; position: relative;
    box-shadow: 0 18px 40px rgba(20, 44, 63, .12);
}
.kg-pin-step { display: none; }
.kg-pin-step.is-on { display: block; animation: kg-step .28s cubic-bezier(.2,.9,.3,1); }
@keyframes kg-step { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.kg-pin-title { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.kg-pin-sub   { margin: 0 0 20px; font-size: 14px; color: var(--kg-ink-soft); }
.kg-pin-hello { margin: 8px 0 18px; font-size: 18px; font-weight: 800; }

/* --- اختيار الطفل --- */
.kg-kids {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 11px; margin-top: 18px;
}
.kg-kid {
    background: var(--kg-surface); border: 0; border-radius: 18px;
    padding: 15px 8px 12px; cursor: pointer; font-family: inherit;
    display: grid; gap: 7px; justify-items: center;
    box-shadow: 0 4px 0 var(--kg-line);
    animation: kg-kid-in .32s cubic-bezier(.2,1.4,.4,1) backwards;
    animation-delay: calc(var(--d) * 45ms);
    transition: transform .12s, box-shadow .12s;
}
@keyframes kg-kid-in { from { opacity: 0; transform: translateY(12px) scale(.94); } to { opacity: 1; transform: none; } }
.kg-kid:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--kg-line); }
.kg-kid-face { font-size: 40px; line-height: 1; }
.kg-kid-name { font-size: 14px; font-weight: 800; color: var(--kg-ink); }

/* --- الوجه والاسم في خطوة الرقم --- */
.kg-pin-face {
    width: 78px; height: 78px; margin: 4px auto 10px;
    display: grid; place-items: center; font-size: 42px; line-height: 1;
    background: var(--kg-surface); border-radius: 50%;
    box-shadow: 0 4px 0 var(--kg-line);
}
.kg-pin-back {
    position: absolute; inset-inline-start: 14px; top: 14px;
    width: 38px; height: 38px; border: 0; border-radius: 12px; cursor: pointer;
    background: var(--kg-surface); box-shadow: 0 3px 0 var(--kg-line);
    font-size: 17px; display: grid; place-items: center; color: var(--kg-ink);
}
[dir="ltr"] .kg-pin-back span { transform: scaleX(-1); }

/* --- أربع نجوم بدل النقاط: يشوف الطفل إنو عم يكتب بلا ما يشوف رقمه --- */
.kg-dots { display: flex; gap: 10px; justify-content: center; margin: 4px 0 6px; }
.kg-dots i {
    width: 26px; height: 26px; display: inline-block;
    background-color: transparent;
    -webkit-mask: var(--kg-star-svg) center / contain no-repeat;
            mask: var(--kg-star-svg) center / contain no-repeat;
    box-shadow: none;
    transition: transform .16s, background-color .16s;
}
.kg-dots i::before { content: none; }
.kg-dots i {
    background-color: var(--kg-line);
}
.kg-dots i.is-on { background-color: var(--kg-teal); }
.kg-dots i.is-pop { transform: scale(1.35) rotate(-8deg); }
.kg-dots.is-wrong { animation: kg-shake .42s cubic-bezier(.36,.07,.19,.97); }
.kg-dots.is-wrong i.is-on { background-color: var(--kg-coral); }
.kg-dots.is-ok i { background-color: var(--kg-teal); animation: kg-dot-ok .4s ease; }
@keyframes kg-shake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-7px); }
    40%, 60% { transform: translateX(7px); }
}
@keyframes kg-dot-ok { 40% { transform: scale(1.4); } 100% { transform: scale(1); } }

.kg-pin-msg { min-height: 22px; margin: 0 0 14px; font-size: 14px; font-weight: 700; }
.kg-pin-msg.is-ok { color: var(--kg-teal); }
.kg-pin-msg.is-no { color: var(--kg-coral); }

/* --- لوحة الأرقام --- */
.kg-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kg-key {
    aspect-ratio: 1 / 1; border: 0; border-radius: 18px; cursor: pointer;
    background: var(--kg-surface); color: var(--kg-ink);
    font-family: inherit; font-size: 26px; font-weight: 800;
    box-shadow: 0 4px 0 var(--kg-line);
    display: grid; place-items: center;
    transition: transform .1s, box-shadow .1s, background .12s;
}
.kg-key:active, .kg-key.is-tap {
    transform: translateY(3px); box-shadow: 0 1px 0 var(--kg-line);
    background: var(--kg-teal-soft);
}
.kg-key.is-ghost { background: transparent; box-shadow: none; font-size: 22px; color: var(--kg-ink-soft); }
.kg-key.is-ghost:active { background: var(--kg-line); }
.kg-key.is-empty { visibility: hidden; }

.kg-pin-go { display: inline-grid; place-items: center; min-width: 170px; text-decoration: none; }
.kg-pin-out { display: block; margin-top: 14px; font-size: 13px; color: var(--kg-ink-soft); }

@media (max-width: 380px) {
    .kg-key { font-size: 23px; border-radius: 15px; }
    .kg-kid-face { font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) {
    .kg-pin-step, .kg-kid { animation: none; }
    .kg-dots.is-wrong, .kg-dots.is-ok i { animation: none; }
}

/* ============================================================
   مبدّل اللغة للطفل — الحرف نفسه هو الأيقونة
   ============================================================ */
.kg-kidlang {
    display: flex; gap: 12px; justify-content: center;
    margin: 22px auto 4px; max-width: 320px;
}
.kg-kidlang-opt {
    flex: 1;
    display: grid; gap: 3px; justify-items: center;
    padding: 12px 8px 10px;
    background: var(--kg-surface); border-radius: 20px;
    text-decoration: none; color: var(--kg-ink-soft);
    box-shadow: 0 4px 0 var(--kg-line);
    transition: transform .14s cubic-bezier(.2,1.5,.5,1), box-shadow .14s, background .18s, color .18s;
}
.kg-kidlang-opt:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--kg-line); }

.kg-kidlang-glyph {
    font-size: 34px; font-weight: 800; line-height: 1.15;
    transition: transform .18s cubic-bezier(.2,1.6,.5,1);
}
.kg-kidlang-name { font-size: 12.5px; font-weight: 700; letter-spacing: .01em; }

.kg-kidlang-opt.is-on {
    background: var(--kg-teal); color: #fff;
    box-shadow: 0 4px 0 var(--kg-teal-dark);
    transform: translateY(-2px);
}
.kg-kidlang-opt.is-on .kg-kidlang-glyph { transform: scale(1.12); }
.kg-kidlang-opt.is-on:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--kg-teal-dark); }

/* على شاشة الدخول: فوق البطاقة */
.kg-pin .kg-kidlang { margin: 0 auto 16px; max-width: 280px; }

@media (prefers-reduced-motion: reduce) {
    .kg-kidlang-opt, .kg-kidlang-glyph { transition: none; }
}
.kg-pin-alt {
    display: block; text-align: center; margin-top: 18px;
    font-size: 13px; color: var(--kg-ink-soft); text-decoration: none;
    border-bottom: 1px dashed currentColor; width: fit-content;
    margin-inline: auto; padding-bottom: 1px;
}
.kg-pin-alt:hover { color: var(--kg-teal-dark); }

/* ---------- صفحة النطق المستقلة ---------- */
.kg-speak-shell { max-width: 480px; }
.kg-speak-page { text-align: center; padding: 4px 2px 8px; }
.kg-speak-top {
    display: flex; justify-content: space-between;
    font-weight: 700; font-size: 14px; color: var(--kg-ink-soft);
    margin-bottom: 12px; font-variant-numeric: tabular-nums;
}
.kg-speak-card {
    background: var(--kg-surface); border-radius: 20px;
    padding: 14px; margin-bottom: 18px;
    box-shadow: 0 4px 0 var(--kg-line);
}
.kg-speak-pic {
    height: clamp(120px, 24vh, 170px); border-radius: 14px;
    display: grid; place-items: center; overflow: hidden;
    background: var(--kg-paper); margin-bottom: 10px;
}
.kg-speak-pic img { width: 100%; height: 100%; object-fit: cover; }
.kg-speak-pic svg { width: 55%; height: 55%; }
.kg-speak-pic .kg-emoji { font-size: clamp(52px, 13vh, 76px); line-height: 1; }
.kg-speak-word { font-size: 32px; font-weight: 800; color: var(--kg-teal); line-height: 1.3; margin-bottom: 10px; }
.kg-speak-hear { min-width: 140px; }

.kg-speak-msg { min-height: 46px; margin: 14px 0 6px; font-weight: 700; font-size: 15px; line-height: 1.5; }
.kg-speak-msg.is-ok  { color: var(--kg-teal); }
.kg-speak-msg.is-mid { color: #a97400; }
.kg-speak-msg.is-no  { color: var(--kg-coral); }

.kg-speak-actions { margin-top: 6px; }
.kg-speak-end { padding: 28px 12px; }
.kg-speak-end h2 { margin: 6px 0 10px; color: var(--kg-ink); }
.kg-speak-big { font-size: 44px; font-weight: 800; color: var(--kg-teal); margin: 0; line-height: 1.1; }
.kg-speak-endbtns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.kg-speak-endbtns .kg-btn { min-width: 140px; text-decoration: none; display: inline-grid; place-items: center; }

/* ---------- صفحة "رتّب الجملة" المستقلة ---------- */
.kg-sentence-shell { max-width: 520px; }
.kg-sentence-page { text-align: center; padding: 4px 2px 8px; }
.kg-sentence-pic {
    font-size: clamp(52px, 13vh, 76px); line-height: 1;
    margin: 6px 0 14px;
}
.kg-wslots {
    display: flex; flex-wrap: wrap; justify-content: center;
    gap: 8px; min-height: 54px; margin-bottom: 18px;
}
.kg-wslot {
    min-width: 64px; height: 48px; padding: 0 10px;
    border-radius: 12px; border: 2px dashed var(--kg-line);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700; color: var(--kg-ink);
}
.kg-wslot.is-filled {
    border-style: solid; background: var(--kg-surface);
    box-shadow: 0 3px 0 var(--kg-line);
    animation: kg-pop .25s ease;
}
.kg-wpool { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.kg-wtile {
    padding: 10px 16px; border: 0; border-radius: 14px;
    background: var(--kg-surface); color: var(--kg-ink);
    font-family: inherit; font-size: 17px; font-weight: 700;
    cursor: pointer; box-shadow: 0 5px 0 #cfe0e2;
    transition: transform .1s ease, box-shadow .1s ease, background .15s ease;
}
.kg-wtile:hover { background: #fbfeff; }
.kg-wtile:active { transform: translateY(3px); box-shadow: 0 2px 0 #cfe0e2; }
.kg-wtile.is-used { visibility: hidden; }
.kg-wtile.is-wrong {
    background: var(--kg-coral-soft); color: var(--kg-coral);
    box-shadow: 0 5px 0 #f3b6b2; animation: kg-shake .4s ease;
}
.kg-wtile.is-near {
    background: #fff6d8; color: #9a7b00;
    box-shadow: 0 5px 0 #f0dd9b; animation: kg-near-shake .4s ease;
}
.kg-sentence-final { font-size: 20px; font-weight: 800; color: var(--kg-teal); margin: 10px 0 16px; }

/* رسالة الكاش العالق */
.kg-stuck {
    margin-top: 16px; padding: 14px; border-radius: 14px;
    background: var(--kg-mango); color: #3b2600; text-align: center;
}
.kg-stuck p { margin: 0 0 10px; font-weight: 700; font-size: 14px; line-height: 1.5; }
.kg-stuck .kg-btn { min-width: 150px; }

/* درجة «لم يلعب» كانت ناقصة من سلّم الخريطة الحرارية */
.kg-heat-0 { background: #e8eef0; }

/* أزرار التخطّي: أهدأ من الأزرار الأساسية */
.kg-listen-skip, .kg-write-skip {
    background: transparent;
    box-shadow: inset 0 0 0 2px var(--kg-line);
    color: var(--kg-ink-soft);
}
.kg-listen-skip:active, .kg-write-skip:active {
    transform: translateY(2px); box-shadow: inset 0 0 0 2px var(--kg-line);
}

/* حاويات لا تحتاج تنسيقاً خاصاً لكن نثبّتها لتفادي الوراثة الغريبة */
.kg-stage { display: block; }
.kg-modal-body { display: block; }

/* ============================================================
   فهم الكلمة
   ============================================================ */
.kg-match-shell, .kg-memory-shell { max-width: 560px; }
.kg-match-page { text-align: center; padding: 4px 2px 8px; }
.kg-match-top, .kg-mem-top {
    display: flex; justify-content: space-between;
    font-weight: 700; font-size: 14px; color: var(--kg-ink-soft);
    margin-bottom: 14px; font-variant-numeric: tabular-nums;
}
.kg-match-ask, .kg-mem-ask { margin: 0 0 8px; color: var(--kg-ink-soft); font-size: 14.5px; }
.kg-match-word {
    font-size: 34px; font-weight: 800; color: var(--kg-teal);
    line-height: 1.35; margin-bottom: 18px; overflow-wrap: anywhere;
}

.kg-match-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kg-match-opt {
    aspect-ratio: 4 / 3; border: 0; border-radius: 18px; cursor: pointer; padding: 8px;
    background: var(--kg-surface); overflow: hidden;
    display: grid; place-items: center;
    box-shadow: 0 4px 0 var(--kg-line);
    transition: transform .12s, box-shadow .12s, background .2s;
}
.kg-match-opt img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
.kg-match-opt svg { width: 62%; height: 62%; }
.kg-match-opt .kg-emoji { font-size: clamp(40px, 11vw, 62px); line-height: 1; }
.kg-match-opt:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--kg-line); }
.kg-match-opt.is-right { box-shadow: 0 0 0 4px var(--kg-teal), 0 4px 0 var(--kg-teal-dark); }
.kg-match-opt.is-wrong { opacity: .38; box-shadow: 0 4px 0 var(--kg-line); }
.kg-match-opt.is-hint  { box-shadow: 0 0 0 4px var(--kg-mango), 0 4px 0 var(--kg-line); }
.kg-match-opt:disabled { cursor: default; }

.kg-match-msg { min-height: 26px; margin: 14px 0 0; font-weight: 700; font-size: 15px; }
.kg-match-msg.is-ok { color: var(--kg-teal); }
.kg-match-msg.is-no { color: var(--kg-coral); }

/* ============================================================
   الذاكرة
   ============================================================ */
.kg-mem-page { text-align: center; padding: 4px 2px 8px; }
.kg-mem-bar { height: 6px; border-radius: 3px; background: var(--kg-line); overflow: hidden; margin-bottom: 16px; }
.kg-mem-bar i { display: block; height: 100%; width: 100%; background: var(--kg-mango); transition: width 5s linear; }

.kg-mem-show { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-bottom: 18px; }
.kg-mem-card {
    background: var(--kg-surface); border-radius: 16px; padding: 12px 10px;
    box-shadow: 0 4px 0 var(--kg-line); min-width: 104px;
    display: grid; gap: 6px; justify-items: center;
}
.kg-mem-card img { width: 76px; height: 60px; object-fit: cover; border-radius: 10px; }
.kg-mem-card svg { width: 56px; height: 56px; }
.kg-mem-card .kg-emoji { font-size: 44px; line-height: 1; }
.kg-mem-card span { font-weight: 800; font-size: 14px; color: var(--kg-ink); }

.kg-mem-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 10px; margin-bottom: 18px; }
.kg-mem-opt {
    aspect-ratio: 1; border: 0; border-radius: 16px; cursor: pointer; padding: 6px;
    background: var(--kg-surface); display: grid; place-items: center; overflow: hidden;
    box-shadow: 0 4px 0 var(--kg-line);
    transition: transform .12s, box-shadow .12s, opacity .2s;
}
.kg-mem-opt img { width: 100%; height: 100%; object-fit: cover; border-radius: 11px; }
.kg-mem-opt svg { width: 64%; height: 64%; }
.kg-mem-opt .kg-emoji { font-size: clamp(30px, 8vw, 42px); line-height: 1; }
.kg-mem-opt.is-picked { box-shadow: 0 0 0 4px var(--kg-teal), 0 4px 0 var(--kg-teal-dark); transform: translateY(-2px); }
.kg-mem-opt.is-right  { box-shadow: 0 0 0 4px var(--kg-teal), 0 4px 0 var(--kg-teal-dark); }
.kg-mem-opt.is-wrong  { opacity: .35; }

.kg-match-end, .kg-mem-end { padding: 28px 12px; }
.kg-match-big, .kg-mem-big { font-size: 44px; font-weight: 800; color: var(--kg-teal); margin: 0; line-height: 1.1; }
.kg-match-endbtns, .kg-mem-endbtns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.kg-match-endbtns .kg-btn, .kg-mem-endbtns .kg-btn { min-width: 140px; text-decoration: none; display: inline-grid; place-items: center; }

@media (max-width: 400px) {
    .kg-match-word { font-size: 28px; }
    .kg-mem-card { min-width: 88px; }
}

/* ============================================================
   طابق الصورة والكلمة
   ============================================================ */
.kg-pairs-shell { max-width: 560px; }
.kg-pairs-page { text-align: center; padding: 4px 2px 8px; }
.kg-pairs-top {
    display: flex; justify-content: space-between;
    font-weight: 700; font-size: 14px; color: var(--kg-ink-soft);
    margin-bottom: 14px; font-variant-numeric: tabular-nums;
}
.kg-pairs-ask { margin: 0 0 14px; color: var(--kg-ink-soft); font-size: 14.5px; }

.kg-pairs-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
.kg-pairs-grid[data-cols="4"] { grid-template-columns: repeat(4, 1fr); }

.kg-pairs-card {
    aspect-ratio: 4 / 5; border: 0; border-radius: 16px; cursor: pointer; padding: 0;
    background: transparent; perspective: 700px;
}
.kg-pairs-inner {
    position: relative; width: 100%; height: 100%; display: block;
    transform-style: preserve-3d; transition: transform .35s ease;
}
.kg-pairs-card.is-up .kg-pairs-inner,
.kg-pairs-card.is-matched .kg-pairs-inner { transform: rotateY(180deg); }

.kg-pairs-back, .kg-pairs-front {
    position: absolute; inset: 0; border-radius: 16px; backface-visibility: hidden;
    display: grid; place-items: center; overflow: hidden; padding: 6px;
    box-shadow: 0 4px 0 var(--kg-line);
}
.kg-pairs-back {
    background: var(--kg-grape); color: #fff;
    font-size: 26px; font-weight: 800;
}
.kg-pairs-front {
    background: var(--kg-surface); transform: rotateY(180deg);
}
.kg-pairs-front img { width: 100%; height: 100%; object-fit: cover; border-radius: 11px; }
.kg-pairs-front svg { width: 62%; height: 62%; }
.kg-pairs-front .kg-emoji { font-size: clamp(30px, 9vw, 46px); line-height: 1; }
.kg-pairs-word {
    font-weight: 800; font-size: clamp(15px, 4.6vw, 20px); color: var(--kg-teal-dark);
    overflow-wrap: anywhere; padding: 0 4px;
}

.kg-pairs-card.is-matched .kg-pairs-front { box-shadow: 0 0 0 4px var(--kg-teal), 0 4px 0 var(--kg-teal-dark); }
.kg-pairs-card.is-matched { cursor: default; }
.kg-pairs-card:active .kg-pairs-inner:not([style]) { transform: scale(.97); }

.kg-pairs-end { padding: 28px 12px; }
.kg-pairs-big { font-size: 44px; font-weight: 800; color: var(--kg-teal); margin: 0; line-height: 1.1; }
.kg-pairs-endbtns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.kg-pairs-endbtns .kg-btn { min-width: 140px; text-decoration: none; display: inline-grid; place-items: center; }

@media (max-width: 400px) {
    .kg-pairs-grid { gap: 8px; }
    .kg-pairs-back { font-size: 22px; }
}

/* ============================================================
   شاشة البداية — اختيار اللعبة
   ============================================================ */
.kg-home { max-width: 640px; }
.kg-home-title {
    text-align: center; margin: 18px 0 16px;
    font-size: 21px; font-weight: 800; color: var(--kg-ink);
}

.kg-boxes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 13px;
}

.kg-box {
    position: relative;
    display: grid; gap: 5px; justify-items: center; align-content: start;
    padding: 22px 12px 18px;
    background: var(--kg-surface);
    border-radius: 22px; text-decoration: none;
    box-shadow: 0 5px 0 var(--kg-line);
    transition: transform .14s cubic-bezier(.2,1.4,.5,1), box-shadow .14s;
    animation: kg-box-in .34s cubic-bezier(.2,1.3,.4,1) backwards;
    animation-delay: calc(var(--d) * 55ms);
    overflow: hidden;
}
@keyframes kg-box-in {
    from { opacity: 0; transform: translateY(14px) scale(.95); }
    to   { opacity: 1; transform: none; }
}
.kg-box::before {
    content: ""; position: absolute; inset-inline: 0; top: 0; height: 5px;
    background: var(--kg-teal);
}
.kg-box:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--kg-line); }

.kg-box-icon  { font-size: 44px; line-height: 1.1; }
.kg-box-title { font-size: 17px; font-weight: 800; color: var(--kg-ink); text-align: center; line-height: 1.35; }
.kg-box-desc  { font-size: 12.5px; color: var(--kg-ink-soft); text-align: center; line-height: 1.5; }

.kg-box--teal::before  { background: var(--kg-teal); }
.kg-box--mango::before { background: var(--kg-mango); }
.kg-box--coral::before { background: var(--kg-coral); }
.kg-box--grape::before { background: var(--kg-grape); }

/* روابط ثانوية أهدأ من المربعات */
.kg-home-extra {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
    margin-top: 22px; padding-top: 18px;
    border-top: 1px solid var(--kg-line);
}
.kg-home-extra a {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 15px; border-radius: 999px;
    background: var(--kg-surface); color: var(--kg-ink-soft);
    font-size: 13.5px; font-weight: 700; text-decoration: none;
    box-shadow: 0 2px 0 var(--kg-line);
}
.kg-home-extra a:active { transform: translateY(2px); box-shadow: none; }

@media (max-width: 420px) {
    .kg-boxes { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .kg-box { padding: 18px 8px 15px; border-radius: 18px; }
    .kg-box-icon { font-size: 36px; }
    .kg-box-title { font-size: 15px; }
    .kg-box-desc { font-size: 11.5px; }
}

/* ============================================================
   التصنيف
   ============================================================ */
.kg-sort-shell { max-width: 620px; }
.kg-sort-page { padding: 4px 2px 8px; }
.kg-sort-top {
    display: flex; justify-content: space-between;
    font-weight: 700; font-size: 14px; color: var(--kg-ink-soft);
    margin-bottom: 12px; font-variant-numeric: tabular-nums;
}
.kg-sort-ask { margin: 0 0 14px; text-align: center; color: var(--kg-ink-soft); font-size: 15px; }

.kg-sort-intro {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    justify-content: space-between;
    background: var(--kg-teal-soft); border: 1px solid var(--kg-teal);
    border-radius: 14px; padding: 12px 14px; margin-bottom: 14px;
}
.kg-sort-intro p {
    margin: 0; flex: 1 1 220px; font-weight: 700; font-size: 15px;
    color: var(--kg-teal-dark); line-height: 1.5;
}
.kg-sort-intro-close {
    flex: 0 0 auto; background: var(--kg-teal); color: #fff;
    border: none; border-radius: 10px; padding: 8px 16px;
    font-weight: 800; font-size: 14px; cursor: pointer;
}
.kg-sort-intro-close:active { transform: translateY(1px); }

.kg-sort-cards {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 10px; margin-bottom: 20px; min-height: 96px;
}
.kg-sort-card {
    border: 0; border-radius: 16px; cursor: pointer; padding: 9px 6px 7px;
    background: var(--kg-surface); font-family: inherit;
    display: grid; gap: 4px; justify-items: center;
    box-shadow: 0 4px 0 var(--kg-line);
    transition: transform .13s, box-shadow .13s, opacity .3s;
}
.kg-sort-card:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--kg-line); }
.kg-sort-pic { display: grid; place-items: center; height: 54px; width: 100%; overflow: hidden; }
.kg-sort-pic img { width: 100%; height: 100%; object-fit: cover; border-radius: 9px; }
.kg-sort-pic svg { width: 46px; height: 46px; }
.kg-sort-pic .kg-emoji { font-size: 38px; line-height: 1; }
.kg-sort-word {
    font-size: 13.5px; font-weight: 800; color: var(--kg-ink);
    line-height: 1.3; text-align: center; overflow-wrap: anywhere;
}
.kg-sort-card.is-picked {
    box-shadow: 0 0 0 4px var(--kg-teal), 0 4px 0 var(--kg-teal-dark);
    transform: translateY(-3px);
}
.kg-sort-card.is-wrong { animation: kg-shake .45s cubic-bezier(.36,.07,.19,.97); }
.kg-sort-card.is-done  { opacity: 0; pointer-events: none; transform: scale(.85); }

.kg-baskets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kg-basket {
    border: 3px dashed var(--kg-line); border-radius: 20px;
    background: rgba(255,255,255,.55); cursor: pointer; font-family: inherit;
    padding: 16px 10px 12px; min-height: 156px;
    display: grid; gap: 6px; justify-items: center; align-content: start;
    transition: border-color .18s, background .18s, transform .13s;
}
.kg-basket-icon { font-size: 46px; line-height: 1; }
.kg-basket-name {
    font-size: 17px; font-weight: 800; color: var(--kg-ink);
    text-align: center; line-height: 1.35; overflow-wrap: anywhere;
}
.kg-basket-drop {
    display: flex; flex-wrap: wrap; gap: 5px; justify-content: center;
    margin-top: 4px; min-height: 30px;
}
.kg-basket-chip {
    width: 30px; height: 30px; border-radius: 8px;
    display: grid; place-items: center; overflow: hidden;
    background: var(--kg-surface); box-shadow: 0 1px 0 var(--kg-line);
    animation: kg-chip-in .3s cubic-bezier(.2,1.6,.4,1);
}
@keyframes kg-chip-in { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.kg-basket-chip img { width: 100%; height: 100%; object-fit: cover; }
.kg-basket-chip svg { width: 22px; height: 22px; }
.kg-basket-chip .kg-emoji { font-size: 19px; line-height: 1; }
.kg-basket.is-open { border-color: var(--kg-teal); background: var(--kg-teal-soft); }
.kg-basket.is-hover { transform: scale(1.03); border-style: solid; }

.kg-sort-msg { min-height: 26px; margin: 14px 0 0; text-align: center; font-weight: 700; font-size: 15px; }
.kg-sort-msg.is-ok { color: var(--kg-teal); }
.kg-sort-msg.is-no { color: var(--kg-coral); }

.kg-sort-end { text-align: center; padding: 28px 12px; }
.kg-sort-big { font-size: 44px; font-weight: 800; color: var(--kg-teal); margin: 0; line-height: 1.1; }
.kg-sort-endbtns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.kg-sort-endbtns .kg-btn { min-width: 140px; text-decoration: none; display: inline-grid; place-items: center; }

@media (max-width: 420px) {
    .kg-sort-cards { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .kg-basket { min-height: 138px; padding: 13px 7px 10px; }
    .kg-basket-icon { font-size: 38px; }
    .kg-basket-name { font-size: 15.5px; }
    .kg-sort-word { font-size: 12.5px; }
}
@media (prefers-reduced-motion: reduce) {
    .kg-sort-card, .kg-basket, .kg-basket-chip { animation: none; transition: none; }
}
