/* ---------------------------------------------------------------------------
   touchtype — design tokens
--------------------------------------------------------------------------- */
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/jetbrains-mono-400.woff2") format("woff2");
}

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --bg: #f7f6f3;
  --bg-glow-1: rgba(96, 82, 255, 0.09);
  --bg-glow-2: rgba(30, 170, 150, 0.07);
  --surface: #ffffff;
  --surface-2: #efeee9;
  --surface-3: #e7e5df;
  --ink: #191a20;
  --ink-2: #555866;
  --ink-3: #6e7180;
  --ink-4: #b9bbc4;
  --line: rgba(20, 20, 35, 0.085);
  --line-strong: rgba(20, 20, 35, 0.16);
  --accent: #574bf0;
  --accent-2: #8b5cf6;
  --accent-ink: #ffffff;
  --accent-soft: rgba(87, 75, 240, 0.09);
  --good: #17855b;
  --good-soft: rgba(23, 133, 91, 0.1);
  --bad: #d93a44;
  --bad-soft: rgba(217, 58, 68, 0.12);
  --shadow: 0 1px 2px rgba(20, 20, 35, 0.04), 0 8px 24px -16px rgba(20, 20, 35, 0.25);
  --shadow-lg: 0 24px 60px -24px rgba(18, 16, 40, 0.35);
  --radius: 18px;
  --caret: #574bf0;
  --thumb-left: #574bf0;
  --thumb-right: #0e9584;
  --space-dot: rgba(25, 26, 32, 0.26);
  --veil: rgba(247, 246, 243, 0.72);
  --typing-size: clamp(17px, 3.1vw, 21px);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0b0c11;
  --bg-glow-1: rgba(124, 108, 255, 0.16);
  --bg-glow-2: rgba(45, 212, 191, 0.07);
  --surface: #15171e;
  --surface-2: #1d2029;
  --surface-3: #262a35;
  --ink: #eceef6;
  --ink-2: #a7abbc;
  --ink-3: #8b90a1;
  --ink-4: #454a59;
  --line: rgba(255, 255, 255, 0.075);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #8f86ff;
  --accent-2: #b18cff;
  --accent-ink: #100e26;
  --accent-soft: rgba(143, 134, 255, 0.14);
  --good: #3ddc97;
  --good-soft: rgba(61, 220, 151, 0.12);
  --bad: #ff6b74;
  --bad-soft: rgba(255, 107, 116, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 30px -20px rgba(0, 0, 0, 0.8);
  --shadow-lg: 0 30px 80px -30px rgba(0, 0, 0, 0.85);
  --caret: #a79fff;
  --thumb-left: #a79fff;
  --thumb-right: #2dd4bf;
  --space-dot: rgba(236, 238, 246, 0.3);
  --veil: rgba(11, 12, 17, 0.72);
  --typing-size: clamp(17px, 3.1vw, 21px);
  color-scheme: dark;
}

/* ---------------------------------------------------------------------------
   Base
--------------------------------------------------------------------------- */
:root[data-size="s"] {
  --typing-size: clamp(15px, 2.7vw, 18px);
}

:root[data-size="l"] {
  --typing-size: clamp(20px, 3.9vw, 27px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  position: fixed;
  inset: 0;
  margin: 0;
  background:
    radial-gradient(1100px 600px at 8% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 520px at 100% 0%, var(--bg-glow-2), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

svg {
  display: block;
}

[hidden] {
  display: none !important;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  height: var(--app-h, 100dvh);
}

/* ---------------------------------------------------------------------------
   Top bar
--------------------------------------------------------------------------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 20px);
  padding: max(10px, env(safe-area-inset-top)) clamp(12px, 3vw, 28px) 8px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
  flex: 0 0 auto;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  justify-items: center;
  padding: 6px 5px;
  gap: 2px;
  box-shadow: 0 4px 14px -6px var(--accent), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.brand-mark span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fff;
}

.brand-mark span:nth-child(2) {
  height: 10px;
  border-radius: 3px;
}

.brand-name {
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 17px;
}

.brand-name em {
  font-style: normal;
  color: var(--ink-3);
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 11px;
  background: var(--surface-2);
  margin-inline: auto;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
  white-space: nowrap;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(20, 20, 35, 0.08);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  display: grid;
  place-items: center;
  transition: background 140ms ease, color 140ms ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.icon-btn svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.goal-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}

.goal-badge svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-dasharray: 56.5;
  stroke-dashoffset: var(--goal-offset, 56.5);
  transform: rotate(-90deg);
  transition: stroke-dashoffset 500ms ease;
}

.goal-badge.is-complete {
  color: var(--good);
}

/* ---------------------------------------------------------------------------
   Views
--------------------------------------------------------------------------- */
main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  width: 100%;
}

.view {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 clamp(12px, 3vw, 28px);
}

.view-practice {
  padding-bottom: 4px;
}

/* HUD */
.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(14px, 4vw, 30px);
  padding: 10px 2px 2px;
}

.hud-stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
}

.hud-value {
  font-size: clamp(17px, 2.2vw, 21px);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  transition: color 160ms ease;
}

.hud-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.hud-stat.is-low .hud-value {
  color: var(--bad);
}

.hud-grow {
  flex: 1 1 auto;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-2);
  height: 32px;
  padding: 0 11px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.ghost-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ghost-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.ghost-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.ghost-btn-small {
  height: 26px;
  padding: 0 9px;
  font-size: 11.5px;
  border-radius: 7px;
}

/* focus keys */
.focus-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 2px 2px 6px;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 600;
}

.focus-group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.focus-group > span {
  letter-spacing: 0.02em;
}

.kbd-chip {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.03);
}

.kbd-chip.is-new {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.focus-next {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-3);
  white-space: nowrap;
}

.focus-next b {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.mini-bar {
  width: 54px;
  height: 4px;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
}

.mini-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 400ms ease;
}

/* Stage & typing text */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: clamp(4px, 1vh, 14px) 0;
  cursor: text;
}

.typing {
  width: 100%;
  max-width: 860px;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: flex-start;
  text-align: left;
  column-gap: 0.55em;
  row-gap: 0.1em;
  padding: 10px 0.6em 10px 2px;
  font-family: var(--font-mono);
  font-size: var(--typing-size);
  line-height: 1.7;
  letter-spacing: 0.01em;
  font-variant-ligatures: none;
  user-select: none;
  -webkit-user-select: none;
  scroll-behavior: smooth;
}

.typing:focus,
.typing:focus-visible {
  outline: none;
}

.typing::-webkit-scrollbar {
  display: none;
}

.word {
  display: inline-flex;
  position: relative;
  padding: 0 0.06em;
  border-radius: 7px;
  color: var(--ink-3);
  white-space: nowrap;
  transition: color 200ms ease;
}

.word.is-done {
  color: var(--ink-4);
}

.word.is-active {
  color: var(--ink);
}

.ch {
  position: relative;
  display: inline-block;
  min-width: 0.6em;
  text-align: center;
}

.ch.is-bad {
  color: var(--bad);
  background: var(--bad-soft);
  border-radius: 4px;
  text-decoration: underline wavy var(--bad) 1px;
  text-underline-offset: 4px;
}

.ch.is-caret::before {
  content: "";
  position: absolute;
  left: 0.04em;
  right: 0.04em;
  bottom: -0.02em;
  height: 0.13em;
  min-height: 2px;
  border-radius: 3px;
  background: var(--caret);
  box-shadow: 0 0 0.4em var(--accent-soft);
}

.ch.is-caret.is-left-thumb::before {
  background: var(--thumb-left);
}

.ch.is-caret.is-right-thumb::before {
  background: var(--thumb-right);
}

.ch.is-caret.is-bad::before {
  background: var(--bad);
}

/* Thumb travel hint, floating directly above the caret character. The hand
   dot and colour say which thumb; repeated arrows say which way and how far. */
.thumb-tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% - 0.45em);
  transform: translateX(-50%);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.22em;
  padding: 0.14em 0.36em;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--thumb-left);
  font-family: var(--font-mono);
  font-size: 0.54em;
  line-height: 1;
  letter-spacing: 0.03em;
  white-space: nowrap;
  pointer-events: none;
}

.thumb-tip[data-hand="right"] {
  color: var(--thumb-right);
}

.thumb-tip .hand-dot {
  width: 0.34em;
  height: 0.34em;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.thumb-tip[data-hand="left"] .hand-dot {
  order: -1;
}

.thumb-tip .moves {
  color: inherit;
}

.typing.is-paused .thumb-tip {
  opacity: 0;
}

/* Visible space markers, like keybr — especially useful at line ends. */
.word:not(:last-child)::before {
  content: "";
  position: absolute;
  left: calc(100% + 0.185em);
  top: 52%;
  width: 0.17em;
  height: 0.17em;
  border-radius: 50%;
  background: var(--space-dot);
  transform: translateY(-50%);
  pointer-events: none;
}

.word.is-awaiting-space::after {
  content: "";
  position: absolute;
  left: calc(100% - 0.02em);
  right: auto;
  bottom: -0.02em;
  /* same width as a character cell's underline (0.6em - 0.08em + letter-spacing) */
  width: 0.53em;
  height: 0.13em;
  min-height: 2px;
  border-radius: 3px;
  background: var(--caret);
  box-shadow: 0 0 0.4em var(--accent-soft);
}

.typing.is-paused .ch.is-caret::before {
  opacity: 0.3;
}

.hint {
  flex: 0 0 auto;
  min-height: 22px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink-3);
  text-align: center;
  transition: color 160ms ease, opacity 160ms ease;
  padding: 0 10px;
}

.hint.is-error {
  color: var(--bad);
  font-weight: 600;
}

.hint.is-good {
  color: var(--good);
  font-weight: 600;
}

.hint kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-2);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--ink-2);
}

/* run footer */
.runfoot {
  flex: 0 0 auto;
  padding: 6px 2px calc(2px + env(safe-area-inset-bottom));
}

.runprogress {
  height: 3px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
}

.runprogress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2) 70%, #29c7a8);
  transition: width 220ms ease;
}

.runmeta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 7px;
  font-size: 12px;
  color: var(--ink-3);
  min-height: 26px;
}

.runmeta > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   Device keyboard bridge
--------------------------------------------------------------------------- */
.type-input {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 1;
  width: 2px;
  height: 2px;
  margin: 0;
  padding: 0;
  border: 0;
  resize: none;
  opacity: 0;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: transparent;
  font-size: 16px;
  line-height: 1;
}

.type-input:focus,
.type-input:focus-visible {
  outline: none;
  box-shadow: none;
}

.type-tap {
  position: absolute;
  left: 50%;
  bottom: 2px;
  z-index: 2;
  transform: translate(-50%, 4px);
  display: none;
  align-items: center;
  gap: 7px;
  padding: 7px 12px 7px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease, transform 200ms ease;
}

.type-tap svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body.is-touch .type-tap {
  display: inline-flex;
}

body.is-touch:not(.input-focused) .type-tap {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.is-touch.input-focused .type-tap {
  display: none;
}

/* While the OS keyboard is up, give the text every pixel we can. */
body.kb-open .topbar {
  padding-top: max(6px, env(safe-area-inset-top));
  padding-bottom: 2px;
}

body.kb-open .focus-row {
  min-height: 28px;
  padding-bottom: 2px;
}

body.kb-open .hud {
  padding-top: 4px;
}

body.kb-open .typing {
  font-size: calc(var(--typing-size) * 0.94);
  line-height: 1.6;
}

/* Phones need a little more leading so the thumb hint can sit between rows
   without touching the line above. */
body.is-touch .typing {
  line-height: 1.95;
}

body.is-touch.kb-open .typing {
  line-height: 1.85;
}

/* ---------------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------------- */
.btn {
  height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 100ms ease, background 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.985);
}

.btn svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary {
  background: var(--accent);
  background: linear-gradient(180deg, var(--accent), color-mix(in oklab, var(--accent) 88%, #000));
  color: var(--accent-ink);
  box-shadow: 0 8px 20px -10px var(--accent), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--line);
}

.btn-secondary:hover {
  background: var(--surface-3);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  height: 38px;
  font-size: 13px;
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.btn-danger {
  background: var(--bad-soft);
  color: var(--bad);
}

.btn-block {
  width: 100%;
}

/* ---------------------------------------------------------------------------
   Sheets & toasts
--------------------------------------------------------------------------- */
.sheet-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 12, 20, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 220ms ease;
  pointer-events: auto;
}

.sheet {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 26px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(10px) scale(0.985);
  transition: opacity 220ms ease, transform 260ms cubic-bezier(0.2, 0.9, 0.2, 1);
  outline: none;
}

.sheet-root.is-open .sheet-backdrop,
.sheet-root.is-open .sheet {
  opacity: 1;
  transform: none;
}

.sheet h2 {
  margin: 0 0 6px;
  font-size: 21px;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.sheet p {
  margin: 0;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.55;
}

.sheet-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 0;
  background: var(--surface-2);
  color: var(--ink-2);
  display: grid;
  place-items: center;
}

.sheet-close svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 22px;
}

.sheet-actions .row {
  display: flex;
  gap: 8px;
}

.sheet-actions .row > * {
  flex: 1;
}

.sheet-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

.sheet-eyebrow .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.toasts {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 62px);
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: min(92vw, 420px);
}

.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 9px 15px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in 260ms cubic-bezier(0.2, 0.9, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toast .kbd-chip {
  background: rgba(255, 255, 255, 0.12);
  border-color: transparent;
  color: inherit;
  height: 19px;
  min-width: 19px;
  font-size: 11px;
}

.toast.is-out {
  animation: toast-out 220ms ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(6px) scale(0.97); }
}

/* ---------------------------------------------------------------------------
   Pause veil
--------------------------------------------------------------------------- */
.pause-veil {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--veil);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 20px;
  animation: fade-in 200ms ease;
}

.pause-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pause-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  position: relative;
  margin-bottom: 6px;
}

.pause-icon::before,
.pause-icon::after {
  content: "";
  position: absolute;
  top: 15px;
  width: 4px;
  height: 14px;
  border-radius: 2px;
  background: var(--ink-2);
}

.pause-icon::before { left: 18px; }
.pause-icon::after { right: 18px; }

.pause-card h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.pause-card p {
  margin: 0 0 12px;
  color: var(--ink-2);
  font-size: 13px;
}

.pause-sub {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 4px;
}

@keyframes fade-in {
  from { opacity: 0; }
}

/* ---------------------------------------------------------------------------
   Intro sheet
--------------------------------------------------------------------------- */
.intro-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  place-items: center;
  padding: 10px 8px;
  gap: 3px;
  margin-bottom: 16px;
  box-shadow: 0 10px 26px -12px var(--accent);
}

.intro-mark span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
}

.intro-mark span:nth-child(2) {
  height: 14px;
  border-radius: 3px;
}

.feature-list {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.feature-list li {
  display: flex;
  gap: 11px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink-2);
}

.feature-list .icon {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
}

.feature-list svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.feature-list b {
  color: var(--ink);
  font-weight: 650;
}

/* ---------------------------------------------------------------------------
   Results sheet
--------------------------------------------------------------------------- */
.result-hero {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 18px 0 4px;
}

.result-wpm {
  font-size: 56px;
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, var(--ink), color-mix(in oklab, var(--accent) 65%, var(--ink)));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.result-unit {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.metric {
  background: var(--surface-2);
  border-radius: 13px;
  padding: 11px 12px;
}

.metric span {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 3px;
}

.metric b {
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.result-keys {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 13px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.result-keys .label {
  font-size: 12.5px;
  color: var(--ink-2);
  font-weight: 600;
}

.result-keys .chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.result-note {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--ink-3);
  text-align: center;
}

/* ---------------------------------------------------------------------------
   Progress view
--------------------------------------------------------------------------- */
.view-progress {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 28px;
  display: block;
  scrollbar-width: thin;
}

.progress-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 2px 16px;
}

.progress-head h1 {
  margin: 0;
  font-size: clamp(22px, 3.4vw, 28px);
  letter-spacing: -0.03em;
}

.progress-head p {
  margin: 4px 0 0;
  color: var(--ink-3);
  font-size: 13px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-card .value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-top: 6px;
}

.stat-card .value b {
  font-size: clamp(22px, 3vw, 27px);
  font-weight: 680;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.stat-card .value small {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-3);
}

.stat-card .foot {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--ink-3);
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.005em;
}

.panel .sub {
  font-size: 11.5px;
  color: var(--ink-3);
}

.chart {
  width: 100%;
  height: auto;
  aspect-ratio: 600 / 170;
  max-height: 240px;
  display: block;
  overflow: visible;
}

.chart .grid-line {
  stroke: var(--line);
  stroke-width: 1;
}

.chart .axis-label {
  fill: var(--ink-3);
  font-size: 9px;
  font-family: var(--font-ui);
  font-weight: 600;
}

.chart .area {
  fill: url(#chartFill);
}

.chart .line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart .dot {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 2;
}

.chart .dot-last {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 2.5;
}

.chart-empty {
  height: 168px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--ink-3);
  font-size: 12.5px;
  padding: 0 16px;
}

.goal-ring-card {
  display: flex;
  align-items: center;
  gap: 16px;
}

.ring-wrap {
  position: relative;
  width: 84px;
  height: 84px;
  flex: 0 0 auto;
}

.ring-wrap svg {
  width: 84px;
  height: 84px;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--surface-3);
  stroke-width: 9;
}

.ring-fill {
  fill: none;
  stroke: url(#ringGrad);
  stroke-width: 9;
  stroke-linecap: round;
  transition: stroke-dashoffset 700ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.ring-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  line-height: 1.05;
}

.ring-text b {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.ring-text small {
  display: block;
  font-size: 9.5px;
  color: var(--ink-3);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.goal-copy h3 {
  font-size: 15px;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.goal-copy p {
  margin: 0;
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.5;
}

.goal-copy .streak {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 9px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--surface-2);
  padding: 4px 9px;
  border-radius: 999px;
}

.goal-copy .streak svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* heatmap */
.heatmap {
  display: flex;
  flex-direction: column;
  gap: 5px;
  user-select: none;
  -webkit-user-select: none;
}

.heat-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.heat-key {
  flex: 1 1 0;
  max-width: 46px;
  aspect-ratio: 1 / 1;
  min-height: 26px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: clamp(11px, 2.5vw, 13px);
  font-weight: 600;
  display: grid;
  place-items: center;
  position: relative;
  padding: 0;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.heat-key:hover,
.heat-key.is-selected {
  transform: translateY(-1px);
  box-shadow: 0 0 0 2px var(--accent);
}

.heat-key[data-level="0"] {
  border: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--ink-4);
}

.heat-key .lvl-ring {
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  border-radius: 0 0 7px 7px;
  opacity: 0.9;
}

.heat-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  font-size: 10.5px;
  color: var(--ink-3);
  font-weight: 600;
}

.heat-legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.heat-legend .mid {
  flex: 1 1 auto;
  height: 6px;
  border-radius: 4px;
  background: linear-gradient(90deg, hsl(4 72% 58% / 0.85), hsl(38 88% 55% / 0.85), hsl(150 62% 42% / 0.85));
}

.key-detail {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 11px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  font-size: 12px;
  color: var(--ink-3);
}

.key-detail .big {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.key-detail dl {
  display: flex;
  gap: 14px;
  margin: 0;
  flex-wrap: wrap;
}

.key-detail dt {
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 1px;
}

.key-detail dd {
  margin: 0;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.weak-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.weak-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
}

.weak-row .letter {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ink-2);
  text-align: center;
}

.weak-row .bar {
  height: 7px;
  border-radius: 5px;
  background: var(--surface-2);
  overflow: hidden;
}

.weak-row .bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.weak-row .val {
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  font-weight: 600;
  font-size: 11.5px;
  min-width: 34px;
  text-align: right;
}

.panel-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
}

.learned-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.learned-strip .kbd-chip {
  opacity: 0.9;
}

/* ---------------------------------------------------------------------------
   Settings sheet
--------------------------------------------------------------------------- */
.settings {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 18px;
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.setting:last-of-type {
  border-bottom: 0;
}

.setting .text {
  min-width: 0;
}

.setting .text b {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.setting .text span {
  display: block;
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 2px;
  line-height: 1.4;
}

.switch {
  flex: 0 0 auto;
  width: 42px;
  height: 25px;
  border-radius: 999px;
  border: 0;
  background: var(--surface-3);
  position: relative;
  transition: background 180ms ease;
  padding: 0;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 180ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.switch[aria-checked="true"] {
  background: var(--accent);
}

.switch[aria-checked="true"]::after {
  transform: translateX(17px);
}

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  flex: 0 0 auto;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 7px;
  transition: background 140ms ease, color 140ms ease;
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.goal-slider {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.goal-slider output {
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--ink-2);
  min-width: 40px;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  border-radius: 3px;
  background: var(--surface-3);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  cursor: pointer;
}

.sheet-footnote {
  margin-top: 16px;
  font-size: 11.5px;
  color: var(--ink-3);
  text-align: center;
}

.sheet-section-label {
  margin: 20px 0 2px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .panel-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  .goal-badge {
    display: none;
  }

  .brand-name {
    font-size: 16px;
  }

  .tab {
    padding: 7px 10px;
    font-size: 12.5px;
  }

  .typing {
    column-gap: 0.5em;
    line-height: 1.75;
  }

  .view {
    padding-inline: 14px;
  }

  .hud-stat-time {
    display: none;
  }

  .focus-row {
    font-size: 11.5px;
  }

  .sheet {
    align-self: end;
    border-radius: 24px 24px 0 0;
    width: 100%;
    max-width: none;
    padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
    transform: translateY(14px);
  }

  .sheet-root {
    padding: 0;
    align-items: end;
  }

  .sheet-root.is-open .sheet {
    transform: none;
  }

  .sheet-actions {
    position: sticky;
    bottom: -20px;
    background: var(--surface);
    margin: 16px -20px -20px;
    padding: 10px 20px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
  }

  .toasts {
    top: calc(env(safe-area-inset-top) + 58px);
  }

  .brand-mark {
    width: 28px;
    height: 28px;
  }
}

@media (max-width: 520px) {
  .brand-name em {
    display: none;
  }
}

@media (max-width: 380px) {
  .brand-name {
    display: none;
  }

  .tab {
    padding: 7px 9px;
    font-size: 12.5px;
  }

  .icon-btn {
    width: 32px;
  }

}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar {
    padding-top: 4px;
    padding-bottom: 2px;
  }

  .hud {
    padding: 0 2px;
  }

  .hud-stat-time,
  .focus-row {
    display: none;
  }

  .typing {
    line-height: 1.5;
  }

  .runfoot {
    padding-bottom: 2px;
  }

  .hint {
    min-height: 16px;
    font-size: 11.5px;
    margin-top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
