/* ==========================================================================
   MathMaster – spausdinamas A4 darbo lapas
   ==========================================================================

   Du režimai viename faile:
     * EKRANE – lapas rodomas kaip peržiūra tamsiame fone (galima pasirinkti
       kitą variantą arba uždaryti);
     * SPAUSDINANT (`@media print`) – viskas, išskyrus patį lapą, paslepiama,
       o lapas paverčiamas tikru A4 puslapiu su 12 mm paraštėmis.

   Matmenys nurodyti milimetrais, todėl išvaizda nepriklauso nuo ekrano.
   ========================================================================== */

.ws-overlay[hidden] { display: none; }

.ws-overlay {
  position: fixed; inset: 0; z-index: 90;
  overflow: auto; padding: 24px 16px 60px;
  background: rgba(15, 23, 42, .72);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}

/* ------------------------------ įrankiai -------------------------------- */

.ws-toolbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  max-width: 210mm; margin: 0 auto 16px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--card); box-shadow: var(--shadow-md);
}
.ws-hint { font-size: .8rem; color: var(--muted); font-weight: 600; }

/* -------------------------------- lapas --------------------------------- */

.ws-sheet {
  width: 210mm; min-height: 297mm;
  margin: 0 auto 18px; padding: 12mm 12mm 10mm;
  background: #FFFFFF; color: #0F172A;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .35);
  font-size: 10.5pt; line-height: 1.35;
}

.ws-head {
  display: flex; gap: 10mm; align-items: flex-start;
  padding-bottom: 3mm; margin-bottom: 4mm;
  border-bottom: 2px solid #4F46E5;
}
.ws-head-main { flex: 1; min-width: 0; }
.ws-brand { margin: 0 0 1mm; font-size: 9pt; font-weight: 800; color: #4F46E5; letter-spacing: .02em; }
.ws-title { margin: 0 0 2.5mm; font-size: 14pt; font-weight: 800; line-height: 1.15; }
.ws-title-2 { margin: 0; font-size: 13pt; font-weight: 800; }

.ws-fields { display: flex; flex-wrap: wrap; gap: 4mm 8mm; font-size: 9.5pt; font-weight: 600; }
.ws-field { display: inline-flex; align-items: baseline; gap: 2mm; }
.ws-line {
  display: inline-block; min-width: 26mm;
  border-bottom: 1px solid #94A3B8; text-align: center; font-weight: 700;
}
.ws-line-lg { min-width: 58mm; }
.ws-line-sm { min-width: 16mm; }

.ws-qr { display: flex; flex-direction: column; align-items: center; gap: 1mm; width: 26mm; }
.ws-qr svg { width: 24mm; height: 24mm; display: block; }
.ws-qr-cap { font-size: 6.5pt; color: #475569; text-align: center; line-height: 1.15; }
.ws-qr-none {
  display: grid; place-items: center; width: 24mm; height: 24mm;
  border: 1px dashed #94A3B8; color: #94A3B8; font-size: 8pt; font-weight: 700;
}

/* ------------------------------ uždaviniai ------------------------------ */

.ws-tasks {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 4mm 6mm;
}
.ws-task {
  border: 1px solid #CBD5E1; border-radius: 2mm;
  padding: 3mm 3mm 2mm; break-inside: avoid; page-break-inside: avoid;
}
.ws-task-head { display: flex; align-items: center; gap: 2mm; margin-bottom: 1.5mm; }
.ws-no {
  width: 6mm; height: 6mm; display: grid; place-items: center;
  border-radius: 50%; background: #4F46E5; color: #FFFFFF;
  font-size: 8.5pt; font-weight: 800;
}
.ws-diff { font-size: 7pt; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.ws-diff-1 { color: #16A34A; }
.ws-diff-2 { color: #D97706; }
.ws-diff-3 { color: #DC2626; }

.ws-prompt { font-size: 10pt; min-height: 8mm; }
.ws-prompt .math { font-weight: 700; }
.ws-viz { margin: 1.5mm 0; text-align: center; }
/* Geometrijos brėžiniai ir funkcijų grafikai popieriuje buvo per maži –
   mokiniai nematydavo kraštinių/kampų žymų. `svg` (be `width`/`height`
   atributų, tik `viewBox` – žr. `shapeSVG`/`coordGridHTML`) ir `img`
   (paruoštos PNG diagramos) dabar auga iki bent 50mm aukščio, bet neperžengia
   85mm pločio – tiek telpa į vieno uždavinio kortelės plotį 2 stulpelių
   tinklelyje. */
.ws-viz img,
.ws-viz svg {
  display: block; margin: 0 auto;
  width: auto; height: auto;
  min-height: 50mm; max-width: 85mm;
}

.ws-space { display: block; margin: 2mm 0 1.5mm; }
.ws-space span { display: block; height: 5mm; border-bottom: 1px dotted #CBD5E1; }

.ws-ans { font-size: 9pt; font-weight: 700; display: flex; align-items: baseline; gap: 2mm; }
.ws-ans-line { flex: 1; border-bottom: 1.5px solid #0F172A; height: 4mm; }

.ws-foot {
  display: flex; justify-content: space-between; gap: 6mm;
  margin-top: 5mm; padding-top: 2mm;
  border-top: 1px solid #E2E8F0;
  font-size: 7.5pt; color: #64748B;
}

/* Kraštutinis atvejis: labai ilgos sąlygos. Sumažiname raidžių dydį, kad
   visi dešimt uždavinių vis tiek liktų viename lape. */
.ws-sheet.is-tight { font-size: 9.5pt; }
.ws-sheet.is-tight .ws-prompt { font-size: 9pt; min-height: 6mm; }
.ws-sheet.is-tight .ws-task { padding: 2mm 2.5mm 1.5mm; }
.ws-sheet.is-tight .ws-space span { height: 4.5mm; }
.ws-sheet.is-tight .ws-title { font-size: 13pt; }

/* --------------------------- antras puslapis ---------------------------- */

.ws-sheet-2 { min-height: auto; }
.ws-head-2 { align-items: center; }

.ws-table {
  width: 100%; border-collapse: collapse; margin-top: 4mm; font-size: 10pt;
}
.ws-table th, .ws-table td {
  border: 1px solid #CBD5E1; padding: 2mm 3mm; text-align: left;
}
.ws-table th { background: #EEF2FF; font-size: 9pt; font-weight: 800; }
.ws-t-no { width: 12mm; text-align: center; font-weight: 800; }
.ws-t-ans { font-weight: 700; }
.ws-t-tag { color: #475569; font-size: 9pt; }
/* Kiekvienos eilutės savas QR kodas – veda TIESIAI į to uždavinio interaktyvų
   sprendimą su algebriniais žingsniais (žr. `worksheetLink(taskId)` module.js
   faile), o ne vien į bendrą temos puslapį. */
.ws-t-qr { width: 12mm; padding: 1mm 2mm; text-align: center; }
.ws-t-qr svg { width: 9mm; height: 9mm; display: block; margin: 0 auto; }

.ws-note { margin-top: 5mm; font-size: 9pt; color: #475569; line-height: 1.5; }

/* ============================== SPAUSDINIMAS ============================= */

@media print {
  @page { size: A4 portrait; margin: 0; }

  /* Rodomas TIK darbo lapas. */
  body.ws-open > *:not(#worksheet) { display: none !important; }
  body.ws-open { background: #FFFFFF; }

  .ws-overlay {
    position: static; padding: 0; background: none; overflow: visible;
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .no-print { display: none !important; }

  .ws-sheet {
    width: auto; min-height: auto; margin: 0; padding: 12mm;
    box-shadow: none; break-after: page; page-break-after: always;
  }
  .ws-sheet:last-child { break-after: auto; page-break-after: auto; }

  .ws-task { border-color: #94A3B8; }
  .ws-space span { border-bottom-color: #94A3B8; }

  /* Spalvos privalo atsispausdinti ir be „foninės grafikos“. */
  .ws-no { background: #4F46E5 !important; color: #FFFFFF !important;
           -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .ws-table th { background: #EEF2FF !important;
                 -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ----------------------------- mažas ekranas ---------------------------- */

@media screen and (max-width: 820px) {
  .ws-sheet { width: 100%; min-height: auto; padding: 6mm; }
  .ws-tasks { grid-template-columns: 1fr; }
  .ws-toolbar { max-width: 100%; }
}
