:root {
  --graphite: #25272A; --graphite-2: #3A3C40; --steel: #8D8F90;
  --bone: #ECE6DA; --bone-2: #F5F0E6; --text: #1F2022; --faded: #68635A;
  --signal: #C21F1B; --rule: #25272A40;
  --type: "American Typewriter", "Courier New", Courier, ui-monospace, monospace;
  --ui: ui-monospace, "SF Mono", Menlo, "Courier New", monospace;
  --pad: 18px; --lh: 2.4rem;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--graphite); }
body { margin: 0; color: var(--text); font: 400 1rem/1.45 var(--type); }
h1, h2, h3, p, dl, dd, ol { margin: 0; padding: 0; }
ol { list-style: none; }
button, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; background: none; border: 0; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }

#app { max-width: 880px; margin: 0 auto; background: var(--bone); min-height: 100dvh; display: flex; flex-direction: column; padding: 0 var(--pad); }
.masthead { padding: 18px 0 14px; text-align: center; }
h1 { display: inline-flex; align-items: center; gap: 12px; font-size: clamp(1.45rem, 6.4vw, 2.1rem); font-weight: 700; line-height: 1.1; letter-spacing: -.01em; text-align: left; text-wrap: balance; }
h1 img { width: 1.8em; height: 1.8em; flex: none; display: block; }

.platen { margin-inline: calc(var(--pad) * -1); height: 58px; background: var(--graphite); border-bottom: 4px solid var(--steel); display: flex; align-items: flex-end; justify-content: space-between; padding: 0 18px 12px; position: relative; }
.platen::after { content: ""; position: absolute; left: 0; right: 0; bottom: 24px; height: 4px; background: var(--signal); }
.guide { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 1; }
.screw { width: 16px; height: 16px; border-radius: 50%; background: var(--steel); position: relative; z-index: 1; }
.screw::after { content: ""; position: absolute; left: 2px; right: 2px; top: 7px; height: 2px; background: var(--graphite); transform: rotate(-35deg); }

#options { padding-top: 12px; }
#mode-options { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
#mode-options button { min-height: 44px; font-size: .9375rem; border-bottom: 1px solid var(--rule); color: var(--faded); }
#mode-options [data-pressed="true"] { color: var(--text); font-weight: 700; border-bottom: 3px solid var(--signal); }

#test { display: flex; flex-direction: column; padding-top: 18px; }
#prompt { font-size: clamp(1.4rem, 5.6vw, 1.75rem); line-height: var(--lh); height: calc(var(--lh) * 3); overflow: hidden; cursor: text; color: var(--faded); }
[data-word] { display: inline-block; margin-right: .6em; }
[data-char-state="correct"] { color: var(--text); }
[data-char-state="incorrect"], [data-char-state="extra"] { color: var(--signal); text-decoration: underline 2px; text-underline-offset: 3px; }
[data-char-state="missed"] { color: var(--faded); text-decoration: line-through; }
[data-word-state="current"] { font-weight: 700; }
[data-cursor] { box-shadow: -2px 0 0 var(--signal); }
[data-cursor-after] { box-shadow: 2px 0 0 var(--signal); }

label[for="typing-input"] { margin-top: 10px; font-size: .875rem; color: var(--faded); }
#typing-input { display: block; width: 100%; height: 52px; margin-top: 4px; padding: 13px 14px; background: var(--graphite); color: var(--bone-2); caret-color: var(--signal); border: 0; border-bottom: 3px solid var(--steel); border-radius: 2px; resize: none; overflow: hidden; white-space: pre; font-size: 16px; line-height: 22px; }
#typing-input:focus { outline: none; border-bottom-color: var(--signal); }
#typing-input:disabled { opacity: 1; }
#status { min-height: 1.45em; margin-top: 8px; text-align: center; font-size: .9375rem; color: var(--faded); }

#live-stats { display: grid; grid-template-columns: 1fr 1fr; align-items: end; margin-top: 2px; }
#live-stats .time { grid-column: 1 / -1; text-align: center; }
#live-stats .time dt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
#live-stats .time dd { font-size: clamp(6rem, 30vw, 9rem); font-weight: 700; line-height: 1; letter-spacing: -.02em; color: var(--graphite); }
#live-stats div:not(.time) { display: flex; justify-content: center; align-items: baseline; gap: 8px; font-size: .9375rem; color: var(--faded); padding: 6px 0; }
#live-stats div:not(.time) dd { font-size: 1.375rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

.deck { display: grid; gap: 10px; margin-top: 14px; }
#duration-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#duration-options button { min-height: 52px; border: 2px solid var(--graphite); border-radius: 3px; font-size: 1.125rem; font-weight: 700; }
#duration-options [data-pressed="true"] { background: var(--graphite); color: var(--bone-2); }
#duration-options button:disabled { border-color: var(--rule); color: var(--faded); cursor: default; }
#duration-options button:disabled[data-pressed="true"] { background: none; border-color: var(--graphite); color: var(--text); }
#restart, #again { min-height: 54px; background: var(--signal); color: #fff; border-radius: 3px; font-size: 1.25rem; font-weight: 700; }
#share-copy { min-height: 54px; border: 2px solid var(--graphite); border-radius: 3px; font-size: 1.125rem; font-weight: 700; }

#app[data-state="finished"] #test > :not(#status) { display: none; }
#results { padding-top: 10px; }
h2 { font-size: 1.375rem; font-weight: 700; line-height: 1.2; padding-bottom: 6px; border-bottom: 2px solid var(--graphite); }
h3 { font-size: 1.0625rem; font-weight: 700; margin-top: 22px; }
#new-best { margin-top: 12px; color: var(--signal); font-weight: 700; font-size: 1.125rem; }
#results dl { margin-top: 2px; }
#results dl div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--rule); }
#results dl dd { font-weight: 700; font-variant-numeric: tabular-nums; }
#results .headline { flex-direction: column; align-items: center; gap: 0; padding: 8px 0 14px; }
#results .headline dd { order: -1; font-size: clamp(6rem, 30vw, 9rem); line-height: 1; letter-spacing: -.02em; }
#most-missed { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 6px; font-weight: 700; }
#share-text { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; background: var(--bone-2); border: 1px solid var(--rule); border-radius: 2px; resize: none; font-size: 1rem; }
#history { margin-top: 34px; padding-bottom: 28px; }
#history-list li { padding: 9px 0; border-bottom: 1px solid var(--rule); font-size: .9375rem; }
#history-list:empty::before { content: "No tests yet."; display: block; padding: 9px 0; color: var(--faded); }

.basket { margin: auto calc(var(--pad) * -1) 0; height: 64px; background: var(--graphite); overflow: hidden; }
.basket svg { display: block; width: 100%; height: 100%; }

/* Phone with the keyboard up: keep the words and the input together. */
@media (max-width: 719px) {
  #app:has(#typing-input:focus) .masthead, #app:has(#typing-input:focus) .platen,
  #app:has(#typing-input:focus) #options, #app:has(#typing-input:focus) #history,
  #app:has(#typing-input:focus) .basket, #app:has(#typing-input:focus) .deck,
  #app:has(#typing-input:focus) label[for="typing-input"], #app:has(#typing-input:focus) #status { display: none; }
  #app:has(#typing-input:focus) #test { padding-top: 8px; }
  #app:has(#typing-input:focus) #live-stats { order: -1; grid-template-columns: repeat(3, 1fr); margin: 0 0 6px; }
  #app:has(#typing-input:focus) #live-stats .time { grid-column: auto; }
  #app:has(#typing-input:focus) #live-stats .time dd { font-size: 2.25rem; }
  #app:has(#typing-input:focus) #prompt { --lh: 2.1rem; }
}
@media (min-width: 720px) {
  :root { --pad: 48px; --lh: 2.9rem; }
  #app { margin-top: 28px; min-height: calc(100dvh - 28px); border-radius: 2px 2px 0 0; }
  .platen { height: 64px; }
  #mode-options { display: flex; justify-content: center; gap: 28px; }
  #mode-options button { border-bottom-color: transparent; padding: 0 2px; }
  #prompt { font-size: 1.875rem; }
  #live-stats { grid-template-columns: 1fr auto 1fr; }
  #live-stats .time { grid-column: 2; grid-row: 1; }
  #live-stats div:not(.time) dd { font-size: 1.75rem; }
  .deck { grid-template-columns: 3fr 1fr; }
  #results .deck { grid-template-columns: 1fr 1fr; }
  #results dl { display: grid; grid-template-columns: 1fr 1fr; column-gap: 40px; }
  #results .headline { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
