/* Public pages: a printed book (paper, ink, one stamp colour). Loaded after main.css, scoped to body.book.
   One light palette on purpose: no dark mode. Layout and palette follow https://www.danielwhite.uk/.
   Fonts are self-hosted (Google Fonts is unreliable from Iran), SIL OFL: static/fonts/OFL.txt */
@font-face {
  font-family: "IM Fell English"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/IMFellEnglish-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "IM Fell English"; font-style: italic; font-weight: 400; font-display: swap;
  src: url("../fonts/IMFellEnglish-Italic.woff2") format("woff2");
}
@font-face {
  font-family: "IM Fell English SC"; font-weight: 400; font-display: swap;
  src: url("../fonts/IMFellEnglishSC-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Naskh Arabic"; font-weight: 400 700; font-display: swap;
  src: url("../fonts/NotoNaskhArabic-wght.woff2") format("woff2");
}

:root { color-scheme: light; }
body.book {
  --paper: #efe6d2; --print: #f7f1e3; --sheet: #fcf9f1;
  --ink-1: #2b2118; --ink-2: #3d3229; --ink-3: #54483d; --ink-4: #7d7064; --ink-5: #a89b8b;
  --stamp: #8a3b24;
  --hairline: 1px solid color-mix(in oklab, var(--ink-1) 22%, transparent);
  --serif: "IM Fell English", "Noto Naskh Arabic", Georgia, serif;
  --caps: "IM Fell English SC", "IM Fell English", "Noto Naskh Arabic", Georgia, serif;
  --page: 46rem; --measure: 60ch; --plate: 36rem; --gutter: 1rem; --flow: 2.5rem;
  /* main.css tokens, remapped so the shared components (forms, chat, fit result) take the book palette */
  --bg: var(--paper); --card: var(--print); --text: var(--ink-3); --muted: var(--ink-4);
  --line: color-mix(in oklab, var(--ink-1) 22%, transparent); --soft: var(--print);
  --accent: var(--stamp); --accent-2: var(--stamp); --accent-soft: color-mix(in oklab, var(--stamp) 12%, transparent);
  --ok: #3f6b2c; --ok-bg: #e3ebd2; --warn: #8a5a12; --warn-bg: #f1e3bf; --bad: #9b2118; --bad-bg: #f1d7cf;
  --shadow: none; --shadow-lg: 0 6px 20px rgba(60, 40, 20, .14); --radius: 0;
  margin: 0; min-height: 100svh; background: var(--paper); color: var(--ink-3);
  font: 1.1875rem / 1.75 var(--serif); overflow-wrap: break-word;
}
html:has(body.book) { background: #efe6d2; }
body.book::after {
  content: ""; position: fixed; inset: 0; z-index: 10; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .17 0 0 0 0 .13 0 0 0 0 .09 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.book *, .book *::before, .book *::after { scrollbar-width: thin; scrollbar-color: var(--ink-5) transparent; }
.book h1, .book h2, .book h3 { color: var(--ink-1); font-weight: 400; line-height: 1.3; text-wrap: balance; }
.book p { text-wrap: pretty; }
.book a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .18em; }
.book a:hover { color: var(--stamp); }
.book :focus-visible { outline: 1.5px solid var(--ink-1); outline-offset: 3px; }
.book ::selection { background: color-mix(in oklab, var(--stamp) 22%, transparent); }
.book .caps { font-family: var(--caps); letter-spacing: .06em; }
.book .hint { color: var(--ink-4); font-style: italic; }
/* Roman numerals from a number in --n, as in the printed book */
.book .num { counter-reset: n var(--n); }
.book .num::before { content: counter(n, upper-roman); }
/* Page numbers are plain Persian digits; chapter numbers stay Roman */
.book .folio.num::before { content: counter(n, persian); }

/* The sheet: running head, leaf, foot */
.book .running-head, .book .leaf, .book .leaf-foot { width: min(100% - 2 * var(--gutter), var(--page)); margin-inline: auto; }
.book .running-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; padding: 1.25rem 0 .6rem;
  border-bottom: var(--hairline); font-size: .875rem; line-height: 1.3;
}
.book .running-head a { display: inline-block; padding-block: .4rem; margin-block: -.4rem; text-decoration: none; }
.book .running-head > :last-child { justify-self: end; text-align: end; }
.book .leaf { padding-block: clamp(2rem, 6vw, 4rem) 3rem; }
.book .leaf > * + * { margin-top: var(--flow); }
.book .leaf-foot {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline; gap: 1rem; padding-block: 1.5rem 3rem;
  border-top: var(--hairline); font-size: 1rem;
}
.book .leaf-foot > :last-child { justify-self: end; font-style: italic; }
.book .leaf-foot > :first-child { font-style: italic; }
.book .leaf-foot a { display: inline-block; padding-block: .4rem; margin-block: -.4rem; text-decoration: none; }
@media (width < 36rem) {
  .book .leaf-foot { grid-template-columns: 1fr 1fr; }
  .book .leaf-foot .folio { display: none; }
}

/* Title page */
.book .title-page, .book .imprint, .book .begin { text-align: center; }
.book .title-name { font-size: clamp(2.25rem, 1.5rem + 3vw, 3.5rem); line-height: 1.15; letter-spacing: .08em; margin: 0; }
.book .title-or { margin: .5rem 0 0; font-size: 1.5rem; font-style: italic; }
.book .title-being { max-width: 42ch; margin: 1rem auto 0; color: var(--ink-4); display: flex; flex-wrap: wrap; justify-content: center; gap: .25rem 1rem; }
.book .title-being > span { unicode-bidi: isolate; }
.book .plate { max-width: 22rem; margin-inline: auto; }
.book .plate-frame { padding: 10px; border: 1px solid var(--ink-1); }
.book .monogram {
  display: grid; place-items: center; aspect-ratio: 3 / 4; border: 1px solid var(--ink-1);
  font-size: 7rem; font-style: italic; color: var(--ink-1); animation: print-in 1.6s cubic-bezier(.16, 1, .3, 1) both;
  background: repeating-linear-gradient(0deg, transparent 0 5px, color-mix(in oklab, var(--ink-1) 7%, transparent) 5px 6px);
}
.book .plate figcaption { margin-top: .6rem; font-size: 1rem; font-style: italic; text-align: center; }
.book .plate .caps { font-style: normal; }
@keyframes print-in { 0% { clip-path: inset(0 0 100% 0); } }
.book .imprint { font-size: .875rem; }

/* Contents */
.book .contents { max-width: 30rem; margin-inline: auto; }
.book .contents h2 { text-align: center; font-size: 1.25rem; margin: 0 0 1rem; }
.book .contents ol { list-style: none; padding: 0; margin: 0; }
.book .contents a { display: flex; align-items: baseline; gap: .5rem; padding-block: .2rem; text-decoration: none; }
.book .contents .no { min-width: 2.6em; }
.book .contents .dots { flex: 1; min-width: 1rem; border-bottom: 1px dotted var(--ink-4); transform: translateY(-.3em); }
.book .contents .no::after { content: "."; }
.book .begin { font-style: italic; }
.book .specimen-links { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem 1.5rem; font-style: italic; }

/* Chapter opening */
.book .chapter-title { text-align: center; }
.book .kicker { margin: 0 0 .5rem; font-size: .95rem; color: var(--stamp); }
.book .chapter-title h1 { font-size: clamp(2rem, 1.4rem + 2.6vw, 3rem); margin: 0; }
.book .fleuron { margin: 1.25rem 0 0; font-size: .7rem; color: var(--stamp); }
.book .chapter-body { margin-top: var(--flow); }
.book .prose { max-width: var(--measure); margin-inline: auto; }
.book .prose p { margin: 0; white-space: pre-line; }
.book .prose-opening > p:first-child::first-letter {
  float: inline-start; font-size: 3.4em; line-height: 1; margin-inline-end: .1em; color: var(--ink-1);
}
.book .company { display: block; color: var(--ink-4); font-style: italic; font-size: 1rem; }
.book .date { color: var(--ink-4); font-style: italic; font-size: .95rem; white-space: nowrap; direction: ltr; }
.book .date.current { color: var(--stamp); }
.book h2 { font-size: 1.4rem; }

/* Tags read as running text */
.book .tags { display: flex; flex-wrap: wrap; gap: .3rem .8rem; margin-top: 10px; text-align: start; }
.book .tags span {
  background: none; color: var(--ink-4); border-radius: 0; padding: 0; font-size: .85rem; font-style: normal;
  font-family: system-ui, sans-serif; unicode-bidi: isolate; direction: inherit;
}
html[lang="fa"] body.book { --serif: "Noto Naskh Arabic", Georgia, serif; --caps: var(--serif); }
html[lang="fa"] .book .company,
html[lang="fa"] .book .title-or { font-style: normal; }
.book bdi { unicode-bidi: isolate; }

/* Experience */
.book .timeline { list-style: none; margin: 0; padding: 0; }
.book .exp { position: relative; padding-inline-start: 28px; padding-bottom: 28px; }
.book .exp:last-child { padding-bottom: 0; }
.book .exp::before { content: ""; position: absolute; inset-inline-start: 5px; top: 14px; bottom: -14px; width: 1px; background: var(--ink-5); }
.book .exp:last-child::before { display: none; }
.book .exp::after {
  content: ""; position: absolute; inset-inline-start: 0; top: 10px; width: 11px; height: 11px;
  transform: rotate(45deg); border: 1px solid var(--stamp); background: var(--paper);
}
.book .exp-head { display: flex; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; align-items: baseline; }
.book .exp-head b { font-size: 1.25rem; font-weight: 400; color: var(--ink-1); }
.book .exp ul, .book .proj ul { margin: 8px 0 0; padding-inline-start: 18px; }
.book .exp li::marker, .book .proj li::marker { color: var(--stamp); }

/* Skills */
.book .skill-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.book .skill-group { border: var(--hairline); padding: 14px 18px; background: var(--print); }
.book .skill-group b { font-weight: 400; color: var(--ink-1); font-size: 1.1rem; }

/* Projects */
.book .personalize { border: var(--hairline); padding: 16px 18px; margin-bottom: 20px; background: var(--print); }
.book .personalize .hint { margin: 0 0 8px; }
.book .projects { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.book .proj {
  display: flex; flex-direction: column; border: var(--hairline); padding: 18px; background: var(--print);
  transition: border-color .25s, box-shadow .25s, transform .25s;
}
.book .proj:hover { transform: translateY(-3px); border-color: var(--ink-1); box-shadow: var(--shadow-lg); }
.book .proj.top { border-color: var(--stamp); box-shadow: inset 0 0 0 1px var(--stamp); }
.book .proj-head b { font-size: 1.25rem; font-weight: 400; color: var(--ink-1); }
.book .proj p { margin: 8px 0 0; }
.book .proj-thumb { margin: -18px -18px 14px; border-radius: 0; border-bottom: var(--hairline); background: var(--paper); }
.book .proj-thumb img { filter: grayscale(.85) sepia(.3) contrast(1.05); transition: filter .4s, transform .6s; }
.book .proj:hover .proj-thumb img { filter: none; transform: scale(1.03); }
.book .status { background: none; border: 1px solid var(--ok); color: var(--ok); border-radius: 0; font-style: italic; }
.book .proj summary { color: var(--stamp); font-style: italic; }
.book .proj-links a { border-radius: 0; border: var(--hairline); text-decoration: none; }
.book .proj-links a:hover { border-color: var(--stamp); }
.book .role-note { font-style: italic; color: var(--stamp); }
.book .role-note.muted { color: var(--ink-4); }

/* Education and languages */
.book .split { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 32px; }
.book .edu { margin-bottom: 12px; }
.book .edu b { display: block; font-weight: 400; color: var(--ink-1); }
.book .langs li { display: flex; flex-direction: column; padding: 6px 0; border-bottom: 1px dotted var(--ink-5); }
.book .langs li:last-child { border: 0; }
.book .langs span { color: var(--ink-4); font-style: italic; }

/* Buttons and forms */
.book button, .book .btn {
  border-radius: 0; background: var(--ink-1); color: var(--sheet); font-weight: 400; letter-spacing: .03em;
  padding: 7px 22px; transition: background .2s, color .2s, border-color .2s;
}
.book button:hover, .book .btn:hover { background: var(--stamp); color: var(--sheet); transform: none; box-shadow: none; text-decoration: none; }
.book button.ghost { background: none; color: var(--ink-1); border: 1px solid var(--ink-1); }
.book button.ghost:hover { background: var(--ink-1); color: var(--sheet); }
.book .pill { background: none; color: var(--ink-3); border: var(--hairline); border-radius: 99px; }
.book .pill:hover { background: none; color: var(--stamp); border-color: var(--stamp); }
.book .pill.on { background: var(--ink-1); color: var(--sheet); border-color: var(--ink-1); }
.book textarea, .book input, .book select {
  background: var(--sheet); color: var(--ink-1); border: var(--hairline); border-radius: 0; font-size: 1.05rem;
}
.book textarea:focus, .book input:focus, .book select:focus { outline: none; border-color: var(--ink-1); box-shadow: 0 0 0 3px var(--accent-soft); }
.book textarea::placeholder, .book input::placeholder { color: var(--ink-5); }

/* Ask and fit */
.book .ai > .hint { margin-top: 0; }
.book .msg { border-radius: 0; }
.book .msg.me { background: var(--ink-1); color: var(--sheet); }
.book .msg.bot { background: var(--print); border: var(--hairline); }
.book .fit-overall b { border-radius: 0; }
.book .reqs li { border-radius: 0; border: var(--hairline); background: var(--print); }
.book .reqs .mark { border-radius: 0; }

.book .quote { text-align: center; margin-inline: auto; max-width: var(--measure); padding: 0; color: var(--ink-4); }
.book .quote p { font-size: 1.5rem; line-height: 1.6; font-style: italic; color: var(--ink-2); margin: 0; }
.book .quote footer { margin-top: .5rem; font-style: italic; }

/* Arrows point toward the start (prev) or the end (next) of the line, so they flip with the page direction */
/* ‹ and › are mirrored by the bidi algorithm inside right-to-left text, so isolate them as left-to-right */
.book .arrow { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.book .arrow::before { content: "‹"; }
.book .arrow.next::before { content: "›"; }
[dir="rtl"] .book .arrow::before { content: "›"; }
[dir="rtl"] .book .arrow.next::before { content: "‹"; }
.book .arrow.prev { margin-inline-end: .3em; }
.book .arrow.next { margin-inline-start: .3em; }

/* Turning the page */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: turn-out .26s cubic-bezier(.23, 1, .32, 1) both; }
::view-transition-new(root) { animation: turn-in .38s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes turn-out { to { opacity: 0; transform: translateX(var(--turn, 2%)); } }
@keyframes turn-in { 0% { opacity: 0; transform: translateX(calc(var(--turn, 2%) * -1)); } }
[dir="rtl"] { --turn: -2%; }

@media print {
  .book .personalize, .book .ai, .book .running-head, .book .leaf-foot, .book::after { display: none; }
  body.book { background: #fff; }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* base.html wraps every page in <main class="wrap">; the book sets its own measure */
.book .wrap { max-width: none; padding: 0; }

/* Panel: the same sheet of paper, with working furniture */
.book section {
  background: var(--print); border: var(--hairline); border-radius: 0; box-shadow: none; padding: 28px; margin-top: 28px;
}
.book section h2 { margin: 0 0 18px; }
.book h2 .icon { display: none; }
.book .row.between h2 { margin: 0; }
.book .flash { border-radius: 0; border-inline-start: 3px solid var(--ok); background: var(--ok-bg); font-style: italic; }
.book .flash.error { border-inline-start-color: var(--bad); }
.book .warn-note { border-radius: 0; border-inline-start: 3px solid var(--warn); }
.book .stat {
  background: var(--sheet); border: var(--hairline); border-radius: 0; color: var(--ink-3); text-decoration: none;
  transition: border-color .2s, transform .2s, box-shadow .2s;
}
.book .stat:hover { border-color: var(--ink-1); transform: translateY(-2px); box-shadow: var(--shadow-lg); color: var(--ink-3); }
.book .stat b { font-weight: 400; color: var(--ink-1); font-size: 1.8rem; }
.book .stat.name b { font-size: 1.25rem; }
.book .stat small { color: var(--ink-4); font-style: italic; font-size: 1rem; }
.book .items td, .book .items th { border-bottom: var(--hairline); }
.book .items tr:hover td { background: color-mix(in srgb, var(--paper) 70%, transparent); }
.book .items .actions a { text-decoration: none; font-style: italic; }
.book a.danger, .book button.link.danger { color: var(--bad); }
.book button.danger { background: var(--bad); }
.book button.danger:hover { background: var(--ink-1); }
.book button.link { background: none; color: var(--stamp); padding: 0; font-style: italic; letter-spacing: 0; }
.book button.link:hover { background: none; color: var(--ink-1); text-decoration: underline; }
.book .btn.ghost { background: none; color: var(--ink-1); border: 1px solid var(--ink-1); }
.book .btn.ghost:hover { background: var(--ink-1); color: var(--sheet); }
.book .panel-form label { font-weight: 400; font-style: italic; color: var(--ink-2); }
.book .panel-form fieldset { border: var(--hairline); border-radius: 0; background: var(--sheet); }
.book .panel-form legend { font-weight: 400; font-style: italic; }
.book .panel-form .helptext { color: var(--ink-4); font-style: italic; }
.book .panel-form input[type=checkbox] { accent-color: var(--stamp); }
.book .errorlist { color: var(--bad); font-style: italic; }
.book details { border-bottom: var(--hairline); }
.book pre { background: var(--sheet); border: var(--hairline); border-radius: 0; }
.book .gallery-admin img { border-radius: 0; border: var(--hairline); }
.book .grade { border-radius: 0; font-weight: 400; font-style: italic; }
.book .review th { font-style: italic; }
.book .auth-box { width: min(100% - 2 * var(--gutter), 30rem); margin: 4rem auto; text-align: center; }
.book .auth-box h2 { text-align: center; }

/* Panel: a ledger. The page is one sheet of paper, the menu is a column of index tabs along its edge
   (like a dictionary's thumb index); the open tab is part of the sheet. Narrow screens get a scrolling strip. */
.book .panel-leaf { width: min(100% - 2 * var(--gutter), 66rem); margin: 0 auto; padding: 2rem 0 4rem; }
.book .panel-nav .spacer, .book .panel-nav::before, .book .panel-nav .icon { display: none; }
.book .panel-nav form { display: block; }
.book .panel-main > :first-child { margin-top: 0; }
.book .panel-main { min-width: 0; }
.book .panel-main section { background: none; border: 0; box-shadow: none; padding: 0; margin-top: 0; }
.book .panel-main section + section { margin-top: 2.2rem; padding-top: 2.2rem; border-top: var(--hairline); }
.book .panel-main .flash { margin: 0 0 1.4rem; }
.book .panel-nav a, .book .panel-nav button.link {
  font-family: var(--serif); font-size: 1.05rem; text-decoration: none; cursor: pointer;
}
.book .panel-nav > :nth-child(1) { --glaze: #8a3b24; }
.book .panel-nav > :nth-child(2) { --glaze: #2f6b6b; }
.book .panel-nav > :nth-child(3) { --glaze: #b0822b; }
.book .panel-nav > :nth-child(4) { --glaze: #3a4f7a; }
.book .panel-nav > :nth-child(5) { --glaze: #5f6b2f; }
.book .panel-nav > :nth-child(6) { --glaze: #6b3a5a; }
.book .panel-nav > :nth-child(7) { --glaze: #2f6b6b; }
.book .panel-nav > :nth-child(8) { --glaze: #b0822b; }
.book .panel-nav > :nth-child(9) { --glaze: #3a4f7a; }
.book .panel-nav > :nth-child(10) { --glaze: #5f6b2f; }

@media (width >= 64rem) {
  .book .panel-leaf { display: grid; grid-template-columns: 10.5rem minmax(0, 1fr); align-items: start; }
  .book .panel-main {
    position: relative; z-index: 1; min-height: 30rem; padding: 2.4rem 2.6rem; background: var(--print); border: var(--hairline);
    /* a few leaves of paper showing under the page */
    box-shadow: -3px 3px 0 -1px var(--print), -3px 3px 0 0 var(--line), -6px 6px 0 -1px var(--print), -6px 6px 0 0 var(--line);
  }
  .book .panel-nav {
    position: sticky; top: 2.2rem; z-index: 2; display: flex; flex-direction: column; gap: .4rem; padding: 0;
    border: 0; background: none; box-shadow: none;
  }
  .book .panel-nav > a {
    position: relative; display: flex; align-items: center; margin-inline-end: -1px; padding: .55rem 1rem .55rem .8rem;
    color: var(--ink-3); background: color-mix(in oklab, var(--ink-1) 7%, var(--paper));
    border: 1px solid var(--line); border-inline-end-color: transparent;
    border-radius: .7rem 0 0 .7rem; transition: background .2s, color .2s, padding .2s;
  }
  [dir="rtl"] .book .panel-nav > a { border-radius: 0 .7rem .7rem 0; }
  .book .panel-nav > a:hover { background: color-mix(in oklab, var(--ink-1) 3%, var(--paper)); color: var(--stamp); padding-inline-start: 1rem; }
  /* the open tab is the same paper as the page and covers its edge */
  .book .panel-nav > a.active {
    z-index: 3; background: var(--print); color: var(--stamp); padding-inline-start: 1.15rem; border-inline-end-color: var(--print);
    border-color: var(--ink-1); border-inline-end-color: var(--print);
  }
  .book .panel-nav > a.active::after { content: "◆"; position: absolute; inset-inline-end: .55rem; font-size: .5rem; color: var(--stamp); }
  /* tools sit apart from the resume sections; the site link and logout are quiet text under the tabs */
  .book .panel-nav > :nth-child(8) { margin-top: 1.1rem; }
  .book .panel-nav > :nth-child(12), .book .panel-nav > form {
    margin: 0; padding: 0 .3rem; background: none; border: 0; border-radius: 0; font-style: italic; color: var(--ink-4); width: auto;
  }
  .book .panel-nav > :nth-child(12) { margin-top: 1.4rem; }
  .book .panel-nav > :nth-child(12):hover, .book .panel-nav > form button.link:hover { background: none; color: var(--stamp); padding-inline-start: .3rem; }
  .book .panel-nav > form button.link { background: none; color: var(--ink-4); padding: .3rem .3rem; width: auto; font-size: 1.05rem; }
}
@media (width < 64rem) {
  .book .panel-main { padding: 1.5rem 1.4rem 2rem; background: var(--print); border: var(--hairline); }
  .book .panel-nav {
    position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: nowrap; align-items: stretch; border-radius: 0; box-shadow: none; gap: 0; margin-inline: calc(var(--gutter) * -1);
    padding: 0 var(--gutter); overflow-x: auto; scrollbar-width: none; white-space: nowrap;
    background: var(--paper); border: 0; border-bottom: var(--hairline); margin-bottom: 1.5rem;
  }
  .book .panel-nav::-webkit-scrollbar { display: none; }
  .book .panel-leaf { padding-top: 0; }
  .book .panel-nav a, .book .panel-nav button.link {
    display: flex; align-items: center; flex: none; padding: .8rem .85rem; background: none; border: 0; border-radius: 0;
    border-bottom: 2px solid transparent; color: var(--ink-3); box-shadow: none; width: auto;
  }
  .book .panel-nav a::before {
    content: ""; width: .4rem; height: .4rem; margin-inline-end: .55rem; transform: rotate(45deg); background: var(--ink-5);
  }
  .book .panel-nav a:hover, .book .panel-nav button.link:hover { background: none; color: var(--stamp); }
  .book .panel-nav a.active { color: var(--stamp); border-bottom-color: var(--stamp); }
  .book .panel-nav a.active::before { background: var(--stamp); }
  .book .panel-nav form { display: flex; }
  .book .panel-nav button.link { color: var(--ink-4); font-style: italic; }
}
@media (width < 40rem) {
  .book section { padding: 18px 16px; margin-top: 18px; }
  .book .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .book .row.between { flex-wrap: wrap; gap: .6rem; }
  .book .items .actions a { display: inline-block; margin-top: .25rem; }
  .book .inline-form input { min-width: 0; flex-basis: 100%; }
  .book .auth-box { margin-block: 2rem; }
}

/* Glaze on the dashboard tiles too */
.book .stat { border-top: 3px solid var(--glaze, var(--stamp)); }
.book .stats > :nth-child(6n+1) { --glaze: #8a3b24; } .book .stats > :nth-child(6n+2) { --glaze: #2f6b6b; }
.book .stats > :nth-child(6n+3) { --glaze: #b0822b; } .book .stats > :nth-child(6n+4) { --glaze: #3a4f7a; }
.book .stats > :nth-child(6n+5) { --glaze: #5f6b2f; } .book .stats > :nth-child(6n) { --glaze: #6b3a5a; }
.book .stat:hover { border-color: var(--glaze, var(--ink-1)); border-top-color: var(--glaze, var(--ink-1)); }

/* Panel: finishing touches so the ledger reads like the rest of the book */
.book .panel-main h2 { font-size: clamp(1.7rem, 1.3rem + 1.4vw, 2.2rem); margin-bottom: 1.4rem; }
.book .panel-main h2::after { content: "◆"; display: block; margin-top: .35rem; font-size: .55rem; color: var(--stamp); }
.book .panel-main .row.between { align-items: flex-start; }
.book .panel-main .hint { margin-top: 0; }
.book .panel-main .stats { gap: 14px; margin-top: 1.2rem; }
.book .panel-main .stat {
  position: relative; background: var(--sheet); border: var(--hairline); border-top: 2px solid var(--glaze, var(--stamp));
  padding: 16px 18px; text-align: start;
}
.book .panel-main .stat b { font-size: 2.1rem; line-height: 1.2; }
.book .panel-main .stat.name b { font-size: 1.35rem; line-height: 1.5; padding-top: .35rem; }
.book .panel-main .stat small { display: block; margin-top: .2rem; font-family: var(--caps); font-style: normal; letter-spacing: .04em; }
.book .items { counter-reset: row; }
.book .items tr { counter-increment: row; }
.book .items td:first-child::before { content: counter(row, persian) "."; display: inline-block; min-width: 2.2em; color: var(--ink-5); font-family: var(--caps); }
.book .items td { padding-block: .8rem; border-bottom-style: dotted; border-bottom-color: var(--ink-5); }
.book .items td:first-child a { text-decoration: none; color: var(--ink-1); font-size: 1.1rem; }
.book .items td:first-child a:hover { color: var(--stamp); }
.book .panel-main label { color: var(--ink-2); }
.book .panel-main input, .book .panel-main textarea, .book .panel-main select { background: var(--sheet); }
.book .panel-main .hint, .book .panel-main .helptext { font-size: 1rem; }

@media (width >= 64rem) {
  /* a printed inner frame, like the plates on the title page */
  .book .panel-main::before {
    content: ""; position: absolute; inset: .55rem; border: 1px solid color-mix(in oklab, var(--ink-1) 16%, transparent); pointer-events: none;
  }
  .book .panel-nav { counter-reset: tab; gap: .5rem; }
  .book .panel-nav > a { padding-block: .7rem; box-shadow: -1px 2px 0 color-mix(in oklab, var(--ink-1) 8%, transparent); }
  [dir="rtl"] .book .panel-nav > a { box-shadow: 1px 2px 0 color-mix(in oklab, var(--ink-1) 8%, transparent); }
  .book .panel-nav > a:not(:nth-child(12))::before {
    counter-increment: tab; content: counter(tab, upper-roman); min-width: 1.9rem; margin-inline-end: .35rem;
    font-family: var(--caps); font-size: .85rem; letter-spacing: .06em; color: var(--ink-5); transition: color .2s;
  }
  .book .panel-nav > a:hover::before, .book .panel-nav > a.active::before { color: var(--stamp); }
  .book .panel-nav > a.active { box-shadow: none; }
}

@media (width < 64rem) {
  .book .panel-nav a, .book .panel-nav button.link { font-size: 1rem; }
  .book .panel-nav { padding-block: 0; }
  .book .panel-main h2 { margin-bottom: 1rem; }
}
@media (width < 40rem) {
  .book .panel-main { padding: 1.2rem 1rem 1.6rem; margin-inline: calc(var(--gutter) * -.5); }
  .book .panel-main h2 { font-size: 1.6rem; }
  .book .panel-main .stat b { font-size: 1.7rem; }
  .book .panel-main .stat.name b { font-size: 1.15rem; }
  .book .items td:first-child::before { min-width: 1.6em; }
  .book .panel-main .row.between .btn { padding: 6px 14px; }
}

/* Panel tables on phones and small tablets: each row becomes a short card instead of squeezed columns */
@media (width < 48rem) {
  .book .items:not(.review), .book .items:not(.review) tbody, .book .items:not(.review) tr, .book .items:not(.review) td { display: block; }
  .book .items:not(.review) tr { padding: .85rem 0; border-bottom: 1px dotted var(--ink-5); }
  .book .items:not(.review) tr:last-child { border-bottom: 0; }
  .book .items:not(.review) td { padding: 0; border: 0; background: none !important; }
  .book .items:not(.review) td:first-child { overflow-wrap: anywhere; }
  .book .items:not(.review) td:first-child::before { float: inline-start; min-width: 2em; }
  .book .items:not(.review) td:first-child { padding-inline-start: 0; }
  .book .items:not(.review) td:not(:first-child) {
    display: inline-block; margin-top: .3rem; margin-inline-end: 1.1rem; padding-inline-start: 0; font-size: .95rem;
  }
  .book .items:not(.review) td:nth-child(2):not(.actions) { margin-inline-start: 2em; }
  .book .items:not(.review) td.actions { display: block; margin: .45rem 0 0; padding-inline-start: 2em; text-align: start; }
  .book .items:not(.review) td.actions a { margin-inline: 0 1.2rem; }
  .book .items:not(.review) td.nowrap { white-space: normal; }
  /* the review grid keeps its columns and scrolls sideways */
  .book .items.review { display: block; overflow-x: auto; }
  .book .items.review td:first-child { min-width: 13rem; }
  .book .panel-main details summary { overflow-wrap: anywhere; }
  .book .panel-main pre { font-size: .85rem; overflow-x: auto; }
  .book .panel-main .row.between { align-items: center; }
}

/* Top strip: language on the left, music on the right, on every page and in either direction */
.book .topbar {
  display: flex; justify-content: center; align-items: center; flex-wrap: wrap; column-gap: 1.6rem; direction: ltr;
  width: min(100% - 2 * var(--gutter), var(--page)); margin-inline: auto; padding-block: .8rem 0;
  font-size: .875rem; line-height: 1.3; view-transition-name: topbar;
}
.book .langswitch { display: flex; align-items: center; }
.book .langswitch > * + *::before { content: "·"; margin-inline: .55rem; color: var(--ink-5); }
.book .langswitch a, .book .langswitch span { display: inline-block; padding-block: .45rem; text-decoration: none; }
.book .langswitch .on { color: var(--stamp); border-bottom: 1px solid var(--stamp); }
.book .langswitch [lang="fa"] { font-family: "Noto Naskh Arabic", var(--serif); font-size: 1rem; }

/* The music box: plain words, a click plays, another click stops */
.book .player .play {
  padding: .45rem .2rem; border: 0; border-bottom: 1px solid transparent; border-radius: 0; background: none;
  font: inherit; color: var(--ink-3); cursor: pointer; transition: color .15s, border-color .15s;
}
.book .player .play:hover { color: var(--stamp); }
.book .player.playing .play { color: var(--stamp); border-bottom-color: var(--stamp); }

/* Your portrait in the frame: printed like a halftone plate, grey ink on the paper (the file itself is untouched) */
.book .portrait-box { position: relative; border: 1px solid var(--ink-1); background: var(--paper); isolation: isolate; }
.book .portrait {
  display: block; inline-size: 100%; block-size: auto; aspect-ratio: 3 / 4; object-fit: cover;
  filter: grayscale(1) contrast(1.35) brightness(1.05); mix-blend-mode: multiply;
  animation: print-in 1.6s cubic-bezier(.16, 1, .3, 1) both;
}
/* fine screen of lines and dots in paper colour over the picture, which breaks it into printed grain */
.book .portrait-box::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    repeating-linear-gradient(0deg, var(--paper) 0 1px, transparent 1px 3px),
    radial-gradient(circle at 1px 1px, var(--paper) .7px, transparent 1px) 0 0 / 3px 3px;
  opacity: .55;
}

/* English reads left to right: plain digits for page numbers, and Arabic script must not be letter-spaced */
html[lang="en"] .book .folio.num::before { content: counter(n); }
html[lang="fa"] .book .caps, html[lang="fa"] .book .title-name { letter-spacing: 0; }
@media print { .book .topbar { display: none; } }

/* Keep comma separators attached to their skill, including in RTL pages. */
.book .tags span:not(:last-child)::after { content: ","; }
