:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #8a97a6;
  --line: #e3e8ee;
  --accent: #3b6ef5;
  --tgt: #1b64d6;
  --tgt-bg: #e6efff;
  --learning-bg: #fff2cf;
  --learning-ink: #8a6d00;
  --review-bg: #ece4ff;
  --review-ink: #6a3fd0;
  --picked-bg: #ffd8d8;
  --picked-ink: #b02020;
  --danger: #d9534f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
header {
  padding: 20px 24px 8px;
}
header h1 { margin: 0; font-size: 24px; }
header .sub { margin: 4px 0 0; color: var(--muted); }
main {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mt { margin-top: 10px; }
label { color: var(--muted); font-size: 14px; }

input, select, textarea, button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}
textarea { width: 100%; resize: vertical; margin: 8px 0; }
.num { width: 72px; }
select { min-width: 200px; }

button {
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 14px;
}
button:hover { filter: brightness(1.05); }
button.ghost { background: #eef1f5; color: var(--ink); padding: 8px 10px; }
button.danger, button.ghost.danger:hover { background: var(--danger); color: #fff; }
button.preset { background: #eef1f5; color: var(--ink); padding: 6px 10px; }
button:disabled { opacity: .5; cursor: default; }

.presets { display: inline-flex; gap: 6px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0; }
.msg { color: var(--muted); font-size: 14px; }
.msg.err { color: var(--danger); }
.msg.ok { color: #2e9e5b; }

.counts { display: flex; gap: 12px; margin-top: 8px; color: var(--muted); font-size: 14px; }
.counts b { color: var(--ink); }

details summary { cursor: pointer; color: var(--accent); margin-top: 12px; }

/* Real-quote epigraph shown above the generated passage */
.epigraph {
  margin: 4px 0 14px;
  padding: 10px 16px;
  background: #f0f0fb;
  border-left: 3px solid var(--review-ink);
  border-radius: 6px;
}
.epigraph .epq { font-style: italic; font-size: 17px; line-height: 1.5; }
.epigraph .epby { color: var(--review-ink); margin-top: 6px; font-weight: 600; }
.epigraph .ephint { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* Passage metadata (title / author / description) shown above the text */
.cardmeta {
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 12px;
  margin: 4px 0 14px;
}
.cardmeta .ct { font-size: 20px; font-weight: 700; line-height: 1.3; }
.cardmeta .ca { color: var(--muted); font-style: italic; margin-top: 2px; }
.cardmeta .cd { color: var(--muted); font-size: 14px; margin-top: 5px; }

/* Reader */
.reader {
  font-size: 19px;
  line-height: 1.9;
  padding: 6px 2px;
  white-space: pre-wrap;
}
/* every word is clickable */
.w {
  display: inline-block;
  position: relative;
  min-width: 4ch; /* room for ~4 letters so the ↻ tab has space on short words */
  text-align: center;
  border-radius: 5px;
  padding: 0 2px;
  cursor: pointer;
}
/* dictionary word, not yet passed */
.w.new {
  background: var(--tgt-bg);
  color: var(--tgt);
  font-weight: 600;
}
/* standalone (not in dictionary) word, not yet passed */
.w.loose.new {
  background: transparent;
  color: var(--tgt);
  font-weight: 400;
  border-bottom: 1px dotted var(--tgt);
}
.w.known { color: var(--muted); background: transparent; font-weight: 400; }
.w.learning {
  background: var(--learning-bg);
  color: var(--learning-ink);
  font-weight: 400;
  border-bottom: none;
}
.w.review {
  background: var(--review-bg);
  color: var(--review-ink);
  font-weight: 400;
  border-bottom: none;
}
.w.picked {
  background: var(--picked-bg) !important;
  color: var(--picked-ink) !important;
  border-bottom: none !important;
  text-decoration: underline;
}
.w.revpick {
  background: var(--review-ink) !important;
  color: #fff !important;
  border-bottom: none !important;
  text-decoration: none;
}

/* hover tab: sends a word to the "Повторить" list. Full-height and INSIDE the
   word bubble at its right edge — so following words can't overlap it and there
   is no external gap to cross. Icon ↻ ("repeat") fits «Повторить». */
.ball {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 16px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: var(--review-ink);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.18);
}
.ball::before { content: "↻"; font-weight: 700; }
.w:hover .ball,
.w.revpick .ball,
.w.review .ball { display: flex; }
.ball:hover { width: 19px; }

.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 20px; }
.chip.newd { background: var(--tgt-bg); color: var(--tgt); }
.chip.newl { background: #fff; color: var(--tgt); border: 1px dotted var(--tgt); }
.chip.known { background: #eef1f5; color: var(--muted); }
.chip.learning { background: var(--learning-bg); color: var(--learning-ink); }
.chip.review { background: var(--review-bg); color: var(--review-ink); }
.chip.picked { background: var(--picked-bg); color: var(--picked-ink); }

.subh { font-size: 14px; color: var(--muted); margin: 14px 0 6px; }

/* Study list */
.badge {
  background: var(--learning-bg);
  color: var(--learning-ink);
  border-radius: 20px;
  padding: 1px 9px;
  font-size: 13px;
  vertical-align: middle;
}
.study { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 24px; }
.study li { padding: 3px 0; break-inside: avoid; }
.study .tr { color: var(--muted); font-size: 13px; }
