@font-face {
  font-family: "VicCursive";
  src: url("VICCURSI.TTF") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "VicModern";
  src: url("Vicmorg_.ttf") format("truetype");
  font-display: swap;
}

:root {
  --font-size: 54px;
  --line-height: 96px;
  --text-offset: 10px;
  --letter-spacing: 0px;
  --word-spacing: 8px;
  --page-padding: 28px;
  --worksheet-font: "VicCursive";
  --line-color: #1b4f8f;
  --dotted-color: rgba(27, 79, 143, 0.65);
  --paper: #ffffff;
  --ink: #202020;
  --trace-ink: rgba(32, 32, 32, 0.18);
  --text-left-inset: 12px;
  --text-right-inset: 28px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f2f4f7;
  color: #172033;
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px;
  background: #ffffff;
  border-bottom: 1px solid #d9dee8;
}

.eyebrow {
  margin: 0 0 4px;
  color: #556070;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 42px);
}

h2 {
  font-size: 18px;
}

.print-button {
  border: 0;
  border-radius: 8px;
  background: #164f91;
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
}

.print-button {
  padding: 12px 18px;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(520px, 1fr);
  gap: 24px;
  padding: 24px;
}

.controls-panel,
.worksheet-page {
  border: 1px solid #d9dee8;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(31, 42, 68, 0.08);
}

.controls-panel {
  align-self: start;
  display: grid;
  gap: 18px;
  padding: 20px;
}

.field {
  display: grid;
  gap: 8px;
  color: #3f4a5f;
  font-size: 14px;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid #c7cfdc;
  border-radius: 10px;
  background: #ffffff;
  color: #111827;
}

textarea {
  min-height: 150px;
  padding: 12px;
  resize: vertical;
}

input,
select {
  min-height: 42px;
  padding: 8px 10px;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.font-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.font-choice-button {
  min-height: 44px;
  border: 1px solid #c7cfdc;
  border-radius: 10px;
  background: #ffffff;
  color: #172033;
  cursor: pointer;
  font-weight: 700;
}

.font-choice-button[aria-pressed="true"] {
  border-color: #164f91;
  background: #164f91;
  color: #ffffff;
}

.range-control {
  display: grid;
  gap: 10px;
  color: #3f4a5f;
  font-size: 14px;
  font-weight: 700;
}

.range-control span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.range-control output {
  padding: 6px 10px;
  border-radius: 8px;
  background: #ffffff;
  color: #111827;
  font-variant-numeric: tabular-nums;
}

.range-control input {
  min-height: 0;
  padding: 0;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #3f4a5f;
  font-weight: 700;
}

.toggle input {
  width: auto;
  min-height: 0;
}

.saved-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid #d9dee8;
  border-radius: 14px;
  background: #f8fafc;
}

.saved-panel h2 {
  font-size: 18px;
}

.saved-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.saved-actions button {
  min-height: 40px;
  border: 1px solid #164f91;
  border-radius: 10px;
  background: #ffffff;
  color: #164f91;
  cursor: pointer;
  font-weight: 700;
}

.saved-actions button:first-child {
  background: #164f91;
  color: #ffffff;
}

.save-status {
  min-height: 18px;
  margin: 0;
  color: #596579;
  font-size: 13px;
}

.preview-wrap {
  overflow: auto;
  padding-bottom: 16px;
}

.worksheet-pages {
  display: grid;
  gap: 24px;
}

.worksheet-page {
  width: 794px;
  min-height: 1123px;
  padding: var(--page-padding);
  background: var(--paper);
  break-after: page;
  page-break-after: always;
}

.worksheet-page:last-child {
  break-after: auto;
  page-break-after: auto;
}

.worksheet-title {
  margin-bottom: 24px;
  color: #3a4252;
  font-size: 18px;
  font-weight: 700;
}

.worksheet-lines {
  display: grid;
  gap: 0;
}

.line-row {
  position: relative;
  height: var(--line-height);
  border-top: 2px solid var(--line-color);
}

.page-end-line {
  border-bottom: 2px solid var(--line-color);
}

.dotted-third {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  height: 2px;
  overflow: visible;
}

.dotted-third line {
  stroke: var(--dotted-color);
  stroke-dasharray: 7 11;
  stroke-linecap: butt;
  stroke-width: 1;
}

.dotted-third.first {
  top: calc(33.333% - 1px);
}

.dotted-third.second {
  top: calc(66.666% - 1px);
}

.line-row::before,
.line-row::after {
  position: absolute;
  left: 0;
  z-index: 1;
  display: none;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.9);
  color: #b42318;
  font-size: 10px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  line-height: 1;
}

.line-row::before {
  top: -8px;
  content: "0px";
}

.line-row::after {
  bottom: -8px;
  content: attr(data-height);
}

.show-measurements .line-row::before,
.show-measurements .line-row::after,
.show-measurements .third-label {
  display: block;
}

.third-label {
  position: absolute;
  right: 0;
  z-index: 1;
  display: none;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.9);
  color: #b42318;
  font-size: 10px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  line-height: 1;
}

.third-label.first {
  top: calc(33.333% - 7px);
}

.third-label.second {
  top: calc(66.666% - 7px);
}

.practice-text {
  position: absolute;
  left: var(--text-left-inset);
  right: var(--text-right-inset);
  top: var(--text-offset);
  color: var(--ink);
  font-family: var(--worksheet-font), cursive;
  font-size: var(--font-size);
  letter-spacing: var(--letter-spacing);
  line-height: 1;
  white-space: nowrap;
  word-spacing: var(--word-spacing);
}

.trace-text-mode .practice-text {
  color: var(--trace-ink);
}

@media (max-width: 960px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
}

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

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

  .app-header,
  .controls-panel {
    display: none;
  }

  .app-layout,
  .preview-wrap {
    display: block;
    padding: 0;
    overflow: visible;
  }

  .worksheet-pages {
    display: block;
  }

  .worksheet-page {
    width: 210mm;
    min-height: 297mm;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}

@media print {
  @media not all and (min-resolution: 0.001dpcm) {
    @supports (-webkit-appearance: none) {
      .worksheet-page {
        width: 200mm;
        min-height: 285mm;
        margin: 6mm auto 0;
      }

      .worksheet-page:last-child {
        break-after: auto;
        page-break-after: auto;
      }
    }
  }
}
