/* ============ tokens ============ */
:root {
  --bg: #f6f1e7;
  --bg-deep: #efe7d8;
  --surface: #fffdf8;
  --surface-2: #fbf6ec;
  --ink: #1d2433;
  --ink-2: #444c5e;
  --muted: #7a7f8d;
  --ink-faint: #d9cfbd;
  --line: #e7ddcc;
  --line-strong: #d6c8b0;
  --lapis: #1f3c88;
  --lapis-ink: #142a66;
  --lapis-soft: #e5eaf7;
  --gold: #b8893b;
  --gold-soft: #f3e6c9;
  --danger: #b4372f;
  --danger-soft: #f9e5e2;
  --ok: #2f7a4f;
  --ok-soft: #e1f1e7;
  --paper-a: #fffdf7;
  --paper-b: #f3ead9;
  --shadow-sm: 0 1px 2px rgb(40 30 10 / .06), 0 2px 6px rgb(40 30 10 / .05);
  --shadow: 0 2px 4px rgb(40 30 10 / .05), 0 12px 32px -8px rgb(40 30 10 / .18);
  --shadow-book: -2px 4px 8px rgb(30 20 5 / .12), -10px 22px 38px -12px rgb(30 20 5 / .38);
  --radius: 16px;
  --font-ui: 'Vazirmatn', system-ui, sans-serif;
  --font-display: 'Markazi Text', 'Vazirmatn', serif;
  --logo-core: #fff8ea;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151d;
    --bg-deep: #0e1117;
    --surface: #1a1f2b;
    --surface-2: #161a24;
    --ink: #ece6da;
    --ink-2: #c3bcae;
    --muted: #8d8a83;
    --ink-faint: #39404f;
    --line: #2a3040;
    --line-strong: #3a4256;
    --lapis: #8ea6f5;
    --lapis-ink: #b7c7ff;
    --lapis-soft: #232c45;
    --gold: #d8ae66;
    --gold-soft: #3a3020;
    --danger: #f08a80;
    --danger-soft: #3d2222;
    --ok: #7fcf9d;
    --ok-soft: #1d3426;
    --paper-a: #232838;
    --paper-b: #1c2130;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .3);
    --shadow: 0 2px 4px rgb(0 0 0 / .25), 0 16px 36px -10px rgb(0 0 0 / .6);
    --shadow-book: -2px 4px 8px rgb(0 0 0 / .35), -10px 22px 38px -12px rgb(0 0 0 / .7);
    --logo-core: #12151d;
    color-scheme: dark;
  }
}

/* ============ base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.85;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body > main { flex: 1; }
img { max-width: 100%; display: block; }
a { color: var(--lapis); text-decoration: none; }
a:hover { color: var(--lapis-ink); }
h1, h2, h3 { line-height: 1.4; margin: 0; font-weight: 700; }
p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--lapis); outline-offset: 2px; border-radius: 6px; }
.i { flex: none; }
.wrap { width: min(1180px, 100% - 32px); margin-inline: auto; }
/* A middle dot would read as the Persian zero (۰) next to Persian digits, so lists use a small diamond. */
.sep-list > * + *::before {
  content: ""; display: inline-block; width: 5px; height: 5px; margin: 0 9px 2px;
  background: currentColor; opacity: .55; transform: rotate(45deg); vertical-align: middle;
}
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ============ buttons & inputs ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 46px; padding: 0 22px;
  border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 15px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--lapis); color: var(--lapis); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--lapis); border-color: var(--lapis); color: #fff; box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--lapis) 70%, transparent); }
.btn-primary:hover { background: var(--lapis-ink); border-color: var(--lapis-ink); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #0e1117; } :root:not([data-theme="light"]) .btn-primary:hover { color: #0e1117; } }
.btn-lg { min-height: 54px; font-size: 16px; padding: 0 28px; }
.btn[disabled] { opacity: .6; pointer-events: none; }

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--lapis) 22%, transparent);
  border-top-color: var(--lapis);
  animation: spin .8s linear infinite; display: inline-block;
}
.btn .spinner { width: 18px; height: 18px; border-width: 2.5px; border-color: rgb(255 255 255 / .35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ header & footer ============ */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 68px; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); }
.brand:hover { color: var(--ink); }
.brand span { display: flex; flex-direction: column; line-height: 1.3; }
.brand strong { font-family: var(--font-display); font-size: 27px; font-weight: 700; letter-spacing: -.2px; }
.brand small { font-size: 12px; color: var(--muted); }
.header-nav { display: flex; gap: 6px; }
.header-nav a { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 10px; color: var(--ink-2); font-weight: 500; font-size: 15px; }
.header-nav a:hover { background: var(--surface); color: var(--lapis); }

.site-footer { border-top: 1px solid var(--line); background: var(--bg-deep); margin-top: 72px; }
.footer-inner { display: flex; align-items: center; gap: 24px; padding: 28px 0; font-size: 13.5px; color: var(--muted); }
.footer-inner p { flex: 1; }
.footer-brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 21px; color: var(--ink); font-weight: 700; }
.footer-link { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 500; }
@media (max-width: 720px) {
  .brand small { display: none; }
  .footer-inner { flex-direction: column; text-align: center; gap: 12px; }
}

/* ============ hero ============ */
.hero {
  position: relative; overflow: hidden;
  background:
    radial-gradient(1200px 400px at 85% -10%, color-mix(in srgb, var(--gold) 14%, transparent), transparent 70%),
    radial-gradient(800px 400px at 0% 110%, color-mix(in srgb, var(--lapis) 9%, transparent), transparent 70%);
}
.hero::before {
  content: ""; position: absolute; inset: 0; opacity: .5; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23b8893b' stroke-opacity='.16'%3E%3Crect x='22' y='22' width='20' height='20'/%3E%3Crect x='22' y='22' width='20' height='20' transform='rotate(45 32 32)'/%3E%3C/g%3E%3C/svg%3E");
  mask-image: linear-gradient(to bottom, #000, transparent 85%);
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent 85%);
}
.hero-inner { position: relative; display: grid; grid-template-columns: 1.15fr .85fr; align-items: center; gap: 40px; padding: 64px 0 56px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 14px; border-radius: 99px;
  background: var(--gold-soft); color: color-mix(in srgb, var(--gold) 75%, var(--ink));
  font-size: 13.5px; font-weight: 600;
}
.hero h1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(38px, 5.4vw, 66px); line-height: 1.25; margin: 18px 0 16px;
  letter-spacing: -.5px; text-wrap: balance;
}
.hero h1 em { font-style: normal; color: var(--lapis); position: relative; white-space: nowrap; }
.hero h1 em::after {
  content: ""; position: absolute; inset-inline: 2%; bottom: .08em; height: .14em; border-radius: 99px;
  background: color-mix(in srgb, var(--gold) 45%, transparent); z-index: -1;
}
.lead { font-size: 17.5px; color: var(--ink-2); max-width: 560px; line-height: 2; }
.hero-art { width: 100%; max-width: 420px; justify-self: center; filter: drop-shadow(0 18px 30px rgb(40 30 10 / .12)); }
.hero-star { transform-origin: 210px 92px; animation: float 7s ease-in-out infinite; }
@keyframes float { 50% { transform: translate(210px, 84px) rotate(8deg); } }
@media (prefers-reduced-motion: reduce) { .hero-star { animation: none; } }

.search {
  margin-top: 30px; display: flex; align-items: center; gap: 10px;
  max-width: 560px; padding: 7px 7px 7px 7px; padding-inline-start: 18px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 16px;
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--lapis); box-shadow: 0 0 0 4px color-mix(in srgb, var(--lapis) 14%, transparent); }
.search .i { color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 16px; padding: 8px 0; }
.search input::-webkit-search-cancel-button { display: none; }
.search button {
  border: 0; border-radius: 11px; padding: 10px 20px; cursor: pointer;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 15px;
}
.search button:hover { background: var(--lapis); color: #fff; }

@media (max-width: 860px) {
  .hero-inner { grid-template-columns: 1fr; padding: 36px 0 28px; gap: 8px; }
  .hero-art { display: none; }
  .lead { font-size: 16px; }
}

/* ============ shelf ============ */
.shelf { padding-top: 40px; }
.shelf-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.shelf-head h2, .steps h2, .description h2, .toc-preview h2 { font-family: var(--font-display); font-size: 32px; font-weight: 700; }
.clear-filter { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; }

.tag-filter { list-style: none; margin: 0 0 28px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.tag-filter a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 99px; font-size: 14px; font-weight: 500;
  color: var(--ink-2); background: var(--surface); border: 1px solid var(--line);
  transition: all .15s;
}
.tag-filter a span { font-size: 12px; color: var(--muted); }
.tag-filter a:hover { border-color: var(--lapis); color: var(--lapis); }
.tag-filter a.active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.tag-filter a.active span { color: color-mix(in srgb, var(--bg) 70%, transparent); }

.book-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 40px 28px;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
}
@media (max-width: 560px) { .book-grid { grid-template-columns: repeat(2, 1fr); gap: 28px 16px; } }

.book-card { display: flex; flex-direction: column; gap: 14px; color: var(--ink); }
.book-card:hover { color: var(--ink); }
.book-card:hover .book-cover { transform: translateY(-6px) rotate(-.6deg); box-shadow: -4px 8px 12px rgb(30 20 5 / .14), -16px 32px 48px -14px rgb(30 20 5 / .45); }
.book-meta h3 { font-size: 16.5px; font-weight: 700; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-author { font-size: 14px; color: var(--ink-2); }
.book-translator { font-size: 13px; color: var(--muted); }
.book-facts { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* A book cover: the spine of a Persian book is on the right. */
.book-cover {
  position: relative; aspect-ratio: 2 / 3; overflow: hidden;
  border-radius: 10px 4px 4px 10px;
  background: var(--paper-b); box-shadow: var(--shadow-book);
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), box-shadow .35s;
}
.book-cover::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to left, rgb(0 0 0 / .24), rgb(255 255 255 / .16) 2.5%, rgb(0 0 0 / .08) 4.5%, transparent 9%, transparent 94%, rgb(255 255 255 / .08));
}
.cover-img { width: 100%; height: 100%; object-fit: cover; }
.cover-art {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 16% 14%; text-align: center; color: #fbf3df;
  background:
    radial-gradient(circle at 50% 34%, hsl(var(--hue) 40% 38% / .0) 0 30%, transparent 31%),
    linear-gradient(160deg, hsl(var(--hue) 46% 30%), hsl(calc(var(--hue) + 30) 50% 18%));
}
.cover-frame { position: absolute; inset: 7%; border: 1px solid rgb(232 202 140 / .55); border-radius: 3px; }
.cover-frame::before { content: ""; position: absolute; inset: 4px; border: 1px solid rgb(232 202 140 / .25); border-radius: 2px; }
.cover-star { width: 30px; height: 30px; position: relative; margin-bottom: 4px; }
.cover-star::before, .cover-star::after { content: ""; position: absolute; inset: 4px; background: #e2c181; border-radius: 2px; }
.cover-star::after { transform: rotate(45deg); }
.cover-art strong { font-family: var(--font-display); font-size: clamp(18px, 2.2vw, 26px); line-height: 1.35; font-weight: 700; text-wrap: balance; }
.cover-art small { font-size: 12.5px; opacity: .8; }
.book-cover-lg .cover-art strong { font-size: clamp(24px, 3.2vw, 36px); }
.book-cover-lg .cover-art small { font-size: 15px; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 64px 16px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ============ steps ============ */
.steps { margin-top: 72px; }
.steps ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; counter-reset: s; }
.steps li {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  padding: 26px 24px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.steps li .i { color: var(--gold); margin-bottom: 6px; }
.steps li strong { font-size: 17px; }
.steps li span { color: var(--ink-2); font-size: 14.5px; }
.steps li::before {
  counter-increment: s; content: counter(s, persian);
  position: absolute; top: 18px; inset-inline-end: 22px;
  font-family: var(--font-display); font-size: 44px; line-height: 1; color: var(--ink-faint); font-weight: 700;
}
@media (max-width: 760px) { .steps ol { grid-template-columns: 1fr; } }

/* ============ book page ============ */
.book-page { padding-top: 22px; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); margin-bottom: 26px; }
.crumbs span { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-hero { display: grid; grid-template-columns: minmax(220px, 330px) 1fr; gap: 56px; align-items: start; }
.book-cover-lg { position: sticky; top: 96px; }
.book-info { min-width: 0; }
.book-info > h1 { font-family: var(--font-display); font-size: clamp(36px, 4.6vw, 56px); line-height: 1.3; margin: 10px 0 6px; text-wrap: balance; }
.byline { font-size: 17px; color: var(--ink-2); }
.byline strong { color: var(--ink); }
.tags { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags a, .tags span {
  display: inline-block; padding: 2px 12px; border-radius: 99px; font-size: 13px; font-weight: 500;
  background: var(--lapis-soft); color: var(--lapis);
}
.tags a:hover { background: var(--lapis); color: #fff; }
.facts { list-style: none; padding: 0; margin: 22px 0 0; display: flex; flex-wrap: wrap; gap: 10px 22px; color: var(--ink-2); font-size: 14.5px; }
.facts li { display: flex; align-items: center; gap: 7px; }
.facts .i { color: var(--gold); }

.unlock-card {
  margin: 30px 0 8px; padding: 26px; border-radius: 20px;
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line-strong); box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.unlock-card::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 5px;
  background: linear-gradient(var(--gold), color-mix(in srgb, var(--gold) 40%, var(--lapis)));
}
.unlock-head { display: flex; gap: 14px; align-items: flex-start; }
.unlock-head > .i { color: var(--gold); margin-top: 3px; }
.unlock-head h2 { font-size: 19px; }
.unlock-head p { color: var(--ink-2); font-size: 14.5px; margin-top: 4px; }
.unlock-form { display: flex; gap: 10px; margin-top: 20px; }
.unlock-form input {
  flex: 1; min-width: 0; height: 54px; padding: 0 18px;
  border-radius: 13px; border: 1.5px solid var(--line-strong); background: var(--bg);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 21px; letter-spacing: 2.5px; text-align: center;
  transition: border-color .15s, box-shadow .15s;
}
.unlock-form input::placeholder { color: var(--ink-faint); }
.unlock-form input:focus { outline: none; border-color: var(--lapis); box-shadow: 0 0 0 4px color-mix(in srgb, var(--lapis) 14%, transparent); }
.unlock-form .btn { height: 54px; }
.unlock-form.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.form-msg { min-height: 1.6em; margin-top: 10px; font-size: 14px; font-weight: 500; color: var(--danger); }
.form-msg.ok { color: var(--ok); }
.fine-print { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.unlocked .unlock-head > .i { color: var(--ok); }
.unlocked::before { background: linear-gradient(var(--ok), color-mix(in srgb, var(--ok) 50%, var(--lapis))); }
.unlocked .btn { margin-top: 20px; width: 100%; }
.progress { height: 6px; border-radius: 99px; background: var(--line); margin-top: 18px; overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(to left, var(--lapis), var(--gold)); }

.description, .toc-preview { margin-top: 44px; }
.description h2, .toc-preview h2 { font-size: 28px; margin-bottom: 12px; }
.description p { font-size: 16.5px; line-height: 2.1; color: var(--ink-2); text-align: justify; }
.description p + p { margin-top: 12px; }
.toc-preview ol { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.toc-preview li { display: flex; align-items: baseline; gap: 16px; padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 15.5px; }
.toc-num { font-family: var(--font-display); font-size: 20px; color: var(--gold); min-width: 1.6em; font-weight: 700; }

@media (max-width: 820px) {
  .book-hero { grid-template-columns: 1fr; gap: 26px; }
  .book-cover-lg { position: relative; top: 0; width: min(62%, 240px); justify-self: center; }
  .book-info { text-align: start; }
  .unlock-card { padding: 20px; }
  .unlock-form { flex-direction: column; }
  .unlock-form .btn { width: 100%; }
}

/* ============ error page ============ */
.error-page { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; padding: 80px 0 40px; }
.error-page h1 { font-family: var(--font-display); font-size: 40px; }
.error-page p { color: var(--ink-2); max-width: 440px; }
.error-page .btn { margin-top: 12px; }
.error-star { position: relative; width: 120px; height: 120px; display: grid; place-items: center; margin-bottom: 10px; }
.error-star::before, .error-star::after { content: ""; position: absolute; inset: 14px; border: 2px solid var(--gold); border-radius: 8px; }
.error-star::after { transform: rotate(45deg); }
.error-star span { font-family: var(--font-display); font-size: 34px; font-weight: 700; color: var(--lapis); }
