:root {
      --ink:#1c1917;
      --ink-soft:#44403c;
      --muted:#78716c;
      --line:#e7e5e4;
      --bg:#fafaf9;
      --accent:#2563eb;
      --accent-soft:#dbeafe;
      --ok:#16a34a;
    }
    * { box-sizing: border-box; }
    html, body { margin:0; padding:0; background:var(--bg); color:var(--ink); font-family:'Heebo', system-ui, -apple-system, Arial, sans-serif; }
    .wrap { max-width: 820px; margin: 0 auto; padding: 18px 16px 80px; }

    .topbar {
      display:flex; align-items:center; justify-content:space-between;
      padding: 10px 14px; background:#fff; border:1px solid var(--line);
      border-radius: 14px; margin-bottom: 14px;
    }
    .topbar a { color: var(--accent); font-weight: 800; text-decoration:none; font-size:14px; }
    .topbar .brand { font-weight:800; font-size:14px; color:var(--ink); }

    /* Loading / error states */
    .state { text-align:center; padding:40px 16px; color:var(--muted); }
    .state.error { color:#b91c1c; }
    .state .retry { display:inline-block; margin-top:12px; padding:8px 14px; border-radius:8px; background:var(--accent); color:#fff; text-decoration:none; font-weight:700; }

    /* === Worksheet (the printable doc) === */
    .worksheet {
      background:#fff;
      border-radius: 16px;
      padding: 28px 28px 32px;
      border: 1px solid var(--line);
      box-shadow: 0 4px 20px rgba(0,0,0,.04);
    }
    .ws-header {
      display:flex; align-items:flex-end; justify-content:space-between;
      gap:16px; padding-bottom:14px; border-bottom: 2px solid var(--ink); margin-bottom:18px;
    }
    .ws-title { font-size: 22px; font-weight: 800; line-height:1.2; margin:0; }
    .ws-meta { font-size: 12px; color: var(--muted); line-height:1.7; text-align:left; min-width: 160px; }
    .ws-meta b { color: var(--ink); }
    .ws-fields { display:flex; gap:12px; padding: 10px 0 18px; font-size:13px; color: var(--ink-soft); border-bottom: 1px dashed var(--line); margin-bottom:18px; }
    .ws-fields .f { flex:1; display:flex; align-items:baseline; gap:6px; }
    .ws-fields .f span { font-weight:700; }
    .ws-fields .line { flex:1; border-bottom:1px solid var(--line); transform: translateY(-3px); }

    .ws-intro {
      background: var(--accent-soft);
      padding: 12px 14px; border-radius: 10px; margin-bottom: 18px;
      font-size: 13.5px; color: var(--ink-soft); line-height:1.6;
    }

    /* === Reading passage block === */
    .passage-block {
      background: #fffbeb;
      border: 1px solid #fde68a;
      border-radius: 12px;
      padding: 14px 16px 16px;
      margin: 18px 0 12px;
      page-break-inside: avoid;
      break-inside: avoid;
    }
    .passage-head {
      display:flex; align-items:baseline; gap:10px;
      margin-bottom: 8px; padding-bottom:6px;
      border-bottom: 1px dashed #fcd34d;
    }
    .passage-head .p-tag {
      background: #b45309; color:#fff;
      padding: 2px 10px; border-radius: 999px;
      font-size: 11px; font-weight: 800; flex: 0 0 auto;
    }
    .passage-head .p-title { margin: 0; font-size: 14.5px; font-weight: 800; color: #78350f; }
    .passage-body { font-size: 13.5px; line-height: 1.75; color: var(--ink-soft); }
    .passage-body p { margin: 0 0 8px; }
    .passage-body p:last-child { margin-bottom: 0; }
    .passage-block[data-lang="en"] .passage-body { text-align: left; }

    .q {
      padding: 14px 0 16px;
      border-bottom: 1px solid var(--line);
      page-break-inside: avoid;
      break-inside: avoid;
    }
    .q:last-of-type { border-bottom: 0; }
    .q-head {
      display:flex; align-items:baseline; gap:8px; margin-bottom:8px;
    }
    .q-num {
      flex: 0 0 auto;
      background: var(--ink); color:#fff;
      border-radius: 999px;
      padding: 2px 10px;
      font-weight: 800; font-size: 13px;
      min-width: 28px; text-align:center;
    }
    .q-diff { font-size:11px; color:var(--muted); margin-inline-start:auto; }
    .q-stimulus { font-size: 14px; line-height:1.65; margin: 0 0 8px; color: var(--ink-soft); white-space:pre-wrap; }
    .q-text { font-size: 15px; line-height:1.65; margin: 0 0 10px; color: var(--ink); white-space:pre-wrap; }
    .q-opts { list-style: none; padding: 0; margin: 0; counter-reset: opt; }
    .q-opts li {
      display:flex; align-items:flex-start; gap:8px;
      padding: 5px 0;
      font-size: 14px; line-height:1.6;
      counter-increment: opt;
    }
    .q-opts li::before {
      content: counter(opt, hebrew) ".";
      font-weight: 800; min-width: 22px; color: var(--ink-soft);
    }
    /* English worksheets use Latin numerals */
    .worksheet[data-script="en"] .q-opts li::before {
      content: "(" counter(opt, lower-alpha) ")";
    }

    /* === Answer key === */
    .answer-key {
      margin-top: 28px;
      padding-top: 18px;
      border-top: 3px double var(--ink);
      page-break-before: always;
      break-before: page;
    }
    .answer-key h2 { font-size: 18px; margin: 0 0 12px; }
    .ak-grid {
      display:grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
      gap: 8px;
      margin-bottom: 20px;
    }
    .ak-grid .ak-cell {
      background: var(--bg);
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 8px 10px;
      font-size: 13px;
    }
    .ak-cell b { color: var(--ok); }
    .explanations h3 { font-size: 15px; margin: 18px 0 6px; }
    .ex-item {
      padding: 10px 0;
      border-bottom: 1px dashed var(--line);
      font-size: 13.5px; line-height:1.65; color: var(--ink-soft);
      page-break-inside: avoid;
    }
    .ex-item b { color: var(--ink); }

    .ws-footer {
      margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line);
      text-align:center; font-size: 12px; color: var(--muted);
    }
    .ws-footer a { color: var(--accent); font-weight:700; text-decoration:none; }

    /* === Fresh / frozen banner === */
    .fresh-banner {
      background: linear-gradient(90deg, #dbeafe, #ede9fe);
      border: 1px solid #c7d2fe;
      border-radius: 10px;
      padding: 9px 14px;
      font-size: 13px;
      color: var(--ink-soft);
      margin: 14px 0 6px;
      text-align: center;
    }
    .fresh-banner a { color: var(--accent); font-weight: 800; text-decoration: underline; }
    .fresh-banner b { color: var(--ink); }
    .fresh-banner:empty { display: none; }

    /* === Toggle answer key === */
    .ws-controls-inline {
      display:flex; gap:8px; flex-wrap:wrap; padding: 12px 0 4px;
    }
    .ws-controls-inline button {
      padding: 8px 14px; border-radius: 999px; border:1px solid var(--line); background:#fff;
      font-family: inherit; font-weight: 700; font-size: 13px; cursor:pointer;
      touch-action: manipulation;
    }
    .ws-controls-inline button.primary { background: var(--accent); color:#fff; border-color: var(--accent); }
    .ws-controls-inline button:hover { background: var(--bg); }
    .ws-controls-inline button.primary:hover { background: #1e40af; }
    .answer-key[hidden] { display: none !important; }

    /* === Hide chrome during html2pdf desktop capture === */
    .psychome-pdf-generating .topbar,
    .psychome-pdf-generating .ws-controls-inline,
    .psychome-pdf-generating .no-print { display: none !important; }
    .psychome-pdf-generating .answer-key[hidden] { display: block !important; }

    /* === Print CSS — clean A4 output === */
    @media print {
      body { background: #fff !important; }
      .topbar, .ws-controls-inline, .psychome-share-fab, .a11y-fab, .a11y-panel, .skip-link, .no-print { display:none !important; }
      .answer-key[hidden] { display: block !important; } /* always print key */
      .wrap { padding: 0; max-width: none; }
      .worksheet { box-shadow:none; border:0; padding: 0; border-radius: 0; }
      .q, .ex-item { page-break-inside: avoid; break-inside: avoid; }
      .ws-header, h2, h3 { page-break-after: avoid; }
      a { color: inherit !important; text-decoration: none !important; }
      .ws-meta { color: #555 !important; }
    }

    @media (max-width:640px) {
      .wrap { padding: 10px 10px 80px; }
      .worksheet { padding: 18px 14px 22px; }
      .ws-title { font-size: 18px; }
      .ws-header { flex-direction: column; align-items: flex-start; }
      .ws-meta { text-align: right; }
      .ws-fields { flex-direction: column; gap: 6px; }
    }
    /* === LTR-isolated math sub-expressions inside Hebrew RTL ===
       Prevents "(2³ × 2²) / 2⁴" from being scrambled to "(2⁴ / ²2 × ³2)" */
    .math-ltr { direction: ltr; unicode-bidi: bidi-override; display: inline-block; }
