/* بیت‌یاب — the whole site is one old Persian verse book.
   Light on purpose: cream paper, brown ink, gold and lapis only as decoration. */

@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/Vazirmatn-wght.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Nastaliq';
  src: url('../fonts/NotoNastaliqUrdu-arabic.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --desk: #efe4cb;
  --paper: #f5ead0;
  --paper-edge: #e6d3a6;
  --ink: #37210f;
  --ink-soft: #6a4b2f;
  --gold: #b8892b;
  --gold-light: #d9b65a;
  --lapis: #1f3f7a;
  --lapis-deep: #17305f;
  --rose: #a2412c;
  --leather: #cdab7c;
  --leather-dark: #a9834f;

  --ui: 'Vazirmatn', 'Vazir', Tahoma, sans-serif;
  --verse: 'Nastaliq', 'Vazirmatn', serif;

  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .42 0 0 0 0 .28 0 0 0 0 .12 0 0 0 .16 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
  --band: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'%3E%3Crect width='30' height='30' fill='%231f3f7a'/%3E%3Crect x='.5' y='.5' width='29' height='29' fill='none' stroke='%23d9b65a'/%3E%3Crect x='9.5' y='9.5' width='11' height='11' fill='none' stroke='%23d9b65a'/%3E%3Cg fill='%23d9b65a'%3E%3Cpath d='M15 2.6 17.2 5 15 7.4 12.8 5Z'/%3E%3Cpath d='M15 22.6 17.2 25 15 27.4 12.8 25Z'/%3E%3Cpath d='M5 12.6 7.4 15 5 17.4 2.6 15Z'/%3E%3Cpath d='M25 12.6 27.4 15 25 17.4 22.6 15Z'/%3E%3Ccircle cx='5' cy='5' r='2'/%3E%3Ccircle cx='25' cy='5' r='2'/%3E%3Ccircle cx='5' cy='25' r='2'/%3E%3Ccircle cx='25' cy='25' r='2'/%3E%3C/g%3E%3C/svg%3E");
}

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; overflow: hidden; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--desk);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.9;
  direction: rtl;
  text-align: right;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
bdi, [dir='ltr'] { unicode-bidi: isolate; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--lapis); text-underline-offset: 3px; }
svg.defs { position: absolute; }

:focus-visible { outline: 2px solid var(--lapis); outline-offset: 3px; border-radius: 4px; }

/* ---------- the desk ---------- */

.desk {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px calc(6px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 90% at 50% 40%, #f6edd8 0%, var(--desk) 60%, #e7d9b9 100%);
  perspective: 2200px;
  perspective-origin: 50% 20%;
  /* the open book is wider than a phone screen; nothing may widen the page */
  overflow: hidden;
  width: 100%;
}

.tools {
  display: flex;
  gap: 6px;
  width: min(100%, 480px);
  justify-content: flex-end; /* left side in a right-to-left page */
  opacity: 0;
  visibility: hidden;
  transition: opacity .5s ease, visibility .5s;
}
.book-open .tools { opacity: 1; visibility: visible; }
.tool {
  position: relative;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(184, 137, 43, .55);
  border-radius: 50%;
  background: rgba(245, 234, 208, .8);
  color: var(--ink-soft);
  transition: background .2s, color .2s;
}
.tool svg { width: 22px; height: 22px; }
.tool:hover, .tool[aria-pressed='true'] { background: var(--lapis); color: #f6ecd2; border-color: var(--lapis); }
.tool__count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--rose);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.credit {
  margin: 0;
  max-width: 44rem;
  font-size: .72rem;
  line-height: 1.6;
  color: var(--ink-soft);
  text-align: center;
  opacity: .85;
}

/* ---------- the book ---------- */

.book {
  position: relative;
  flex: 1 1 auto;
  width: min(100%, 480px);
  min-height: 0;
  max-height: 860px;
  margin: 6px 14px 34px 18px; /* room for the page edges and the boards */
  width: min(calc(100% - 32px), 460px);
  transform-style: preserve-3d;
  /* --shift slides the closed book to the middle; --zoom is used on phones */
  --shift: 0%;
  --zoom: 1;
  transform: translateX(var(--shift)) rotateX(7deg);
  transform-origin: 50% 70%;
}
/* Closed, only the right half of the book exists (under the cover), so the
   whole book sits a quarter to the right to be in the middle of the desk. */
.book[data-state='closed'] { --shift: 25%; --zoom: var(--zc, 1); }

.spread {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  visibility: hidden;
  border-radius: 6px;
  transform-style: preserve-3d;
}

/* Stacked sheets: every pair of lines is one more sheet under the page. */
:root {
  --sheets-left:
    -1px 1px 0 #cbb584, -2px 2px 0 #f3e8cb, -3px 3px 0 #cbb584, -4px 4px 0 #f3e8cb,
    -5px 5px 0 #c6af7c, -6px 6px 0 #f1e5c6, -7px 7px 0 #c6af7c, -8px 8px 0 #f1e5c6,
    -9px 9px 0 #bfa772, -10px 10px 0 #efe2c0, -11px 11px 0 #bfa772, -12px 12px 0 #ecdeb9,
    -13px 13px 0 #b59c66;
  --sheets-right:
    1px 1px 0 #cbb584, 2px 2px 0 #f3e8cb, 3px 3px 0 #cbb584, 4px 4px 0 #f3e8cb,
    5px 5px 0 #c6af7c, 6px 6px 0 #f1e5c6, 7px 7px 0 #c6af7c, 8px 8px 0 #f1e5c6,
    9px 9px 0 #bfa772, 10px 10px 0 #efe2c0, 11px 11px 0 #bfa772, 12px 12px 0 #ecdeb9,
    13px 13px 0 #b59c66;
  --paper-inset: inset 0 0 70px rgba(150, 105, 45, .28), inset 0 0 6px rgba(120, 80, 30, .35);
}

/* leather boards: a little larger than the pages, lying under them */
.boards {
  position: absolute;
  inset: -9px -12px -24px -20px;
  border-radius: 10px;
  background:
    var(--noise),
    linear-gradient(90deg, var(--leather-dark), var(--leather) 12%, var(--leather) 88%, var(--leather-dark));
  box-shadow:
    inset 0 0 0 1px rgba(255, 240, 205, .35),
    inset 0 0 30px rgba(110, 75, 30, .5),
    0 4px 0 #8c6a3c,
    0 34px 50px -22px rgba(60, 40, 10, .7),
    0 8px 14px rgba(60, 40, 10, .3);
  transform: translateZ(-6px);
  /* --k = 1 shows only the left half (while the cover is still over there) */
  --k: 0;
  clip-path: inset(-110px calc(var(--k) * 50% - (1 - var(--k)) * 110px) -110px -110px);
}

.book[data-state='open'] .spread,
.book[data-state='opening'] .spread { visibility: visible; }
/* While the book opens, the right page is not there yet: the cover and the
   loose pages bring it over. */
.book[data-state='opening'] #page-main { visibility: hidden; }

.page {
  position: relative;
  overflow: hidden;
  min-height: 0;
  border-radius: 6px;
  background:
    var(--noise),
    radial-gradient(60% 35% at 18% 12%, rgba(176, 132, 62, .12), transparent 70%),
    radial-gradient(45% 30% at 86% 88%, rgba(160, 110, 50, .14), transparent 70%),
    linear-gradient(180deg, #f7edd6, var(--paper) 40%, #f1e3c2);
  box-shadow: var(--paper-inset), var(--sheets-left);
}
/* a soft dip towards the spine, so the page looks bent and not flat */
.page::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(270deg, rgba(60, 35, 10, .28), rgba(90, 60, 20, .08) 7%, transparent 16%, transparent 90%, rgba(255, 252, 240, .35));
}

.page__frame {
  position: absolute;
  inset: 10px;
  border: 9px solid var(--lapis);
  border-image: var(--band) 10 round;
  pointer-events: none;
}
.page__frame::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid var(--gold);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px rgba(184, 137, 43, .6);
}

.page__corner {
  position: absolute;
  width: 84px;
  height: 84px;
  pointer-events: none;
  opacity: .32;
}
.page__corner--a { left: 26px; bottom: 26px; }
.page__corner--b { right: 26px; top: 26px; transform: rotate(180deg); }

.page__body {
  position: absolute;
  inset: 24px;
  padding: 16px 8px 10px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(184, 137, 43, .5) transparent;
}

.spine { display: none; }

/* ---------- the cover ---------- */

.cover {
  --thick: 36px;
  position: absolute;
  inset: 0 auto 0 0;
  width: 50%;
  transform-style: preserve-3d;
  transform-origin: right center;
  z-index: 5;
  will-change: transform;
}
.book[data-state='open'] .cover { display: none; }

.cover__face {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.cover__face--front {
  transform: translateZ(var(--thick));
  transition: box-shadow .45s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 44px 30px 34px;
  background:
    var(--noise),
    radial-gradient(90% 70% at 50% 42%, #d9bb8e 0%, var(--leather) 55%, var(--leather-dark) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 240, 205, .35),
    inset 0 0 60px rgba(110, 75, 30, .45),
    -1px 1px 0 #8c6a3c,
    -2px 2px 0 #f3e8cb, -3px 3px 0 #cbb584, -4px 4px 0 #f3e8cb, -5px 5px 0 #c6af7c,
    -6px 6px 0 #f1e5c6, -7px 7px 0 #c6af7c, -8px 8px 0 #f1e5c6, -9px 9px 0 #bfa772,
    -10px 10px 0 #efe2c0, -11px 11px 0 #bfa772, -12px 12px 0 #efe2c0, -13px 13px 0 #bfa772,
    -14px 14px 0 #ecdeb9, -15px 15px 0 #b59c66, -16px 16px 0 #ecdeb9, -17px 17px 0 #b59c66,
    -18px 18px 0 #a9834f, -20px 20px 0 #8c6a3c,
    -24px 46px 50px -18px rgba(60, 40, 10, .7);
}
.cover__face--back {
  /* the last page of the block that lifts with the cover */
  transform: rotateY(180deg) translateZ(-3px);
  background: var(--noise), linear-gradient(180deg, #f7edd6, var(--paper) 40%, #f1e3c2);
  box-shadow: var(--paper-inset);
}
.cover__face--back > .page { position: absolute; inset: 0; border-radius: 0 6px 6px 0; box-shadow: none; }
/* When the block lifts, its drawn sheets fade and the real edges show. */
.book[data-state='opening'] .cover__face--front {
  box-shadow: inset 0 0 0 1px rgba(255, 240, 205, .35), inset 0 0 60px rgba(110, 75, 30, .45);
}
/* The real thickness of the block: the paper edges you see while it turns. */
.cover__edge {
  position: absolute;
  background:
    repeating-linear-gradient(90deg, #f3e8cb 0 1px, #cbb584 1px 2px, #efe2c0 2px 3px, #bfa772 3px 4px);
}
.cover__edge--fore {
  top: 0;
  bottom: 0;
  left: 0;
  width: calc(var(--thick) - 3px);
  transform-origin: left center;
  transform: translateZ(3px) rotateY(-90deg);
  border-right: 3px solid var(--leather-dark);
}
.cover__edge--foot {
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--thick) - 3px);
  transform-origin: center bottom;
  transform: translateZ(3px) rotateX(-90deg);
  background:
    repeating-linear-gradient(0deg, #f3e8cb 0 1px, #cbb584 1px 2px, #efe2c0 2px 3px, #bfa772 3px 4px);
  border-top: 3px solid var(--leather-dark);
}

/* pressed (tooled) frame in the leather */
.cover__frame {
  position: absolute;
  inset: 16px;
  border: 2px solid rgba(120, 82, 36, .55);
  border-radius: 4px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 238, 200, .3),
    0 0 0 1px rgba(255, 238, 200, .25),
    inset 0 0 0 7px rgba(205, 171, 124, 0),
    inset 0 0 0 8px rgba(184, 137, 43, .85),
    inset 0 0 0 9px rgba(120, 82, 36, .4);
  pointer-events: none;
}
.cover__lachak { position: absolute; width: 64px; height: 64px; filter: drop-shadow(0 1px 0 rgba(90, 60, 20, .5)); }
.cover__lachak--1 { top: 30px; left: 30px; }
.cover__lachak--2 { top: 30px; right: 30px; transform: scaleX(-1); }
.cover__lachak--3 { bottom: 30px; left: 30px; transform: scaleY(-1); }
.cover__lachak--4 { bottom: 30px; right: 30px; transform: scale(-1); }

.cover__center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 0;
  text-align: center;
}
.medallion {
  position: relative;
  height: min(46vh, 340px);
  aspect-ratio: 220 / 340;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 2px 1px rgba(90, 60, 20, .55));
}
.medallion__shape { position: absolute; inset: 0; width: 100%; height: 100%; }
.medallion__title {
  position: relative;
  margin: 0;
  padding-bottom: .35em;
  font-family: var(--verse);
  font-weight: 700;
  font-size: clamp(2rem, 9.5vw, 2.9rem);
  line-height: 2.2;
  color: #4a2e10;
  text-shadow: 0 1px 0 rgba(255, 235, 180, .6);
}
.cover__tagline {
  margin: 6px 0 0;
  font-family: var(--verse);
  font-size: 1.3rem;
  line-height: 2.3;
  color: #4a2e10;
}
.cover__poets {
  margin: 0;
  font-size: .82rem;
  letter-spacing: .02em;
  color: #5d3f1c;
}

.cover__foot {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.open-btn {
  min-height: 48px;
  padding: 8px 34px;
  border: 1.5px solid #8a6420;
  border-radius: 999px;
  background: linear-gradient(135deg, #e3c46c, #c0902f 55%, #dcb95a);
  color: #3d2409;
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 2px 0 rgba(90, 60, 20, .5), inset 0 1px 0 rgba(255, 245, 210, .7);
  transition: transform .2s ease, box-shadow .2s ease;
}
.open-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 0 rgba(90, 60, 20, .45), inset 0 1px 0 rgba(255, 245, 210, .7); }
.open-btn:active { filter: brightness(.95); box-shadow: 0 1px 0 rgba(90, 60, 20, .5); }
.cover__load {
  margin: 0;
  min-height: 1.6em;
  font-size: .76rem;
  line-height: 1.6;
  color: #5d3f1c;
  text-align: center;
}

/* gold line that draws itself around the cover while the model loads */
.cover__trace {
  --p: 0;
  position: absolute;
  inset: 9px;
  border: 2px solid #f1d98a;
  border-radius: 6px;
  pointer-events: none;
  filter: drop-shadow(0 0 2px rgba(255, 230, 150, .8));
  -webkit-mask: conic-gradient(from 0deg, #000 calc(var(--p) * 1%), transparent 0);
  mask: conic-gradient(from 0deg, #000 calc(var(--p) * 1%), transparent 0);
}

/* ---------- page turning ---------- */

.leaf {
  position: absolute;
  inset: 0 auto 0 0;
  width: 50%;
  z-index: 4;
  transform-style: preserve-3d;
  transform-origin: right center;
  will-change: transform;
  pointer-events: none;
}
.leaf__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.leaf__face > .page { position: absolute; inset: 0; display: block; }
.leaf__face--back { transform: rotateY(180deg); }
.leaf__shade {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(60, 35, 10, .0), rgba(60, 35, 10, .35));
  opacity: 0;
  pointer-events: none;
}
.leaf--right { inset: 0 0 0 auto; transform-origin: left center; }
.leaf--right .page, .hold:not(.hold--left) .page { border-radius: 0 6px 6px 0; }
.leaf__face > .leaf__shade { background: linear-gradient(90deg, rgba(60, 35, 10, .1), rgba(60, 35, 10, .45)); }
.leaf--loose .leaf__face--front .page { border-radius: 6px 0 0 6px; box-shadow: var(--paper-inset); }
.leaf--loose .leaf__face--back .page { border-radius: 0 6px 6px 0; }
/* shadow that the falling block throws on the desk */
.cast {
  position: absolute;
  inset: -4% -6% -8% 50%;
  /* soft on every side without a blur filter (a blurred layer leaves a
     faint box on the desk in 3D) */
  background: radial-gradient(closest-side at 38% 52%, rgba(50, 30, 8, .5), rgba(50, 30, 8, .22) 55%, transparent);
  opacity: 0;
  transform: translateZ(-5px);
  pointer-events: none;
}
.hold { position: absolute; inset: 0 0 0 auto; width: 50%; z-index: 3; pointer-events: none; }
.hold--left { inset: 0 auto 0 0; }
.hold > .page { position: absolute; inset: 0; display: block; }

/* ---------- page content: shared ---------- */

.head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  text-align: center;
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(184, 137, 43, .55);
  flex: none;
}
.head__poet { font-weight: 800; font-size: 1.02rem; color: var(--rose); line-height: 1.7; }
.head__src { font-size: .78rem; color: var(--ink-soft); line-height: 1.6; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 6px 20px;
  border-radius: 999px;
  border: 1.5px solid var(--gold);
  background: rgba(250, 242, 222, .9);
  color: var(--ink);
  font-weight: 600;
  font-size: .95rem;
  line-height: 1.5;
  transition: background .2s, color .2s, border-color .2s;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:hover { background: rgba(217, 182, 90, .25); }
/* no movement on press: inside the tilted 3D book a button that moves under
   the finger loses the click */
.btn:active { filter: brightness(.93); }
.btn--main { background: var(--lapis); border-color: var(--gold-light); color: #f8efd8; }
.btn--main:hover { background: var(--lapis-deep); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn--icon { width: 46px; padding: 0; }
.btn--on { background: var(--rose); border-color: var(--rose); color: #fff; }

.muted { color: var(--ink-soft); font-size: .84rem; line-height: 1.8; }
.rule {
  height: 12px;
  margin: 10px auto;
  width: 60%;
  flex: none;
  background:
    radial-gradient(circle, var(--gold) 2.4px, transparent 3px) center / 12px 12px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left center / calc(50% - 12px) 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right center / calc(50% - 12px) 1px no-repeat;
}

/* ---------- first page: search ---------- */

.sarlowh {
  position: relative;
  flex: none;
  margin: 12px 2px 14px;
  padding: 8px;
  border-radius: 4px;
  background:
    radial-gradient(circle at 12px 12px, rgba(217, 182, 90, .55) 1.3px, transparent 1.8px) 0 0 / 16px 16px,
    radial-gradient(circle at 4px 4px, rgba(217, 182, 90, .35) 1px, transparent 1.5px) 0 0 / 16px 16px,
    linear-gradient(180deg, #25498c, var(--lapis-deep));
  border: 1px solid var(--gold);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4.5px var(--gold), 0 3px 8px rgba(60, 40, 10, .25);
}
/* thin gold-and-blue rays above the headpiece, as in old manuscripts */
.sarlowh::before {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: calc(100% + 5px);
  height: 12px;
  background:
    repeating-linear-gradient(90deg, var(--lapis) 0 1.5px, transparent 1.5px 9px),
    repeating-linear-gradient(90deg, transparent 0 4.5px, var(--gold) 4.5px 5.5px, transparent 5.5px 9px);
  -webkit-mask: linear-gradient(90deg, transparent, #000 30%, #000 70%, transparent);
  mask: linear-gradient(90deg, transparent, #000 30%, #000 70%, transparent);
}
.sarlowh__plate {
  padding: 2px 10px 6px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fbf3dd, #f1e2bd);
  border: 1.5px solid var(--gold-light);
  box-shadow: inset 0 0 0 2px rgba(184, 137, 43, .35);
  text-align: center;
}
.sarlowh__title {
  margin: 0;
  font-family: var(--verse);
  font-weight: 700;
  font-size: 1.55rem;
  line-height: 2.3;
  color: var(--lapis-deep);
}

.ask { display: flex; flex-direction: column; gap: 8px; flex: none; margin: auto 0; }
.ask__label { font-weight: 700; font-size: 1rem; color: var(--rose); text-align: center; }
.ask__box { position: relative; }
.ask__input {
  display: block;
  width: 100%;
  min-height: 6.9rem;
  padding: .25rem 2px .25rem 46px;
  border: 0;
  border-radius: 0;
  resize: none;
  background:
    repeating-linear-gradient(180deg, transparent 0 calc(2.2rem - 1px), rgba(184, 137, 43, .55) calc(2.2rem - 1px) 2.2rem);
  color: var(--ink);
  font: 500 1.05rem/2.2rem var(--ui);
  direction: rtl;
}
.ask__input::placeholder { color: rgba(106, 75, 47, .7); }
.ask__input:focus { outline: none; background-color: rgba(255, 250, 235, .45); }
.ask__mic { position: absolute; left: 0; bottom: 4px; }
.ask__mic.is-listening { background: var(--rose); border-color: var(--rose); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(162, 65, 44, .18); } }

/* suggestions: one row that scrolls sideways, with a gold bar that shows it */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; flex: none; overscroll-behavior-x: contain; }
.chips::-webkit-scrollbar { height: 7px; }
.chips::-webkit-scrollbar-track { background: rgba(184, 137, 43, .16); border-radius: 4px; }
.chips::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 4px; }
.chips::-webkit-scrollbar-thumb:hover { background: #9c7220; }
@supports not selector(::-webkit-scrollbar) {
  .chips { scrollbar-width: thin; scrollbar-color: var(--gold) rgba(184, 137, 43, .16); }
}
.chip {
  flex: none;
  min-height: 40px;
  padding: 2px 14px;
  border: 1px solid rgba(184, 137, 43, .7);
  border-radius: 999px;
  background: rgba(217, 182, 90, .14);
  color: var(--ink);
  font-size: .86rem;
  white-space: nowrap;
}
.chip:hover { background: rgba(217, 182, 90, .3); }

.ask__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.ask__actions .btn { flex: 1 1 9rem; }
.status { margin: 6px 0 0; text-align: center; min-height: 1.7em; }
.status b { color: var(--lapis); font-weight: 700; }

.how { margin: 0; padding: 0; list-style: none; counter-reset: how; display: grid; gap: 10px; }
.how li { counter-increment: how; display: grid; grid-template-columns: 2.1rem 1fr; gap: 10px; align-items: start; font-size: .92rem; line-height: 1.9; }
.how li::before {
  content: counter(how, persian);
  width: 2.1rem;
  height: 2.1rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--gold);
  color: var(--lapis);
  font-weight: 800;
  background: rgba(217, 182, 90, .16);
}
.side-title { margin: 6px 0 8px; font-size: 1.05rem; font-weight: 800; color: var(--rose); text-align: center; }

/* ---------- verse page ---------- */

.verse {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .2rem;
  min-height: 9rem;
  padding: 6px 2px;
}
.verse p {
  margin: 0;
  font-family: var(--verse);
  font-size: clamp(1.2rem, .7rem + 2.4vw, 2.05rem);
  line-height: 2.6;
  color: var(--ink);
  text-wrap: balance;
}
.verse .m1 { text-align: right; padding-left: 4%; }
.verse .m2 { text-align: left; padding-right: 4%; }
.verse--long p { font-size: clamp(1.02rem, .62rem + 1.8vw, 1.7rem); line-height: 2.5; }

/* the hemistichs appear from right to left, like ink from a pen */
.ink { clip-path: inset(-20% 0 -20% 100%); }
.ink.is-written { clip-path: inset(-20% 0 -20% 0); transition: clip-path 1.25s cubic-bezier(.3, .1, .3, 1); }
.ink.is-written.m2 { transition-delay: .75s; }

.meaning {
  flex: none;
  margin: 2px 0 6px;
  padding: 10px 14px;
  border-right: 3px solid var(--gold);
  background: rgba(217, 182, 90, .13);
  border-radius: 4px;
  font-size: .92rem;
  line-height: 2;
}
.meaning__label { display: block; font-size: .76rem; font-weight: 700; color: var(--rose); }
.meaning[hidden] { display: none; }

.acts { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; flex: none; margin: 4px 0; }
.acts .btn { min-height: 44px; padding: 4px 14px; font-size: .86rem; }

.pager {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid rgba(184, 137, 43, .55);
}
.pager__num { font-size: .86rem; color: var(--ink-soft); font-weight: 600; }
.pager .btn { min-height: 44px; padding: 4px 14px; font-size: .86rem; }
.pager .btn[disabled] { opacity: .35; cursor: default; }

.query-echo { margin: 0 0 8px; text-align: center; font-size: .86rem; color: var(--ink-soft); }
.query-echo q { quotes: '«' '»'; color: var(--ink); font-weight: 600; }

/* ---------- whole poem (fal) ---------- */

.poem { flex: 1 1 auto; margin: 4px 0; padding: 0; list-style: none; }
.poem li { padding: 2px 0 8px; border-bottom: 1px dotted rgba(184, 137, 43, .5); }
.poem li:last-child { border-bottom: 0; }
.poem p { margin: 0; font-family: var(--verse); font-size: clamp(1.02rem, .9rem + .8vw, 1.3rem); line-height: 2.6; }
.poem .m1 { text-align: right; padding-left: 8%; }
.poem .m2 { text-align: left; padding-right: 8%; }
/* a ghazal on a page that only turns past: smaller, never scrolls, and
   fades out at the foot of the page if it is too long */
.page__body--still {
  overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 82%, transparent 98%);
  mask-image: linear-gradient(#000 82%, transparent 98%);
}
.poem--page p { font-size: clamp(.92rem, .8rem + .5vw, 1.14rem); line-height: 2.3; }
.poem--page li { padding: 0 0 4px; }

.niyat { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.niyat__text { font-family: var(--verse); font-size: 1.5rem; line-height: 2.5; margin: 0; color: var(--lapis-deep); }

/* ---------- bookmarks ---------- */

.marks { margin: 6px 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.mark {
  width: 100%;
  display: block;
  text-align: right;
  padding: 6px 12px 8px;
  border: 1px solid rgba(184, 137, 43, .6);
  border-radius: 6px;
  background: rgba(255, 250, 235, .5);
}
.mark:hover { background: rgba(217, 182, 90, .2); }
.mark__verse { display: block; font-family: var(--verse); font-size: 1.05rem; line-height: 2.5; }
.mark__src { display: block; font-size: .76rem; color: var(--ink-soft); }
.empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--ink-soft); }

/* ---------- small things ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: min(92vw, 26rem);
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--lapis-deep);
  color: #f8efd8;
  font-size: .88rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
  z-index: 20;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.noscript { position: fixed; inset: auto 0 0; margin: 0; padding: 12px; background: var(--rose); color: #fff; text-align: center; }
.only-wide { display: none; }
.only-narrow { display: none !important; }

/* two pages, always: each one dips towards the middle of the book */
.page--main { border-radius: 0 6px 6px 0; box-shadow: var(--paper-inset), var(--sheets-right); }
.page--side { border-radius: 6px 0 0 6px; }
.page--main::after { background: linear-gradient(90deg, rgba(60, 35, 10, .3), rgba(90, 60, 20, .08) 8%, transparent 18%, transparent 90%, rgba(255, 252, 240, .3)); }
.page--side::after { background: linear-gradient(270deg, rgba(60, 35, 10, .3), rgba(90, 60, 20, .08) 8%, transparent 18%, transparent 90%, rgba(255, 252, 240, .3)); }

/* ---------- wide screens: an open book with two pages ---------- */

@media (min-width: 900px) and (min-height: 560px) {
  .desk { gap: 10px; padding: 14px 20px; }
  .tools { width: min(100%, 1120px); }
  .book { width: min(calc(100% - 60px), 1100px); max-height: 700px; margin: 8px 30px 34px; transform: translateX(var(--shift)) rotateX(11deg); }

  .boards { inset: -10px -24px -26px; }
  .page__body { inset: 30px; padding: 22px 30px 14px; }
  .page__corner { width: 124px; height: 124px; opacity: .75; }
  /* one drawing per page, placed where no text sits */
  .page--main .page__corner--a,
  .page--side .page__corner--b { display: none; }
  .page--main .head { padding-inline: 16%; }
  .page--side .page__body { padding-bottom: 150px; }

  /* soft shadow where the two pages meet */
  .spine {
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 70px;
    transform: translateX(-50%);
    background: linear-gradient(90deg, transparent, rgba(90, 60, 20, .16) 42%, rgba(60, 35, 10, .34) 50%, rgba(90, 60, 20, .16) 58%, transparent);
    pointer-events: none;
    z-index: 2;
  }

  .only-wide { display: revert; }
  .verse p { font-size: clamp(1.5rem, 1rem + 1.25vw, 2.1rem); }
  .verse--long p { font-size: clamp(1.25rem, .9rem + 1vw, 1.75rem); }
  .medallion { height: min(44vh, 330px); }
}

/* ---------- phones: the same open book, made smaller to fit ----------
   The book is laid out at a fixed size (--bw by --bh, set in js/app.js) and
   then scaled down (--bs), so it looks just like the wide version. Closed,
   the cover is zoomed in (--zc) to fill the screen. */

@media not all and (min-width: 900px) and (min-height: 560px) {
  .book {
    flex: none;
    width: var(--bw, 600px);
    height: var(--bh, 480px);
    max-height: none;
    margin:
      calc(var(--bh, 480px) * (var(--bs, .6) - 1) / 2 + 10px)
      calc(var(--bw, 600px) * (var(--bs, .6) - 1) / 2)
      calc(var(--bh, 480px) * (var(--bs, .6) - 1) / 2 + 44px);
    transform: scale(calc(var(--bs, .6) * var(--zoom))) translateX(var(--shift)) rotateX(9deg);
    transform-origin: 50% 50%;
  }
  .boards { inset: -9px -20px -24px; }
  /* The closed cover fills the screen and zooms out while it opens, so the
     small print waits until the book lies open, then shows below it. */
  .credit { transition: opacity .4s ease; }
  .book:not([data-state='open']) ~ .credit { opacity: 0; pointer-events: none; }

  .spine {
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 44px;
    transform: translateX(-50%);
    background: linear-gradient(90deg, transparent, rgba(90, 60, 20, .16) 42%, rgba(60, 35, 10, .34) 50%, rgba(90, 60, 20, .16) 58%, transparent);
    pointer-events: none;
    z-index: 2;
  }

  .page__frame { inset: 8px; border-width: 7px; }
  .page__body { inset: 20px; padding: 14px 6px 8px; }
  .page--main .page__corner--a,
  .page--side .page__corner--b { display: none; }
  .page__corner { width: 76px; height: 76px; opacity: .5; left: 20px; bottom: 20px; }
  .page__corner--b { left: auto; bottom: auto; right: 20px; top: 20px; opacity: .3; }
  .page--side .page__body { padding-bottom: 96px; }

  .poem--page p { font-size: .86rem; }
  .poem--page .m1 { padding-left: 0; }
  .poem--page .m2 { padding-right: 0; }
  .verse p { font-size: 1.16rem; }
  .verse--long p { font-size: 1rem; }
  .verse .m1 { padding-left: 0; }
  .verse .m2 { padding-right: 0; }
  .sarlowh { margin-inline: 0; }
  .sarlowh__title { font-size: 1.35rem; }
  .ask__input { font-size: .98rem; }
  .ask__actions .btn { flex: 1 1 100%; }
  .acts .btn, .pager .btn { padding: 4px 11px; font-size: .82rem; }
  .how li { font-size: .86rem; }
  .cover__lachak { width: 52px; height: 52px; }
  .book .medallion { height: 215px; }
  .book .cover__face--front { padding: 40px 28px 30px; }
  .medallion__title { font-size: clamp(1.7rem, 8vw, 2.5rem); }
}

/* a phone held sideways: the round buttons stand beside the book */
@media (orientation: landscape) and (max-height: 559px) {
  .desk { position: relative; }
  .tools { position: absolute; top: 10px; left: 10px; width: auto; flex-direction: column; z-index: 6; }
}

@media (max-height: 640px) {
  .credit { display: none; }
  .medallion { height: 38vh; }
  .cover__face--front { padding: 34px 26px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .ink { clip-path: none; }
}
