:root {
  --paper: #ffffff;
  --desk: #e3e8ef;
  --ink: #c4161c;            /* the teacher's red: marks, grade, handwriting, the Turn it in button */
  --ink-dark: #9e1015;
  --solid: #25272d;          /* structure: buttons, borders, focus */
  --type: #25272d;
  --faint: #6b6f78;
  --line: 32px;               /* one ruled line: every text line sits on it */
  --hand: "Caveat", "Bradley Hand", cursive;
  --typed: "Courier Prime", "Courier New", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  display: flow-root;          /* keep the sheet's margins inside the page (no stray scroll) */
  background: var(--desk);
  color: var(--type);
  font: 17px/var(--line) var(--typed);
  min-height: 100vh;
}

/* The page is a plain sheet of paper. */
.sheet {
  position: relative;
  display: flex; flex-direction: column;     /* footer sits at the bottom of the page */
  max-width: 860px;
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(var(--line) * 2) 56px;
  background-color: var(--paper);
}
@media (min-width: 900px) {
  .sheet { margin: 32px auto; min-height: calc(100vh - 64px); box-shadow: 0 1px 2px rgba(40, 50, 70, .12), 0 12px 32px rgba(40, 50, 70, .10); }
}
@media (max-width: 520px) {
  .sheet { padding-left: 16px; padding-right: 16px; }
}

.brand {
  margin: 0 0 var(--line);
  font: 700 64px/64px var(--hand);
  color: var(--ink);
}
.lede {
  margin: 0 0 var(--line);
  font-size: 22px;
  line-height: var(--line);
  max-width: 34ch;
}
.lede-small { font-size: 19px; max-width: none; }
.aside { margin: 0; color: var(--faint); font-size: 15px; }
.error { margin: calc(var(--line) / 2) 0 0; font-size: 16px; line-height: 1.5; color: #a1121a; }
.view[hidden] { display: none; }

/* the one orchestrated moment: the pen circles "graded" */
.circled { position: relative; display: inline-block; padding: 0 2px; }
.circled svg { position: absolute; left: -14px; top: -8px; width: calc(100% + 28px); height: calc(100% + 16px); overflow: visible; pointer-events: none; }
.circled path { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; vector-effect: non-scaling-stroke;
  stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 900ms 450ms cubic-bezier(.6,.1,.3,1) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .circled path { animation: none; stroke-dashoffset: 0; } }

/* passcode */
.gate label { display: block; font: 700 26px/var(--line) var(--hand); color: var(--solid); padding: 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
input[type=password], input[type=text] {
  font: 18px var(--typed); color: var(--type);
  height: var(--line); padding: 0 4px; min-width: 0; flex: 1 1 220px; max-width: 320px;
  border: 0; border-bottom: 2px solid var(--type); background: transparent; border-radius: 0;
}
input:focus { outline: none; border-bottom-color: #000; }

/* buttons */
.btn {
  font: 700 16px var(--typed); letter-spacing: .01em;
  color: #fff; background: var(--solid); border: 2px solid var(--solid);
  height: var(--line); padding: 0 16px; border-radius: 3px 5px 4px 6px; cursor: pointer;
}
.btn:hover { background: #000; border-color: #000; }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-quiet { color: var(--solid); background: transparent; }
.btn-quiet:hover { background: rgba(0, 0, 0, .05); border-color: #000; }
#submit { background: var(--ink); border-color: var(--ink); }
#submit:hover:not(:disabled) { background: var(--ink-dark); border-color: var(--ink-dark); }
.link-btn { font: 16px var(--typed); color: var(--solid); background: none; border: 0; padding: 0 4px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:focus-visible { outline: 3px solid #2f6fd6; outline-offset: 3px; }
.btn-big { height: calc(var(--line) * 1.5); font-size: 18px; padding: 0 26px; margin-top: calc(var(--line) / 2); }
.btn:focus-visible { outline: 3px solid #2f6fd6; outline-offset: 3px; }

/* one box for everything: paste text, drop a file, or choose one */
.composer {
  border: 2px solid #c9cfd8; border-radius: 8px; background: #fff;
  transition: border-color .15s;
}
.composer:focus-within, .composer.drag { border-color: var(--solid); }
.composer.drag { background: rgba(0, 0, 0, .03); }
.paste {
  display: block; width: 100%; margin: 0; padding: 14px 16px;
  font: 17px/1.6 var(--typed); color: var(--type);
  min-height: 10em; resize: vertical; border: 0; background: transparent; border-radius: 8px 8px 0 0;
}
.paste[hidden] { display: none; }
.btn[hidden] { display: none; }
.paste::placeholder { color: #8d94a0; }
.paste:focus { outline: none; }
.file-chip {
  display: flex; align-items: center; gap: 10px; margin: 16px; padding: 12px 14px;
  border-radius: 6px; background: #f2f3f5; color: var(--solid);
  min-height: calc(10em - 32px); align-content: center;
}
.file-chip[hidden] { display: none; }
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.file-name { font: 700 26px/1.25 var(--hand); overflow-wrap: anywhere; }
.file-meta { font-size: 15px; line-height: 1.4; color: var(--faint); }
.file-remove {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: #fff; color: var(--type); font: 400 24px/36px var(--typed);
}
.file-remove:focus-visible { outline: 3px solid #2f6fd6; outline-offset: 2px; }
.composer-foot {
  display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap;
  padding: 10px 12px; border-top: 1px solid #e3e6eb;
}
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }
#file:focus-visible + .file-btn { outline: 3px solid #2f6fd6; outline-offset: 3px; }
.composer.has-file .file-btn { height: auto; padding: 0 4px; border: 0; background: none; font-weight: 400; text-decoration: underline; text-underline-offset: 3px; }
.composer.has-file .composer-hint { display: none; }
.composer-hint { color: var(--faint); font-size: 15px; line-height: 1.4; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* working */
.status { margin: 0 0 var(--line); font-size: 19px; }
.caret { display: inline-block; width: .6ch; height: 1.1em; margin-left: 2px; vertical-align: -3px; background: var(--type); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .caret { animation: none; } }

/* results */
.result-head { margin-bottom: calc(var(--line) / 2); }
.result-head .aside { font-size: 14px; line-height: 1.4; margin-top: -4px; }
.result-title { margin: 0;
  font: 400 20px/1.35 var(--typed); color: var(--type); }
.action-bar {
  position: sticky; bottom: 0; z-index: 5;
  margin: var(--line) -56px 0; padding: 12px 56px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96); border-top: 1px solid #e3e6eb;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.action-bar-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.action-bar .link-btn { margin-left: auto; }
@media (max-width: 520px) {
  .action-bar { margin-left: -16px; margin-right: -16px; padding-left: 16px; padding-right: 16px; }
}
.pages { display: grid; gap: 28px; margin: 0 -24px; }
@media (max-width: 520px) { .pages { margin: 0 -8px; } }
.page-btn { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; width: 100%; }
.page-btn:focus-visible { outline: 3px solid #2f6fd6; outline-offset: 4px; }
.pages img { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 1px 2px rgba(40,50,70,.18), 0 8px 24px rgba(40,50,70,.12); }

/* full-size viewer */
.viewer {
  position: fixed; inset: 0; z-index: 50;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: rgba(30, 34, 42, .88);
  padding: 64px 16px 48px;
  cursor: zoom-out;
}
.viewer[hidden] { display: none; }
.viewer-pages { display: grid; gap: 24px; justify-items: center; }
.viewer-pages img {
  display: block; width: min(100%, 1100px); height: auto; background: #fff; cursor: default;
  scroll-margin-top: 64px; box-shadow: 0 8px 32px rgba(0, 0, 0, .35);
}
.viewer-close {
  position: fixed; top: 12px; right: 12px; z-index: 51;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: #fff; color: var(--type); font: 400 30px/44px var(--typed); cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}
.viewer-close:focus-visible { outline: 3px solid #2f6fd6; outline-offset: 2px; }
html.viewer-open, html.viewer-open body { overflow: hidden; }
@media (max-width: 600px) {
  .viewer { padding: 64px 0 40px; }
  .viewer-pages { gap: 12px; }
}

.foot { margin-top: auto; padding-top: calc(var(--line) * 2); color: var(--faint); font-size: 14px; line-height: 1.5; max-width: 62ch; }
.foot > p { margin: 6px 0 0; }
.privacy { margin: 0; color: var(--faint); font-size: 14px; line-height: 1.5; }
.privacy summary { cursor: pointer; width: fit-content; list-style: none; display: flex; align-items: center; gap: 6px; }
.privacy summary::-webkit-details-marker { display: none; }
.privacy summary:hover { color: var(--solid); text-decoration: underline; text-underline-offset: 3px; }
.privacy summary:focus-visible { outline: 3px solid #2f6fd6; outline-offset: 2px; }
.privacy p { margin: 6px 0 0 22px; }
.lock { width: 15px; height: 15px; flex: none; fill: currentColor; stroke: currentColor; stroke-width: 1.6; }
.lock path { fill: none; }
