/* ==========================================================================
   گنجورند — Ganjoorand web
   Parchment & turquoise by day, ink & gold by night.
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #f4eee2;
  --bg-2: #eadfca;
  --card: #fffaf0;
  --card-2: #fbf3e2;
  --ink: #2a2433;
  --ink-soft: #4a4153;
  --muted: #8a7d70;
  --line: rgba(140, 104, 44, 0.24);
  --accent: #17766f;
  --accent-2: #1f958b;
  --accent-ink: #ffffff;
  --gold: #b88a35;
  --gold-soft: rgba(184, 138, 53, 0.14);
  --glass: rgba(255, 250, 240, 0.78);
  --shadow: 0 28px 60px -28px rgba(70, 45, 10, 0.45), 0 2px 6px rgba(70, 45, 10, 0.06);
  --danger: #a8402f;

  --verse-size: 1.5rem;
  --font-ui: "Vazirmatn", "Noto Sans Arabic UI", "Noto Sans Arabic", "DejaVu Sans", system-ui, sans-serif;
  --font-poem: "Noto Naskh Arabic", "Vazirmatn", "Noto Sans Arabic", "DejaVu Sans", serif;
  --radius: 28px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1018;
    --bg-2: #171826;
    --card: #1a1b29;
    --card-2: #202136;
    --ink: #efe8d8;
    --ink-soft: #cfc7b6;
    --muted: #9a917f;
    --line: rgba(226, 184, 102, 0.22);
    --accent: #3fb5aa;
    --accent-2: #63d0c5;
    --accent-ink: #07211f;
    --gold: #e2b866;
    --gold-soft: rgba(226, 184, 102, 0.12);
    --glass: rgba(26, 27, 41, 0.78);
    --shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.85), 0 2px 8px rgba(0, 0, 0, 0.3);
    --danger: #ef8b79;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1018;
  --bg-2: #171826;
  --card: #1a1b29;
  --card-2: #202136;
  --ink: #efe8d8;
  --ink-soft: #cfc7b6;
  --muted: #9a917f;
  --line: rgba(226, 184, 102, 0.22);
  --accent: #3fb5aa;
  --accent-2: #63d0c5;
  --accent-ink: #07211f;
  --gold: #e2b866;
  --gold-soft: rgba(226, 184, 102, 0.12);
  --glass: rgba(26, 27, 41, 0.78);
  --shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.85), 0 2px 8px rgba(0, 0, 0, 0.3);
  --danger: #ef8b79;
}

/* ---------- Base ---------- */

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-underline-offset: 3px; }

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

.i {
  width: 1.15em; height: 1.15em;
  flex: none;
  fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Backdrop: soft glows + faint geometric lattice ---------- */

.backdrop {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60rem 36rem at 85% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    radial-gradient(48rem 30rem at 0% 110%, color-mix(in srgb, var(--gold) 18%, transparent), transparent 70%),
    linear-gradient(var(--bg), var(--bg-2));
}
.backdrop::after {
  content: ""; position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='88' height='88' viewBox='0 0 88 88'%3E%3Cg fill='none' stroke='%23b88a35' stroke-opacity='.16' stroke-width='1'%3E%3Crect x='22' y='22' width='44' height='44'/%3E%3Crect x='22' y='22' width='44' height='44' transform='rotate(45 44 44)'/%3E%3Ccircle cx='44' cy='44' r='9'/%3E%3C/g%3E%3C/svg%3E");
  -webkit-mask-image: radial-gradient(ellipse at 50% 0%, #000 0%, transparent 62%);
          mask-image: radial-gradient(ellipse at 50% 0%, #000 0%, transparent 62%);
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  padding: .7rem clamp(1rem, 4vw, 2.2rem);
  padding-top: max(.7rem, env(safe-area-inset-top));
  background: linear-gradient(var(--bg), color-mix(in srgb, var(--bg) 0%, transparent));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.brand { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; color: var(--ink); }
.brand-mark { width: 2.1rem; height: 2.1rem; }
.bm-bg { fill: var(--accent); }
.bm-star { fill: #f1d28b; }
.brand-mark circle.bm-bg { fill: var(--accent); }
.brand-name { font-weight: 800; font-size: 1.25rem; letter-spacing: -.01em; }

.tools { display: flex; gap: .35rem; }

.icon-btn {
  position: relative;
  display: inline-grid; place-items: center;
  width: 2.5rem; height: 2.5rem;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  transition: background .2s, color .2s, border-color .2s, transform .15s;
}
.icon-btn:hover { background: var(--gold-soft); color: var(--ink); border-color: var(--line); }
.icon-btn:active { transform: scale(.94); }
.icon-btn small {
  position: absolute; bottom: .35rem; inset-inline-end: .4rem;
  font-size: .8rem; font-weight: 800; line-height: 1; color: var(--gold);
}
.icon-btn.solid { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.icon-btn.solid:hover { background: var(--accent-2); color: var(--accent-ink); }

/* ---------- Hero / search ---------- */

.page { width: min(100% - 2rem, 52rem); margin: 0 auto; padding-bottom: 9rem; }

.hero { text-align: center; padding: clamp(.4rem, 2.5vw, 1.4rem) 0 1rem; }

.eyebrow {
  margin: 0 0 .6rem;
  display: inline-block;
  padding: .15rem .9rem;
  font-size: .8rem; letter-spacing: .04em;
  color: var(--gold);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--gold-soft);
}

.hero h1 {
  margin: .2rem 0 .4rem;
  font-family: var(--font-poem);
  font-size: clamp(1.9rem, 6vw, 3rem);
  font-weight: 700;
  line-height: 1.3;
  background: linear-gradient(120deg, var(--ink) 30%, var(--accent) 70%, var(--gold));
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.lead { margin: 0 auto 1.2rem; max-width: 36rem; color: var(--muted); font-size: .98rem; }

.search {
  position: relative;
  display: flex; align-items: center; gap: .5rem;
  padding: .4rem .45rem .4rem .4rem;
  padding-inline-start: 1.1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: border-color .2s, box-shadow .2s;
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.search-icon { color: var(--muted); width: 1.3rem; height: 1.3rem; }
.search input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  padding: .7rem .2rem;
  font-size: 1rem;
  text-align: start;
}
.search input::placeholder { color: var(--muted); opacity: .85; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem 1.25rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600; font-size: .95rem; white-space: nowrap;
  text-decoration: none;
  transition: transform .15s, background .2s, box-shadow .2s, border-color .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  color: var(--accent-ink);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--accent) 70%, transparent);
}
.btn.primary:hover { box-shadow: 0 10px 26px -8px color-mix(in srgb, var(--accent) 85%, transparent); }
.btn.ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn.ghost:hover { background: var(--gold-soft); color: var(--ink); }
.btn.ghost[aria-pressed="true"] { color: var(--danger); border-color: currentColor; }
.btn.ghost[aria-pressed="true"] .i { fill: currentColor; }
.btn.small { padding: .4rem .9rem; font-size: .85rem; }
.btn[disabled] { opacity: .6; pointer-events: none; }

/* suggestions */
.suggest {
  position: absolute; top: calc(100% + .5rem); inset-inline: 1rem; z-index: 10;
  padding: .35rem;
  text-align: start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.suggest button {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  padding: .55rem .8rem;
  background: none; border: 0; border-radius: 12px;
  text-align: start; color: var(--ink-soft);
}
.suggest button:hover, .suggest button[aria-selected="true"] { background: var(--gold-soft); color: var(--ink); }
.suggest .i { color: var(--muted); width: 1rem; height: 1rem; }
.suggest span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chips */
.chips {
  display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem;
  margin-top: .9rem; min-height: 2.4rem;
}
.chip {
  padding: .35rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  color: var(--ink-soft);
  font-size: .92rem;
  transition: background .2s, border-color .2s, color .2s, transform .15s;
  animation: rise .5s both;
  animation-delay: calc(var(--i, 0) * 40ms);
}
.chip:hover { background: var(--gold-soft); border-color: var(--gold); color: var(--ink); transform: translateY(-1px); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.ghost-chip { border-style: dashed; color: var(--gold); }

/* ---------- Notice ---------- */

.notice {
  margin: 0 auto 1.2rem; max-width: 36rem;
  padding: .7rem 1.1rem;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  background: color-mix(in srgb, var(--danger) 10%, var(--card));
  color: var(--danger);
  text-align: center; font-size: .95rem;
}

/* ---------- Poem card ---------- */

.poem-card {
  position: relative;
  padding: clamp(1.6rem, 5vw, 3.2rem) clamp(1.1rem, 5vw, 3rem) clamp(1.4rem, 4vw, 2.4rem);
  background:
    radial-gradient(40rem 20rem at 50% -8%, var(--gold-soft), transparent 70%),
    var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  isolation: isolate;
}
/* inner gilded frame */
.poem-card::before {
  content: ""; position: absolute; inset: 9px; z-index: -1;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 9px);
  pointer-events: none;
}

.poem-head { text-align: center; }
.kicker {
  margin: 0 0 .35rem;
  font-size: .85rem; color: var(--gold); letter-spacing: .02em;
}
.poem-title {
  margin: 0;
  font-family: var(--font-poem);
  font-size: clamp(1.35rem, 4.2vw, 1.9rem);
  font-weight: 700; line-height: 1.5;
}

/* ornament */
.orn { display: flex; align-items: center; justify-content: center; gap: .8rem; margin: 1.1rem auto; max-width: 18rem; }
.orn::before, .orn::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold));
}
.orn::after { background: linear-gradient(270deg, transparent, var(--gold)); }
.orn i { width: .55rem; height: .55rem; background: var(--gold); transform: rotate(45deg); box-shadow: 0 0 0 3px var(--gold-soft); }
.orn.small { margin: 1.8rem auto 1rem; max-width: 10rem; opacity: .8; }

/* verses */
.verses {
  font-family: var(--font-poem);
  font-size: var(--verse-size);
  line-height: 2.25;
  color: var(--ink);
  margin-top: .6rem;
}

.couplet { margin: 0 0 .15rem; opacity: 0; animation: rise .6s cubic-bezier(.2,.7,.2,1) forwards; animation-delay: calc(min(var(--i, 0), 24) * 45ms); }
.couplet.pair {
  display: grid; grid-template-columns: 1fr 1fr;
  column-gap: clamp(1.4rem, 7vw, 4.5rem);
  align-items: baseline;
  position: relative;
}
.couplet.pair .m:first-child { text-align: end; }   /* right hemistich leans toward the centre */
.couplet.pair .m:last-child  { text-align: start; } /* left hemistich leans toward the centre */
.couplet.pair::after {
  content: ""; position: absolute; top: 50%; inset-inline-start: 50%;
  width: 4px; height: 4px; margin-inline-start: -2px;
  border-radius: 50%; background: var(--gold); opacity: .55;
  transform: translateY(-50%);
}
.couplet.single, .couplet.stack { text-align: center; }
.couplet.note { text-align: center; font-size: .8em; color: var(--muted); font-family: var(--font-ui); line-height: 1.9; }
.couplet.prose { text-align: justify; text-justify: inter-word; line-height: 2.1; font-size: .92em; }
.m { display: block; padding-inline: .1rem; }

::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

.poem-foot { text-align: center; color: var(--muted); font-size: .85rem; }
.metre { margin: .2rem 0; font-style: italic; }
.rec-note { margin: .2rem 0 0; }

/* empty + skeleton states */
.poem-card .empty { text-align: center; color: var(--muted); padding: 2.4rem 0; }
.poem-card:not(.is-empty) .empty,
.poem-card.is-loading .empty { display: none; }
.poem-card.is-loading .poem-content { display: none; }
.skeleton { display: none; }
.poem-card.is-loading .skeleton { display: flex; flex-direction: column; align-items: center; gap: 1.1rem; padding: .6rem 0 1rem; }
.sk {
  display: block; height: .9rem; border-radius: 99px;
  background: linear-gradient(90deg, var(--gold-soft) 25%, color-mix(in srgb, var(--gold) 30%, transparent) 50%, var(--gold-soft) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.sk-s { width: 7rem; } .sk-l { width: 14rem; height: 1.4rem; } .sk-m { width: min(80%, 26rem); }
.sk-orn { width: 9rem; height: 1px; background: var(--line); }

/* ---------- Dock ---------- */

.dock {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  padding: 0 .8rem max(.9rem, env(safe-area-inset-bottom));
  pointer-events: none;
}
.dock-inner {
  pointer-events: auto;
  display: flex; flex-direction: column; gap: .5rem;
  width: min(100%, 38rem);
  padding: .55rem;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
}
.actions { display: flex; gap: .45rem; justify-content: center; flex-wrap: nowrap; }
.actions .btn.primary { flex: 1.4; }
.actions .btn.ghost { flex: 1; padding-inline: .8rem; }

.player {
  display: flex; align-items: center; gap: .6rem;
  padding: .3rem .5rem .1rem;
}
.player[hidden] { display: none; }
.time { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.6rem; text-align: center; }
.player select {
  max-width: 9.5rem;
  padding: .3rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: .8rem;
  text-overflow: ellipsis;
}

input[type="range"] {
  flex: 1; min-width: 0; height: 1.4rem;
  -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer;
  --p: 0%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent) var(--p), var(--gold-soft) var(--p));
  border: 1px solid var(--line);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 99px; background: var(--gold-soft); border: 1px solid var(--line); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 99px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px;
  border-radius: 50%; background: var(--gold); border: 2px solid var(--card);
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 2px solid var(--card); }

/* ---------- Drawer ---------- */

.drawer {
  width: min(92vw, 26rem); max-height: min(80vh, 36rem);
  margin: auto;
  padding: 0;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
}
.drawer[open] { display: flex; flex-direction: column; animation: pop .25s cubic-bezier(.2,.8,.2,1); }
.drawer::backdrop { background: rgba(10, 8, 18, .5); backdrop-filter: blur(3px); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: .8rem .9rem .5rem 1rem; }
.tabs { display: flex; gap: .3rem; padding: .25rem; background: var(--gold-soft); border-radius: 999px; }
.tabs button {
  border: 0; background: transparent; padding: .35rem 1rem; border-radius: 999px;
  color: var(--muted); font-size: .9rem; font-weight: 600;
}
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.drawer-list { list-style: none; margin: 0; padding: .3rem .6rem; overflow: auto; flex: 1; }
.drawer-list li button {
  display: block; width: 100%; padding: .65rem .8rem; text-align: start;
  border: 0; background: none; border-radius: 14px; color: var(--ink-soft);
}
.drawer-list li button:hover { background: var(--gold-soft); color: var(--ink); }
.drawer-list .sub { display: block; font-size: .78rem; color: var(--muted); }
.drawer-list .empty-li { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.drawer-foot { padding: .6rem; text-align: center; border-top: 1px solid var(--line); }

/* ---------- Toasts & footer ---------- */

.toasts {
  position: fixed; z-index: 60; inset-inline: 0; bottom: 8.5rem;
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  pointer-events: none;
}
.toast {
  padding: .55rem 1.1rem; border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-size: .9rem; box-shadow: var(--shadow);
  animation: pop .25s both, fade .3s 2.2s forwards;
}

.site-foot { text-align: center; font-size: .78rem; color: var(--muted); padding: 0 1rem 7.5rem; }

/* ---------- Motion ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { to { opacity: 0; transform: translateY(6px); } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; scroll-behavior: auto !important; }
  .couplet { opacity: 1; }
}

/* ---------- Small screens ---------- */

@media (max-width: 36rem) {
  .eyebrow, .lead { display: none; }
  .hero h1 { font-size: 1.6rem; margin-bottom: .9rem; }
  .chips { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; padding-bottom: .3rem; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .search { border-radius: 26px; flex-wrap: wrap; padding: .5rem; }
  .search-icon { display: none; }
  .search input { flex: 1 1 100%; padding-inline: .8rem; }
  .search .btn { flex: 1 1 100%; }
  .suggest { inset-inline: .5rem; }

  /* stack hemistichs, first leaning right, second leaning left */
  .couplet.pair { grid-template-columns: 1fr; row-gap: 0; margin-bottom: .6rem; }
  .couplet.pair .m:first-child { text-align: start; }
  .couplet.pair .m:last-child  { text-align: end; padding-inline-end: 0; }
  .couplet.pair::after { display: none; }

  .actions .lbl { display: none; }
  .actions .btn.ghost { flex: 0 0 3rem; padding-inline: 0; }
  .brand-name { font-size: 1.1rem; }
}

@media print {
  .topbar, .dock, .hero, .site-foot, .backdrop { display: none !important; }
  .poem-card { box-shadow: none; border: 0; }
  body { background: #fff; color: #000; }
}
