/* المعجم — one search row and its results. The page carries no logo and no
   coloured band: white (or near-black) ground, one green for what is chosen,
   and the lexicon text in Scheherazade New. Type stays modest on purpose —
   the largest thing on the page is the word being searched. */

@font-face { font-family: 'Scheherazade New'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('fonts/scheherazade-new-400.woff2') format('woff2'); }
@font-face { font-family: 'Scheherazade New'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('fonts/scheherazade-new-700.woff2') format('woff2'); }
@font-face { font-family: 'Cairo'; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url('fonts/cairo-arabic.woff2') format('woff2'); }

:root {
  /* public/theme.js keeps the browser bar on --bg: #fcfefd / #090f0c */
  --bg: oklch(0.995 0.002 165); --field: oklch(1 0 0);
  --ink: oklch(0.22 0.02 165); --soft: oklch(0.46 0.02 165); --line: oklch(0.9 0.008 165);
  --accent: oklch(0.45 0.09 168); --accent-soft: oklch(0.95 0.025 168); --hover: oklch(0.96 0.008 165);
  --arabic: 'Scheherazade New', 'Amiri', serif;
  --ui: 'Cairo', system-ui, sans-serif;
  color-scheme: light;
}
/* Light is the default; dark only when chosen (public/theme.js sets data-theme). */
:root[data-theme="dark"] {
  --bg: oklch(0.16 0.01 168); --field: oklch(0.19 0.012 168);
  --ink: oklch(0.93 0.01 160); --soft: oklch(0.72 0.02 160); --line: oklch(0.28 0.015 168);
  --accent: oklch(0.76 0.1 168); --accent-soft: oklch(0.26 0.04 168); --hover: oklch(0.21 0.012 168);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink); font-family: var(--ui); direction: rtl; }
a { color: var(--accent); }
button, select, input { font: inherit; }
.col { width: 100%; max-width: 720px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Header: one row (search · theme), a meta line, the words found ── */
.top { position: sticky; top: 0; z-index: 2; background: var(--bg); border-bottom: 1px solid var(--line);
  padding-top: max(12px, env(safe-area-inset-top)); }
.row { display: flex; align-items: center; gap: 6px; }
.field { flex: 1; min-width: 0; display: flex; align-items: center; height: 46px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--field); transition: border-color .15s ease-out, box-shadow .15s ease-out; }
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-go { flex: none; width: 42px; height: 100%; display: grid; place-items: center; border: 0; border-radius: 10px;
  background: none; color: var(--soft); cursor: pointer; }
.field-go:hover { color: var(--accent); }
.field-go svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.field-input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; color: var(--ink); outline: none;
  font-family: var(--arabic); font-size: 23px; padding: 0 0 4px 12px; }
.field-input::placeholder { color: var(--soft); opacity: 1; }
.field-input::-webkit-search-cancel-button { display: none; }

/* The theme switch is the icon alone: no ring around it. */
.theme-btn { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink); cursor: pointer; transition: background-color .15s ease-out; }
.theme-btn:hover { background: var(--hover); }
.theme-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.theme-btn .i-sun { display: none; }
:root[data-theme="dark"] .theme-btn .i-sun { display: block; }
:root[data-theme="dark"] .theme-btn .i-moon { display: none; }

.meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; padding: 6px 0;
  font-size: 12.5px; color: var(--soft); }
.picker { display: flex; align-items: center; gap: 6px; min-width: 0; }
.picker-label { flex: none; }
.picker select { min-width: 0; max-width: 100%; min-height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--field); color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer; }
.picker select.narrowed { border-color: var(--accent); color: var(--accent); }
.root-line { flex: none; white-space: nowrap; }
.root-line b { font-family: var(--arabic); font-size: 19px; font-weight: 700; color: var(--ink); letter-spacing: .12em; margin-inline-start: 4px; }

/* The headwords the typed word might be, best first: tabs on the header's rule. */
.family { display: flex; gap: 0 18px; overflow-x: auto; scrollbar-width: none; margin-bottom: -1px; }
.family::-webkit-scrollbar { display: none; }
.tab { flex: none; padding: 0 0 6px; border: 0; border-bottom: 2px solid transparent; background: none; cursor: pointer;
  font-family: var(--arabic); font-size: 19px; line-height: 1.6; color: var(--soft); }
.tab:hover { color: var(--ink); }
.tab[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--accent); }

/* ── Start screen: nothing searched yet (html.home, set by theme.js) ──
   The search sits a little above the middle — the eye's centre, and still
   clear of a phone keyboard once the field is focused. The first search sends
   it up to the header (app.js animates the move). */
.try, .dict-chips { display: none; }
:root.home .top { position: static; flex: 1; display: flex; flex-direction: column; justify-content: center;
  border-bottom: 0; padding-bottom: 16vh; }
:root.home .top .col { max-width: 600px; }
:root.home .field { height: 54px; border-radius: 12px; }
:root.home .field-input { font-size: 25px; }
:root.home .theme-btn { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; }
:root.home .meta, :root.home .family, :root.home .results { display: none; }
:root.home .try { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 2px 14px;
  margin-top: 16px; font-size: 12.5px; color: var(--soft); }
.try-word { padding: 2px 0; border: 0; background: none; cursor: pointer; color: var(--ink);
  font-family: var(--arabic); font-size: 20px; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 6px;
  transition: text-decoration-color .15s ease-out; }
.try-word:hover { text-decoration-color: var(--accent); }
:root.home .dict-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 18px; }
.dict-chip { min-height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer;
  color: var(--soft); font-size: 13.5px; font-weight: 600; transition: border-color .15s ease-out, background-color .15s ease-out, color .15s ease-out; }
.dict-chip:hover { color: var(--ink); }
.dict-chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }

/* ── Results ────────────────────────────────────────────────────── */
.results { flex: 1; padding-top: 2px; padding-bottom: 32px; }
.note { margin: 22px 0; color: var(--soft); font-size: 14px; line-height: 1.8; }
.note-action { display: inline-block; margin-top: 10px; min-height: 36px; padding: 0 14px; border: 1px solid var(--accent); border-radius: 8px;
  background: transparent; color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; }

.entry { padding: 16px 0; border-bottom: 1px solid var(--line); }
.src { font-size: 12.5px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.text { font-family: var(--arabic); font-size: 19px; line-height: 1.8; overflow-wrap: anywhere; }
.title { font-size: 21px; font-weight: 700; line-height: 1.5; }
/* Numbered meanings hang their number in a narrow column; an unnumbered line
   that follows a meaning lines up with its text. */
.lines.numbered .ln { display: grid; grid-template-columns: 1.5em 1fr; gap: 2px; }
.lines .n { color: var(--accent); font-weight: 700; }
.lines .ln + .ln { margin-top: 2px; }
/* A long entry opens folded, fading out, until «عرض المزيد». */
.text.clamped { max-height: 14em; overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.more { margin-top: 6px; padding: 6px 0; border: 0; background: transparent; color: var(--accent); cursor: pointer;
  font-size: 14px; font-weight: 600; }
.more:disabled { opacity: .5; }

/* The root lexicons: a grid of boxes, the one picked opens beneath it. */
.roots { margin-top: 26px; }
.roots-title { margin: 0 0 8px; font-size: 14px; font-weight: 500; color: var(--soft); }
.roots-title b { font-family: var(--arabic); font-size: 19px; color: var(--ink); }
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.book { display: block; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--field);
  color: var(--ink); text-align: start; cursor: pointer; font-size: 14px; font-weight: 600; transition: border-color .15s ease-out, background-color .15s ease-out; }
.book small { display: block; margin-top: 2px; color: var(--soft); font-size: 12.5px; font-weight: 400; }
.book:hover { border-color: color-mix(in oklch, var(--accent) 45%, var(--line)); }
.book[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); }
.book-panel .entry { border-bottom: 0; }

/* One root lexicon picked: its other roots fold under their names. */
.root-entry { border-bottom: 1px solid var(--line); }
.root-entry > summary { padding: 12px 0; cursor: pointer; font-size: 14px; font-weight: 600; }
.root-entry > .text { padding-bottom: 12px; }

/* ── Footer ─────────────────────────────────────────────────────── */
.foot { padding-top: 14px; padding-bottom: max(18px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
  color: var(--soft); font-size: 12.5px; line-height: 1.7; }

@media (min-width: 721px) {
  .top { padding-top: 18px; }
  .text { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
