:root {
  color-scheme: light;
  --desk: #d8d0c2;
  --desk-line: rgba(89, 76, 60, 0.12);
  --paper: #fbfaf5;
  --paper-edge: #d8d3c7;
  --folder: #bda66e;
  --ink: #1d252a;
  --muted: #5d625f;
  --navy: #263e54;
  --navy-dark: #1b2f40;
  --red: #8b342f;
  --error-bg: #f2dcd6;
  --focus: #245a78;
  --paper-shadow: 0 3px 6px rgba(58, 48, 37, 0.12);
  font-family: Arial, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html, body { min-width: 0; min-height: 100%; overflow-x: hidden; }
body { margin: 0; min-height: 100dvh; background: var(--desk); color: var(--ink); }
button, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.desk {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  padding: clamp(22px, 4vh, 46px) clamp(18px, 5vw, 70px);
  background: var(--desk);
}

.desk-grain {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  opacity: 0.42;
}

.desk-grain::before {
  content: "";
  position: absolute;
  left: -2%;
  top: 34px;
  width: 104%;
  height: 1px;
  background: var(--desk-line);
  transform: rotate(0.2deg);
  box-shadow:
    0 72px var(--desk-line), 0 144px var(--desk-line), 0 216px var(--desk-line),
    0 288px var(--desk-line), 0 360px var(--desk-line), 0 432px var(--desk-line),
    0 504px var(--desk-line), 0 576px var(--desk-line), 0 648px var(--desk-line),
    0 720px var(--desk-line), 0 792px var(--desk-line), 0 864px var(--desk-line),
    0 936px var(--desk-line), 0 1008px var(--desk-line);
}

.paper {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: 1px;
  box-shadow: var(--paper-shadow);
}

.folder {
  position: absolute;
  width: min(750px, calc(100vw - 44px));
  height: min(640px, calc(100dvh - 70px));
  left: 50%;
  top: 50%;
  transform: translate(-47%, -48%) rotate(1.7deg);
  background: var(--folder);
  border: 1px solid #a48d58;
  box-shadow: 0 3px 6px rgba(61, 48, 28, 0.08);
}

.folder::before {
  content: "";
  position: absolute;
  left: -1px;
  top: -28px;
  width: 210px;
  height: 30px;
  background: var(--folder);
  border: 1px solid #a48d58;
  border-bottom: 0;
}

.home-screen { min-height: calc(100dvh - clamp(44px, 8vh, 92px)); display: grid; place-items: center; }
.home-paper { display: contents; }
.desk-fragment { display: none; pointer-events: none; }
.desktop-object { display: none; pointer-events: none; }
.cover-sheet { width: min(650px, calc(100vw - 60px)); padding: clamp(30px, 5vw, 52px); transform: rotate(-0.55deg); }
.cover-copy h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 4vw, 3rem); line-height: 1.15; font-weight: 500; }
.course-name { margin: 14px 0 0; font-size: 1.12rem; line-height: 1.4; }
.instruction { margin: 32px 0 20px; font-family: Georgia, "Times New Roman", serif; font-size: 1.12rem; line-height: 1.5; }
.practice-options { margin: 0 0 24px; padding: 0; border: 0; font-family: Georgia, "Times New Roman", serif; }
.practice-options legend { margin-bottom: 6px; font-weight: 700; }
.practice-options label { display: flex; align-items: center; gap: 10px; min-height: 44px; width: fit-content; cursor: pointer; }
.practice-options input { margin: 0; width: 18px; height: 18px; accent-color: var(--navy); }
.practice-options input:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.start-button, .result-actions button {
  min-height: 46px;
  padding: 11px 25px;
  border: 1px solid var(--navy);
  border-radius: 2px;
  background: var(--navy);
  color: #fbfaf5;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 0 var(--navy-dark);
}
.start-button:hover, .result-actions button:hover { background: var(--navy-dark); }
.start-button:active, .result-actions button:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--navy-dark); }
button:focus-visible, .typing-sheet:focus-within { outline: 3px solid var(--focus); outline-offset: 4px; }

.practice-screen { min-height: calc(100dvh - clamp(44px, 8vh, 92px)); display: grid; place-items: center; }
.practice-folder { width: min(860px, calc(100vw - 120px)); height: min(700px, calc(100dvh - 46px)); transform: translate(-52%, -48%) rotate(-1.2deg); }
.paper-stack { position: relative; width: min(790px, calc(100vw - 76px)); max-height: calc(100dvh - 56px); overflow: auto; scrollbar-width: thin; padding: 2px 14px 30px; }
.source-sheet, .typing-sheet { width: 100%; padding: clamp(25px, 4vw, 42px) clamp(28px, 5vw, 58px); }
.source-sheet { min-height: 310px; transform: rotate(0.24deg); z-index: 1; }
.document-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 24px; padding-bottom: 14px; border-bottom: 1px solid #9d9a90; }
.document-heading h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1rem; font-weight: 700; letter-spacing: 0.08em; }
.source-text { margin: 25px 0 3px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.02rem, 1.45vw, 1.16rem); line-height: 1.64; white-space: pre-wrap; }
.source-line { margin: 24px 0 0; color: var(--muted); font-size: 0.86rem; line-height: 1.45; }
.current-char { background: #e8dfba; box-shadow: inset 0 -1px #756d47; }

.typing-sheet { min-height: 250px; margin-top: -8px; transform: rotate(-0.38deg); }
.typing-sheet label { display: block; color: var(--ink); font-size: 1rem; }
.typing-field textarea {
  display: block;
  width: 100%;
  min-height: 116px;
  margin-top: 20px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--navy);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(16px, 1.45vw, 1.16rem);
  line-height: 1.64;
  resize: none;
}
.typing-field textarea:disabled { opacity: 1; color: var(--ink); -webkit-text-fill-color: var(--ink); }

.attempt-controls {
  min-height: 48px;
  margin-top: 16px;
  padding-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-top: 1px solid #9d9a90;
  color: var(--ink);
}
.attempt-controls p { margin: 0; font-size: 1rem; font-weight: 650; white-space: nowrap; }
.attempt-controls time { margin-left: 0.3em; color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 750; }
.attempt-controls div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px 20px; }
.attempt-controls button,
.pause-notice button,
.document-confirm button {
  min-height: 36px;
  padding: 6px 1px 5px;
  border: 0;
  border-bottom: 2px solid currentColor;
  border-radius: 0;
  background: transparent;
  color: var(--navy);
  font-size: 1rem;
  font-weight: 650;
  white-space: nowrap;
}
.attempt-controls button:hover,
.pause-notice button:hover,
.document-confirm button:hover { color: var(--ink); }
.attempt-controls button:active,
.pause-notice button:active,
.document-confirm button:active { transform: translateY(1px); }

.pause-notice,
.document-confirm {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid #c4c0b5;
}
.pause-notice { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.pause-notice strong { font-family: Georgia, "Times New Roman", serif; font-size: 1.12rem; font-weight: 700; }
.document-confirm p { margin: 0 0 12px; font-family: Georgia, "Times New Roman", serif; font-size: 1rem; line-height: 1.45; }
.document-confirm div { display: flex; gap: 22px; }
.sr-status { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.result-slip {
  position: fixed;
  right: clamp(20px, 5vw, 76px);
  top: 18vh;
  width: 270px;
  z-index: 3;
  padding: 26px 25px 24px;
  background: #eee4a9;
  border: 1px solid #cfc17d;
  border-radius: 1px;
  box-shadow: var(--paper-shadow);
  transform: rotate(1.2deg);
}
.result-slip h2 { margin: 0 0 22px; font-family: Georgia, "Times New Roman", serif; font-size: 1.25rem; }
.result-slip dl { margin: 0; }
.result-slip dl div { display: flex; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.result-slip dt, .result-slip dd { margin: 0; font-size: 1rem; }
.result-slip dt { font-weight: 650; }
.result-slip dd { font-weight: 750; }
.result-slip dl div:first-child { padding-bottom: 10px; border-bottom: 1px solid #b8aa69; }
.result-slip dl div:first-child dt,
.result-slip dl div:first-child dd { font-size: 1.08rem; }
.result-source { margin: 19px 0 0; padding-top: 14px; border-top: 1px solid #b8aa69; font-size: 0.82rem; line-height: 1.45; }
.result-source a { color: var(--navy); }
.result-actions { display: grid; gap: 12px; margin-top: 24px; }
.result-actions button { width: 100%; }
.result-actions .plain-button { background: transparent; color: var(--navy); box-shadow: none; }
.result-actions .plain-button:hover { background: rgba(38, 62, 84, 0.08); }
.result-actions .home-action { justify-self: center; width: auto; min-height: 44px; padding: 8px 3px; border: 0; border-bottom: 1px solid currentColor; border-radius: 0; background: transparent; color: var(--navy); font-weight: 500; box-shadow: none; }
.result-actions .home-action:hover { background: transparent; color: var(--ink); }
.result-actions .home-action:active { box-shadow: none; }

@media (min-width: 781px) {
  .home-screen, .practice-screen { position: relative; isolation: isolate; }
  .home-paper { display: block; position: relative; width: min(610px, calc(100vw - 230px)); transform: translateX(-65px); }
  .cover-sheet { width: 100%; }
  .home-screen > .folder { left: calc(50% - 65px); width: min(710px, calc(100vw - 150px)); height: min(600px, calc(100dvh - 86px)); }
  .practice-folder { left: calc(50% - 45px); }
  .paper-stack { transform: translateX(-45px); }
  .desktop-object { display: block; position: absolute; z-index: -1; }
  .desktop-pad {
    left: calc(50% + 220px);
    top: calc(50% + 145px);
    width: 260px;
    height: 330px;
    border: 1px solid #c8bb79;
    border-top: 18px solid #c8bb79;
    background: #eadf99;
    transform: rotate(-6deg);
    box-shadow: 0 2px 4px rgba(58, 48, 37, 0.09);
  }
  .desktop-pad::before {
    content: "";
    position: absolute;
    top: 28px;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(75, 102, 137, 0.25);
    box-shadow: 0 28px rgba(75, 102, 137, 0.25), 0 56px rgba(75, 102, 137, 0.25), 0 84px rgba(75, 102, 137, 0.25), 0 112px rgba(75, 102, 137, 0.25), 0 140px rgba(75, 102, 137, 0.25), 0 168px rgba(75, 102, 137, 0.25), 0 196px rgba(75, 102, 137, 0.25), 0 224px rgba(75, 102, 137, 0.25), 0 252px rgba(75, 102, 137, 0.25);
  }
  .desktop-pen {
    left: calc(50% + 430px);
    top: 19%;
    width: 9px;
    height: 212px;
    background: var(--navy);
    border: 1px solid var(--navy-dark);
    border-radius: 2px 2px 0 0;
    transform: rotate(12deg);
    box-shadow: 1px 1px 2px rgba(58, 48, 37, 0.09);
  }
  .desktop-pen::before { content: ""; position: absolute; top: 17px; right: -3px; width: 3px; height: 60px; border: 1px solid #777c7b; border-left: 0; }
  .desktop-pen::after { content: ""; position: absolute; bottom: -12px; left: 0; border-left: 3px solid transparent; border-right: 3px solid transparent; border-top: 12px solid #8c8778; }
  .home-paper > .clip-fragment { display: block; position: absolute; z-index: 2; top: -9px; left: 31px; width: 13px; height: 35px; border: 2px solid #777c7b; border-radius: 7px; transform: rotate(-7deg); }
  .home-paper > .clip-fragment::before { content: ""; position: absolute; inset: 4px 2px 3px; border: 1px solid #8c9291; border-top: 0; border-radius: 0 0 4px 4px; }
}

@media (min-width: 781px) and (max-width: 1120px) {
  .home-paper { width: min(610px, calc(100vw - 160px)); transform: translateX(-25px); }
  .home-screen > .folder { left: calc(50% - 25px); }
  .desktop-pen { left: auto; right: 6px; }
  .desktop-pad { left: auto; right: -65px; }
  .paper-stack { transform: none; }
  .practice-folder { left: 50%; }
}

@media (max-width: 1120px) {
  .result-slip { right: 22px; top: auto; bottom: 22px; }
  .practice-screen.is-complete .paper-stack { transform: translateX(-110px); }
}

@media (max-width: 780px) {
  html, body { overflow-x: clip; overflow-y: visible; }
  .desk { padding: 28px 8px 32px; overflow: visible; }
  .home-screen > .folder { display: none; }
  .home-paper { display: block; position: relative; z-index: 1; width: calc(100vw - 42px); }
  .cover-sheet { width: 100%; padding: 30px 28px; transform: none; }
  /* Mobile paint order: fragments 0, paper 1, native input/controls 2, results 3. */
  .desk-fragment { display: block; position: absolute; z-index: 0; pointer-events: none; }
  .paper { position: relative; z-index: 1; }
  .cover-copy { position: relative; z-index: 2; }
  .folder-fragment {
    top: -5px;
    left: -5px;
    width: calc(100% - 4px);
    height: 90px;
    background: var(--folder);
    border: 1px solid #a48d58;
    transform: rotate(-0.6deg);
  }
  .folder-fragment::before {
    content: "";
    position: absolute;
    top: -13px;
    left: 15px;
    width: 82px;
    height: 14px;
    border: 1px solid #a48d58;
    border-bottom: 0;
    border-radius: 3px 3px 0 0;
    background: var(--folder);
  }
  .pad-fragment {
    bottom: -11px;
    right: 0;
    width: 94px;
    height: 88px;
    background: #eadf99;
    border: 1px solid #c8bb79;
    transform: rotate(4deg);
  }
  .pad-fragment::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 8px;
    height: 1px;
    background: rgba(75, 102, 137, 0.3);
    box-shadow: 0 -18px rgba(75, 102, 137, 0.3), 0 -36px rgba(75, 102, 137, 0.3);
  }
  .clip-fragment {
    z-index: 2;
    top: -9px;
    left: 31px;
    width: 13px;
    height: 35px;
    border: 2px solid #777c7b;
    border-radius: 7px;
    transform: rotate(-7deg);
  }
  .clip-fragment::before {
    content: "";
    position: absolute;
    inset: 4px 2px 3px;
    border: 1px solid #8c9291;
    border-top: 0;
    border-radius: 0 0 4px 4px;
  }
  .practice-screen { width: 100%; min-height: 0; display: block; }
  .practice-folder { display: none; }
  .paper-stack { position: relative; z-index: 1; width: 100%; max-height: none; overflow: visible; padding: 0; }
  .source-sheet, .typing-sheet { position: relative; z-index: 1; width: 100%; padding: 22px 20px; transform: none; }
  .source-sheet {
    position: sticky;
    top: var(--practice-view-top, 0px);
    z-index: 3;
    min-height: 0;
    max-height: min(240px, calc(var(--practice-view-height, 100dvh) * 0.38));
    overflow-y: auto;
    overscroll-behavior: auto;
  }
  .typing-sheet { min-height: 224px; margin-top: -1px; }
  .document-heading { display: block; position: sticky; top: -21px; z-index: 1; padding-top: 21px; background: var(--paper); margin-top: -21px; }
  .document-heading h1 { margin-top: 0; }
  .source-text, .typing-field textarea { font-size: 1.0625rem; line-height: 1.55; }
  .source-text { margin-top: 18px; }
  .typing-field textarea {
    position: relative;
    z-index: 2;
    min-height: 96px;
    margin-top: 16px;
    color: var(--ink);
    -webkit-text-fill-color: var(--ink);
    opacity: 1;
    background: transparent;
    caret-color: var(--navy);
    max-height: calc(var(--practice-view-height, 100dvh) * 0.32);
    overflow-y: auto;
  }
  .attempt-controls, .pause-notice, .document-confirm { position: relative; z-index: 2; }
  .attempt-controls { display: block; margin-top: 12px; padding-top: 10px; }
  .attempt-controls p { min-height: 32px; display: flex; align-items: center; }
  .attempt-controls div { display: flex; justify-content: space-between; gap: 4px 14px; }
  .attempt-controls button,
  .pause-notice button,
  .document-confirm button { min-height: 44px; padding: 9px 3px 8px; }
  .pause-notice { min-height: 56px; margin-top: 8px; padding-top: 7px; }
  .document-confirm { margin-top: 8px; padding-top: 11px; }
  .document-confirm div { gap: 18px; }
  .practice-screen.is-complete .paper-stack { transform: none; }
  .result-slip {
    position: relative;
    z-index: 3;
    inset: auto;
    width: min(100%, 360px);
    margin: 12px auto 24px;
    padding: 24px 22px;
    transform: rotate(0.6deg);
  }
  .result-actions button { min-height: 48px; }
}

@media (max-width: 340px) {
  .source-sheet, .typing-sheet { padding-right: 16px; padding-left: 16px; }
  .attempt-controls div { justify-content: flex-start; column-gap: 20px; }
}

@media (max-width: 780px) and (max-height: 600px) {
  .desk { padding-top: 25px; }
  .source-text { font-size: 1rem; line-height: 1.45; }
  .typing-sheet { min-height: 210px; }
}

@media (max-height: 720px) and (min-width: 781px) {
  .desk { padding-top: 18px; padding-bottom: 18px; }
  .paper-stack { max-height: calc(100dvh - 36px); }
  .source-sheet, .typing-sheet { padding-top: 22px; padding-bottom: 22px; }
  .source-text { margin-top: 17px; line-height: 1.5; }
  .typing-field textarea { min-height: 86px; margin-top: 14px; line-height: 1.5; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media (forced-colors: active) {
  .current-char { forced-color-adjust: none; color: CanvasText; background: Highlight; }
}
