/* Kinyan reader — mobile-first, scales to desktop, prints as a study sheet.
   The layout is deliberately app-shaped (sticky header, thumb-reachable
   controls, one column of content) because this is a website standing in for
   an app; widening it for desktop should not turn it into a different design. */

@font-face {
  font-family: 'Frank Ruhl Libre';
  font-weight: 300 900;
  font-display: swap;
  src: url('FrankRuhlLibre.f9bf269666.ttf') format('truetype');
}

:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #2a2620;
  --muted: #9a917f;
  --accent: #8a6d3b;
  --line: #e7e0d2;
  --hi: #fbeecb;
  --heman: #7a5c2e;
  --en: #33564f;
  --ensep: #c2a15a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06);
  --he-size: 25px;
  --maxw: 720px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17150f;
    --card: #201d16;
    --ink: #ece5d6;
    --muted: #8d8474;
    --accent: #c9a45f;
    --line: #322d22;
    --hi: #3a3016;
    --heman: #e0c383;
    --en: #8fc4b6;
    --ensep: #a9803f;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ---------------------------------------------------------------- header */

.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 0 0;
}
.top .bar {
  display: flex; align-items: center; gap: 10px;
  max-width: var(--maxw); margin: 0 auto; padding: 10px 14px;
}
.iconbtn {
  flex: none; width: 38px; height: 38px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--bg); color: var(--accent);
  font-size: 17px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}
.iconbtn:disabled { opacity: .32; cursor: default; }
.iconbtn:active:not(:disabled) { background: var(--hi); }

.title {
  flex: 1; min-width: 0; text-align: center;
  background: none; border: 0; color: inherit; cursor: pointer; padding: 0;
  font: inherit;
}
.title .he {
  font-family: 'Frank Ruhl Libre', serif; font-weight: 800; font-size: 19px;
  direction: rtl; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.title .sub {
  font-size: 11px; color: var(--muted); letter-spacing: .07em;
  text-transform: uppercase; margin-top: 1px;
}
.title .sub::after { content: " ▾"; opacity: .55; }
/* the vocabulary header is not a picker, so it must not look like one */
.title.static { cursor: default; }
.title.static .sub::after { content: none; }

.toolbar {
  display: flex; gap: 7px; justify-content: center; flex-wrap: wrap;
  max-width: var(--maxw); margin: 0 auto; padding: 0 14px 10px;
}
.chip {
  font-size: 12.5px; padding: 6px 13px; border-radius: 15px;
  border: 1px solid var(--line); background: var(--bg); color: var(--accent);
  cursor: pointer; user-select: none; font-family: inherit;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip:disabled { opacity: .4; cursor: default; }

/* ---------------------------------------------------------------- content */

main { max-width: var(--maxw); margin: 0 auto; padding: 10px 12px 92px; }

.seg {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 13px 13px 11px; margin: 0 0 11px; box-shadow: var(--shadow);
}
.seg .tag {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 9px;
}
.seg .tag .k { color: var(--accent); font-weight: 700; }

.words { display: flex; flex-wrap: wrap; gap: 10px 4px; direction: rtl; align-items: flex-start; }
.set { display: flex; flex-direction: column; align-items: center; margin: 0 5px; }
.setrow { display: flex; direction: rtl; gap: 0 8px; align-items: flex-start; }

.w {
  display: flex; flex-direction: column; align-items: center;
  padding: 3px 4px 2px; border-radius: 9px; cursor: pointer;
  transition: background .12s;
}
.w .he {
  font-family: 'Frank Ruhl Libre', serif; font-weight: 500;
  font-size: var(--he-size); line-height: 1.38; color: var(--ink);
}
.w .tl {
  font-size: 11px; color: var(--muted); direction: ltr; margin-top: 1px;
  white-space: nowrap;
}
.w.sel { background: var(--hi); }
.w.sel .tl { color: var(--heman); font-weight: 600; }

.en {
  direction: ltr; font-size: 12px; line-height: 1.32; color: var(--en);
  text-align: center; margin-top: 3px; max-width: 190px;
}
.en .sep { color: var(--ensep); font-weight: 700; margin-right: 4px; }

body.hide-tl .w .tl { display: none; }
body.hide-en .en { display: none; }
body.hide-en .words { gap: 5px 10px; }
body.hide-en .set { margin: 0; }

.note {
  background: var(--card); border: 1px dashed var(--line); border-radius: 14px;
  padding: 13px 15px; color: var(--muted); font-size: 13px; margin: 0 0 11px;
}
.note b { color: var(--ink); }

/* Attribution. CC BY-NC requires credit wherever the text is shown, so this
   sits on every page and is deliberately not hidden when printing. */
.credit {
  margin: 18px 2px 0; padding-top: 12px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 11.5px; line-height: 1.6; text-align: center;
}
.credit a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* ---------------------------------------------------------------- footer nav */

.pager {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
}
.pager .inner { display: flex; gap: 9px; max-width: var(--maxw); margin: 0 auto; }
.pager a, .pager span {
  flex: 1; text-align: center; padding: 11px 8px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); font-size: 13.5px;
  color: var(--accent); font-weight: 600;
}
.pager span { opacity: .35; }

/* ---------------------------------------------------------------- index */

.hero { text-align: center; padding: 22px 14px 6px; }
.hero h1 {
  font-family: 'Frank Ruhl Libre', serif; font-weight: 800; font-size: 30px;
  margin: 0; direction: rtl;
}
.hero p { color: var(--muted); font-size: 13.5px; margin: 6px 0 0; }

.grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  margin: 14px 0 4px;
}
.grid a {
  position: relative; display: grid; place-items: center; gap: 1px;
  aspect-ratio: 1 / 1; border-radius: 13px; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 15px; font-weight: 600; color: var(--ink);
}
.grid a:active { background: var(--hi); }
.grid a .dot {
  width: 5px; height: 5px; border-radius: 50%; background: var(--ensep);
}
.grid a.plain .dot { background: transparent; }

.legend {
  display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
  color: var(--muted); font-size: 12px; margin: 14px 0 26px;
}
.legend i { display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--ensep); margin-right: 5px; vertical-align: middle; }

.sectionhead {
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin: 20px 0 8px; font-weight: 700;
}

/* ---------------------------------------------------------------- picker */

.picker[hidden] { display: none !important; }
.picker {
  position: fixed; inset: 0; z-index: 40; background: rgba(20, 17, 12, .45);
  display: grid; place-items: end center;
}
.picker .sheet {
  width: 100%; max-width: var(--maxw); max-height: 78vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 16px 14px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
}
.picker h2 { margin: 0 0 12px; font-size: 15px; text-align: center; }
.picker .close {
  display: block; width: 100%; margin-top: 12px; padding: 12px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
}

/* ---------------------------------------------------------------- responsive */

@media (min-width: 640px) {
  :root { --he-size: 27px; --maxw: 760px; }
  .en { font-size: 12.5px; max-width: 220px; }
  .w .tl { font-size: 11.5px; }
  main { padding: 16px 16px 96px; }
  .hero h1 { font-size: 36px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; }
}

@media (min-width: 1024px) {
  :root { --he-size: 29px; --maxw: 900px; }
  .seg { padding: 17px 18px 14px; border-radius: 18px; }
  .en { max-width: 250px; }
  /* the pager stops being a thumb bar and sits with the content */
  .pager { position: static; border-top: 0; background: transparent; padding: 4px 12px 40px; }
  main { padding-bottom: 8px; }
}

/* ---------------------------------------------------------------- print */

@page { size: letter; margin: 0.6in; }

@media print {
  :root { --he-size: 23px; --maxw: none; }
  body { background: #fff; color: #000; }
  .top, .pager, .picker, .no-print { display: none !important; }
  main { max-width: none; padding: 0; }
  .seg {
    background: none; border: 0; border-top: 1px solid #ccc;
    border-radius: 0; box-shadow: none; padding: 8px 0 4px; margin: 0 0 6px;
    break-inside: auto;
  }
  .set { break-inside: avoid; }
  .en { color: #1f4f45; }
  .w .tl { color: #555; }
  /* printing follows what is on screen, so a hidden row stays hidden */
}

/* ---------------------------------------------------------------- vocabulary */

.vocab { list-style: none; margin: 0 0 10px; padding: 0; }
.vocab li {
  display: flex; align-items: baseline; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 12px; margin: 0 0 6px; box-shadow: var(--shadow);
}
.vocab .vn { color: var(--muted); font-size: 10.5px; min-width: 2.1em; flex: none; }
.vocab .vw {
  font-family: 'Frank Ruhl Libre', serif; font-weight: 500; font-size: 21px;
  direction: rtl; flex: none; min-width: 5.5em; text-align: right;
}
.vocab .vg { flex: 1; font-size: 13px; color: var(--en); direction: ltr; }
.vocab .vg.none { color: var(--muted); font-style: italic; }

@media (min-width: 640px) {
  .vocab { columns: 2; column-gap: 14px; }
  .vocab li { break-inside: avoid; }
}
@media (min-width: 1024px) { .vocab { columns: 3; } }
@media print { .vocab { columns: 2; } .vocab li { border: 0; box-shadow: none;
  background: none; padding: 3px 0; break-inside: avoid; } }

/* ---------------------------------------------------------------- quiz */

.qwrap { max-width: 560px; margin: 0 auto; }
.qbar { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 4px 0 14px; }
.qbar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .25s; }
.qcount { text-align: center; font-size: 11.5px; color: var(--muted); letter-spacing: .06em; }

.qcard {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px 18px; box-shadow: var(--shadow); text-align: center;
}
.qprompt { margin: 6px 0 4px; }
.qprompt.he { font-family: 'Frank Ruhl Libre', serif; font-weight: 500; font-size: 40px;
  direction: rtl; line-height: 1.35; }
.qprompt.en { font-size: 22px; font-weight: 600; color: var(--en); }
.qhint { color: var(--muted); font-size: 12.5px; margin-bottom: 16px; }

.qopts { display: grid; gap: 8px; }
.qopt {
  font: inherit; font-size: 14.5px; text-align: left; padding: 13px 15px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  color: var(--ink); cursor: pointer;
}
.qopt:active:not(:disabled) { background: var(--hi); }
.qopt:disabled { cursor: default; opacity: .75; }
.qopt.right { background: #e8f3ec; border-color: #7fae90; color: #17512f; opacity: 1; }
.qopt.wrong { background: #f7e9e6; border-color: #c79086; color: #7a2f22; opacity: 1; }

.qinput {
  width: 100%; font: inherit; font-family: 'Frank Ruhl Libre', serif; font-size: 30px;
  padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); text-align: center;
}
.qinput.right { border-color: #7fae90; background: #e8f3ec; }
.qinput.wrong { border-color: #c79086; background: #f7e9e6; }

.qgo {
  margin-top: 12px; width: 100%; font: inherit; font-weight: 600; font-size: 14.5px;
  padding: 12px; border-radius: 12px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer;
}
.qgo:disabled { opacity: .45; cursor: default; }

.qfeed { margin-top: 14px; }
.qfeed .fline { font-weight: 700; font-size: 14px; }
.qfeed.good .fline { color: #17703f; }
.qfeed.bad .fline { color: #a33a26; }
.qfeed .fans { margin-top: 6px; font-size: 15px; }
.qfeed .fans .he { font-family: 'Frank Ruhl Libre', serif; font-size: 24px; direction: rtl; }
.qfeed .fnote { color: var(--muted); font-size: 12px; margin-top: 4px; }
.qdone { font-size: 40px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .qopt.right { background: #17301f; border-color: #3f7a55; color: #b9e3c6; }
  :root:not([data-theme="light"]) .qopt.wrong { background: #331d19; border-color: #8a4c40; color: #ecbcb0; }
  :root:not([data-theme="light"]) .qinput.right { background: #17301f; border-color: #3f7a55; }
  :root:not([data-theme="light"]) .qinput.wrong { background: #331d19; border-color: #8a4c40; }
}
