:root {
  --paper: #f5efe3;
  --paper-deep: #ebe2d0;
  --ink: #1f2a37;
  --ink-soft: #4b5563;
  --muted: #8a7f6d;
  --line: rgba(31, 42, 55, 0.12);
  --rule: rgba(47, 111, 106, 0.09);
  --accent: #b5523b;
  --card: #fffaf1;
  --shadow: 0 1px 0 rgba(31,42,55,.05), 0 18px 40px -18px rgba(60, 40, 20, .35);
  --radius: 18px;
  --display: "Alexandria", "IBM Plex Sans Arabic", sans-serif;
  --body: "IBM Plex Sans Arabic", "Alexandria", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }

/* notebook paper backdrop */
.paper {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(192,138,46,.13), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(47,111,106,.12), transparent 60%),
    repeating-linear-gradient(to bottom, transparent 0 35px, var(--rule) 35px 36px),
    var(--paper);
}
.paper::after {
  content: ""; position: absolute; top: 0; bottom: 0; right: 64px; width: 2px;
  background: rgba(181, 82, 59, .18);
}

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 28px; flex-wrap: wrap;
  padding: 22px clamp(20px, 5vw, 72px);
}
.brand { display: inline-flex; align-items: center; gap: 12px; font-family: var(--display); font-weight: 700; font-size: 1.05rem; }
.brand-mark {
  width: 30px; height: 34px; border-radius: 4px 7px 7px 4px; position: relative;
  background: var(--accent); box-shadow: inset -7px 0 0 rgba(0,0,0,.22);
}
.brand-mark::after { content: ""; position: absolute; inset: 7px 10px auto 5px; height: 3px; background: rgba(255,255,255,.7); border-radius: 2px; box-shadow: 0 6px 0 rgba(255,255,255,.45); }

.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: .92rem; color: var(--ink-soft); }
.crumbs a, .crumbs span { padding: 6px 12px; border-radius: 999px; }
.crumbs a { background: rgba(255,250,241,.7); border: 1px solid var(--line); transition: background .2s, transform .2s; }
.crumbs a:hover { background: var(--card); transform: translateY(-1px); }
.crumbs span.current { color: var(--ink); font-weight: 600; }
.crumbs .sep { padding: 0; color: var(--muted); }

main { flex: 1; padding: 8px clamp(20px, 5vw, 72px) 64px; outline: none; }
.foot { padding: 24px clamp(20px, 5vw, 72px); color: var(--muted); font-size: .85rem; border-top: 1px dashed var(--line); }

/* headings */
.page-head { max-width: 760px; margin: 18px 0 40px; }
.eyebrow { display: inline-block; font-family: var(--display); font-weight: 500; font-size: .85rem; color: var(--accent); letter-spacing: .02em; margin-bottom: 10px; }
.page-head h1 { font-family: var(--display); font-weight: 800; font-size: clamp(2rem, 4.6vw, 3.4rem); line-height: 1.25; margin: 0 0 12px; }
.page-head p { margin: 0; font-size: 1.1rem; color: var(--ink-soft); line-height: 1.8; }

.back {
  display: inline-flex; align-items: center; gap: 8px; margin-bottom: 8px;
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,250,241,.8);
  color: var(--ink-soft); cursor: pointer; transition: transform .2s, background .2s;
}
.back:hover { background: var(--card); transform: translateX(3px); }
.back svg { width: 16px; height: 16px; }

/* entrance animation */
.rise { opacity: 0; transform: translateY(18px); animation: rise .6s cubic-bezier(.2,.8,.2,1) forwards; animation-delay: calc(var(--i, 0) * 90ms); }
@keyframes rise { to { opacity: 1; transform: none; } }

/* ===== Home: bookshelf ===== */
.shelf {
  position: relative;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(16px, 2.5vw, 36px);
  align-items: end; padding: 0 clamp(0px, 2vw, 24px) 34px; max-width: 1180px;
}
.shelf::after {
  content: ""; position: absolute; inset: auto -12px 0 -12px; height: 22px; border-radius: 6px;
  background: linear-gradient(#a8794b, #8a5f37); box-shadow: 0 16px 30px -12px rgba(80,50,20,.5), inset 0 3px 0 rgba(255,255,255,.18);
}
.book-tile { display: flex; flex-direction: column; align-items: center; gap: 18px; padding-bottom: 6px; position: relative; z-index: 1; }
.book-tile:nth-child(1) { --tilt: -2deg; }
.book-tile:nth-child(2) { --tilt: 1.5deg; margin-bottom: 0; }
.book-tile:nth-child(3) { --tilt: -1deg; }
.book-tile:nth-child(4) { --tilt: 2deg; }
.book-tile .book { transform: rotate(var(--tilt, 0deg)); transition: transform .45s cubic-bezier(.2,.8,.2,1), box-shadow .45s; }
.book-tile:hover .book, .book-tile:focus-visible .book { transform: translateY(-16px) rotate(0deg) scale(1.02); box-shadow: 0 40px 50px -24px rgba(50,30,10,.55); }
.book-tile:focus-visible { outline: none; }
.book-tile:focus-visible .label { outline: 3px solid var(--book); outline-offset: 4px; }
.book-tile .label { text-align: center; border-radius: 12px; padding: 4px 10px; }
.book-tile .label strong { display: block; font-family: var(--display); font-weight: 700; font-size: 1.2rem; }
.book-tile .label small { color: var(--ink-soft); font-size: .95rem; }
.book-tile .open {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; padding: 8px 16px; border-radius: 999px;
  background: var(--book); color: #fff; font-size: .9rem; font-weight: 600; opacity: .92; transition: gap .25s, opacity .25s;
}
.book-tile:hover .open { gap: 12px; opacity: 1; }
.open svg { width: 15px; height: 15px; }

/* the book object */
.book {
  position: relative; width: 100%; max-width: 300px; aspect-ratio: 3 / 4;
  border-radius: 6px 14px 14px 6px; overflow: hidden; background: var(--book);
  box-shadow: 0 30px 40px -22px rgba(50,30,10,.55), 0 2px 0 rgba(0,0,0,.08);
}
.book img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 2; }
.book::before { /* spine (on the right for RTL books) */
  content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 7%; z-index: 3;
  background: linear-gradient(to left, rgba(0,0,0,.28), rgba(0,0,0,.08) 70%, rgba(255,255,255,.14));
}
.book::after { /* page sheen */
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: linear-gradient(120deg, rgba(255,255,255,.18), transparent 40%, transparent 70%, rgba(0,0,0,.12));
}
.cover-art { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; padding: 12% 14% 12% 18%; color: #fff; }
.cover-art .shapes { position: absolute; inset: 0; opacity: .9; }
.cover-art .shapes span { position: absolute; border-radius: 50%; }
.cover-art .s1 { width: 70%; aspect-ratio: 1; left: -22%; bottom: -14%; background: rgba(255,255,255,.12); }
.cover-art .s2 { width: 34%; aspect-ratio: 1; left: 18%; bottom: 22%; border: 3px solid rgba(255,255,255,.35); }
.cover-art .s3 { width: 16%; aspect-ratio: 1; right: 22%; top: 38%; background: rgba(255,255,255,.85); }
.cover-art .s4 { width: 120%; height: 18%; left: -10%; top: 30%; border-radius: 0 !important; background: rgba(0,0,0,.08); transform: rotate(-8deg); }
.cover-art .top { position: relative; font-size: .85rem; opacity: .85; letter-spacing: .03em; }
.cover-art .ttl { position: relative; font-family: var(--display); font-weight: 800; font-size: clamp(1.4rem, 2.6vw, 2.1rem); line-height: 1.25; }
.cover-art .grade { position: relative; display: inline-block; align-self: flex-start; padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,.92); color: var(--book); font-weight: 600; font-size: .9rem; }

/* ===== Terms page ===== */
.term-layout { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: clamp(24px, 5vw, 64px); align-items: start; max-width: 1180px; }
.term-layout .book { max-width: 260px; transform: rotate(-2deg); }
.terms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.term {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
  min-height: 300px; padding: 30px 30px 26px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .35s cubic-bezier(.2,.8,.2,1), box-shadow .35s, border-color .35s;
}
.term:nth-child(2) { margin-top: 48px; }
.term:hover, .term:focus-visible { transform: translateY(-6px); border-color: var(--book); box-shadow: 0 30px 50px -24px rgba(60,40,20,.45); outline: none; }
.term .num {
  position: absolute; left: -10px; bottom: -48px; font-family: var(--display); font-weight: 800; font-size: 15rem; line-height: 1;
  color: var(--book); opacity: .1; transition: opacity .35s, transform .5s;
}
.term:hover .num { opacity: .2; transform: translateY(-8px); }
.term .tag { align-self: flex-start; font-size: .85rem; padding: 5px 12px; border-radius: 999px; background: color-mix(in srgb, var(--book) 12%, transparent); color: var(--book); font-weight: 600; }
.term h2 { margin: 0 0 6px; font-family: var(--display); font-weight: 800; font-size: clamp(1.5rem, 2.8vw, 2.2rem); }
.term p { margin: 0; color: var(--ink-soft); }
.term .go { position: relative; display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--book); }
.term .go svg { width: 18px; height: 18px; transition: transform .3s; }
.term:hover .go svg { transform: translateX(-6px); }

/* ===== Units page ===== */
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 22px; max-width: 1180px; }
.unit {
  position: relative; display: flex; flex-direction: column; gap: 14px; padding: 26px 24px 22px; min-height: 200px;
  background: var(--card); border: 1px solid var(--line); border-radius: 6px var(--radius) var(--radius) var(--radius);
  box-shadow: var(--shadow); transition: transform .3s cubic-bezier(.2,.8,.2,1), border-color .3s;
}
.unit::before { /* index tab */
  content: attr(data-n); position: absolute; top: -14px; right: 22px; min-width: 44px; height: 28px; padding: 0 12px;
  display: grid; place-items: center; border-radius: 8px 8px 0 0; background: var(--book); color: #fff;
  font-family: var(--display); font-weight: 700; font-size: .9rem;
}
.unit:hover, .unit:focus-visible { transform: translateY(-5px) rotate(-.4deg); border-color: var(--book); outline: none; }
.unit .u-title { font-size: .9rem; color: var(--book); font-weight: 600; }
.unit h3 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 1.35rem; line-height: 1.4; }
.unit .meta { margin-top: auto; display: flex; justify-content: space-between; align-items: center; color: var(--ink-soft); font-size: .9rem; border-top: 1px dashed var(--line); padding-top: 14px; }
.unit .meta svg { width: 18px; height: 18px; color: var(--book); transition: transform .3s; }
.unit:hover .meta svg { transform: translateX(-5px); }

/* ===== Lessons page ===== */
.lessons { list-style: none; padding: 0; margin: 0; max-width: 860px; display: grid; gap: 14px; counter-reset: l; }
.lesson {
  display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 18px;
  padding: 16px 18px 16px 22px; border-radius: 16px; background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(31,42,55,.04), 0 10px 24px -18px rgba(60,40,20,.35);
  transition: transform .25s, border-color .25s, box-shadow .25s;
}
a.lesson:hover, a.lesson:focus-visible { transform: translateX(-6px); border-color: var(--book); outline: none; box-shadow: 0 18px 30px -18px rgba(60,40,20,.45); }
.lesson .n {
  width: 64px; height: 64px; display: grid; place-items: center; border-radius: 14px;
  background: color-mix(in srgb, var(--book) 12%, var(--card)); color: var(--book);
  font-family: var(--display); font-weight: 800; font-size: 1.5rem;
}
.lesson h3 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 1.15rem; }
.lesson small { color: var(--muted); }
.lesson .cta { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 999px; background: var(--book); color: #fff; font-weight: 600; font-size: .95rem; white-space: nowrap; }
.lesson .cta svg { width: 16px; height: 16px; }
.lesson.soon { opacity: .72; border-style: dashed; }
.lesson.soon .cta { background: transparent; color: var(--muted); border: 1px dashed var(--muted); }

/* empty + error states */
.empty {
  max-width: 560px; padding: 40px 32px; border-radius: var(--radius); border: 2px dashed var(--line);
  background: rgba(255,250,241,.6); text-align: center; color: var(--ink-soft); line-height: 1.8;
}
.empty svg { width: 64px; height: 64px; color: var(--accent); opacity: .6; margin-bottom: 8px; }
.empty h2 { font-family: var(--display); color: var(--ink); margin: 0 0 6px; font-size: 1.35rem; }

/* responsive */
@media (max-width: 900px) {
  .term-layout { grid-template-columns: 1fr; }
  .term-layout .book { max-width: 180px; }
}
@media (max-width: 760px) {
  .paper::after { right: 22px; }
  .shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 30px 18px; padding-bottom: 24px; }
  .shelf::after { display: none; }
  .book-tile .book { max-width: 220px; }
  .book-tile .label strong { font-size: 1rem; }
  .terms { grid-template-columns: 1fr; }
  .term { min-height: 220px; }
  .term:nth-child(2) { margin-top: 0; }
  .lesson { grid-template-columns: 48px 1fr; }
  .lesson .n { width: 48px; height: 48px; font-size: 1.2rem; }
  .lesson .cta { grid-column: 1 / -1; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .rise { opacity: 1; transform: none; }
}
