/* رقن — editorial-greeting style: a centred 1100px column on a 12-column grid (77px columns,
   16px gutters: 12 × 77 + 11 × 16 = 1100), tonal panels, the accent on data and the caret only. */
:root {
  --ground: #efe9dd;            /* warm paper, not bright white */
  --surface: #f7f2e8;
  --raised: #fbf7ef;
  --active: #e6dfd0;
  --border: #e0d6c3;
  --rule: #e7dfcf;
  --control: #d2c7b2;
  --ornament: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='none' stroke='%23a38b5c' stroke-opacity='0.22' stroke-width='1'%3E%3Cpath d='M17 17h22v22H17z'/%3E%3Cpath d='M28 12.4 43.6 28 28 43.6 12.4 28z'/%3E%3Cpath d='M28 0v12.4M28 43.6V56M0 28h12.4M43.6 28H56'/%3E%3Ccircle cx='28' cy='28' r='4'/%3E%3Cpath d='M0 0l5 5M56 0l-5 5M0 56l5-5M56 56l-5-5'/%3E%3C/g%3E%3C/svg%3E");
  --text: #1f201d;
  --muted: #5e5e5b;
  --pending: #74746e;
  --accent: #1b6e66;
  --accent-pale: #e3f0ee;
  --ok-bg: #d7f0de;            /* a letter typed right */
  --bad-bg: #fbd3ce;           /* a letter typed wrong */
  --positive: #2e7d32;
  --negative: #b42318;
  --negative-pale: #fdecea;
  --chart-1: #1b6e66;
  --chart-muted: #cec4b1;
  --grid: #e4dccc;
  --axis-ink: #5e5e5b;
  --ink: #1f201d;
  --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e;
  --pill-neutral-bg: #e9e1d2; --pill-neutral-ink: #3d3d3a;
  --primary: #1f201d; --on-primary: #fbf7ef; --primary-hover: #3a3b37;
  --quiet-hover: #e4dccb;
  --lift: #fdfaf3;              /* a control or card raised off a panel */
  --negative-ink: #7a1d14; --negative-hover: #f9dcd8;
  --f-pinky: #f1e6f3; --f-ring: #e3ecf8; --f-middle: #e1f1e7; --f-index: #f8eed8; --f-thumb: #ebe4d6;   /* finger zones on the keyboard */
  --f-pinky-ink: #8e4a99; --f-ring-ink: #3b6db3; --f-middle-ink: #2f8455; --f-index-ink: #a8741a; --f-thumb-ink: #6b6b66;
  --hand-skin: #b9b2a7; --hand-line: #5e5a54;   /* the drawn hands on the keyboard */
  color-scheme: light;

  --radius-card: 22px;
  --radius-inner: 14px;
  --radius-control: 999px;
  --sidebar-width: 232px;
  --gap: 16px;
  --pad: 20px;
  --control-height: 38px;

  --font: "Instrument Sans", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --fs-title: 28px;
  --fs-section: 15px;
  --fs-kpi: 24px;
  --fs-lead: 32px;
  --fs-body: 14px;
  --fs-small: 13px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --ground: #111111;
  --surface: #191919;
  --raised: #1f1f1f;
  --active: #262626;
  --border: #2e2e2e;
  --rule: #262626;
  --control: #474747;
  --text: #f1f1ee;
  --muted: #b4b4b0;
  --pending: #8e8e89;
  --accent: #4db6aa;
  --accent-pale: #18302d;
  --ok-bg: #173b29;
  --bad-bg: #4d2321;
  --positive: #3fc07a;
  --negative: #f0706a;
  --negative-pale: #3a1c1b;
  --chart-1: #4db6aa;
  --chart-muted: #555552;
  --grid: #2b2b2b;
  --axis-ink: #b4b4b0;
  --ink: #f1f1ee;
  --pill-positive-bg: #172a1d; --pill-positive-ink: #3fc07a;
  --pill-neutral-bg: #2a2a2a; --pill-neutral-ink: #d4d4d0;
  --primary: #f1f1ee; --on-primary: #111111; --primary-hover: #d8d8d4;
  --quiet-hover: #303030;
  --lift: #383838;
  --negative-ink: #f7a49f; --negative-hover: #4a2321;
  --f-pinky: #33263a; --f-ring: #1f2a3a; --f-middle: #1d3326; --f-index: #3a3020; --f-thumb: #2a2a2a;
  --f-pinky-ink: #d39be0; --f-ring-ink: #8db6f0; --f-middle-ink: #74cf98; --f-index-ink: #e7b765; --f-thumb-ink: #b4b4b0;
  --hand-skin: #8d877e; --hand-line: #d6d1c9;
  --ornament: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='0.045' stroke-width='1'%3E%3Cpath d='M17 17h22v22H17z'/%3E%3Cpath d='M28 12.4 43.6 28 28 43.6 12.4 28z'/%3E%3Cpath d='M28 0v12.4M28 43.6V56M0 28h12.4M43.6 28H56'/%3E%3Ccircle cx='28' cy='28' r='4'/%3E%3Cpath d='M0 0l5 5M56 0l-5 5M0 56l5-5M56 56l-5-5'/%3E%3C/g%3E%3C/svg%3E");
  color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #111111;
  --surface: #191919;
  --raised: #1f1f1f;
  --active: #262626;
  --border: #2e2e2e;
  --rule: #262626;
  --control: #474747;
  --text: #f1f1ee;
  --muted: #b4b4b0;
  --pending: #8e8e89;
  --accent: #4db6aa;
  --accent-pale: #18302d;
  --ok-bg: #173b29;
  --bad-bg: #4d2321;
  --positive: #3fc07a;
  --negative: #f0706a;
  --negative-pale: #3a1c1b;
  --chart-1: #4db6aa;
  --chart-muted: #555552;
  --grid: #2b2b2b;
  --axis-ink: #b4b4b0;
  --ink: #f1f1ee;
  --pill-positive-bg: #172a1d; --pill-positive-ink: #3fc07a;
  --pill-neutral-bg: #2a2a2a; --pill-neutral-ink: #d4d4d0;
  --primary: #f1f1ee; --on-primary: #111111; --primary-hover: #d8d8d4;
  --quiet-hover: #303030;
  --lift: #383838;
  --negative-ink: #f7a49f; --negative-hover: #4a2321;
  --f-pinky: #33263a; --f-ring: #1f2a3a; --f-middle: #1d3326; --f-index: #3a3020; --f-thumb: #2a2a2a;
  --f-pinky-ink: #d39be0; --f-ring-ink: #8db6f0; --f-middle-ink: #74cf98; --f-index-ink: #e7b765; --f-thumb-ink: #b4b4b0;
  --hand-skin: #8d877e; --hand-line: #d6d1c9;
  --ornament: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='0.045' stroke-width='1'%3E%3Cpath d='M17 17h22v22H17z'/%3E%3Cpath d='M28 12.4 43.6 28 28 43.6 12.4 28z'/%3E%3Cpath d='M28 0v12.4M28 43.6V56M0 28h12.4M43.6 28H56'/%3E%3Ccircle cx='28' cy='28' r='4'/%3E%3Cpath d='M0 0l5 5M56 0l-5 5M0 56l5-5M56 56l-5-5'/%3E%3C/g%3E%3C/svg%3E");
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ornament) center top / 56px 56px fixed, var(--ground);
  color: var(--text);
  font: 400 var(--fs-body)/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd, ol, ul, fieldset { margin: 0; padding: 0; }
ol, ul { list-style: none; }
fieldset { border: 0; min-width: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-pale); }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 22px;
  padding: 28px 12px 20px;
  border-inline-end: 1px solid var(--border);
  background: color-mix(in srgb, var(--ground) 82%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; padding-inline: 10px; text-decoration: none; }
.mark { width: 34px; height: 34px; flex: none; }
.brand-text { display: grid; line-height: 1.25; }
.brand-text strong { font-size: 18px; font-weight: 600; }
.brand-text span { font-size: var(--fs-small); color: var(--muted); }

/* the account card: who is practising, whether it is saved, and the score */
.account { display: grid; gap: 12px; margin-inline: 10px; padding: 14px; border-radius: var(--radius-inner); background: var(--surface); }
.acct-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.acct-avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
}
.acct-avatar img { width: 100%; height: 100%; object-fit: cover; }
.acct-id { display: grid; min-width: 0; line-height: 1.4; }
.acct-id strong { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-id em { font-style: normal; font-size: 12px; color: var(--muted); }
.sync::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-inline-end: 6px; vertical-align: 1px; background: var(--chart-muted); }
.sync.is-synced::before, .sync.is-idle::before { background: var(--positive); }
.sync.is-syncing::before { background: var(--accent); }
.sync.is-error::before, .sync.is-offline::before { background: var(--negative); }
.acct-score { display: grid; grid-template-columns: 1fr auto; align-items: baseline; column-gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
.acct-score span { font-size: 13px; color: var(--muted); }
.acct-score strong { font-size: 20px; font-weight: 500; line-height: 1.2; }
.acct-score em { grid-column: 1 / -1; font-style: normal; font-size: 12px; color: var(--muted); }
.btn-google { background: var(--lift); color: var(--text); border-color: var(--control); }
.btn-google:hover { background: var(--quiet-hover); }
.account .btn-google { width: 100%; height: 36px; padding-inline: 10px; font-size: 13px; }
.g-mark { width: 16px; height: 16px; flex: none; }
.acct-warn { font-size: 12px; line-height: 1.5; color: var(--negative-ink); background: var(--negative-pale); padding: 8px 10px; border-radius: 10px; }
#acctNote.is-warn { color: var(--negative); }

/* the switch between the Arabic and the English page */
.lang-switch { display: flex; gap: 2px; padding: 3px; margin-inline: 10px; border-radius: var(--radius-control); background: var(--active); }
.lang-switch a {
  flex: 1; height: 32px; display: grid; place-items: center; border-radius: var(--radius-control);
  color: var(--muted); font-size: 13px; text-decoration: none; transition: background-color 120ms ease, color 120ms ease;
}
.lang-switch a:hover { color: var(--text); }
.lang-switch a[aria-current="page"] { background: var(--lift); color: var(--text); font-weight: 500; }
.lang-switch a[lang="ar"] { font-family: "IBM Plex Sans Arabic", var(--font); }

.nav { display: grid; gap: 2px; }
.nav a, .side-row {
  display: flex; align-items: center; gap: 10px;
  height: 36px; padding-inline: 10px; border-radius: 10px;
  text-decoration: none; color: var(--muted); font-size: 14px;
  transition: background-color 120ms ease, color 120ms ease;
}
.nav a:hover, .side-row:hover { background: var(--surface); color: var(--text); }
.nav a[aria-current="page"] { background: var(--active); color: var(--text); font-weight: 500; }
.nav svg, .side-row svg, .menu-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.side-foot { margin-top: auto; display: grid; gap: 12px; }
.side-foot .seg { display: flex; margin-inline: 10px; }
.seg-theme button, .seg-sound button { flex: 1; }
.side-foot .seg-sound button { padding-inline: 6px; }
.side-row { width: 100%; border: 0; background: none; cursor: pointer; text-align: start; }
.side-state { margin-inline-start: auto; font-size: var(--fs-small); color: var(--muted); }
.side-row[aria-pressed="true"] .side-state { color: var(--accent); }
.side-note { padding-inline: 10px; font-size: var(--fs-small); line-height: 1.6; color: var(--muted); }

.topbar { display: none; }

.main { min-width: 0; padding: 56px 32px 72px; }
.col {
  max-width: 1100px; margin-inline: auto;
  display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap);
  align-items: start;
}
.span-12 { grid-column: span 12; }
.span-9 { grid-column: span 9; }
.span-8 { grid-column: span 8; }
.span-6 { grid-column: span 6; }
.span-4 { grid-column: span 4; }
.span-3 { grid-column: span 3; }

/* ---------- title row ---------- */
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
h1, .view-title { font-size: var(--fs-title); line-height: 1.35; font-weight: 500; letter-spacing: -0.01em; text-wrap: balance; }
.sub { margin-top: 6px; font-size: 15px; color: var(--muted); max-width: 70ch; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--control-height); padding-inline: 18px;
  border-radius: var(--radius-control); border: 1px solid transparent;
  font-size: 14px; font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background-color 120ms ease, transform 80ms ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-quiet { background: var(--active); color: var(--text); }
.btn-quiet:hover { background: var(--quiet-hover); }
.btn-danger { background: var(--negative-pale); color: var(--negative-ink); }
.btn-danger:hover { background: var(--negative-hover); }
kbd {
  font: inherit; font-size: 11px; line-height: 1;
  padding: 4px 6px; border-radius: 6px;
  background: color-mix(in srgb, var(--on-primary) 18%, transparent); color: inherit;
}
.btn-quiet kbd { background: var(--lift); }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--radius-control); background: var(--active); }
.seg button {
  height: 32px; padding-inline: 14px; border: 0; border-radius: var(--radius-control);
  background: transparent; color: var(--muted); font-size: 13px; cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--lift); color: var(--text); font-weight: 500; }

.chip {
  display: inline-flex; align-items: center; height: 22px; padding-inline: 9px;
  border-radius: var(--radius-control); background: var(--pill-neutral-bg); color: var(--pill-neutral-ink);
  font-size: 12px; font-weight: 400; vertical-align: 2px; margin-inline-start: 6px;
}
.pill { display: inline-flex; align-items: center; height: 20px; padding-inline: 8px; border-radius: 999px; font-size: 11px; }
.pill-positive { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.link { color: var(--accent); font-size: 13px; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: var(--pad); min-width: 0; box-shadow: 0 1px 2px color-mix(in srgb, var(--text) 4%, transparent); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; min-height: 32px; }
.card-title { font-size: var(--fs-section); font-weight: 600; line-height: 1.4; }
.meta { font-size: var(--fs-small); color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; gap: 10px; }

/* live figures: one strip split by hairlines; the speed leads */
.live { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.live-cell { padding: 4px 20px 6px; border-inline-start: 1px solid var(--border); min-width: 0; }
.live-cell:first-child { border-inline-start: 0; padding-inline-start: 4px; }
.live dt, .kpi dt { font-size: 13px; color: var(--muted); }
.live dd { font-size: var(--fs-kpi); line-height: 1.3; font-variant-numeric: tabular-nums; margin-top: 2px; }
.live .is-lead dd { font-size: var(--fs-lead); }
.live small, .kpi small, .records small, .res-wpm small { font-size: 13px; color: var(--muted); }
.live p { font-size: var(--fs-small); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- the sheet: the one white card on this screen ---------- */
.sheet {
  position: relative;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-inner);
  padding: 28px 36px;
  cursor: text;
  outline: none;
}
.sheet[data-lang="ar"] { --ts: 30px; --lh: 62px; }
.sheet[data-lang="en"] { --ts: 27px; --lh: 50px; }
.type-input {
  position: absolute; inset-block-start: 0; inset-inline-start: 0;
  width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none; overflow: hidden;
}
.text {
  position: relative; overflow: hidden;
  height: calc(var(--lh) * 3);
  font-size: var(--ts); line-height: var(--lh);
  color: var(--pending);
}
.text[lang="ar"] { font-family: "IBM Plex Sans Arabic", var(--font); }
.text[lang="en"] { font-family: "Instrument Sans", var(--font); letter-spacing: 0.005em; }
.text-inner { transition: transform 160ms ease; will-change: transform; }
/* typed letters are marked like a highlighter: green when right, red when wrong.
   Square ends, so a run of letters reads as one continuous band. */
.text-inner .ok { color: var(--text); background: var(--ok-bg); }
.text-inner .bad { color: var(--negative); background: var(--bad-bg); }
/* the caret: a short bar under the letter to type next, as wide as that letter */
.caret {
  position: absolute; top: 0; left: 0;
  height: 3px; border-radius: 2px; background: var(--accent);
  transition: transform 70ms linear, width 70ms linear;
  pointer-events: none;
}
.caret.blink { animation: blink 1.05s steps(1) 0.6s infinite; }
.caret.is-blocked { background: var(--negative); }
@keyframes blink { 50% { opacity: 0; } }
.sheet:not(.is-focused) .caret { opacity: 0.35; animation: none; }
.focus-note {
  position: absolute; inset-inline: 0; bottom: 8px; text-align: center;
  font-size: var(--fs-small); color: var(--muted);
  opacity: 0; transition: opacity 160ms ease; pointer-events: none;
}
.sheet:not(.is-focused):not(.is-running):not(.is-done) .focus-note { opacity: 1; }
.sheet.is-done { cursor: default; }
.sheet.jolt { animation: jolt 180ms ease; }
@keyframes jolt { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 24px; margin-top: 12px; padding-inline: 4px; }
.rule { font-size: var(--fs-small); color: var(--muted); }
.rule a { color: var(--accent); }
.hint { font-size: 13px; color: var(--negative-ink); background: var(--negative-pale); padding: 6px 12px; border-radius: 10px; }

/* result, shown in the sheet when the time is up */
.result { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 36px; align-items: start; }
.result:focus { outline: none; }
.res-title { font-size: var(--fs-section); font-weight: 600; }
.res-wpm { font-size: 40px; line-height: 1.2; margin-top: 6px; }
.res-wpm .num { font-weight: 400; }
.verdict { margin-top: 8px; font-size: 14px; color: var(--text); }
.verdict.is-up::before, .verdict.is-record::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-inline-end: 8px; vertical-align: 1px;
}
.verdict.is-up { color: var(--accent); font-weight: 500; }
.res-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; margin: 18px 0 20px; }
.res-list div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--rule); }
.res-list dt { color: var(--muted); font-size: 13px; }
.res-list dd { font-size: 14px; }
.res-chart .card-title { margin-bottom: 10px; }
.chart { position: relative; min-height: 120px; }
.chart.is-empty { display: grid; place-items: center; min-height: 220px; }

/* ---------- level ladder ---------- */
.ladder { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.rung button {
  display: grid; gap: 2px; width: 100%; height: 100%;
  padding: 12px; text-align: start;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-inner);
  cursor: pointer; transition: background-color 120ms ease, border-color 120ms ease;
}
.rung button:hover { background: var(--lift); border-color: var(--control); }
.rung-n { font-size: 20px; line-height: 1.2; color: var(--muted); }
.rung-name { font-size: 13px; font-weight: 600; line-height: 1.4; min-height: 2.8em; }
.rung-note { font-size: 13px; color: var(--muted); line-height: 1.45; min-height: 2.9em; }
.rung-gate { font-size: 13px; margin-top: 6px; }
.rung-track { display: block; height: 4px; border-radius: 2px; background: var(--rule); margin: 8px 0 6px; overflow: hidden; }
.rung-track span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.rung-best { font-size: 13px; color: var(--muted); }
.rung.is-done .rung-n, .rung.is-done .rung-gate { color: var(--accent); }
.rung.is-done .rung-track span { background: var(--chart-muted); }
.rung.is-current button { background: var(--lift); border-color: var(--text); }
.rung.is-current .rung-n { color: var(--text); }
.rung.is-ahead .rung-name { color: var(--muted); font-weight: 500; }
.rung.is-locked button { cursor: not-allowed; border-style: dashed; background: transparent; }
.rung.is-locked button:hover { background: transparent; border-color: var(--border); }
.rung.is-locked .rung-name, .rung.is-locked .rung-note, .rung.is-locked .rung-gate { color: var(--pending); font-weight: 500; }
.rung.is-locked .rung-track span { background: var(--chart-muted); }
.rung-n .lock { width: 14px; height: 14px; margin-inline-start: 6px; vertical-align: 1px; fill: none; stroke: currentColor; stroke-width: 1.4; }
.lv.is-ahead .lv-val { color: var(--muted); }

/* ---------- records ---------- */
.row-fill { align-self: stretch; display: flex; flex-direction: column; }
.row-fill > .ladder, .row-fill > .records, .row-fill > .misses, .row-fill > .inner-card, .row-fill > .levels { flex: 1; }
.misses:has(> .empty) { place-content: center; border: 1px dashed var(--control); border-radius: var(--radius-inner); }
.inner-card { display: flex; flex-direction: column; justify-content: center; }
.records { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px 16px; align-content: start; }
/* records run as one strip: the title and the link on one line above four figures */
.records-panel { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 16px; }
.records-panel .panel-head { margin-bottom: 14px; }
.records-panel .records { grid-column: 1 / -1; grid-row: 2; }
.records-panel > .link { grid-column: 2; grid-row: 1; margin: 0 0 14px; align-self: center; }
.rec { padding: 0; }
.rec dt { font-size: 13px; color: var(--muted); }
.rec dd { font-size: 20px; line-height: 1.35; }
.rec em { display: block; font-style: normal; font-size: 13px; color: var(--muted); }
.panel > .link { display: inline-block; margin-top: 12px; }

/* ---------- stats ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); padding-block: 18px; }
.kpi { padding-inline: 18px; border-inline-start: 1px solid var(--border); min-width: 0; }
.kpi:first-child { border-inline-start: 0; padding-inline-start: 4px; }
.kpi dd { font-size: var(--fs-kpi); line-height: 1.35; margin-top: 4px; }
.kpi.is-lead dd { font-size: var(--fs-lead); line-height: 1.25; }
.kpi p { font-size: var(--fs-small); color: var(--muted); }
.inner-card { background: var(--raised); border: 1px solid var(--border); border-radius: var(--radius-inner); padding: 16px 16px 8px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 8px; }

.misses { display: grid; gap: 4px; align-content: start; }
.miss-row {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) 40px 44px; align-items: center; gap: 12px;
  padding: 3px 6px; margin-inline: -6px; border-radius: 12px; text-decoration: none; color: inherit;
}
a.miss-row:hover { background: var(--lift); }
.miss-go { font-size: 12px; color: var(--accent); text-align: end; opacity: 0; transition: opacity 120ms ease; }
a.miss-row:hover .miss-go, a.miss-row:focus-visible .miss-go { opacity: 1; }
.misses li.empty { display: block; }
.key {
  display: inline-grid; place-items: center; min-width: 40px; height: 40px; padding-inline: 6px;
  border-radius: 999px; background: var(--lift); border: 1px solid var(--control);
  font-size: 17px; font-family: "Instrument Sans", var(--font);
}
.key.is-ar { font-family: "IBM Plex Sans Arabic", var(--font); font-size: 18px; }
.misses .key:not(.is-ar) { font-size: 16px; }
.misses .bar { display: block; height: 8px; background: var(--rule); border-radius: 4px; overflow: hidden; }
.misses .bar span { display: block; height: 100%; background: var(--chart-muted); border-radius: inherit; }
.misses .bar span.is-top { background: var(--negative); }
.misses .num { text-align: end; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { font-size: var(--fs-small); font-weight: 400; color: var(--muted); text-align: start; padding: 0 10px 10px; white-space: nowrap; }
.table td, .table tbody th { padding: 12px 10px; border-top: 1px solid var(--border); text-align: start; white-space: nowrap; font-weight: 400; }
.table .num { text-align: end; }
.table th:first-child, .table td:first-child { padding-inline-start: 4px; }
.table th:last-child, .table td:last-child { padding-inline-end: 4px; }
.table small { color: var(--muted); font-size: 12px; }
.table strong { font-weight: 600; }
.table td.empty { text-align: center; }
.cell-main { color: var(--text); }

.lv-lead { margin: -6px 0 14px; font-size: 13px; color: var(--muted); }
.lv-list { display: grid; gap: 10px; }
.lv { display: grid; grid-template-columns: 18px minmax(0, 1fr) minmax(0, 0.8fr) 84px; align-items: center; gap: 12px; font-size: 14px; }
.lv .rung-track { margin: 0; }
.lv-n { color: var(--muted); }
.lv-val { color: var(--muted); font-size: 13px; text-align: end; }
.lv.is-current .lv-n, .lv.is-current .lv-name { color: var(--text); font-weight: 600; }
.lv.is-done .lv-n, .lv.is-done .lv-val { color: var(--accent); }
.lv.is-done .rung-track span { background: var(--chart-muted); }
.lv.is-ahead .lv-name { color: var(--muted); }

/* ---------- settings ---------- */
.set-group { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); gap: var(--gap); padding-block: 8px; }
.set-label h2 { font-size: var(--fs-section); font-weight: 600; }
.set-label p { margin-top: 6px; font-size: 13px; color: var(--muted); max-width: 40ch; }
.set-label .warn { color: var(--negative); }
.set-panel { display: grid; padding-block: 6px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 60px; padding-block: 10px; border-bottom: 1px solid var(--rule); }
.set-row:last-child { border-bottom: 0; }
.set-row > span { display: grid; gap: 2px; min-width: 0; }
.set-row strong { font-weight: 500; }
.set-row em { font-style: normal; font-size: 13px; color: var(--muted); }
label.set-row { cursor: pointer; }
.set-row.radio { justify-content: flex-start; align-items: flex-start; }
.set-row.radio input { margin-top: 5px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.set-row input[type="range"] { width: 220px; accent-color: var(--accent); }
.select { height: var(--control-height); padding-inline: 12px; border-radius: 10px; border: 1px solid var(--control); background: var(--lift); min-width: 220px; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 40px; height: 24px; border-radius: 12px; background: var(--control);
  position: relative; cursor: pointer; transition: background-color 140ms ease; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: transform 140ms ease;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(-16px); }
[dir="ltr"] .switch:checked::after { transform: translateX(16px); }

/* ---------- score ---------- */
.res-points { margin-top: 2px; font-size: 14px; color: var(--accent); font-weight: 500; }
.score-card { text-align: end; flex: none; }
.score-card dt { font-size: 13px; color: var(--muted); }
.score-card dd { font-size: var(--fs-lead); line-height: 1.2; font-weight: 500; }
.score-card p { font-size: var(--fs-small); color: var(--muted); }
.set-score { font-size: 22px; font-weight: 500; }

/* ---------- key drills ---------- */
.drill-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 18px; margin-bottom: 18px; }
.drill-key {
  display: grid; place-items: center; width: 64px; height: 64px; border-radius: 18px;
  background: var(--raised); border: 1px solid var(--border); font-size: 34px; line-height: 1;
}
.drill-key[lang="ar"], [lang="ar"] .drill-key { font-family: "IBM Plex Sans Arabic", var(--font); }
.drill-id { display: grid; gap: 2px; min-width: 0; }
.drill-how { font-size: 14px; }
.drill-how b, .finger-note b { font-weight: 600; font-size: 1.15em; }
.drill-forms, .drill-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.drill-forms { max-width: 360px; justify-content: flex-end; }
.forms-label { font-size: 13px; color: var(--muted); margin-inline-end: 4px; }
.form-chip {
  display: inline-flex; align-items: baseline; gap: 6px; height: 34px; padding-inline: 12px;
  border-radius: var(--radius-control); border: 1px solid var(--control); background: var(--lift);
  cursor: pointer; transition: background-color 120ms ease;
}
.form-chip:hover { background: var(--quiet-hover); }
.form-chip span { font-size: 18px; line-height: 1; font-family: "IBM Plex Sans Arabic", var(--font); }
.form-chip em { font-style: normal; font-size: 12px; color: var(--muted); }
.dk-inline { font-weight: 600; }
/* the drilled letter in the text, until it is typed */
.text-inner .tg { color: var(--accent); background: var(--accent-pale); }
.drill-hint { margin-top: 10px; }

.res-note { font-size: 13px; color: var(--muted); margin: -6px 0 18px; }
.res-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hist { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding: 8px 0 0; border-bottom: 1px solid var(--rule); margin-bottom: 10px; }
.hist li { flex: 1; max-width: 48px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.hist-bar { width: 100%; background: var(--chart-muted); border-radius: 6px 6px 0 0; }
.hist li:last-child .hist-bar { background: var(--accent); }
.hist .num { font-size: 12px; color: var(--muted); padding-bottom: 4px; }

/* the letter picker */
.drill-top { margin-bottom: 16px; }
.dk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 8px; }
.dk {
  position: relative; display: grid; place-items: center; gap: 0; width: 100%; height: 62px; padding: 6px 0 4px;
  border-radius: var(--radius-inner); border: 1px solid var(--border); background: transparent; cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.dk:hover { background: var(--lift); border-color: var(--control); }
.dk[aria-pressed="true"] { background: var(--lift); border-color: var(--text); }
.dk-ch { font-size: 22px; line-height: 1.1; }
.dk-ch[lang="ar"] { font-family: "IBM Plex Sans Arabic", var(--font); }
.dk-n { font-size: 12px; color: var(--muted); }
.dk.is-good::after, .dk.is-weak::after { content: ""; position: absolute; top: 7px; inset-inline-end: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--positive); }
.dk.is-weak::after { background: var(--negative); }
.pick-sub { font-size: 13px; font-weight: 500; color: var(--muted); margin: 18px 0 10px; }

/* the keyboard: every key tinted by the finger that strikes it */
.kb-wrap {
  display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 24px; align-items: center;
  margin-top: 16px; padding: 18px; border-radius: var(--radius-inner); background: var(--raised); border: 1px solid var(--border);
}
.kb { font-family: "Instrument Sans", var(--font); }
.kb-svg { display: block; width: 100%; height: auto; overflow: hidden; user-select: none; -webkit-user-select: none; }
.kb-key { cursor: pointer; }
.kb-cap { fill: var(--f-thumb); stroke: color-mix(in srgb, var(--text) 14%, transparent); stroke-width: 1; transition: fill 90ms ease, stroke 90ms ease; }
.kb-key.f-L5 .kb-cap, .kb-key.f-R5 .kb-cap { fill: var(--f-pinky); }
.kb-key.f-L4 .kb-cap, .kb-key.f-R4 .kb-cap { fill: var(--f-ring); }
.kb-key.f-L3 .kb-cap, .kb-key.f-R3 .kb-cap { fill: var(--f-middle); }
.kb-key.f-L2 .kb-cap, .kb-key.f-R2 .kb-cap { fill: var(--f-index); }
.kb-key.is-blank { cursor: default; }
.kb-key.is-blank .kb-cap { fill: transparent; stroke-dasharray: 3 3; }
.kb-key.is-home .kb-cap { stroke: color-mix(in srgb, var(--text) 38%, transparent); }
.kb-key text { fill: var(--text); pointer-events: none; }
.kb-bump { fill: var(--text); opacity: 0.45; }
.kb-main { font-size: 17px; text-anchor: middle; dominant-baseline: middle; }
.kb-main[lang="ar"] { font-family: "IBM Plex Sans Arabic", var(--font); font-size: 19px; }
.kb-shift { font-size: 11px; text-anchor: middle; font-family: "IBM Plex Sans Arabic", var(--font); }
.kb-shift[text-anchor="end"] { text-anchor: end; }
.kb-key text.kb-shift, .kb-key text.kb-latin, .kb-key text.kb-name { fill: var(--muted); }
.kb-latin { font-size: 10px; }
.kb-name { font-size: 11px; }
.kb-key.is-next .kb-cap, .kb-key.is-demo .kb-cap { fill: var(--accent); stroke: var(--accent); }
.kb-key.is-next text, .kb-key.is-demo text, .kb-key.is-next text.kb-shift, .kb-key.is-next text.kb-latin, .kb-key.is-next text.kb-name,
.kb-key.is-demo text.kb-shift, .kb-key.is-demo text.kb-latin { fill: #fff; }
.kb-key.is-next .kb-bump { fill: #fff; }
.kb-key.is-alt .kb-cap { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 3; }
.kb-key.is-hit .kb-cap { stroke: var(--positive); stroke-width: 3; }
.kb-key.is-miss .kb-cap { stroke: var(--negative); stroke-width: 3; }

/* two drawn hands resting on the keyboard: the one that strikes the next key reaches for it, that finger traced */
.kb-hands { pointer-events: none; }
.kb-hands .h-skin { fill: var(--hand-skin); fill-opacity: 0.16; }
.kb-hands .h-line { fill: none; stroke: var(--hand-line); stroke-width: 1.4; stroke-miterlimit: 10; stroke-opacity: 0.6; }
.kb-hands .h-skin.h-line { fill: var(--hand-skin); }
.kb-hands .h-reach { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.kb-hands .h-nail { opacity: 0.5; }
.kb-hands .h-nail-ink { fill: var(--hand-line); }
.kb-hands .hand-l, .kb-hands .hand-r { transition: opacity 120ms ease; }
.kb-hands :is(.hand-l, .hand-r):not(.is-reaching) { opacity: 0.55; }
.kb.no-hands .kb-hands { display: none; }
.kb-side { display: grid; gap: 12px; align-content: center; }
.kb-wrap.is-practice { grid-template-columns: minmax(0, 1fr); gap: 10px; justify-items: center; }
.kb-wrap.is-practice .kb { width: 100%; max-width: 760px; }
.kb-wrap.is-practice .finger-note { min-height: 1.6em; }
.hands-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); cursor: pointer; }
.finger-note { font-size: 14px; min-height: 3em; text-align: center; }
.kb-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.kb-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; background: var(--f-thumb); }
.kb-legend .f-L5 { background: var(--f-pinky-ink); }
.kb-legend .f-L4 { background: var(--f-ring-ink); }
.kb-legend .f-L3 { background: var(--f-middle-ink); }
.kb-legend .f-L2 { background: var(--f-index-ink); }
.kb-legend .f-T { background: var(--f-thumb-ink); }
.kb-note { font-size: 12px; line-height: 1.6; color: var(--muted); text-align: center; }

/* ---------- tablet and phone: the sidebar folds into a top bar ---------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px; height: 52px; padding-inline: 16px;
    background: var(--ground); border-bottom: 1px solid var(--border);
  }
  .topbar .brand { padding: 0; }
  .topbar .mark { width: 28px; height: 28px; }
  .top-title { font-weight: 600; font-size: 15px; }
  .menu-btn { margin-inline-start: auto; width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; border-radius: 10px; cursor: pointer; }
  .menu-btn svg { width: 20px; height: 20px; }
  .side {
    position: fixed; inset: 52px 0 0 0; z-index: 30; height: auto;
    border: 0; padding: 20px 16px; display: none;
  }
  .side .brand { display: none; }
  .menu-open .side { display: flex; }
  .nav a, .side-row { height: 48px; font-size: 16px; }
  .main { padding: 32px 24px 56px; }
  .span-9, .span-3, .span-8, .span-4 { grid-column: span 12; }
  .ladder { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .records { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 18px; }
  .kpi:nth-child(4) { border-inline-start: 0; padding-inline-start: 4px; }
  .kb-wrap { grid-template-columns: minmax(0, 1fr); }
  .account { margin-inline: 0; }
}
@media (max-width: 800px) {
  .span-6 { grid-column: span 12; }
  .set-group { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .result { grid-template-columns: minmax(0, 1fr); gap: 20px; }
}
@media (max-width: 640px) {
  :root { --fs-title: 22px; --fs-lead: 28px; --fs-kpi: 22px; --pad: 16px; --radius-card: 18px; }
  .main { padding: 24px 16px 48px; }
  .title-row { flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 12px; }
  .title-row .btn { align-self: flex-start; }
  .panel-head { flex-wrap: wrap; }
  .controls { width: 100%; }
  .seg { flex: 1 1 auto; }
  .seg button { flex: 1; padding-inline: 8px; height: 36px; }
  .live { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 12px; }
  .live-cell:nth-child(3) { border-inline-start: 0; padding-inline-start: 4px; }
  .live-cell { padding-inline: 14px; }
  .sheet { padding: 18px 16px 26px; }
  .sheet[data-lang="ar"] { --ts: 22px; --lh: 46px; }
  .sheet[data-lang="en"] { --ts: 20px; --lh: 38px; }
  .ladder { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .records { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); padding-block: 16px; }
  .kpi { padding-inline: 14px; }
  .kpi:nth-child(odd) { border-inline-start: 0; padding-inline-start: 4px; }
  .kpi:nth-child(4) { border-inline-start: 1px solid var(--border); padding-inline-start: 14px; }
  .res-list { grid-template-columns: minmax(0, 1fr); }
  .chart.is-empty { min-height: 140px; }
  .set-row { flex-wrap: wrap; }
  .set-row input[type="range"], .select { width: 100%; min-width: 0; }
  .log th:nth-child(5), .log td:nth-child(5), .log th:nth-child(7), .log td:nth-child(7) { display: none; }
  .score-card { text-align: start; }
  .drill-head { grid-template-columns: auto minmax(0, 1fr); }
  .drill-forms { grid-column: 1 / -1; justify-content: flex-start; max-width: none; }
  .kb-wrap { padding: 10px; }
  .kb-main { font-size: 22px; }
  .kb-main[lang="ar"] { font-size: 24px; }
  .kb-shift, .kb-latin, .kb-name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .text-inner, .caret, .btn, .switch, .switch::after { transition: none; }
  .caret.blink, .sheet.jolt { animation: none; }
}
