@font-face {
  font-family: "Obcoro Pixel";
  src: url("/assets/fusion-pixel-12px-monospaced-zh_tw.ttf.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #030909;
  --panel: #040B09F7;
  --ink: #70F995;
  --bright: #9AFFB1;
  --muted: #599D72;
  --line: #2A6940;
  --accent: #FA785C;
  --accent-line: #D45B43;
  --rule: #193C29;
  --inset: 16px;
}

*, *::before, *::after { box-sizing: border-box; border-radius: 0; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 400 16px/1.5 "Obcoro Pixel", monospace;
  font-synthesis: none;
}
h1, h2, p, dl, dd { margin: 0; }
h1, h2, strong { font-weight: 400; }
button, textarea { margin: 0; font: inherit; }
:focus-visible { outline: 2px solid #9AFFB1; outline-offset: 3px; }
::selection { background: #245137; color: var(--bright); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.page {
  max-width: 66rem;
  margin-inline: auto;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.page-head { display: grid; gap: 16px; margin-bottom: 16px; }
h1 {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--bright);
  font-size: 36px;
  line-height: 1.2;
}
.keyboard { width: 36px; height: 26px; flex: none; color: var(--ink); }
.languages { display: flex; }
button {
  position: relative;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--panel);
  cursor: var(--ob-cursor-pointer, pointer);
  transition: color 120ms ease, border-color 120ms ease, background-color 120ms ease;
}
.languages button { flex: 1; }
.languages button + button { margin-left: -1px; }
.languages button::before {
  content: "";
  width: 7px;
  height: 7px;
  border: 1px solid var(--muted);
}
.languages [aria-pressed="true"] {
  z-index: 1;
  border-color: var(--ink);
  color: var(--bright);
  background: #102619;
}
.languages [aria-pressed="true"]::before { border-color: var(--ink); background: var(--ink); }
button:focus-visible { z-index: 2; }
.workspace { display: grid; gap: 14px; }
.panel { min-width: 0; border: 1px solid var(--line); background: var(--panel); }
.section-head, .input-head, footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.section-head {
  min-height: 46px;
  padding: 8px var(--inset);
  border-bottom: 1px solid var(--rule);
}
h2, .input-head label { color: var(--bright); font-size: 18px; line-height: 1.4; }
.counter, .clock, .scores { font-variant-numeric: tabular-nums; }
.counter, .clock, .status, .metric-label, dt { color: var(--muted); font-size: 16px; }
#typed-count { color: var(--ink); }
.reading {
  display: grid;
  align-content: center;
  padding: 18px var(--inset) 20px;
  background: #09160F;
}
#passage {
  color: var(--muted);
  font-size: 24px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-break: strict;
  text-wrap: balance;
}
#passage .correct { color: var(--bright); }
#passage .next { position: relative; background: #11271B; }
#passage .next::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 -1px;
  width: 2px;
  background: var(--ink);
}
#passage .wrong {
  color: var(--accent);
  background: #2D1914;
  text-decoration: underline double;
  text-underline-offset: 3px;
}
.track { display: flex; gap: 1px; height: 4px; background: var(--panel); }
.track i { flex: 1; min-width: 0; background: var(--rule); }
.track .correct { background: var(--ink); }
.track .wrong { background: var(--accent); }
.writing { padding: 14px var(--inset) var(--inset); }
.input-head { margin-bottom: 8px; }
.input-caption { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 10px; }
#extra-count { color: var(--accent); font-size: 14px; }
.clock, .status { display: inline-flex; align-items: center; gap: 7px; }
.clock { flex: none; color: var(--ink); font-size: 18px; }
.clock svg { width: 16px; height: 16px; color: var(--muted); }
textarea {
  display: block;
  width: 100%;
  height: 108px;
  min-height: 108px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--bright);
  caret-color: var(--bright);
  font-size: 20px;
  line-height: 1.5;
  resize: none;
}
textarea::placeholder { color: var(--muted); opacity: 1; }
textarea:read-only { border-color: var(--rule); color: var(--ink); }
.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border: 1px solid currentColor;
}
[data-state="running"] .status { color: var(--ink); }
[data-state="running"] .status::before { background: currentColor; }
[data-state="finished"] { border-color: var(--ink); }
[data-state="finished"] .section-head { background: #132D1E; }
[data-state="finished"] .status { color: var(--bright); }
[data-state="finished"] .status::before {
  width: 10px; height: 6px;
  border-width: 0 0 2px 2px;
  transform: translateY(-1px) rotate(-45deg);
}
.scores {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 14px var(--inset);
}
.metric-label { display: flex; align-items: center; gap: 8px; }
#speed { display: block; margin-top: 4px; color: var(--bright); font-size: clamp(36px, 12.32vw, 48px); line-height: 1.1; overflow-wrap: anywhere; }
#speed.long-value { font-size: 32px; }
#unit { border-left: 1px solid var(--line); padding-left: 8px; color: var(--ink); font-size: 14px; white-space: nowrap; }
.details { display: grid; gap: 8px; border-left: 1px solid var(--rule); padding-left: 14px; }
.details div { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
dd { color: var(--bright); font-size: 24px; line-height: 1.2; }
dd small { margin-left: 2px; font-size: 18px; }
.has-errors { color: var(--accent); }
.actions { padding: 0 var(--inset) var(--inset); }
.primary {
  width: 100%;
  isolation: isolate;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 18px;
}
.primary svg { width: 16px; height: 16px; }
.primary::before, .primary::after {
  position: absolute;
  z-index: -1;
  inset: 0;
  content: "";
  background: var(--accent-line);
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
  transition: background-color 120ms ease;
}
.primary::after { inset: 1px; background: #26130E; }
footer {
  flex-wrap: wrap;
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}
@media (hover: hover) {
  .languages button:hover { z-index: 1; border-color: var(--ink); background: #173321; }
  .primary:hover::before { background: var(--accent); }
  .primary:hover::after { background: #402019; }
}
.languages button:active { background: #21472F; }
.primary:active::after { background: #50291F; }
button:disabled, textarea:disabled { opacity: .5; cursor: default; }

@media (min-width: 48rem) {
  :root { --inset: 24px; }
  .page {
    padding-top: max(clamp(48px, 10vh, 92px), env(safe-area-inset-top));
    padding-inline: max(28px, env(safe-area-inset-left)) max(28px, env(safe-area-inset-right));
  }
  .page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
  h1 { gap: 18px; font-size: 48px; }
  .keyboard { width: 50px; height: auto; }
  .languages button { min-width: 90px; }
  .workspace { grid-template-columns: minmax(0, 2.1fr) minmax(240px, 1fr); gap: 18px; }
  .section-head { min-height: 56px; }
  h2, .input-head label { font-size: 20px; }
  .reading { min-height: 148px; padding-block: 22px; }
  #passage { font-size: 24px; line-height: 1.65; }
  .writing { padding-top: 20px; }
  textarea { min-height: 116px; resize: vertical; }
  .results { display: flex; flex-direction: column; }
  .scores { flex: 1; grid-template-columns: 1fr; align-content: center; gap: 18px; padding-block: 22px; }
  #speed { font-size: 60px; }
  #speed.long-value { font-size: 44px; }
  #unit { font-size: 16px; }
  .details { padding: 14px 0 0; border-left: 0; border-top: 1px solid var(--rule); }
  dd { font-size: 24px; }
  footer { margin-top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

.footer-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}