:root {
  --bg: #f5f0e6; --surface: #fffdf8; --surface-2: #efe8da; --ink: #1d221f; --muted: #5f655f;
  --line: #ddd3c2; --accent: #2f5d50; --accent-ink: #fff; --accent-soft: #dce8e2; --brass: #a9792c;
  --good: #2e7d4f; --good-soft: #e1f1e6; --bad: #b3413a; --bad-soft: #f8e3e0; --warn: #9a6a12; --warn-soft: #f7ecd4;
  --light: #efe0c2; --dark: #b28659; --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px rgba(40, 30, 10, .08);
  --r: 14px;
  --f-body: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --f-head: "IBM Plex Sans Arabic", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131614; --surface: #1b1f1c; --surface-2: #232824; --ink: #ece7dc; --muted: #a2a79f;
    --line: #333a35; --accent: #7fbfa6; --accent-ink: #0f1a15; --accent-soft: #23362e; --brass: #d3a85a;
    --good: #6fcf97; --good-soft: #1d3326; --bad: #f08a80; --bad-soft: #3a2220; --warn: #e3b55c; --warn-soft: #3a2f18;
    --light: #e3d3b4; --dark: #9c7550; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131614; --surface: #1b1f1c; --surface-2: #232824; --ink: #ece7dc; --muted: #a2a79f;
  --line: #333a35; --accent: #7fbfa6; --accent-ink: #0f1a15; --accent-soft: #23362e; --brass: #d3a85a;
  --good: #6fcf97; --good-soft: #1d3326; --bad: #f08a80; --bad-soft: #3a2220; --warn: #e3b55c; --warn-soft: #3a2f18;
  --light: #e3d3b4; --dark: #9c7550; color-scheme: dark;
}
.lang-en { --f-head: "Fraunces", Georgia, serif; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16.5px/1.75 var(--f-body); }
.lang-en body { line-height: 1.6; }
h1, h2, h3, h4 { font-family: var(--f-head); font-weight: 700; line-height: 1.25; margin: 0 0 .5em; text-wrap: balance; }
.lang-en h1, .lang-en h2, .lang-en h3 { font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: clamp(1.9rem, 4.5vw, 2.8rem); }
h3 { font-size: 1.2rem; }
h4 { font-size: 1.02rem; margin-top: 1em; }
p { margin: 0 0 .8em; }
ul, ol { padding-inline-start: 1.3em; margin: 0 0 .9em; }
li { margin: .25em 0; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: .92em; }
.lang-ar [data-l="en"], .lang-en [data-l="ar"] { display: none !important; }

/* header */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1160px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font: 700 1.25rem var(--f-head); white-space: nowrap; }
.brand .pc { width: 34px; height: 34px; position: static; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 6px 11px; border-radius: 999px; text-decoration: none; color: var(--muted); white-space: nowrap; font-size: .94rem; font-weight: 500; }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.on { background: var(--accent); color: var(--accent-ink); }
.nav a.hl-link:not(.on) { color: var(--accent); }
.lang { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 6px 14px; font: 500 .9rem var(--f-body); cursor: pointer; white-space: nowrap; }
.lang:hover { border-color: var(--accent); }

main { max-width: 1160px; margin: 0 auto; padding: 24px 16px 48px; }
.kicker { color: var(--brass); font-weight: 700; font-size: .85rem; letter-spacing: .04em; margin: 0 0 .3em; }
.lang-en .kicker { text-transform: uppercase; letter-spacing: .1em; font-size: .75rem; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 62ch; }
.sec { margin: 36px 0 14px; font-size: 1.4rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 500 .95rem var(--f-body); text-decoration: none; cursor: pointer; transition: transform .08s, background .15s, border-color .15s; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); padding-inline: 6px; }
.ctl { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }

/* home */
.hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: 28px; align-items: center; padding: 18px 0 8px; }
.goal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 22px; box-shadow: var(--shadow); }
.goal-pcs { display: flex; gap: 6px; margin-bottom: 8px; }
.goal-pcs .pc { position: static; width: 56px; height: 56px; }
.progress { margin-top: 26px; display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: .95rem; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: var(--p, 0%); background: var(--accent); border-radius: 99px; transition: width .4s; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card { position: relative; display: block; text-align: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 18px 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: transform .15s, border-color .15s; font: inherit; cursor: pointer; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card h3 { margin: 8px 0 4px; }
.card p { color: var(--muted); margin: 0; font-size: .94rem; }
.card-n { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.card-done { position: absolute; top: 16px; inset-inline-end: 16px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); }
.card.done .card-done { background: var(--good); border-color: var(--good); }
.card.done .card-done::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 22px; }
.feature { display: flex; gap: 14px; align-items: flex-start; padding: 20px; border-radius: var(--r); background: var(--accent-soft); color: var(--ink); text-decoration: none; border: 1px solid transparent; }
.feature:hover { border-color: var(--accent); }
.feature .pc { position: static; flex: 0 0 56px; height: 56px; }
.feature p { margin: 0; color: var(--muted); }

/* lessons */
.lesson-head { margin-bottom: 18px; }
.lesson { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 480px); gap: 32px; align-items: start; }
.lesson.play { grid-template-columns: minmax(0, 560px) minmax(0, 1fr); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px 22px; box-shadow: var(--shadow); }
.stage { position: sticky; top: 72px; }
.note { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; }
.box { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.box h4 { margin-top: 0; }
.next { margin-top: 28px; display: flex; justify-content: flex-end; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tab { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: 500 .94rem var(--f-body); cursor: pointer; }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tab .pc { position: static; width: 26px; height: 26px; }
.piece-tabs .tabs { gap: 6px; }
.piece-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.piece-head h3 { margin: 0; font-size: 1.5rem; }
.piece-head p { margin: 0; }
.pc.big { position: static; width: 64px; height: 64px; flex: 0 0 64px; }
.value { margin-inline-start: auto; text-align: center; background: var(--surface-2); border-radius: 12px; padding: 4px 14px; }
.value small { display: block; color: var(--muted); font-size: .75rem; }
.value b { font-size: 1.3rem; }
.value b.long { font-size: .95rem; }

.values { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.values div { display: flex; flex-direction: column; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 6px 10px 4px; min-width: 58px; }
.values .pc { position: static; width: 42px; height: 42px; }
.nota { border-collapse: collapse; width: 100%; margin-bottom: 1em; font-size: .95rem; }
.nota td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.nota td:first-child { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; white-space: nowrap; color: var(--accent); width: 1%; }
.tips li { margin: .4em 0; }

/* messages */
.say { margin-top: 12px; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); min-height: 48px; }
.say.info { background: var(--surface); }
.say.good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.say.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.say.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

/* board */
.board { position: relative; width: 100%; max-width: 560px; margin-inline: auto; border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 6px color-mix(in srgb, var(--dark) 70%, #3b2a18), var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1; }
.sq { position: relative; border: 0; padding: 0; margin: 0; cursor: pointer; font: inherit; -webkit-tap-highlight-color: transparent; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 3; }
.pc { position: absolute; inset: 0; background-size: 100% 100%; background-repeat: no-repeat; pointer-events: none; }
.sq .pc { z-index: 1; }
.cf, .cr { position: absolute; font: 700 clamp(9px, 1.6vw, 12px)/1 var(--f-body); z-index: 2; pointer-events: none; }
.cf { right: 3px; bottom: 2px; }
.cr { left: 3px; top: 3px; }
.sq.light .cf, .sq.light .cr { color: var(--dark); }
.sq.dark .cf, .sq.dark .cr { color: var(--light); }
.sq::before, .sq::after { content: ""; position: absolute; pointer-events: none; }
.sq::before { inset: 0; z-index: 0; }
.sq.hl::before { background: rgba(47, 93, 80, .22); }
.sq.last::before { background: rgba(232, 196, 64, .45); }
.sq.sel::before { background: rgba(47, 120, 90, .5); }
.sq.hint::before { background: rgba(70, 130, 220, .38); }
.sq.pick::before { background: rgba(70, 130, 220, .55); }
.sq.target::before { box-shadow: inset 0 0 0 4px var(--accent); background: rgba(47, 93, 80, .3); }
.sq.check::before { background: radial-gradient(circle, rgba(230, 40, 30, .9) 0%, rgba(230, 40, 30, .5) 40%, transparent 72%); }
.sq.danger::before { background: rgba(200, 60, 50, .35); }
.sq.hit::before { background: rgba(46, 160, 90, .6); }
.sq.wrong::before { background: rgba(210, 50, 40, .6); }
.sq.miss::before { box-shadow: inset 0 0 0 4px #e8902a; background: rgba(232, 144, 42, .3); }
.sq.dot::after { z-index: 2; width: 30%; height: 30%; left: 35%; top: 35%; border-radius: 50%; background: rgba(20, 50, 35, .38); }
.sq.cap::after { z-index: 2; inset: 0; border-radius: 50%; box-shadow: inset 0 0 0 5px rgba(20, 50, 35, .45); }
@media (hover: hover) { .sq.dot:hover::after { background: rgba(20, 50, 35, .6); } }

.promo { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(0, 0, 0, .45); }
.promo-box { background: var(--surface); border-radius: 14px; padding: 14px; text-align: center; box-shadow: var(--shadow); }
.promo-title { font-weight: 700; margin-bottom: 8px; }
.promo-row { display: flex; gap: 6px; }
.promo-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px; cursor: pointer; color: var(--ink); font: 500 .8rem var(--f-body); }
.promo-btn:hover { border-color: var(--accent); }
.promo-btn .pc { position: static; width: 52px; height: 52px; }

/* quiz */
.quiz { max-width: 760px; }
.modes .mode { padding-top: 14px; }
.mode-ic { position: static !important; display: block; width: 48px; height: 48px; }
.best { display: inline-block; margin-top: 10px; font-size: .82rem; font-weight: 700; color: var(--good); background: var(--good-soft); border-radius: 99px; padding: 2px 10px; }
.quiz-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.quiz-top h2 { margin: 0; font-size: 1.35rem; }
.quiz-meta { margin-inline-start: auto; color: var(--muted); font-size: .92rem; }
.quiz .bar { margin-bottom: 18px; }
.quiz .bar i { width: 0; }
.quiz-q { font-size: 1.2rem; font-weight: 500; margin-bottom: 14px; }
.quiz-stage { max-width: 480px; margin: 0 auto 6px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { min-height: 54px; text-align: start; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 500 1rem var(--f-body); cursor: pointer; transition: border-color .15s, background .15s; }
.opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.opt:disabled { cursor: default; opacity: .7; }
.opt.right { background: var(--good-soft); border-color: var(--good); opacity: 1; }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); opacity: 1; }

/* play */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 500; }
.field select { min-height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); padding: 6px 10px; font: inherit; font-weight: 400; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.moves { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow: auto; font: 500 .95rem ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border-radius: 10px; padding: 6px; min-height: 48px; }
.moves li { display: grid; grid-template-columns: 40px 1fr 1fr; padding: 2px 6px; margin: 0; }
.moves li:nth-child(odd) { background: var(--surface-2); border-radius: 6px; }
.mn { color: var(--muted); }
.play .stage { position: static; }

.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; text-align: center; padding: 18px 16px 28px; }
.foot p { margin: 0; }

@media (max-width: 900px) {
  .hero, .split { grid-template-columns: 1fr; }
  .lesson, .lesson.play { grid-template-columns: 1fr; gap: 18px; }
  .stage { position: static; }
  .lesson .panel { order: 0; }
}
@media (max-width: 640px) {
  .top-in { flex-wrap: wrap; gap: 8px 10px; }
  .nav { order: 3; flex-basis: 100%; }
  .brand { flex: 1; }
  main { padding-top: 16px; }
  .panel { padding: 16px; }
  .opts { grid-template-columns: 1fr; }
  .board { box-shadow: 0 0 0 4px color-mix(in srgb, var(--dark) 70%, #3b2a18); }
  .piece-head { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
