:root {
  color-scheme: light;
  --background: #f2fbf8;
  --surface: #ffffff;
  --ink: #213547;
  --muted: #637381;
  --stroke: #cbd7d3;
  --teal: #10a37f;
  --teal-dark: #08775e;
  --teal-soft: #dff6ee;
  --yellow: #ffcb45;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--background);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--background);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Segoe UI", system-ui, sans-serif;
}

button,
select {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 4px solid rgba(77, 141, 234, 0.32);
  outline-offset: 3px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
  letter-spacing: 0;
}

.site-header,
.resource-intro,
.paper {
  width: min(940px, calc(100% - 32px));
  margin-inline: auto;
}

.site-header {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-block: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-weight: 950;
  text-decoration: none;
}

.brand img {
  border-radius: 8px;
}

.language-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.language-picker select {
  min-height: 42px;
  padding: 8px 30px 8px 10px;
  border: 2px solid rgba(33, 53, 71, 0.17);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 800;
}

.resource-intro {
  padding: 34px 0 30px;
}

.eyebrow,
.paper-brand {
  margin-bottom: 7px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.resource-intro h1 {
  max-width: 720px;
  margin-bottom: 12px;
  font-size: clamp(36px, 6vw, 62px);
  line-height: 1.02;
}

.resource-intro > p:not(.eyebrow) {
  max-width: 650px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
}

.print-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  color: white;
  background: var(--ink);
}

.secondary-button {
  color: var(--ink);
  background: white;
}

.paper {
  min-height: 1280px;
  margin-bottom: 34px;
  padding: 46px 50px 34px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: white;
  box-shadow: 0 16px 42px rgba(33, 53, 71, 0.12);
}

.paper-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 4px solid var(--ink);
}

.paper-header h2 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.08;
}

.fraction-badge {
  width: 66px;
  min-width: 66px;
  display: grid;
  padding: 6px 13px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  text-align: center;
  transform: rotate(4deg);
}

.fraction-badge span {
  font-size: 20px;
  font-weight: 950;
  line-height: 1;
}

.fraction-badge span:first-child {
  padding-bottom: 3px;
  border-bottom: 2px solid var(--ink);
}

.student-fields {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 32px;
  margin: 28px 0 18px;
}

.student-fields label {
  display: flex;
  align-items: end;
  gap: 10px;
  font-size: 13px;
  font-weight: 900;
}

.student-fields i {
  min-width: 70px;
  flex: 1;
  border-bottom: 1.5px solid var(--ink);
}

.instructions {
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.task-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: tasks;
}

.task {
  min-height: 158px;
  position: relative;
  padding: 18px 18px 16px 48px;
  border: 1.5px solid var(--stroke);
  border-radius: 8px;
  counter-increment: tasks;
}

.task::before {
  content: counter(tasks);
  position: absolute;
  top: 16px;
  left: 16px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--ink);
  font-size: 12px;
  font-weight: 950;
}

[dir="rtl"] .task {
  padding-right: 48px;
  padding-left: 18px;
}

[dir="rtl"] .task::before {
  right: 16px;
  left: auto;
}

.task p {
  min-height: 38px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
}

.quarter-grid {
  width: 96px;
  height: 68px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  margin-inline: auto;
  border: 2px solid var(--ink);
}

.quarter-grid i {
  border: 1px solid var(--ink);
}

.fifths {
  width: min(180px, 100%);
  height: 54px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin-inline: auto;
  border: 2px solid var(--ink);
}

.fifths i {
  border-inline-end: 1px solid var(--ink);
}

.fifths i:nth-child(-n + 2) {
  background: var(--teal-soft);
}

.fifths i:last-child {
  border-inline-end: 0;
}

.equation {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  font-size: 24px;
  font-weight: 900;
}

.fraction {
  min-width: 34px;
  display: grid;
  text-align: center;
  line-height: 1.05;
}

.fraction b {
  min-height: 23px;
}

.fraction b:first-child {
  padding-bottom: 3px;
  border-bottom: 2px solid var(--ink);
}

.blank,
.wide-blank {
  display: inline-block;
  min-width: 30px;
  border-bottom: 1.5px solid var(--ink);
}

.wide-blank {
  min-width: 72px;
}

.choice-gap {
  width: 32px;
}

.number-line {
  height: 62px;
  position: relative;
  margin: 12px 14px 0;
}

.number-line .line {
  position: absolute;
  top: 28px;
  right: 0;
  left: 0;
  border-top: 3px solid var(--ink);
}

.number-line i {
  position: absolute;
  top: 20px;
  height: 18px;
  border-left: 3px solid var(--ink);
}

.number-line i:nth-of-type(1) { left: 0; }
.number-line i:nth-of-type(2) { left: 25%; }
.number-line i:nth-of-type(3) { left: 50%; }
.number-line i:nth-of-type(4) { left: 75%; }
.number-line i:nth-of-type(5) { right: 0; }

.number-line b {
  position: absolute;
  top: 40px;
  font-size: 12px;
}

.number-line .zero { left: -3px; }
.number-line .one { right: -3px; }

.answer-line {
  height: 24px;
  margin-top: 12px;
  border-bottom: 1.5px solid var(--ink);
}

.answer-line.short {
  width: 92px;
  margin-inline: auto;
}

.order-values {
  display: flex;
  justify-content: space-around;
  gap: 10px;
  font-size: 19px;
  font-weight: 900;
}

.paper-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--stroke);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.answer-key {
  min-height: auto;
}

.answer-mark {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: white;
  background: var(--teal);
  font-size: 32px;
  font-weight: 950;
}

.answer-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 42px;
  margin: 32px 0;
  padding-left: 24px;
  font-size: 16px;
  font-weight: 800;
}

[dir="rtl"] .answer-list {
  padding-right: 24px;
  padding-left: 0;
}

.answer-list li {
  min-height: 38px;
  padding-inline-start: 6px;
}

.teaching-note {
  padding: 20px 22px;
  border-inline-start: 5px solid var(--teal);
  background: var(--teal-soft);
}

.teaching-note h3 {
  margin-bottom: 6px;
}

.teaching-note p {
  margin-bottom: 0;
  line-height: 1.5;
}

@media (max-width: 700px) {
  .site-header,
  .resource-intro,
  .paper {
    width: min(100% - 20px, 940px);
  }

  .site-header {
    align-items: flex-start;
  }

  .language-picker {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .paper {
    min-height: 0;
    padding: 28px 20px 24px;
  }

  .paper-header h2 {
    font-size: 24px;
  }

  .student-fields,
  .task-grid,
  .answer-list {
    grid-template-columns: 1fr;
  }

  .task {
    min-height: 150px;
  }
}

@page {
  size: A4;
  margin: 12mm;
}

@media print {
  html,
  body {
    background: white;
  }

  .no-print {
    display: none !important;
  }

  .paper {
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .worksheet {
    display: block;
  }

  .answer-key {
    display: none;
  }

  body[data-print-mode="answers"] .worksheet {
    display: none;
  }

  body[data-print-mode="answers"] .answer-key {
    display: block;
  }

  .paper-header {
    padding-bottom: 4mm;
  }

  .student-fields {
    margin: 5mm 0 3mm;
  }

  .instructions {
    margin-bottom: 4mm;
  }

  .task-grid {
    gap: 3mm;
  }

  .task {
    min-height: 39mm;
    padding: 4mm 4mm 3mm 12mm;
    break-inside: avoid;
  }

  [dir="rtl"] .task {
    padding-right: 12mm;
    padding-left: 4mm;
  }

  .task p {
    margin-bottom: 3mm;
  }

  .paper-footer {
    margin-top: 4mm;
  }
}
