/* Structural CSS for worksheets - optimized for printing and handwriting */

/* Import Alegreya font */
@import url("https://fonts.googleapis.com/css2?family=Alegreya:ital,wght@0,400;0,500;0,600;0,700;0,800;0,900;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");

/* Alegreya font weight classes */
.alegreya-regular {
  font-family: "Alegreya", serif;
  font-weight: 400;
  font-style: normal;
}

.alegreya-medium {
  font-family: "Alegreya", serif;
  font-weight: 500;
  font-style: normal;
}

.alegreya-semibold {
  font-family: "Alegreya", serif;
  font-weight: 600;
  font-style: normal;
}

.alegreya-bold {
  font-family: "Alegreya", serif;
  font-weight: 700;
  font-style: normal;
}

.alegreya-extrabold {
  font-family: "Alegreya", serif;
  font-weight: 800;
  font-style: normal;
}

.alegreya-black {
  font-family: "Alegreya", serif;
  font-weight: 900;
  font-style: normal;
}

.alegreya-regular-italic {
  font-family: "Alegreya", serif;
  font-weight: 400;
  font-style: italic;
}

.alegreya-medium-italic {
  font-family: "Alegreya", serif;
  font-weight: 500;
  font-style: italic;
}

.alegreya-semibold-italic {
  font-family: "Alegreya", serif;
  font-weight: 600;
  font-style: italic;
}

.alegreya-bold-italic {
  font-family: "Alegreya", serif;
  font-weight: 700;
  font-style: italic;
}

.alegreya-extrabold-italic {
  font-family: "Alegreya", serif;
  font-weight: 800;
  font-style: italic;
}

.alegreya-black-italic {
  font-family: "Alegreya", serif;
  font-weight: 900;
  font-style: italic;
}

/* Base document layout */
* {
  box-sizing: border-box;
}

body {
  font-family: "Alegreya", "Times New Roman", Times, serif;
  font-size: 12pt;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  background-color: white;
  color: black;
}

.worksheet-container {
  max-width: 8.5in;
  margin: 0 auto;
  padding: 1in;
  min-height: 11in;
}

/* Header styling */
.worksheet-header {
  border-bottom: 2px solid var(--primary-color, #333);
  padding-bottom: 1em;
  margin-bottom: 2em;
}

.worksheet-title {
  font-size: 18pt;
  font-weight: bold;
  text-align: center;
  margin: 0 0 0.5em 0;
}

.worksheet-subtitle {
  font-size: 14pt;
  text-align: center;
  margin: 0 0 1em 0;
  font-style: italic;
}

.worksheet-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1em;
  font-size: 11pt;
}

.student-info {
  display: flex;
  justify-content: space-between;
  margin-top: 1em;
  font-size: 11pt;
}

.fill-blank {
  border-bottom: 1px solid black;
  display: inline-block;
  min-width: 2in;
  margin-left: 0.5em;
  height: 1.2em;
}

.day-blank {
  min-width: 1in;
}

.date-blank {
  min-width: 1.5in;
}

/* Simple table styling - print friendly */
table {
  border-collapse: collapse;
  width: auto;
  margin: 1em auto;
  font-size: 11pt;
}

th, td {
  border: 1px solid black;
  padding: 0.05em 0.15em;
  text-align: center;
  vertical-align: middle;
  background-color: white;
}

th {
  font-weight: bold;
  background-color: white;
}

/* Main content area */
.worksheet-content {
  counter-reset: theorem example exercise question;
}

/* Pedagogical content blocks */
.theorem,
.definition,
.example,
.lemma,
.proposition {
  border: 2px solid var(--primary-color, #333);
  border-radius: 6px;
  padding: 1em;
  margin: 1.5em 0;
  background-color: var(--box-background, #f9f9f9);
  page-break-inside: avoid;
}

.theorem::before {
  content: "Theorem " counter(theorem);
  font-weight: bold;
  color: var(--primary-color, #333);
  display: block;
  margin-bottom: 0.5em;
  counter-increment: theorem;
}

.definition::before {
  content: "Definition";
  font-weight: bold;
  color: var(--primary-color, #333);
  display: block;
  margin-bottom: 0.5em;
}

.example::before {
  content: "Example " counter(example);
  font-weight: bold;
  color: var(--accent-color, #666);
  display: block;
  margin-bottom: 0.5em;
  counter-increment: example;
}

/* Exercise blocks - prominent and spacious */
.exercise {
  border: 1px solid black;
  border-radius: 6px;
  padding: 2em;
  margin: 3em 0;
  background-color: white;
  page-break-inside: avoid;
  counter-increment: exercise;
}

.exercise::before {
  content: "Exercise " counter(exercise);
  font-weight: bold;
  color: black;
  display: block;
  margin-bottom: 0.5em;
  font-size: 13pt;
}

.exercise .timing {
  float: right;
  font-size: 10pt;
  color: var(--accent-color, #007c41);
  font-style: italic;
  background-color: white;
  padding: 0.2em 0.5em;
  border-radius: 3px;
  margin-left: 1em;
}

.exercise .instructions {
  margin-top: 1em;
  font-weight: 500;
  clear: both;
}

/* Student work areas - generous space for handwriting */
.student-work {
  min-height: 3in;
  border: 1px dashed #999;
  margin: 1.5em 0;
  padding: 0.5em;
  background-color: white;
  page-break-inside: avoid;
}

.student-work::before {
  display: none;
}

.student-work.large {
  min-height: 5in;
}

.student-work.medium {
  min-height: 3in;
}

.student-work.small {
  min-height: 1.5in;
}

.student-work.full-page {
  min-height: 7in;
  page-break-before: always;
}

/* Fill-in-the-blank elements */
.blank {
  border-bottom: 1px solid black;
  display: inline-block;
  min-width: 2em;
  margin: 0 0.2em;
}

.blank.short {
  min-width: 1em;
}

.blank.medium {
  min-width: 3em;
}

.blank.long {
  min-width: 5em;
}

/* Fill-in class - content that appears in notes but becomes blank space in worksheets */
.fill-in {
  /* In complete worksheets (notes), show content normally */
  display: inline;
}

/* In student worksheets, replace fill-in content with highlighted blank space */
.worksheet-student .fill-in {
  display: inline;
  background-color: #fff3b3;
  border: 1px solid #e6cc00;
  border-radius: 3px;
  padding: 2px 4px;
  margin: 0;
  color: transparent;
  /* Keep original font size and spacing */
  font-size: inherit;
  line-height: inherit;
  vertical-align: baseline;
}

/* Hide all content within fill-ins including math */
.worksheet-student .fill-in * {
  color: transparent !important;
  background: transparent !important;
}

/* Specifically hide KaTeX math */
.worksheet-student .fill-in .katex,
.worksheet-student .fill-in .katex *,
.worksheet-student .fill-in .math,
.worksheet-student .fill-in .math * {
  color: transparent !important;
  background: transparent !important;
  border-color: transparent !important;
}

/* For block-level fill-ins */
.worksheet-student .fill-in.block {
  display: block;
  background-color: #fff3b3;
  border: 1px solid #e6cc00;
  border-radius: 4px;
  padding: 8px 12px;
  margin: 4px 0;
  color: transparent;
}

/* Ensure block-level fill-ins hide all math content */
.worksheet-student .fill-in.block .katex-display,
.worksheet-student .fill-in.block .math,
.worksheet-student .fill-in.block .katex-display *,
.worksheet-student .fill-in.block .math * {
  color: transparent !important;
  background: transparent !important;
  border-color: transparent !important;
}

/* Size variations - just subtle differences in highlighting */
.worksheet-student .fill-in.small {
  padding: 1px 3px;
}

.worksheet-student .fill-in.medium {
  padding: 2px 4px;
}

.worksheet-student .fill-in.large {
  padding: 3px 5px;
}

.worksheet-student .fill-in.xlarge {
  padding: 4px 6px;
}

/* Questions and prompts */
.question {
  margin: 1.5em 0;
  padding: 1em;
  border-left: 4px solid var(--accent-color, #007c41);
  background-color: var(--question-background, #f8f9fa);
  counter-increment: question;
}

.question::before {
  content: "Question " counter(question) ": ";
  font-weight: bold;
  color: var(--accent-color, #007c41);
}

/* Think-pair-share activities */
.think-pair-share {
  border: 2px dotted var(--accent-color, #007c41);
  padding: 1em;
  margin: 1.5em 0;
  background-color: var(--highlight-background, #f0f8ff);
  page-break-inside: avoid;
}

.think-pair-share::before {
  content: "🤔 Think-Pair-Share Activity";
  display: block;
  font-weight: bold;
  color: var(--accent-color, #007c41);
  margin-bottom: 0.5em;
  font-size: 13pt;
}

.think-pair-share .phase {
  margin: 1em 0;
  padding: 0.5em;
  border-left: 3px solid var(--accent-color, #007c41);
}

.think-pair-share .phase.think::before {
  content: "Think (2 min): ";
  font-weight: bold;
}

.think-pair-share .phase.pair::before {
  content: "Pair (3 min): ";
  font-weight: bold;
}

.think-pair-share .phase.share::before {
  content: "Share (5 min): ";
  font-weight: bold;
}

/* Proof blocks - minimal in student version */
.proof {
  border-left: 3px solid var(--secondary-color, #999);
  padding-left: 1em;
  margin: 1em 0;
  font-style: italic;
  page-break-inside: avoid;
}

.proof::before {
  content: "Proof: ";
  font-weight: bold;
  font-style: normal;
}

.proof::after {
  content: " ∎";
  float: right;
  font-style: normal;
}

/* Solution blocks - instructor version only */
.solution {
  border: 1px solid var(--solution-color, #28a745);
  padding: 1em;
  margin: 1em 0;
  background-color: var(--solution-background, #d4edda);
  page-break-inside: avoid;
}

.solution::before {
  content: "Solution:";
  font-weight: bold;
  color: var(--solution-color, #28a745);
  display: block;
  margin-bottom: 0.5em;
}

/* Math equation blocks */
.equation-block {
  margin: 1.5em 0;
  text-align: center;
}

.equation-block .katex-display {
  margin: 1em 0;
}

/* Key concepts */
.key-concept {
  background-color: var(--key-background, #fff3cd);
  border: 1px solid var(--key-border, #ffeaa7);
  padding: 1em;
  margin: 1em 0;
  border-radius: 6px;
  page-break-inside: avoid;
}

.key-concept::before {
  content: "📌 Key Concept: ";
  font-weight: bold;
  color: var(--key-color, #856404);
}

/* Page elements */
.page-break {
  page-break-before: always;
}

.no-break {
  page-break-inside: avoid;
}

/* Footer */
.worksheet-footer {
  margin-top: 3em;
  padding-top: 1em;
  border-top: 1px solid var(--secondary-color, #ddd);
  font-size: 10pt;
  text-align: center;
  color: var(--secondary-color, #666);
}

/* Print optimizations */
@media print {
  @page {
    size: letter;
    margin: 0;  /* No margins - print software handles this */
  }

  body {
    font-size: 12pt;  /* Keep same as screen */
    background: white;
    color: black;
  }

  .worksheet-container {
    /* Keep similar to screen layout */
    max-width: 8.5in;
    padding: 1in;
    box-shadow: none;
  }

  .student-work {
    background-color: white;
    border: 1px dashed #333;
    /* Add light grid lines for better handwriting */
    background-image: repeating-linear-gradient(
      0deg,
      transparent,
      transparent 1.5em,
      #f0f0f0 1.5em,
      #f0f0f0 calc(1.5em + 1px)
    );
  }

  .student-work::before {
    display: none; /* Remove "Space for your work:" label in print */
  }

  .exercise {
    /* Keep same as screen */
    background-color: white;
    border: 1px solid black;
    border-radius: 6px;
    margin: 3em 0;  /* Keep same as screen */
    padding: 2em;  /* Keep same as screen */
  }

  .exercise::before {
    font-size: 13pt;  /* Keep same as screen */
    color: black;
  }

  .think-pair-share {
    background-color: white;
    border: 1px solid black;
  }

  .think-pair-share::before {
    content: "Think-Pair-Share Activity"; /* Remove emoji in print */
  }

  .key-concept {
    background-color: white;
    border: 1px solid black;
  }

  .key-concept::before {
    content: "Key Concept: "; /* Remove emoji in print */
  }

  .worksheet-header {
    border-bottom: 2px solid black;
    page-break-after: avoid;
  }

  .worksheet-footer {
    display: none; /* Hide footer in print */
  }

  /* Ensure proper page breaks */
  .exercise {
    page-break-inside: avoid;
    /* Don't override margins/padding - use screen values */
  }
  
  .think-pair-share {
    page-break-inside: avoid;
  }

  /* Tables should not break across pages */
  table {
    page-break-inside: avoid;
    width: 100% !important;
    margin: 1em auto !important;
    display: table !important;
    border-collapse: collapse !important;
  }
  
  th, td {
    border: 1px solid black !important;
    padding: 0.1em 0.3em !important;
    text-align: center !important;
    vertical-align: middle !important;
    background-color: white !important;
    display: table-cell !important;
  }
  
  th {
    font-weight: bold !important;
  }

  .student-work.large,
  .student-work.medium {
    page-break-inside: auto; /* Allow breaking for large work areas */
  }

  .full-page {
    page-break-before: always;
  }

  /* Optimize margins and spacing */
  h1, h2, h3 {
    page-break-after: avoid;
  }

  /* Adjust colors for print but maintain structure */
  body, .worksheet-container {
    background-color: white !important;
  }
  
  /* Only change text color to black, keep backgrounds similar */
  * {
    color: black !important;
  }
  
  /* Ensure KaTeX text is black but background is transparent */
  .katex, .katex * {
    color: black !important;
  }

  /* Fix KaTeX/LaTeX rendering in print */
  .katex {
    font-size: 1em !important;
    background: transparent !important;
  }
  
  .katex * {
    background: transparent !important;
    background-color: transparent !important;
  }
  
  .katex .mord {
    background: transparent !important;
  }
  
  .katex .strut {
    background: transparent !important;
  }
  
  .katex .base {
    background: transparent !important;
  }

  .katex-display {
    margin: 1em 0 !important;
    overflow: visible !important;
    background: transparent !important;
  }

  /* Keep inline math inline, but force display math to full width */
  .math.inline {
    overflow: visible !important;
    display: inline-block !important;
    background: transparent !important;
  }

  .math.display {
    overflow: visible !important;
    display: block !important;
    background: transparent !important;
    width: 100% !important;
    max-width: none !important;
  }

  .katex-display {
    width: 100% !important;
    max-width: none !important;
  }


  /* Keep equation block centering in print */
  .equation-block {
    text-align: center !important;
  }

  /* Fix math in tables - allow wrapping for full width in print */
  td .katex, th .katex {
    display: block !important;
    white-space: normal !important;
    background: transparent !important;
    width: 100% !important;
    max-width: none !important;
  }

  /* Style fill-in content in print mode - highlighted empty box */
  .worksheet-student .fill-in {
    color: transparent !important;
    background: white !important;
    border: 2px solid #333 !important;
    border-radius: 3px !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
  }

  .worksheet-student .fill-in * {
    color: transparent !important;
    background: transparent !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
  }

  /* Keep borders visible */
  .exercise,
  .student-work,
  .worksheet-header {
    border-color: black !important;
  }
}

/* Screen-only elements (don't print) */
@media print {
  .no-print {
    display: none;
  }
}

/* Screen view improvements */
@media screen {
  .worksheet-container {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    margin: 2em auto;
    background-color: white;
  }
}
