:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a202c;
  --muted: #5a6577;
  --border: #d5dbe4;
  --accent: #3182ce;
  --accent-dark: #2b6cb0;
  --accent-soft: #ebf8ff;
  --good: #2f855a;
  --good-soft: #e6f6ec;
  --bad: #c53030;
  --bad-soft: #fdecec;
  --warn: #975a16;
  --warn-soft: #fef5e7;
  --radius: 10px;
  --radius-sm: 6px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-sheet: Arial, Helvetica, sans-serif;
  --font-he: "Noto Sans Hebrew", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.5;
}

[lang="he"] { font-family: var(--font-he); }

a { color: var(--accent-dark); }

.topbar {
  background: var(--accent-dark);
  padding: 12px 16px;
}
.brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
}
.brand span { font-weight: 400; margin-left: 6px; opacity: .9; }

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 4px; }
.lede, .hint { color: var(--muted); margin: 0 0 20px; }
.hint { font-size: .9rem; margin: 8px 0 16px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn:focus-visible, .option:focus-visible, .match-item:focus-visible, .tab:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Home */
.lesson-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.lesson-card {
  display: grid;
  gap: 2px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.lesson-card:hover { border-color: var(--accent); }
.lesson-date { color: var(--muted); font-size: .9rem; }
.lesson-title { font-size: 1.15rem; font-weight: 700; }
.lesson-meta { color: var(--muted); font-size: .9rem; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); }
.notice.error { background: var(--bad-soft); color: var(--bad); }

/* Lesson header */
.back { display: inline-block; margin-bottom: 12px; text-decoration: none; }
.lesson-head .lesson-date { margin: 0 0 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 10px 16px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.toggle { display: inline-flex; align-items: center; gap: 8px; margin-right: auto; cursor: pointer; }
.toggle input { width: 18px; height: 18px; }

/* Printable page: an A4 sheet at 96 dpi, scaled down to fit narrow screens */
.page-frame {
  max-width: 794px;
  margin: 0 auto;
  overflow: hidden;
}
.page {
  width: 794px;
  height: 1123px;
  padding: 34px;
  background: #fff;
  color: #1a202c;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 6px 20px rgba(0, 0, 0, .08);
  transform-origin: top left;
  overflow: hidden;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.sheet { font-family: var(--font-sheet); font-size: 14px; }
.sheet-title { text-align: center; font-size: 1.7em; margin: 0; color: #1a365d; }
.sheet-subtitle { text-align: center; font-style: italic; margin: .1em 0 .5em; color: #4a5568; }
.sheet table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.sheet th, .sheet td {
  border: 1px solid #a0aec0;
  padding: .14em .45em;
  vertical-align: middle;
  text-align: left;
  line-height: 1.22;
}
.sheet thead th { background: #3182ce; color: #fff; }
.sheet th.he, .sheet td.he { text-align: right; }
.sheet td.he { font-family: var(--font-he); font-size: 1.12em; line-height: 1.15; }
.sheet td.tr { font-style: italic; }
.sheet tr.section td {
  background: #ebf8ff;
  color: #2b6cb0;
  font-weight: 700;
  text-align: center;
}
.sheet .form { white-space: nowrap; }
.sheet .sep { color: #718096; }
.sheet-notes { margin: .8em 0 0; font-size: .9em; color: #2d3748; }

/* Quiz */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
}
.quiz-progress { color: var(--muted); font-size: .9rem; margin: 0 0 8px; }
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; margin-bottom: 20px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); }
.prompt { font-size: 1.4rem; font-weight: 700; margin: 0 0 20px; }
.options { display: grid; gap: 10px; }
.option, .match-item {
  width: 100%;
  min-height: 52px;
  padding: 10px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
}
.option { text-align: right; }
.option:hover:not(:disabled), .match-item:hover:not(:disabled) { border-color: var(--accent); }
.option:disabled, .match-item:disabled { cursor: default; }
.option.correct, .match-item.matched { border-color: var(--good); background: var(--good-soft); color: var(--text); }
.option.wrong, .match-item.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.faded { opacity: .55; }
.match-item.selected { border-color: var(--accent); background: var(--accent-soft); }
.feedback { margin: 16px 0 0; font-weight: 600; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.feedback .tr { font-style: italic; font-weight: 400; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 20px; }

.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.match-col { display: grid; gap: 10px; align-content: start; }
.match-item.en { font-size: 1rem; text-align: left; }
.match-item.he { text-align: right; }

.field { display: grid; gap: 6px; margin: 16px 0; max-width: 360px; }
.field input {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
}

.score { font-size: 2.6rem; font-weight: 800; margin: 0; color: var(--accent-dark); }
.missed { margin-top: 20px; }
.missed h3 { font-size: 1rem; margin: 0 0 8px; }
.missed ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.missed li { padding: 10px 12px; background: var(--bg); border-radius: var(--radius-sm); }
.missed .he { font-size: 1.2rem; display: block; text-align: right; }
.missed .tr { font-style: italic; color: var(--muted); }
.send-status { color: var(--muted); font-size: .9rem; margin-top: 12px; }
.send-status.bad { color: var(--bad); }

/* Footer */
.site-footer { text-align: center; padding: 0 16px 32px; font-size: .9rem; }
.site-footer a { color: var(--muted); }

/* Teacher dashboard */
.muted { color: var(--muted); }
.dash-toolbar { margin-bottom: 16px; }
.dash-status { margin: 0 auto 0 0; color: var(--muted); font-size: .9rem; }
.dash-card { margin-bottom: 16px; }
.dash-card h2 { font-size: 1.1rem; margin: 0 0 4px; }
.dash-card .hint { margin: 0 0 12px; }
.grid-scroll { overflow-x: auto; }
.score-grid { border-collapse: collapse; min-width: 100%; }
.score-grid th, .score-grid td { padding: 6px; border-bottom: 1px solid var(--border); text-align: center; }
.score-grid thead th { vertical-align: bottom; font-weight: 600; min-width: 110px; }
.score-grid th:first-child { text-align: left; min-width: 120px; position: sticky; left: 0; background: var(--surface); }
.score-grid tbody th { font-weight: 600; }
.col-date { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; }
.col-title { display: block; font-size: .85rem; }
.score-grid td.empty { color: var(--muted); }
.cell {
  display: grid;
  width: 100%;
  min-height: 44px;
  padding: 4px 8px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}
.cell-score { font-weight: 700; }
.cell-tries { font-size: .75rem; color: var(--muted); }
.cell.good, .score-pill.good { background: var(--good-soft); color: var(--good); }
.cell.ok, .score-pill.ok { background: var(--warn-soft); color: var(--warn); }
.cell.low, .score-pill.low { background: var(--bad-soft); color: var(--bad); }
.cell.selected { border-color: var(--accent); }
.cell:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.score-pill { padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.attempts, .recent { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.attempts li { padding: 10px 12px; background: var(--bg); border-radius: var(--radius-sm); }
.attempt-head { display: flex; gap: 12px; align-items: center; }
.attempt-missed { margin: 6px 0 0; font-size: .9rem; }
.recent li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.recent li:last-child { border-bottom: 0; }
.recent-name { font-weight: 600; }
.recent .muted { grid-column: 1; font-size: .9rem; }
.recent .score-pill { grid-column: 2; grid-row: 1 / span 2; align-self: center; }

@media (max-width: 560px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 18px 14px; }
  .prompt { font-size: 1.2rem; }
  .option, .match-item { font-size: 1.15rem; }
  .match-item.en { font-size: .9rem; }
}

/* Printing: only the lesson page, exactly one A4 sheet */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  .no-print, .topbar { display: none !important; }
  main { padding: 0; max-width: none; }
  .page-frame { max-width: none; height: auto !important; overflow: visible; }
  .page {
    transform: none !important;
    box-shadow: none;
    width: 210mm;
    height: 296mm;
    padding: 9mm;
  }
}
