:root {
  --navy: #14324a;
  --navy-2: #0e2436;
  --gold: #b58b4c;
  --gold-soft: #f3e7d1;
  --cream: #f8f4ec;
  --paper: #ffffff;
  --ink: #1d2a35;
  --muted: #687684;
  --line: #e7e0d2;
  --ok: #1f7a4d;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 50, 74, .06), 0 6px 20px rgba(20, 50, 74, .07);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Tajawal", system-ui, sans-serif;
  background: var(--cream);
  color: var(--ink);
  line-height: 1.6;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.wrap { width: min(1180px, 100%); margin-inline: auto; padding-inline: 16px; }
[hidden] { display: none !important; }

/* header */
.top { background: var(--navy); color: #fff; position: relative; z-index: 20; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 68px; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-logo { height: 56px; width: auto; display: block; }
.brand-sub {
  color: #cdd7e0; font-size: .8rem; line-height: 1.35; padding-inline-start: 12px;
  border-inline-start: 1px solid rgba(255, 255, 255, .25);
}
.cart-btn {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, .1); color: #fff; border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 999px; padding: 8px 14px; font-weight: 700;
}
.cart-btn em {
  font-style: normal; background: var(--gold); color: #fff; border-radius: 999px;
  min-width: 22px; height: 22px; display: inline-grid; place-items: center; font-size: .8rem; padding-inline: 6px;
}

/* hero */
.hero { background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%); color: #fff; padding: 22px 0 34px; }
.hero h1 { font-family: "Amiri", serif; font-size: clamp(1.7rem, 4.6vw, 2.6rem); margin: 0 0 6px; line-height: 1.3; }
.hero p { margin: 0; color: #d6dee6; max-width: 60ch; }
.hero .stand { color: var(--gold-soft); white-space: nowrap; }
.hero .promo {
  margin-top: 14px; display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: linear-gradient(90deg, #c99a52, #e2bb72); color: #2b1d07; border-radius: 12px; padding: 8px 14px 8px 8px;
  box-shadow: 0 6px 18px rgba(201, 154, 82, .35);
}
.promo-tag { background: var(--navy-2); color: #f3e7d1; border-radius: 8px; padding: 3px 10px; font-size: .82rem; font-weight: 700; }
.promo b { font-size: 1.15rem; font-weight: 800; }

/* toolbar */
.toolbar { position: sticky; top: 0; z-index: 15; background: rgba(248, 244, 236, .96); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 12px 0 6px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; color: var(--muted); }
.search input { flex: 1; border: 0; outline: 0; background: transparent; padding: 11px 0; min-width: 0; font-size: 1rem; }
/* «تصفح حسب»: sections or subjects */
.browse { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: .88rem; color: var(--muted); }
.browse span { margin-inline-end: 2px; }
.browse button {
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 10px;
  padding: 5px 14px; font-weight: 700; font-size: .88rem;
}
.browse button[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: #fff; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 6px; scrollbar-width: thin; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--paper); border-radius: 999px;
  padding: 6px 14px; font-size: .9rem; white-space: nowrap; color: var(--ink);
}
.chip { display: inline-flex; align-items: center; gap: 6px; }
.chip small { color: var(--muted); background: #f1ece2; border-radius: 999px; padding: 0 7px; font-size: .78rem; line-height: 1.6; }
.chip[aria-pressed="true"] small { background: rgba(255, 255, 255, .16); }
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip[aria-pressed="true"] small { color: #cdd7e0; }

/* grid */
.result-line { color: var(--muted); font-size: .92rem; margin: 14px 0 10px; min-height: 1.5em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 14px; padding-bottom: 40px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.group-head {
  grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin: 18px 0 2px; padding-bottom: 8px; border-bottom: 2px solid var(--line); font-family: "Amiri", serif;
  font-size: 1.45rem; color: var(--navy); line-height: 1.35;
}
.group-head::before { content: ""; width: 6px; align-self: stretch; border-radius: 3px; background: var(--gold); margin-inline-end: 4px; flex: none; }
.group-head span { flex: 1; min-width: 0; }
.group-head small { font-family: "Tajawal", sans-serif; font-size: .82rem; color: var(--muted); font-weight: 500; white-space: nowrap; }
.grid > .group-head:first-child { margin-top: 0; }
.card {
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden; min-width: 0;
}
.cover {
  aspect-ratio: 3 / 4; background: linear-gradient(160deg, #f5f0e6, #ebe3d3); border: 0; padding: 10px;
  display: grid; place-items: center; position: relative;
}
.cover img { width: 100%; height: 100%; object-fit: contain; }
.badge-slot { display: contents; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 800; border-radius: 999px; padding: 3px 10px;
}
.cover .badge { position: absolute; top: 8px; inset-inline-start: 8px; box-shadow: 0 2px 8px rgba(122, 42, 20, .18); }
.badge.low { background: #fff1e0; color: #a3420f; border: 1px solid #f5c79a; }
.badge.low i { width: 8px; height: 8px; border-radius: 50%; background: #e0661d; box-shadow: 0 0 0 0 rgba(224, 102, 29, .6); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(224, 102, 29, 0); } 100% { box-shadow: 0 0 0 0 rgba(224, 102, 29, 0); } }

/* out of stock: grey cover with a rubber-stamp label across it */
.card.is-out .cover img, .dlg-cover.is-out img, .card.is-out .noimg { filter: grayscale(1); opacity: .45; }
.card.is-out h3, .card.is-out .price { color: var(--muted); }
.dlg-cover { position: relative; }
.stamp {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-12deg);
  padding: 6px 14px; border: 3px solid currentColor; border-radius: 8px; background: rgba(255, 255, 255, .88);
  font-weight: 800; font-size: clamp(.9rem, 3.4vw, 1.1rem); white-space: nowrap; letter-spacing: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
.stamp.sold { color: var(--danger); }
.stamp.held { color: var(--navy); }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card h3 {
  font-size: .98rem; margin: 0; line-height: 1.45; font-weight: 700;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.author { color: var(--muted); font-size: .84rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-foot { margin-top: auto; padding-top: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
/* on a card the price sits above a full-width button at every width: price + old price + button don't fit one row */
.card .card-foot { flex-direction: column; align-items: stretch; gap: 6px; }
.card .card-foot .add { width: 100%; min-height: 40px; }
.card .card-foot .stepper { width: 100%; justify-content: space-between; }
.price { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.price b { font-weight: 800; color: var(--navy); font-size: 1.05rem; }
.price small { font-weight: 500; font-size: .78rem; color: var(--muted); }
.price s { color: #8a7f70; font-size: .95rem; font-weight: 700; text-decoration: line-through 1.5px #8a7f70; }
.cover .off {
  position: absolute; bottom: 8px; inset-inline-end: 8px; background: #c0392b; color: #fff; font-size: .74rem; font-weight: 800;
  border-radius: 6px; padding: 2px 8px; box-shadow: 0 2px 8px rgba(192, 57, 43, .3);
}
.dlg-cover .off { position: absolute; bottom: 12px; inset-inline-end: 12px; background: #c0392b; color: #fff; font-weight: 800; border-radius: 6px; padding: 3px 10px; }
.noimg {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border: 1.5px dashed #cdbf9f; border-radius: 10px; background: repeating-linear-gradient(135deg, #f6f1e7 0 10px, #f1eadc 10px 20px);
  color: #7d6a46; text-align: center; padding: 12px; font-size: .82rem; font-weight: 700; line-height: 1.5;
}
.noimg img, .cover .noimg img { width: 62%; max-width: 130px; height: auto; flex: none; opacity: .55; }
.dlg-cover .noimg { min-height: 240px; font-size: .95rem; }
.thumb-ph { width: 52px; height: 68px; display: grid; place-items: center; background: #f1eadc; border-radius: 6px; }
.thumb-ph img { width: 30px; height: 30px; border-radius: 6px; }
.cart-saved { margin: -6px 0 14px; color: var(--ok); font-weight: 700; font-size: .92rem; }
.add {
  border: 0; background: var(--gold); color: #fff; border-radius: 10px; padding: 7px 12px; font-weight: 700; font-size: .9rem; white-space: nowrap;
}
.add:disabled { background: #d9d2c5; cursor: not-allowed; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--gold); border-radius: 10px; overflow: hidden; }
.stepper button { border: 0; background: var(--gold-soft); width: 32px; height: 32px; font-size: 1.1rem; font-weight: 800; color: #7a5a24; }
.stepper button:disabled { opacity: .4; cursor: not-allowed; }
.stepper output { min-width: 28px; text-align: center; font-weight: 800; }
.skeleton { aspect-ratio: 3 / 5; border-radius: var(--radius); background: linear-gradient(90deg, #efe8da, #f7f2e8, #efe8da); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { text-align: center; color: var(--muted); padding: 40px 0 60px; }
.link { background: none; border: 0; color: var(--navy); text-decoration: underline; font-weight: 700; }

.foot { background: var(--navy-2); color: #b8c4cf; font-size: .9rem; padding: 18px 0 90px; }
.foot p { margin: 0; }

/* floating cart (phones) */
.float-cart {
  position: fixed; inset-inline: 16px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 25;
  display: flex; justify-content: space-between; align-items: center; border: 0; border-radius: 14px;
  background: var(--navy); color: #fff; padding: 14px 18px; font-weight: 700; box-shadow: 0 10px 30px rgba(14, 36, 54, .35);
  max-width: 560px; margin-inline: auto;
}
.float-cart b { color: var(--gold-soft); }

/* drawer */
.overlay { position: fixed; inset: 0; background: rgba(14, 36, 54, .45); z-index: 40; }
.drawer {
  position: fixed; z-index: 50; background: var(--paper); display: flex; flex-direction: column;
  top: 0; bottom: 0; inset-inline-end: 0; width: min(440px, 100%);
  transform: translateX(-105%); transition: transform .25s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .2);
}
[dir="rtl"] .drawer { inset-inline-end: auto; left: 0; }
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 1.2rem; }
.icon-btn { border: 0; background: #f1ece2; width: 36px; height: 36px; border-radius: 50%; font-size: 1.4rem; line-height: 1; }
.drawer-body { padding: 12px 16px 24px; overflow-y: auto; flex: 1; }
.cart-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.cart-item { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.cart-item > img { width: 52px; height: 68px; object-fit: contain; background: #f5f0e6; border-radius: 6px; }
.cart-item h4 { margin: 0; font-size: .9rem; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cart-item p { margin: 2px 0 0; color: var(--muted); font-size: .84rem; }
.cart-item .side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.remove { background: none; border: 0; color: var(--danger); font-size: .8rem; padding: 0; }
.cart-empty { color: var(--muted); text-align: center; padding: 30px 0; }
.cart-total { display: flex; justify-content: space-between; align-items: center; font-size: 1.1rem; padding: 14px 0; border-bottom: 2px solid var(--navy); margin-bottom: 14px; }
.cart-total b { color: var(--navy); font-size: 1.25rem; }
.book-form { display: flex; flex-direction: column; gap: 12px; }
.book-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: .92rem; }
.book-form small { color: var(--muted); font-weight: 400; }
.book-form input, .book-form textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fdfbf7; font-weight: 400; font-size: 1rem;
}
.book-form textarea { resize: vertical; min-height: 64px; }
.book-form input:focus, .book-form textarea:focus { border-color: var(--gold); outline: 0; box-shadow: 0 0 0 3px var(--gold-soft); }
.book-form input[dir="ltr"] { text-align: left; }
/* pickup calendar */
.pickup { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin: 0; background: #fdfbf7; }
.pickup legend { font-weight: 700; font-size: .92rem; padding: 0 4px; }
.pickup-hint { margin: 0 0 8px; color: var(--muted); font-size: .8rem; }
.cal-month + .cal-month { margin-top: 10px; }
.cal-title { text-align: center; font-weight: 700; color: var(--navy); margin: 2px 0 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-wd { text-align: center; font-size: .72rem; color: var(--muted); padding-bottom: 2px; }
.cal-day {
  aspect-ratio: 1; min-height: 34px; border: 1px solid transparent; border-radius: 10px; background: transparent;
  font-weight: 700; font-size: .92rem; color: #b9b2a6; display: grid; place-items: center; padding: 0;
}
.cal-day.fair { background: var(--gold-soft); color: #7a5a24; border-color: #ead7b4; }
.cal-day.fair:disabled { background: #f1ede6; color: #c3bcb0; border-color: transparent; text-decoration: line-through; cursor: not-allowed; }
.cal-day.today { box-shadow: inset 0 0 0 2px #cdbf9f; }
.cal-day.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.cal-day:not(:disabled):hover { border-color: var(--gold); }
.pickup-chosen { margin: 8px 0 0; text-align: center; font-size: .88rem; color: var(--muted); }
.pickup-chosen.set { color: var(--navy); font-weight: 800; }
.cal-closed { text-align: center; color: var(--danger); margin: 8px 0; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.primary { border: 0; background: var(--navy); color: #fff; border-radius: 12px; padding: 13px 16px; font-weight: 800; font-size: 1.05rem; }
.primary:disabled { opacity: .6; cursor: wait; }
.fine { color: var(--muted); font-size: .8rem; margin: 0; text-align: center; }
.form-error { background: #fdecea; color: var(--danger); border-radius: 10px; padding: 10px 12px; margin: 0; font-size: .92rem; }
.done { padding: 40px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.done-mark { width: 72px; height: 72px; border-radius: 50%; background: #e3f3ea; color: var(--ok); font-size: 2.4rem; display: grid; place-items: center; }
.done h3 { margin: 8px 0 4px; font-size: 1.35rem; }
.done p { margin: 0; color: var(--muted); }
.done strong { font-size: 1.6rem; color: var(--navy); letter-spacing: 1px; direction: ltr; }
.done .primary { margin-top: 18px; min-width: 200px; }

/* book dialog */
.book-dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); }
.book-dialog::backdrop { background: rgba(14, 36, 54, .55); }
.book-dialog .close { position: absolute; top: 10px; inset-inline-start: 10px; z-index: 2; box-shadow: var(--shadow); }
.dlg-body { display: grid; grid-template-columns: 1fr; }
.dlg-cover { background: linear-gradient(160deg, #f5f0e6, #ebe3d3); padding: 18px; display: grid; place-items: center; }
.dlg-cover img { max-height: 46vh; object-fit: contain; }
.dlg-info { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.dlg-info h2 { margin: 0; font-size: 1.2rem; line-height: 1.5; }
.dlg-info .section-tag { align-self: flex-start; background: var(--gold-soft); color: #7a5a24; border-radius: 999px; padding: 2px 10px; font-size: .8rem; }
.dlg-info .card-foot { padding-top: 12px; }

.toast {
  position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: .92rem; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

@media (min-width: 900px) {
  .float-cart { display: none !important; }
  .foot { padding-bottom: 24px; }
  .dlg-body { grid-template-columns: 220px 1fr; }
  .dlg-cover img { max-height: 360px; }
}
@media (max-width: 520px) {
  .cart-btn span { display: none; }
  .cart-btn { padding: 9px 12px; min-height: 42px; }
  .drawer { width: 100%; }
}

/* phones: price on its own line, the button or stepper full width under it, bigger tap targets */
@media (max-width: 560px) {
  .top-row { min-height: 60px; }
  .brand-logo { height: 44px; }
  .brand { gap: 10px; }
  .brand-sub { font-size: .72rem; padding-inline-start: 10px; }
  .hero { padding: 14px 0 22px; }
  .hero h1 { font-size: 1.55rem; margin-bottom: 4px; }
  .hero p { font-size: .95rem; }
  .toolbar { padding-top: 10px; }
  .result-line { margin: 10px 0 8px; }
  .card-body { padding: 8px 10px 10px; gap: 2px; }
  .card h3 { font-size: .92rem; }
  .author { font-size: .8rem; }
  .card-foot { flex-direction: column; align-items: stretch; gap: 6px; padding-top: 6px; }
  .card-foot .add { width: 100%; min-height: 40px; padding: 8px; }
  .card-foot .stepper { width: 100%; justify-content: space-between; }
  .stepper button { width: 42px; height: 40px; }
  .cover { padding: 8px; }
  .cover .badge { top: 6px; inset-inline-start: 6px; font-size: .72rem; padding: 2px 8px; }
  .cart-item { grid-template-columns: 46px minmax(0, 1fr) auto; gap: 8px; }
  .cart-item > img { width: 46px; height: 60px; }
  .thumb-ph { width: 46px; height: 60px; }
  .noimg { font-size: .74rem; gap: 6px; padding: 8px; }
  .noimg img, .cover .noimg img { width: 70%; height: auto; }
  .hero .promo { margin-top: 12px; }
  .group-head { font-size: 1.2rem; margin-top: 14px; }
  .promo b { font-size: 1.05rem; }
  .cart-item .stepper button { width: 36px; height: 36px; }
  .dlg-info .card-foot { flex-direction: row; align-items: center; }
  .dlg-info .card-foot .add, .dlg-info .card-foot .stepper { width: auto; min-width: 150px; }
  .done strong { font-size: 1.4rem; }
}
@media (max-width: 359px) {
  .wrap { padding-inline: 12px; }
  .brand-sub { display: none; }
  .grid { gap: 8px; }
  .price { font-size: .98rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
