/* views/library.css — page headers, the word library: filters, rows, tags. */

.page-head {
  display: flex; align-items: end; justify-content: space-between; gap: var(--s-5); flex-wrap: wrap;
}
.page-head h1 { font-size: var(--text-3xl); }
.page-head h1 + .hint { margin-top: var(--s-1); }

.recall-strip {
  display: flex; align-items: center; gap: var(--s-3);
  margin: 0 0 var(--s-2); padding: var(--s-3) var(--s-3) var(--s-3) var(--s-5);
  border-radius: var(--r-lg); background: var(--mark-soft); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--mark) 70%, transparent);
}
.recall-strip-main {
  display: flex; align-items: center; gap: var(--s-4);
  flex: 1; min-width: 0; color: inherit; text-decoration: none;
}
.recall-strip-main > span { display: grid; }
.recall-strip-ignore { flex: none; margin-inline-start: auto; }
.recall-strip:hover { border-color: var(--mark); }
@media (max-width: 560px) {
  .recall-strip { flex-wrap: wrap; padding: var(--s-4); }
  .recall-strip-main { flex: 1 1 100%; gap: var(--s-3); }
}

/* Numbered step headings (Add words: 2 Check, 3 Save) */
.step-n {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface-2); color: var(--ink-2);
  font-family: var(--font-display); font-weight: 700;
}

/* ── Library controls ───────────────────────────────────────────
   Search + an icon-only filter button on one row, status as a single
   scrollable row of counted chips. The list starts one short step below. */
.lib-tools { display: grid; gap: var(--s-2); margin: 10px 0 var(--s-3); scroll-margin-top: calc(var(--bar-h) + 10px); }
.lib-search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-2); align-items: stretch; }
.lib-search-row .field { min-height: 46px; }
.lib-search-row input { font-size: 1rem; }
.lib-filter-btn { gap: 6px; min-width: 46px; padding: 0 12px; }
.lib-filter-btn .pill { flex: none; }
.pill {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill);
  background: var(--brand); color: var(--on-brand); font-size: .72rem; font-weight: 700;
}
.pill[hidden] { display: none; }

/* Status: a chip is a state, so the chosen one is ink, not another blue action. */
.chip-row { display: flex; gap: 6px; align-items: center; overflow-x: auto; scrollbar-width: none; padding: 1px; }
.chip-row::-webkit-scrollbar { display: none; }
.chip-row.is-overflow {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
}
.chip-row.is-end { -webkit-mask-image: none; mask-image: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; flex: none;
  min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink-2);
  font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
  transition: background var(--fast), border-color var(--fast), color var(--fast);
}
.chip-n { color: var(--ink-3); font-size: .72rem; font-variant-numeric: tabular-nums; }
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip[aria-pressed="true"] .chip-n { color: color-mix(in srgb, var(--surface) 68%, transparent); }
.chip:disabled { opacity: .4; pointer-events: none; }

/* ── Filter sheet ───────────────────────────────────────────────
   A bottom sheet on phones, a centred sheet elsewhere. Filters update
   the list underneath while it stays open. */
.filter-sheet {
  width: min(660px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
}
.filter-body { padding: var(--s-4) var(--s-5) var(--s-5); gap: var(--s-5); }
/* Two columns while the labels fit; one column at 320 with Larger text, where
   "Any memory" was being clipped inside a 136px select. The minimum is in rem,
   so it grows with Settings → Text size. */
.lib-panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: var(--s-3); }
.filter-sheet .lib-panel-grid { gap: 10px var(--s-3); }
.lib-toggles { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: 0 var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--line); }
.lib-toggles .check { min-height: 42px; }
.filter-foot { justify-content: space-between; gap: var(--s-2); }
.filter-foot .btn-primary { white-space: nowrap; }

/* ── Results: count, Practise / More ──────────────────────────── */
.lib-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: var(--s-2); }
.lib-count { display: flex; align-items: baseline; gap: 8px; min-width: 0; color: var(--ink); }
.lib-count b { font-size: var(--text-sm); font-weight: 700; }
.lib-desc { font-size: var(--text-2xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.lib-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.lib-actions .btn { min-height: 40px; padding: 0 12px; }
.lib-actions .lib-more-btn { padding: 0 10px; }
.lib-more { position: relative; }
.lib-more > summary { list-style: none; }
.lib-more > summary::-webkit-details-marker { display: none; }
.lib-more > summary .icon { transition: transform var(--fast); }
.lib-more[open] > summary { border-color: var(--line-strong); }
.lib-more-menu {
  position: absolute; z-index: 10; inset-inline-start: auto; inset-inline-end: 0; top: calc(100% + 4px); min-width: 210px;
  max-width: calc(100vw - 2 * var(--gutter));
  display: grid; padding: var(--s-1); border-radius: var(--r-md);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2);
}
/* Not enough room below (landscape phones): open upwards instead. */
.lib-more.is-up .lib-more-menu { top: auto; bottom: calc(100% + 4px); }
.lib-more-menu .btn { justify-content: flex-start; }
.lib-more-menu .icon { color: var(--ink-3); }

/* ── Word rows ──────────────────────────────────────────────────
   One grouped card with hairline dividers reads faster than 24 floating
   cards. Phone: two lines (word + Arabic, then one quiet meta line).
   Desktop: word + meta on the left, Arabic on the right, badges, chevron. */
.word-list {
  display: grid; gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.word-list > .btn {
  border: 0; border-top: 1px solid var(--line); border-radius: 0;
  min-height: 50px; background: var(--surface);
}
.word-list > .btn:hover { background: var(--surface-2); }

.word-row { background: var(--surface); border: 0; border-top: 1px solid var(--line); border-radius: 0; }
.word-row:first-child { border-top: 0; }
.word-row[open] { border-color: var(--line); box-shadow: none; }
.word-row summary {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto 20px;
  grid-template-areas: "word ar badges chev" "meta ar badges chev";
  align-items: center; column-gap: var(--s-4); row-gap: 0;
  min-height: 58px; padding: 9px var(--s-4);
  cursor: pointer; list-style: none;
  transition: background var(--fast);
}
.word-row summary::-webkit-details-marker { display: none; }
@media (hover: hover) { .word-row summary:hover { background: #fbfcfe; } }
.word-row-word { grid-area: word; display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.word-row-word b { font-weight: 600; overflow-wrap: anywhere; }
.word-row-dot { display: none; }
.word-row-meta {
  grid-area: meta; min-width: 0;
  font-size: var(--text-2xs); color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.word-row-meta .icon { display: inline; vertical-align: -3px; width: 13px; height: 13px; }
/* The dot travels with the item it separates, so a wrapped phone line starts
   with "· #Work" instead of ending in a bare dot. */
.word-row-freq::before, .word-row-tagline::before, .word-row-note::before { content: " \00b7\00a0"; color: var(--ink-3); }
.word-row-state, .word-row-sep { display: none; }
.word-row-ar { grid-area: ar; text-align: end; color: var(--ink-2); font-size: 1.02rem; overflow-wrap: anywhere; }
.word-row-ar.hint { font-size: var(--text-sm); }
.word-row-badges { grid-area: badges; display: flex; gap: 6px; justify-content: end; }
.word-row-chev { grid-area: chev; color: var(--ink-3); transition: transform var(--fast); }
.word-row[open] .word-row-chev { transform: rotate(90deg); }
.word-row-body {
  display: grid; gap: var(--s-3);
  padding: var(--s-4);
  border-top: 1px solid var(--line);
  background: #fcfdff;
}
.word-row-example { color: var(--ink-2); font-style: italic; }
.word-row-foot { justify-content: space-between; gap: var(--s-2); }
.word-edit { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.word-edit .is-wide { grid-column: 1 / -1; }

@media (max-width: 760px) {
  .word-row summary {
    grid-template-columns: minmax(0, 1fr) auto 16px;
    grid-template-areas: "word ar chev" "meta meta chev";
    min-height: 58px; padding: 8px 14px; column-gap: 10px;
  }  .word-row-word { gap: 7px; }
  .word-row-word b { font-size: 1rem; line-height: 1.35; }
  .word-row-dot {
    display: block; flex: none; width: 7px; height: 7px; border-radius: 50%;
    background: var(--line-strong); align-self: flex-start; margin-top: .48em;
  }
  .word-row[data-status="learning"] .word-row-dot { background: var(--mark); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--on-mark) 28%, transparent); }
  .word-row[data-status="mastered"] .word-row-dot { background: var(--good); }
  .word-row-ar { max-width: 44vw; font-size: .98rem; line-height: 1.45; }
  .word-row-ar.hint { font-size: var(--text-2xs); }
  .word-row-badges { display: none; }
  .word-row-state, .word-row-sep { display: inline; }
  .word-row-state { font-weight: 600; }
  .word-row-state[data-s="learning"] { color: var(--on-mark); }
  .word-row-state[data-s="mastered"] { color: var(--good); }
  .word-row-sep { margin-inline: 3px; color: var(--line-strong); }
  /* On a phone the meta line carries status, type, level and frequency.
     Tags move to the expanded row: they made the collapsed line end in "#…",
     and they are not what you scan a word list for. Frequency stays whole
     ("Top 12,000"), so at Larger text it moves to a second line intact. */
  .word-row-meta {
    font-size: var(--text-2xs); line-height: 1.35;
    white-space: normal; overflow: visible; text-overflow: clip;
  }
  .word-row-freq { white-space: nowrap; }
  .word-row-tagline { display: none; }
  .word-row-body { padding: 14px 14px 16px; }
  .word-row-body > p { font-size: 1rem; }
  .word-row-chev { align-self: center; }
}
/* A word too long for the two-column phone row gets the full width; its
   Arabic and meta move underneath instead of squeezing both sides. */
@media (max-width: 420px) {
  .word-row.is-long summary {
    grid-template-columns: minmax(0, 1fr) 16px;
    grid-template-areas: "word chev" "ar chev" "meta chev";
    align-items: start; row-gap: 1px; padding-block: 10px;
  }
  .word-row.is-long .word-row-ar { max-width: none; text-align: left; }
  .word-row.is-long .word-row-chev { align-self: center; }
}
@media (max-width: 640px) {
  .lib-filter-label { display: none; }
  .lib-filter-btn { width: 46px; min-width: 46px; padding: 0; position: relative; }
  .lib-filter-btn .pill { position: absolute; top: -6px; inset-inline-end: -4px; min-width: 18px; height: 18px; font-size: .64rem; padding: 0 4px; border: 2px solid var(--page, var(--paper)); }
  .chip-row {
    margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter);
    scroll-snap-type: x proximity; scroll-padding-inline: var(--gutter);
  }
  .chip { min-height: 44px; scroll-snap-align: start; }
  .lib-desc { display: none; }
  .lib-bar { gap: 6px; }
  .lib-actions .btn { min-height: 44px; }
  .lib-more-label { display: none; }
  .lib-actions .lib-more-btn { width: 44px; padding: 0; }

  .page-head h1 { font-size: 1.75rem; }

  .filter-sheet {
    width: 100%; max-width: none; max-height: 88dvh;
    margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
  .filter-body { padding: var(--s-4) var(--gutter) var(--s-3); gap: var(--s-4); }
  .filter-foot { padding: var(--s-3) var(--gutter) calc(var(--s-3) + env(safe-area-inset-bottom)); }
  .filter-foot .btn { flex: 1; }
  .filter-foot .btn-quiet { flex: 0 0 auto; }
}
@media (max-width: 360px) {
  .lib-panel-grid { gap: 8px; }
}
@media (min-width: 641px) {
  .lib-filter-btn .lib-filter-label { display: inline; }
}
@media (min-width: 761px) {
  .word-row summary { min-height: 58px; }
}
@media (max-width: 640px) {
  .word-edit { grid-template-columns: 1fr; }
}
/* Tags: your own groups of words. A tag chip opens the library filtered by it. */
.tag {
  display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 0 var(--s-2);
  border-radius: var(--r-pill); background: var(--surface-2); color: var(--ink-2);
  font-size: var(--text-xs); font-weight: 600; text-decoration: none;
}
.tag:hover { background: var(--brand-soft); color: var(--brand); }
.tag small { font-weight: 500; opacity: .75; }
.word-row-tags { gap: 6px; }

/* Edit → Other meanings: pick the sense you met */
.sense-pick { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); }
.sense-list { flex-basis: 100%; }
.senses { display: grid; gap: var(--s-2); list-style: none; padding: 0; margin: 0; }
.sense-opt {
  display: grid; gap: var(--s-1); width: 100%; text-align: start; padding: var(--s-3);
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--ink);
  font: inherit; cursor: pointer; min-height: var(--tap);
}
.sense-opt:hover { border-color: var(--line-strong); }
.sense-opt[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.sense-opt b { font-weight: 500; line-height: 1.45; }
.sense-opt i { color: var(--ink-2); }
.sense-type { font-size: var(--text-xs); color: var(--ink-3); font-weight: 600; }
.sense-type [lang="ar"] { font-family: var(--font-arabic); font-size: calc(var(--text-sm) * var(--arabic-scale)); color: var(--ink-2); }
.word-row-use { justify-self: start; }
/* The weekly report on the home screen (Thursday, Friday): a reward, so it wears the highlighter */
.week-ready { background: var(--mark-soft); border-color: transparent; }
.week-ready .recall-strip-main > .icon:first-child { color: var(--on-mark); }
