:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --text: #1d2433;
    --muted: #5b6475;
    --border: #e3e6ec;
    --primary: #1f5fbf;
    --primary-dark: #174a96;
    --primary-soft: #e8f0fc;
    --accent: #0f9d76;
    --accent-soft: #e3f6f0;
    --warn-soft: #fdf3e2;
    --danger: #c43d3d;
    --danger-soft: #fbe9e9;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
}

/* Dark mode: follows the device, or the ◐ button via data-theme on <html> */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #11151c;
        --surface: #1a2029;
        --text: #e6e9ef;
        --muted: #9aa3b2;
        --border: #2a323e;
        --primary: #5b9bf0;
        --primary-dark: #7fb1f4;
        --primary-soft: #1c2b42;
        --accent: #3cc49b;
        --accent-soft: #163329;
        --warn-soft: #3a2f1a;
        --danger: #f07b7b;
        --danger-soft: #3d1f22;
        --shadow: none;
    }
}
:root[data-theme="dark"] {
    --bg: #11151c;
    --surface: #1a2029;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --border: #2a323e;
    --primary: #5b9bf0;
    --primary-dark: #7fb1f4;
    --primary-soft: #1c2b42;
    --accent: #3cc49b;
    --accent-soft: #163329;
    --warn-soft: #3a2f1a;
    --danger: #f07b7b;
    --danger-soft: #3d1f22;
    --shadow: none;
    }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", system-ui, sans-serif;
    line-height: 1.7;
    font-size: 17px;
}

html[lang="ar"] body { font-family: "IBM Plex Sans Arabic", "Inter", system-ui, sans-serif; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 760px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

h1, h2, h3 { line-height: 1.3; margin: 0 0 .6em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.1rem; }

/* Header */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-grid; place-items: center;
    width: 36px; height: 36px; border-radius: 9px;
    background: var(--primary); color: #fff; font-size: .85rem; font-family: "Inter", sans-serif;
}
.site-nav { display: flex; align-items: center; gap: 4px; }
.site-nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.site-nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.site-nav a.active { color: var(--primary); background: var(--primary-soft); }
.site-nav .lang-switch { border: 1px solid var(--border); color: var(--text); margin-inline-start: 8px; }
.nav-toggle { display: none; }

@media (max-width: 720px) {
    .nav-toggle { display: block; }
    .site-nav {
        display: none; position: absolute; inset-inline: 0; top: 64px;
        flex-direction: column; align-items: stretch;
        background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 16px 16px;
    }
    .site-nav.open { display: flex; }
    .site-nav .lang-switch { margin: 8px 0 0; text-align: center; }
}

/* Sections */
section { padding: 48px 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.btn {
    display: inline-block; padding: 12px 22px; border-radius: 10px; font-weight: 600;
    border: 1px solid transparent; cursor: pointer; font: inherit; font-weight: 600;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { border-color: var(--border); color: var(--text); background: var(--surface); }
.btn-outline:hover { border-color: var(--primary); }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow);
}
.card h3 { margin-bottom: .4em; }
.card p { margin: 0; color: var(--muted); }
a.card { color: inherit; display: block; transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--primary); text-decoration: none; transform: translateY(-2px); }
.lesson-num {
    display: inline-block; font-size: .8rem; font-weight: 600; color: var(--primary);
    background: var(--primary-soft); padding: 2px 10px; border-radius: 99px; margin-bottom: 10px;
}
.meta { font-size: .85rem; color: var(--muted); margin-top: 12px; }

/* Lesson page */
.lesson-header { padding: 40px 0 8px; }
.breadcrumb { font-size: .9rem; color: var(--muted); margin-bottom: 12px; }
.term-en { font-family: "Inter", sans-serif; color: var(--muted); font-weight: 500; font-size: .95em; }
.lesson-body section { padding: 0; margin-bottom: 32px; }
.lesson-body p { margin: 0 0 1em; }
.box { border-radius: var(--radius); padding: 18px 20px; margin-bottom: 28px; }
.box h3 { margin-bottom: .5em; }
.box ul { margin: 0; padding-inline-start: 1.2em; }
.box li { margin-bottom: .4em; }
.box-points { background: var(--primary-soft); }
.box-example { background: var(--accent-soft); }
.terms-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.terms-table th, .terms-table td { padding: 10px 14px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: top; }
.terms-table tr:last-child td { border-bottom: 0; }
.terms-table th { background: var(--bg); font-size: .9rem; color: var(--muted); }
.terms-table td.en { font-family: "Inter", sans-serif; font-weight: 600; direction: ltr; }
.pager { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 40px 0 16px; }

/* Glossary */
.search-input {
    width: 100%; padding: 12px 16px; font: inherit; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); margin-bottom: 20px;
}
.search-input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.gloss-item { padding: 16px 0; border-bottom: 1px solid var(--border); }
.gloss-item h3 { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; margin-bottom: .3em; }
.gloss-item p { margin: 0; color: var(--muted); }

/* Quiz */
.quiz-card { max-width: 680px; }
.quiz-progress { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; margin-bottom: 20px; }
.quiz-progress span { display: block; height: 100%; background: var(--primary); transition: width .3s; }
.options { display: grid; gap: 10px; margin: 18px 0; }
.option {
    text-align: start; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--primary); }
.option:disabled { cursor: default; }
.option.correct { border-color: var(--accent); background: var(--accent-soft); }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); }
.feedback { padding: 14px 16px; border-radius: 10px; background: var(--warn-soft); margin-bottom: 16px; }
.score { font-size: 3rem; font-weight: 700; color: var(--primary); margin: 8px 0; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 28px 0; margin-top: 48px; background: var(--surface); }
.site-footer p { margin: 0 0 6px; }
