/* TwentyDZ · الكتاب الحيّ */
:root { --ink: #10233a; --paper: #fbf7ee; --teal: #0f766e; --amber: #f4b545; --red: #c1121f; --line: rgba(16, 35, 58, .14); }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #e8f5fa; color: var(--ink); font: 500 17px/1.6 Tajawal, system-ui, sans-serif; }
button { font: inherit; color: inherit; }
.m { font-family: 'Readex Pro', Tajawal, sans-serif; unicode-bidi: isolate; white-space: nowrap; }

.kh { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; background: #e8f5fa; }
.kh-top { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: #fffdf8; border-bottom: 1px solid #e5dccb; box-shadow: 0 2px 10px rgba(16, 35, 58, .06); z-index: 5; }
.kh-t { flex: 1; min-width: 0; display: grid; line-height: 1.25; }
.kh-t small { color: #51657a; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kh-t b { font: 800 22px/1.2 'Baloo Bhaijaan 2', Tajawal, sans-serif; }
.kh-top nav { display: flex; gap: 6px; flex-wrap: wrap; }
.kh-b { border: 2px solid #2d6f73; color: var(--ink); background: #fff; border-radius: 12px; padding: 6px 12px; font-weight: 700; cursor: pointer; box-shadow: 0 3px 0 #2d6f73; transition: transform .12s, box-shadow .12s; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.kh-b:active { transform: translateY(2px); box-shadow: 0 1px 0 #2d6f73; }
.kh-sq { width: 42px; height: 40px; padding: 0; }
.kh-ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.kh-close { background: #fdecc8; border-color: #b7791f; box-shadow: 0 3px 0 #b7791f; }
.kh-b.on { background: var(--amber); }
.kh-b:disabled { opacity: .35; cursor: default; }
.kh-home { font-size: 20px; padding: 2px 10px; }

.kh-stage { position: relative; overflow: hidden; background: linear-gradient(180deg, #cfeaf7 0%, #e8f5fa 48%, #fbf5e6 100%); touch-action: none; }
/* our own sky: soft clouds drifting behind the page (the wave button stops them) */
.kh-sky { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.kh-sky i { position: absolute; width: 34vw; height: 9vw; border-radius: 50%; background: radial-gradient(closest-side, rgba(255, 255, 255, .95), rgba(255, 255, 255, 0)); filter: blur(4px); animation: cloud 80s linear infinite; }
.kh-sky i:nth-child(1) { top: 6%; left: -10%; }
.kh-sky i:nth-child(2) { top: 30%; left: 40%; width: 26vw; animation-duration: 110s; animation-delay: -40s; }
.kh-sky i:nth-child(3) { top: 62%; left: 10%; width: 40vw; animation-duration: 95s; animation-delay: -70s; opacity: .8; }
.kh-sky i:nth-child(4) { top: 84%; left: 65%; animation-duration: 120s; animation-delay: -20s; opacity: .7; }
@keyframes cloud { from { transform: translateX(-60vw); } to { transform: translateX(120vw); } }
.kh.still .kh-sky i { animation-play-state: paused; }
.kh-cam { position: absolute; left: 0; top: 0; transform-origin: 0 0; transition: transform .8s cubic-bezier(.65, 0, .25, 1); will-change: transform; }
.kh-cam.instant { transition: none; }
.kh.fast *, .kh.fast *::before { transition: none !important; animation-duration: 1ms !important; animation-delay: 0s !important; }   /* ?fast=1: for checking screenshots */
.kh-page { position: relative; background: #fff; box-shadow: 0 24px 60px -18px rgba(30, 70, 100, .35), 0 0 0 1px rgba(30, 70, 100, .08); }
.kh-img { display: block; width: 100%; height: 100%; user-select: none; }
.kh-spot { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; transition: opacity .6s; }
.kh-spot.on { opacity: 1; }
.kh-spot path { fill: rgba(205, 225, 235, .72); }
.kh-marks, .kh-taps { position: absolute; inset: 0; }
.kh-marks { pointer-events: none; }
.kh-ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.kh-ink polyline { fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }

.kh-m { position: absolute; }
.kh-hl { background: rgba(255, 214, 0, .42); mix-blend-mode: multiply; border-radius: 6px; transform-origin: left; }
.kh-hl.rtl { transform-origin: right; }
.kh-hl.c-p { background: rgba(255, 105, 180, .32); }
.kh-hl.c-g { background: rgba(52, 211, 153, .4); }
.kh-hl.fresh { animation: grow .9s cubic-bezier(.5, 0, .2, 1) both; }
@keyframes grow { from { transform: scaleX(0); } }
.kh-box { border: 7px solid var(--teal); border-radius: 18px; margin: -8px; padding: 8px; box-sizing: content-box; }
.kh-box.c-g { border-color: #16a34a; box-shadow: 0 0 0 6px rgba(22, 163, 74, .15); }
.kh-box.fresh { animation: pop .5s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes pop { from { opacity: 0; transform: scale(1.12); } }
.kh-x svg { width: 100%; height: 100%; overflow: visible; }
.kh-x path { fill: none; stroke: var(--red); stroke-width: 5; stroke-linecap: round; vector-effect: non-scaling-stroke; stroke-width: 8; }
.kh-x.fresh path { stroke-dasharray: 220; animation: draw .7s ease-out both; }
@keyframes draw { from { stroke-dashoffset: 220; } }
.kh-ans { position: absolute; display: flex; align-items: center; white-space: nowrap; padding: 0 .25em; border-radius: .3em;
  font-family: 'Aref Ruqaa', 'Readex Pro', serif; font-weight: 700; color: var(--red); background: rgba(255, 253, 246, .82); line-height: 1; }
.kh-ans.fresh { animation: write 1s steps(12, end) both; }
@keyframes write { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

.kh-tap { position: absolute; border: 0; background: transparent; border-radius: 10px; cursor: pointer; }
.kh-tap:hover { outline: 5px dashed rgba(15, 118, 110, .55); outline-offset: 6px; }
.kh.pen .kh-tap { pointer-events: none; }
.kh.pen .kh-stage { cursor: crosshair; }

.kh-panel { position: absolute; left: 12px; top: 12px; bottom: 12px; width: min(420px, 40%); overflow: auto; z-index: 3;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 8px 8px 0 var(--ink); padding: 14px 18px; animation: slide .45s cubic-bezier(.3, 1.3, .5, 1) both; }
@keyframes slide { from { opacity: 0; transform: translateX(-30px); } }
.kh-panel h3 { margin: 0 0 8px; font: 800 20px/1.3 'Baloo Bhaijaan 2', Tajawal, sans-serif; color: var(--teal); }
.kh-lines { list-style: none; margin: 0; padding: 0; font: 600 26px/1.35 'Readex Pro', sans-serif; }
.kh-lines li { padding: 6px 4px; border-bottom: 1px dashed var(--line); animation: line .5s ease-out both; white-space: nowrap; }
.kh-lines li.done { color: var(--red); font-weight: 800; }
.kh-lines u { text-decoration: none; background: linear-gradient(transparent 62%, rgba(244, 181, 69, .75) 0); border-bottom: 4px solid var(--amber); border-radius: 3px; }
@keyframes line { from { opacity: 0; transform: translateY(-8px); } }
.kh-why { margin: 10px 0 0; color: #36506b; font-size: 16px; }
.kh-cmp { display: grid; gap: 10px; }
.kh-cmp > div { background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 4px 10px; }
.kh-cmp .kh-lines { font-size: 22px; }
.kh-q { font-size: 22px; font-weight: 700; margin: 4px 0 10px; }
.kh-hint { margin: 0 0 8px; color: #36506b; }
.kh-opts { display: grid; gap: 8px; }
.kh-opt { text-align: center; border: 3px solid var(--ink); background: #fff; border-radius: 14px; padding: 10px; font-size: 22px; font-weight: 700; cursor: pointer; box-shadow: 0 4px 0 var(--ink); }
.kh-opt.ok { background: #bbf7d0; border-color: #15803d; }
.kh-opt.no { background: #fecaca; animation: shake .4s; }
.kh-opt small { color: var(--red); font-size: 16px; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.kh-go { margin-top: 12px; background: var(--amber); }

.kh-card { position: absolute; right: 16px; bottom: 14px; max-width: min(560px, 56%); z-index: 3; background: #fff; border: 3px solid var(--ink); border-radius: 18px;
  padding: 10px 16px; box-shadow: 6px 6px 0 var(--amber); font-size: 19px; animation: rise .45s cubic-bezier(.3, 1.4, .5, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }

.kh-board { position: absolute; inset: 0; background: linear-gradient(#ffffff0d 1px, transparent 1px) 0 0 / 100% 38px, #1f3b33; }
.kh.no-page .kh-cam { display: none; }
.kh.no-page .kh-panel { left: 50%; transform: translateX(-50%); width: min(720px, 92%); top: 6%; bottom: auto; max-height: 86%; animation: none; }
.kh.no-page .kh-lines { font-size: 30px; }

.kh-foot { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 8px 14px; background: #fffdf8; border-top: 1px solid #e5dccb; box-shadow: 0 -2px 10px rgba(16, 35, 58, .06); }
.kh-count { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.kh-num { font: 800 26px/1 'Readex Pro', Tajawal, sans-serif; color: var(--ink); white-space: nowrap; }
.kh-num span { font-size: 15px; color: #64748b; }
.kh-count small { color: #64748b; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kh-mid { display: flex; gap: 10px; align-items: center; }
.kh-nav { font-size: 17px; padding: 6px 16px; }
.kh-cur { background: #fcd679; border-color: #b7791f; box-shadow: 0 3px 0 #b7791f; max-width: 36vw; padding: 6px 16px; }
.kh-cur span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kh-end { justify-self: end; }
/* the small page in the corner */
.kh-mini { position: absolute; right: 12px; top: 12px; z-index: 4; display: grid; justify-items: center; gap: 2px; padding: 5px 5px 2px; background: #fff; border: 2px solid #2d6f73; border-radius: 10px; box-shadow: 0 3px 0 #2d6f73; cursor: pointer; }
.kh-mini-pg { position: relative; overflow: hidden; display: block; background: #fff; border: 1px solid #e2e8f0; }
.kh-mini-doc { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; }
.kh-mini-view { position: absolute; border: 2px solid #ea580c; background: rgba(234, 88, 12, .1); border-radius: 2px; transition: all .6s; }
.kh-mini b { font-size: 12px; line-height: 1.3; }
.kh-menu, .kh-pens { top: 12px; right: 118px; }

.kh-menu { position: absolute; right: 12px; top: 12px; z-index: 6; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; padding: 8px; max-height: 80%; overflow: auto; box-shadow: 8px 8px 0 var(--ink); }
.kh-menu ol { margin: 0; padding: 0 22px 0 0; }
.kh-menu button { border: 0; background: none; padding: 6px 8px; cursor: pointer; text-align: right; border-radius: 8px; width: 100%; }
.kh-menu button.on, .kh-menu button:hover { background: var(--amber); }
.kh-pens { position: absolute; right: 12px; top: 12px; z-index: 6; display: flex; gap: 8px; background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 6px; }
.kh-pens [data-c] { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; background: var(--c); outline: 2px solid var(--ink); cursor: pointer; }
.kh-pens [data-c].on { outline: 4px solid var(--amber); }
.kh-modal { position: absolute; inset: 0; z-index: 9; display: grid; place-items: center; background: rgba(30, 60, 80, .35); }
.kh-dlg { width: min(560px, 92%); background: var(--paper); border: 3px solid var(--ink); border-radius: 20px; padding: 16px 20px; box-shadow: 10px 10px 0 var(--ink); }
.kh-dlg h3 { margin: 0 0 6px; color: var(--teal); }

@media (max-width: 760px) {
  .kh-top { flex-wrap: wrap; row-gap: 6px; }
  .kh-t { flex-basis: calc(100% - 60px); }
  .kh-top nav { width: 100%; }
  .kh-top nav .kh-b { padding: 4px 8px; font-size: 14px; }
  .kh-t b { font-size: 18px; }
  .kh-panel { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-height: 46%; }
  .kh-card { left: 8px; right: 8px; max-width: none; bottom: auto; top: 8px; font-size: 16px; }
  .kh-lines { font-size: 21px; }
  .kh-teacher { font-size: 14px; }
  .kh-foot { grid-template-columns: 1fr auto; }
  .kh-mid { grid-column: 1 / -1; grid-row: 1; justify-content: center; }
  .kh-cur { max-width: 44vw; }
  .kh-wide span { display: none; }
  .kh-menu, .kh-pens { right: 12px; }
}

/* the lesson picker */
.pick { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(180deg, #cfeaf7 0%, #e8f5fa 48%, #fbf5e6 100%); color: var(--ink); }
.pick h1 { font: 800 34px/1.2 'Baloo Bhaijaan 2', Tajawal, sans-serif; margin: 0 0 4px; text-align: center; }
.pick p.sub { margin: 0 0 22px; text-align: center; color: #475569; }
.pick .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; width: min(860px, 100%); }
.pick a { display: grid; gap: 8px; text-decoration: none; color: var(--ink); background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; padding: 12px; box-shadow: 8px 8px 0 var(--amber); transition: transform .15s; }
.pick a:hover { transform: translateY(-3px); }
.pick .cov { aspect-ratio: 16/9; border-radius: 14px; background-size: cover; border: 2px solid var(--line); }
.pick b { font: 800 24px/1.2 'Baloo Bhaijaan 2', Tajawal, sans-serif; }
.pick small { color: #51657a; }
.pick .tag { justify-self: start; background: #fde68a; border-radius: 99px; padding: 0 10px; font-size: 14px; font-weight: 700; }
.kh-tab { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 17px; }
.kh-tab th, .kh-tab td { border: 1.5px solid var(--line); padding: 5px 6px; text-align: center; }
.kh-tab thead th { background: #eaf6f3; color: var(--teal); }
.kh-tab tbody tr { animation: line .5s ease-out both; }
/* stacked fractions in the panel and in the handwritten answers */
.kh-frac li { white-space: nowrap; line-height: 1.2; padding: 8px 4px; }
.fr { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 3px; font-size: .9em; line-height: 1.15; }
.fr > span:first-child { border-bottom: 2.5px solid currentColor; padding: 0 5px 1px; }
.fr > span:last-child { padding: 1px 5px 0; }
.kh-ans .fr { font-size: .62em; }
.kh-ans.in-slot:has(.fr) { align-items: center; }
/* lesson 6: constructions */
.geo-svg { display: block; margin: 0 auto; max-width: 100%; height: auto; overflow: visible; }
.geo-svg .pn { font: 700 20px 'Readex Pro', sans-serif; fill: #10233a; }
.geo-svg .nm { font: 700 18px 'Readex Pro', sans-serif; }
.geo-svg .ln { font: 600 16px 'Readex Pro', sans-serif; fill: #475569; }
.geo-svg .pen[pathLength] { stroke-dasharray: 1; stroke-dashoffset: 1; animation: pen 1.1s ease-out forwards; }
.geo-svg circle.pen:not([pathLength]), .geo-svg text.pen, .geo-svg polygon.pen, .geo-svg path.pen:not([pathLength]) { animation: fadein .6s ease-out both; }
@keyframes pen { to { stroke-dashoffset: 0; } }
@keyframes fadein { from { opacity: 0; } }
.kh-geo { background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 8px; }
.kh-say { margin: 8px 0 0; padding-inline-start: 22px; font-size: 17px; }
.kh-say li { animation: line .5s ease-out both; margin: 3px 0; }
.kh.fast .geo-svg .pen { stroke-dashoffset: 0; }
/* generic panels for every subject: reveal, table, sort */
.kh-rev li { white-space: normal; line-height: 1.5; }
.kh-panel .kh-tab { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: 17px; }
.kh-panel .kh-tab th, .kh-panel .kh-tab td { border: 1.5px solid var(--line); padding: 6px 8px; text-align: center; }
.kh-panel .kh-tab tbody th { background: #fff7e0; }
.kh-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; min-height: 10px; }
.kh-chip { border: 2px solid #2d6f73; background: #fff; border-radius: 99px; padding: 5px 14px; font-weight: 700; cursor: pointer; box-shadow: 0 3px 0 #2d6f73; }
.kh-chip.on { background: var(--amber); }
.kh-chip.no { animation: shake .5s; background: #fde2e2; }
.kh-chip.ok { background: #dcfce7; box-shadow: none; cursor: default; }
.kh-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kh-grp { border: 2.5px dashed #2d6f73; border-radius: 14px; padding: 8px; min-height: 90px; cursor: pointer; background: #f0fbf9; }
.kh-grp > b { display: block; text-align: center; color: var(--teal); margin-bottom: 6px; }
.kh-grp > div { display: flex; flex-wrap: wrap; gap: 6px; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
/* the Arabic translation of an English book, shown under each sentence when asked */
.kh.tr .kh-doc [data-ar]::after { content: attr(data-ar); display: block; direction: rtl; text-align: right; unicode-bidi: plaintext;
  margin: 4px 0 2px; padding: 2px 12px; border-radius: 8px; background: #eefaf6; color: #0f766e; font: 600 .8em/1.6 Tajawal, sans-serif; white-space: normal; }
.kh.tr .kh-doc th[data-ar]::after, .kh.tr .kh-doc td[data-ar]::after { text-align: center; padding: 0 4px; background: none; }
.kh-ar { margin: 4px 0 8px; padding: 4px 10px; border-radius: 8px; background: #eefaf6; color: #0f766e; font: 600 16px/1.6 Tajawal, sans-serif; }
.kh-ic-t { font: 800 19px/1 Tajawal, sans-serif; }
.kh-rev .m { white-space: normal; }
