@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Caveat";
  src: url("/fonts/caveat-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --desk: #eef1f4;
  --paper: #ffffff;
  --rule: #dde8f2;
  --margin-line: #eba5a9;
  --ink: #1b2330;
  --ink-soft: #4a5566;
  --pen-red: #c0262d;
  --pen-green: #1a7340;
  --highlight: #fff3a3;
  --focus: #2457c5;
  --line: 32px;
  --font-body: "Atkinson Hyperlegible Next", system-ui, sans-serif;
  --font-pen: "Caveat", "Segoe Print", cursive;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  background: var(--desk);
}

/* Keep a focused field clear of the sticky editor bar. */
html:has(.editor-bar) {
  scroll-padding-bottom: 120px;
}

body {
  margin: 0;
  color: var(--ink);
  font: 400 1.125rem/1.5 var(--font-body);
}

[hidden] {
  display: none !important;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  line-height: 1.2;
}

h1 {
  font-size: 2.25rem;
}

h1:focus {
  outline: none;
}

a {
  color: var(--ink);
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Page: a sheet of ruled exercise paper with a red margin line */

.page {
  position: relative;
  isolation: isolate;
  max-width: 820px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 40px 64px 104px;
  background-color: var(--paper);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--line) - 1px),
    var(--rule) calc(var(--line) - 1px),
    var(--rule) var(--line)
  );
  box-shadow: 0 0 0 1px #d5dbe2;
}

.page::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  bottom: 0;
  left: 80px;
  width: 2px;
  background: var(--margin-line);
}

.masthead {
  display: flex;
  align-items: baseline;
  padding-bottom: 8px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--ink);
}

.brand {
  font: 700 2.5rem/1 var(--font-pen);
  color: var(--pen-red);
  text-decoration: none;
}

.brand:hover {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

.banner {
  margin: 0 0 24px;
  padding: 12px 16px;
  border: 2px solid var(--ink);
  background: var(--highlight);
  font-weight: 700;
}

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 18px;
  font: 700 1rem/1.2 var(--font-body);
  color: var(--ink);
  text-decoration: none;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  /* No background-color: a button that becomes enabled would fade its
     fill in behind text that has already turned white. */
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

.button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.button-primary {
  color: var(--paper);
  background: var(--ink);
  box-shadow: 3px 3px 0 var(--pen-red);
}

.button-primary:hover {
  box-shadow: 4px 4px 0 var(--pen-red);
}

.button-primary:active {
  box-shadow: 1px 1px 0 var(--pen-red);
}

.button-quiet,
.button-quiet:hover,
.button-quiet:active {
  box-shadow: none;
}

.button-quiet:hover {
  background: var(--desk);
}

.button-danger {
  color: var(--paper);
  background: var(--pen-red);
  border-color: var(--pen-red);
}

.button-small {
  min-height: 40px;
  padding: 6px 12px;
  box-shadow: none;
}

.button-large {
  min-height: 52px;
  padding: 12px 28px;
  font-size: 1.125rem;
}

.button:disabled,
.button:disabled:hover,
.button:disabled:active {
  color: var(--ink-soft);
  background: var(--paper);
  border-style: dashed;
  border-color: var(--ink-soft);
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

.stateful {
  display: inline-grid;
  justify-items: center;
}

.stateful > .state {
  grid-area: 1 / 1;
  visibility: hidden;
}

.stateful[data-state="idle"] > [data-for="idle"],
.stateful[data-state="busy"] > [data-for="busy"],
.stateful[data-state="done"] > [data-for="done"],
.stateful[data-state="mark"] > [data-for="mark"],
.stateful[data-state="next"] > [data-for="next"],
.stateful[data-state="finish"] > [data-for="finish"] {
  visibility: visible;
}

.link-button {
  padding: 8px 0;
  font: 700 1rem/1.2 var(--font-body);
  color: var(--pen-red);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  font-weight: 700;
}

.form-message {
  margin-top: 12px;
}

.form-message:empty {
  display: none;
}

.form-message-error {
  color: var(--pen-red);
  font-weight: 700;
}

.meta {
  margin: 8px 0 0;
  color: var(--ink-soft);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
}

/* Home */

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.view-head-actions {
  display: flex;
  gap: 12px;
}

.quiz-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 2px solid var(--ink);
}

.quiz-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 20px 0;
  border-bottom: 1px solid var(--ink-soft);
}

.quiz-row-topic {
  font-size: 1.375rem;
}

.quiz-row-meta {
  margin-top: 4px;
  font-size: 1rem;
  color: var(--ink-soft);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-text {
  font-weight: 700;
  color: var(--pen-red);
}

.empty {
  padding-top: 16px;
  border-top: 2px solid var(--ink);
  color: var(--ink-soft);
}

.empty-note {
  margin-bottom: 4px;
  font: 700 2.25rem/1.1 var(--font-pen);
}

/* Editor */

.field-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

input[type="text"],
textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink-soft);
  border-radius: 6px;
}

input[type="text"]:hover,
textarea:hover {
  border-color: var(--ink);
}

textarea {
  resize: vertical;
}

input[type="text"][aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--pen-red);
}

.field-topic {
  font-size: 1.75rem;
  font-weight: 700;
}

.problem {
  margin-top: 6px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--pen-red);
}

.problem:empty {
  display: none;
}

.problem-list {
  margin: 6px 0 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--pen-red);
}

.question-list {
  margin: 32px 0 16px;
  padding: 0;
  list-style: none;
}

.question-card {
  position: relative;
  padding: 24px 0 28px;
  border-top: 2px solid var(--ink);
}

.question-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.question-number,
.margin-mark {
  position: absolute;
  top: 16px;
  left: -96px;
  width: 64px;
  font: 700 2.5rem/1 var(--font-pen);
  color: var(--pen-red);
  text-align: right;
}

.margin-mark {
  top: 0;
}

.margin-mark .icon {
  width: 40px;
  height: 40px;
}

.question-form,
.notice {
  position: relative;
}

.question-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.question-tools .button {
  white-space: nowrap;
}

.answer-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.answer-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  grid-template-areas:
    "mark label label"
    "mark input remove"
    ". problem problem";
  column-gap: 12px;
  margin-top: 16px;
}

.answer-mark {
  grid-area: mark;
  align-self: end;
  display: grid;
  place-items: center;
  height: 48px;
}

.answer-mark .icon {
  width: 32px;
  height: 32px;
}

.answer-row-right .answer-mark {
  color: var(--pen-green);
}

.answer-row-wrong .answer-mark {
  color: var(--pen-red);
}

.answer-label {
  grid-area: label;
  margin-bottom: 6px;
  font-weight: 700;
}

.answer-input {
  grid-area: input;
}

.answer-row > .button {
  grid-area: remove;
  align-self: center;
}

.answer-row > .problem {
  grid-area: problem;
}

.add-wrong {
  margin-top: 16px;
}

.editor-bar {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 32px;
  padding: 16px 0;
  background: var(--paper);
  border-top: 2px solid var(--ink);
}

.editor-bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.ready-text {
  font-weight: 700;
  color: var(--pen-green);
}

.share-panel {
  margin-top: 24px;
  padding: 20px;
  background: var(--paper);
  border: 2px solid var(--ink);
}

.share-panel h2 {
  font-size: 1.5rem;
}

.share-panel p {
  margin-top: 8px;
}

.share-row {
  display: flex;
  gap: 12px;
  margin: 16px 0;
}

.share-link {
  flex: 1;
}

/* Play */

.progress {
  margin-bottom: 8px;
  font-size: 1rem;
  color: var(--ink-soft);
}

.intro-topic {
  font-size: 2.75rem;
}

.question-form {
  max-width: 640px;
}

.options {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  border: 0;
}

.question-prompt {
  margin-bottom: 20px;
  padding: 0;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
}

.option {
  position: relative;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 10px 14px;
  font-size: 1.125rem;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  cursor: pointer;
}

.option-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.option:has(.option-input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.option:has(.option-input:checked) {
  background: var(--highlight);
}

/* The chosen answer's number is filled in, like a shaded bubble on an
   answer sheet, so the choice does not rest on the yellow alone. */
.option:has(.option-input:checked) .option-key {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
}

.option:has(.option-input:disabled) {
  cursor: default;
}

.option-key {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.option-mark {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1rem;
  font-weight: 700;
}

.option-mark .icon {
  width: 32px;
  height: 32px;
}

.option.is-right {
  border-color: var(--pen-green);
}

.option.is-right .option-mark {
  color: var(--pen-green);
}

.option.is-wrong {
  border-color: var(--pen-red);
}

.option.is-wrong .option-mark {
  color: var(--pen-red);
}

.feedback {
  min-height: 1.5em;
  margin: 20px 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.feedback.is-right {
  color: var(--pen-green);
}

.feedback.is-wrong {
  color: var(--pen-red);
}

/* Score and answer key */

.score-mark {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 220px;
  height: 120px;
  margin-top: 16px;
  color: var(--pen-red);
}

.score-value {
  font: 700 4rem/1 var(--font-pen);
}

.score-circle {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.score-circle path {
  fill: none;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linecap: round;
}

.score-comment {
  margin-top: 8px;
  font: 700 2.25rem/1.1 var(--font-pen);
  color: var(--pen-red);
}

.key-heading {
  margin: 32px 0 8px;
  font-size: 1.5rem;
}

.key-list {
  margin: 16px 0 0;
  padding-left: 1.5em;
}

.key-item {
  padding: 12px 0;
  border-bottom: 1px dotted var(--ink-soft);
}

.key-prompt {
  margin-bottom: 6px;
  font-weight: 700;
}

.key-answer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.key-answer .icon {
  flex: none;
  width: 28px;
  height: 28px;
}

.key-answer.is-right .icon {
  color: var(--pen-green);
}

.key-answer.is-wrong {
  color: var(--ink-soft);
}

.key-answer.is-wrong .icon {
  color: var(--pen-red);
}

.key-answer.is-wrong .key-answer-text {
  text-decoration: line-through;
  text-decoration-color: var(--pen-red);
}

/* Pen marks */

.icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.option-mark .icon path {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: pen-stroke 360ms ease-out forwards;
}

.score-circle path {
  stroke-dasharray: 800;
  stroke-dashoffset: 800;
  animation: pen-stroke 700ms ease-out 150ms forwards;
}

@keyframes pen-stroke {
  to {
    stroke-dashoffset: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }

  .option-mark .icon path,
  .score-circle path {
    animation: none;
    stroke-dashoffset: 0;
  }
}

/* Narrow screens */

@media (max-width: 640px) {
  .page {
    padding: 16px 16px 48px 44px;
  }

  .page::before {
    left: 28px;
  }

  .question-head {
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .question-number {
    position: static;
    width: auto;
    text-align: left;
  }

  .margin-mark {
    display: none;
  }

  html:has(.editor-bar) {
    scroll-padding-bottom: 180px;
  }

  .quiz-row {
    grid-template-columns: 1fr;
  }

  .row-actions {
    justify-content: flex-start;
  }

  .share-row {
    flex-direction: column;
  }

  .intro-topic {
    font-size: 2rem;
  }
}

/* Print: only the answer sheet */

.print-sheet {
  display: none;
}

@media print {
  html,
  body {
    background: #ffffff;
  }

  .page {
    display: none;
  }

  .print-sheet {
    display: block;
    padding-left: 24pt;
    border-left: 1.5pt solid var(--margin-line);
    font: 400 12pt/1.4 var(--font-body);
    color: #000000;
  }

  .print-sheet h1 {
    margin-bottom: 6pt;
    padding-bottom: 4pt;
    border-bottom: 1.5pt solid var(--ink);
    font-size: 20pt;
  }

  .print-option .icon {
    color: var(--pen-green);
  }

  .print-meta {
    margin-bottom: 16pt;
  }

  .print-question {
    margin-bottom: 12pt;
    break-inside: avoid;
  }

  .print-prompt {
    font-weight: 700;
  }

  .print-options {
    margin: 4pt 0 0;
    padding-left: 0;
    list-style: none;
  }

  .print-option {
    display: flex;
    align-items: center;
    gap: 6pt;
  }

  .print-option.is-right {
    font-weight: 700;
  }

  .print-option .icon,
  .print-bullet {
    flex: none;
    width: 14pt;
    height: 14pt;
  }
}

/* A shared link a teacher opens straight into Ctrl+P has no quiz in the
   print sheet yet unless the current view has filled it. Rather than print a
   blank page, let the screen chrome print as-is when the sheet is empty. */
@media print {
  body:has(.print-sheet:empty) .page {
    display: block;
  }

  .print-sheet:empty {
    display: none;
  }
}
