:root {
  --paper: #F6F8FB;
  --desk: #E3E8EF;
  --rule: #B7CDE6;
  --margin: #E7A5A8;
  --ink: #1F3FA8;
  --red: #D2232A;
  --text: #2A2E35;
  --muted: #5F6773;
  --key: #FFFFFF;
  --key-edge: #C6D3E4;
  --script: "Playwrite DE Grund", cursive;
  --ui: "Atkinson Hyperlegible Next", system-ui, sans-serif;
  --lh: clamp(44px, 7.2dvh, 58px);
  color-scheme: light;
}

/* Dark mode is the chalkboard */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1E3A2F;
    --desk: #152A21;
    --rule: rgba(236, 239, 232, 0.16);
    --margin: rgba(255, 154, 138, 0.4);
    --ink: #A9C7FF;
    --red: #FF9A8A;
    --text: #ECEFE8;
    --muted: #B3C1B8;
    --key: rgba(236, 239, 232, 0.07);
    --key-edge: rgba(236, 239, 232, 0.16);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--desk);
  color: var(--text);
  font-family: var(--ui);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.app {
  max-width: 440px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}

@media (min-width: 480px) {
  .app {
    min-height: 0;
    margin: 32px auto;
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(20, 30, 50, 0.08), 0 10px 30px rgba(20, 30, 50, 0.1);
  }
}

/* The exercise-book page */
.sheet-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 4px 10px 16px;
}
.title {
  margin: 0;
  font: 400 24px/1.6 var(--script);
  color: var(--ink);
  text-decoration: underline double;
  text-underline-offset: 7px;
  text-decoration-thickness: 1px;
}
.date {
  margin: 0 0 0 auto;
  font: 400 12px/1.6 var(--script);
  color: var(--ink);
}
.help {
  width: 44px;
  height: 44px;
  align-self: center;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 17px;
}

.lines {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}
.line {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 48px;
  height: var(--lh);
  border-bottom: 1px solid var(--rule);
}
.written {
  align-self: end;
  padding: 0 0 7px 16px;
  font: 400 21px/1 var(--script);
  color: var(--ink);
  white-space: nowrap;
}
.written.long { font-size: 16px; }
.wrong .written {
  text-decoration: underline;
  text-decoration-color: var(--red);
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
}
.current .written::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.95em;
  margin-left: 2px;
  vertical-align: -0.1em;
  background: var(--ink);
  animation: blink 1.1s steps(1) infinite;
}

/* Teacher's red pen: correction between the lines, mark in the margin */
.fix {
  position: absolute;
  top: 4px;
  left: 16px;
  font: 400 13px/1 var(--script);
  color: var(--red);
}
.mark {
  display: grid;
  place-items: center;
  border-left: 1.5px solid var(--margin);
  color: var(--red);
  font: 400 20px/1 var(--script);
}
.mark svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--red);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.fresh .mark path,
.grade.fresh path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 0.35s ease-out forwards;
}
.fresh .fix,
.fresh .mark span { animation: appear 0.35s ease-out both; }

.grade {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
  padding: 14px 20px 4px;
  color: var(--red);
  font-family: var(--script);
}
.grade[hidden] { display: none; }
.grade-label { font-size: 15px; }
.grade-num {
  position: relative;
  padding: 0 12px;
  font-size: 30px;
  line-height: 1.4;
}
.grade-num svg {
  position: absolute;
  inset: -4px -6px;
  width: calc(100% + 12px);
  height: calc(100% + 8px);
  fill: none;
  stroke: var(--red);
  stroke-width: 1.8;
  stroke-linecap: round;
}
.grade-word { font-size: 16px; }

/* Controls below the page */
.desk {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 8px calc(10px + env(safe-area-inset-bottom));
}
.desk [hidden] { display: none; }
.row { display: flex; gap: 8px; }

.btn {
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid var(--key-edge);
  border-radius: 10px;
  background: var(--key);
  font-weight: 600;
  font-size: 16px;
}
.btn.primary {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: transparent;
  background: var(--ink);
  color: var(--paper);
}
.btn svg { width: 22px; height: 22px; fill: currentColor; }
.btn svg .wave { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.chip { flex: 1; color: var(--muted); }
.chip[aria-pressed="true"] {
  color: var(--ink);
  border-color: var(--ink);
}

.hint {
  min-height: 4.4em;
  margin: 0;
  padding: 2px 8px;
  font-size: 15px;
  line-height: 1.45;
}
.hint .note { color: var(--muted); }
.gap {
  display: inline-block;
  width: 4.5em;
  border-bottom: 2px solid var(--ink);
}

.kbd {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 6px 4px;
}
.key {
  height: clamp(42px, 6.4dvh, 54px);
  padding: 0;
  border: 1px solid var(--key-edge);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--key);
  font-weight: 600;
  font-size: 17px;
}
.key:active:not(:disabled) { background: var(--rule); }
.key.pressed { animation: press 0.14s ease-out; }
.key:disabled { opacity: 0.4; }
.key.back { grid-column: span 3; }
.key.back svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; vertical-align: middle; }
.key.action {
  grid-column: 1 / -1;
  margin-top: 2px;
  border-color: transparent;
  background: var(--ink);
  color: var(--paper);
}
.key.action:disabled { opacity: 0.35; }

.empty { margin: 0; padding: 8px 8px 24px; text-align: center; color: var(--muted); font-size: 15px; }
.end { text-align: center; padding: 4px 8px 8px; }
.end .btn { width: 100%; }
.end p { margin: 12px 0 0; color: var(--muted); font-size: 15px; }

dialog {
  max-width: 340px;
  padding: 20px 22px;
  border: 0;
  border-radius: 8px;
  background: var(--paper);
  color: var(--text);
  line-height: 1.5;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin: 0 0 8px; font: 400 22px/1.6 var(--script); color: var(--ink); }
dialog p { margin: 0 0 10px; font-size: 15px; }
dialog form { margin-top: 16px; display: flex; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes appear { from { opacity: 0; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes press { 30% { transform: translateY(2px); background: var(--rule); } }

@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; }
  .fresh .mark path, .grade.fresh path { stroke-dashoffset: 0; }
}
