body { font-family: 'Lexend', sans-serif; }
* { box-sizing: border-box; }
label { font-size: .8rem; font-weight: 500; }
input:not([type="file"]), textarea, select {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .5rem .6rem;
  border: 1px solid #94a3b8;
  border-radius: .25rem;
  background: white;
  color: #1e293b;
  font: inherit;
}
textarea { resize: vertical; font-size: .8rem; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
}
[hidden] { display: none !important; }
.editing-toolbar button, .item-controls button, .item-tools button {
  padding: .35rem .65rem;
  border: 1px solid #cbd5e1;
  border-radius: .25rem;
  background: #f8fafc;
}
.editing-toolbar select { width: auto; margin: 0; }
.csv-dialog { width: min(44rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); overflow-y: auto; padding: 1.25rem; border: 1px solid #94a3b8; border-radius: .5rem; background: white; box-shadow: 0 20px 50px #0f172a33; }
.csv-dialog::backdrop { background: #0f172a99; }
.csv-dialog__close { position: absolute; top: .5rem; right: .5rem; width: 2rem; height: 2rem; padding: 0; border: 1px solid #cbd5e1; border-radius: .25rem; background: #f8fafc; font-size: 1rem; font-weight: bold; line-height: 1; cursor: pointer; }
.csv-dialog__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.copy-fallback { position: fixed; top: -1000px; left: -1000px; }
.worksheet-shell { margin: 1.5rem auto; padding: 0 .75rem; overflow-x: auto; }
.print-area, .answer-key-page {
  width: var(--ws-paper-width, 8.5in);
  min-height: var(--ws-paper-height, 10.5in);
  margin: 0 auto 1.5rem;
  padding: var(--ws-page-margin, .5in);
  font-family: var(--ws-font, 'Lexend', sans-serif);
  font-size: var(--ws-body-size, 12pt);
  line-height: var(--ws-line-height, 1.4);
}
.design-toggles { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin-top: .75rem; }
.design-toggles label, .output-file { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; font-weight: 500; }
.design-toggles input[type="checkbox"], .output-file input[type="checkbox"] {
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
}
.output-file { border: 1px solid #cbd5e1; border-radius: .25rem; background: #f8fafc; padding: .45rem .6rem; }
.output-file input[type="file"] { max-width: 11rem; margin: 0; font-size: .75rem; }
.worksheet-heading { display: grid; grid-template-columns: minmax(0, 1fr) 2.45in; gap: .25in; border-bottom: 2px solid #0f172a; padding-bottom: 1rem; margin-bottom: 1.5rem; align-items: start; }
.worksheet-intro { min-width: 0; }
.student-info { font-size: .8rem; padding-top: .25rem; }
.student-field { display: flex; align-items: baseline; gap: .35rem; min-width: 0; white-space: nowrap; }
.student-line { flex: 1; min-width: .25in; height: 1.4rem; border-bottom: 1px solid #475569; }
.student-row { display: grid; grid-template-columns: minmax(0, 1fr) 1in; gap: .15in; margin-top: .6rem; }
.worksheet-footer { border-top: 1px solid #cbd5e1; margin-top: 3rem; padding-top: 1rem; text-align: center; color: #64748b; font-size: .7rem; }
[contenteditable="true"] { white-space: pre-wrap; overflow-wrap: anywhere; border-radius: .2rem; outline-offset: 3px; }
[contenteditable="true"]:hover, [contenteditable="true"]:focus { background: #fffbeb; }
.passage-card { padding: 1rem; border: 1px solid #cbd5e1; border-radius: .4rem; margin-bottom: 1.5rem; }
.passage-text { font-size: .95em; line-height: var(--ws-passage-line-height, 1.85); }
.passage-paragraph { margin: 0 0 var(--ws-paragraph-gap, .55rem); }
.passage-paragraph:last-child { margin-bottom: 0; }
.question-paragraph { margin: 0; }
.ws-indent-paragraphs .passage-paragraph { text-indent: .35in; }
.ws-number-paragraphs .passage-text { counter-reset: ws-paragraph; }
.ws-number-paragraphs .passage-paragraph { counter-increment: ws-paragraph; }
.ws-number-paragraphs .passage-paragraph::before { content: "[" counter(ws-paragraph) "] "; font-weight: 600; color: #475569; }
.ws-choices-1 .choices { grid-template-columns: 1fr; }
.ws-no-passage-border .passage-card { border: none; padding-left: 0; padding-right: 0; }
.item-controls { position: fixed; inset: auto; margin: 0; width: 19rem; max-width: calc(100vw - 16px); max-height: calc(100dvh - 16px); overflow-y: auto; padding: .8rem; border: 1px solid #94a3b8; border-radius: .5rem; background: white; box-shadow: 0 8px 30px #0f172a33; font-size: .8rem; color: #475569; }
.item-controls:popover-open { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.item-controls:not(:popover-open) { display: none; }
.item-controls select, .item-controls input { width: auto; max-width: 100%; margin: 0; padding: .3rem; }
.item-controls .answer-editor { flex: 1 1 12rem; }
.item-controls select { flex: 1 1 100%; }
.passage-card, .question-card { position: relative; }
.item-tools { position: absolute; right: 0; top: -.8rem; display: flex; gap: .2rem; z-index: 1; opacity: 0; transition: opacity .15s; }
.passage-card:hover > .item-tools, .question-card:hover > .item-tools, .passage-card:focus-within > .item-tools, .question-card:focus-within > .item-tools { opacity: 1; }
.item-tools button { min-width: 2rem; min-height: 2rem; font-weight: bold; }
.drag-handle { cursor: grab; touch-action: none; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.is-dragging { opacity: .5; }
.drop-before::before, .drop-after::after { content: ''; position: absolute; left: 0; right: 0; height: 3px; background: #4f46e5; }
.drop-before::before { top: -5px; }
.drop-after::after { bottom: -5px; }
@media (hover: none) { .item-tools { opacity: 1; } }
.question-card { padding: .5rem 0; margin-bottom: 1.25rem; }
.question-heading { display: flex; align-items: baseline; gap: .4rem; margin-bottom: .5rem; font-weight: 500; line-height: 1.65; }
.question-heading > [contenteditable] { flex: 1; min-width: 0; }
.question-description { margin: 0 0 .6rem 1.5rem; font-size: .8rem; font-style: italic; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem 1rem; margin-left: 1.5rem; font-size: .85rem; }
.choice { display: flex; align-items: baseline; gap: .5rem; min-width: 0; }
.answer-marker { display: inline-block; width: 1rem; height: 1rem; border: 1.5px solid #475569; flex: 0 0 1rem; align-self: flex-start; margin-top: .2rem; }
.answer-circle { border-radius: 50%; }
.choice-text { flex: 1; min-width: 0; line-height: 1.6; }
.writing-lines { margin: .75rem 0 0 1.5rem; }
.standard-line { height: 30px; border-bottom: 1px solid #64748b; margin-top: 8px; }
.primary-line { position: relative; height: 38px; border-top: 1px solid #94a3b8; border-bottom: 2px solid #475569; margin-top: 12px; }
.primary-line::after { content: ''; position: absolute; top: 50%; left: 0; width: 100%; border-top: 1px dashed #94a3b8; }
.drawing-box { height: 8rem; border: 1px dashed #94a3b8; margin: .75rem 0 0 1.5rem; }
.ak-line { padding: .6rem 0; border-bottom: 1px solid #e2e8f0; font-size: .85rem; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
@media screen and (max-width: 700px) {
  .builder-panel, .editing-toolbar { margin-left: .75rem; margin-right: .75rem; }
  .print-area, .answer-key-page { width: 100%; padding: 1.25rem; min-height: auto; }
  .worksheet-heading { grid-template-columns: 1fr; }
  .student-info { width: 100%; max-width: 3in; }
  .choices { grid-template-columns: 1fr; }
}
@media print {
  @page { size: letter; margin: .5in; }
  body { margin: 0 !important; padding: 0 !important; background: white !important; color: black; }
  .no-print { display: none !important; }
  .drop-before::before, .drop-after::after { display: none; }
  .is-dragging { opacity: 1; }
  .worksheet-shell { margin: 0; padding: 0; overflow: visible; }
  .print-area, .answer-key-page { width: 100%; min-height: 0; margin: 0; padding: 0; box-shadow: none; border: none; }
  .answer-key-page { break-before: page; }
  .question-card, .ak-line, .worksheet-heading { break-inside: avoid; }
  .passage-card { border: none; padding: 0; }
  .passage-card h2 { break-after: avoid; }
  .passage-text { orphans: 3; widows: 3; }
  [contenteditable="true"] { outline: none !important; background: transparent !important; }
}
