:root {
  /* Surfaces */
  --bg: #000;
  --bg-soft: #0d0d0d;       /* blog body, modals on phone */
  --surface: #070707;       /* cards, leaderboard rows */

  /* Text */
  --fg: #fff;
  --fg-warm: #e8e6e2;       /* long-form body text */
  --muted: #888;
  --muted-2: #555;

  /* Lines */
  --border: #222;
  --border-2: #2c2c2c;
  --bar: #3a3a3a;

  /* Brand */
  --accent: #ff2d3a;
  --accent-soft: #ff5a64;   /* focus rings, never fills */

  /* Spacing scale (4px base) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  /* Type scale, fluid */
  --t-micro: 11px;
  --t-body: 15px;
  --t-h3: clamp(18px, 2.4vw, 22px);
  --t-h2: clamp(24px, 4vw, 30px);
  --t-h1: clamp(34px, 6vw, 44px);
  --t-word: clamp(56px, 9vw, 112px);

  /* Radii */
  --r-input: 6px;
  --r-card: 10px;
  --r-pill: 999px;

  /* Timing */
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }

/* A11y — visible keyboard focus everywhere */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Honor user motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.hidden { display: none !important; }

/* ---------- Loader / Home screen ---------- */
#loader {
  /* Home has lots of content (samples) — allow it to scroll if the viewport
     is short, and anchor to the top instead of vertically centering. */
  justify-content: flex-start;
  padding: clamp(2rem, 6vh, 5rem) 2rem 4rem;
  overflow-y: auto;
  gap: 1.5rem;
}

#loader-inner {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  align-items: center;
  margin: 0 auto;
}

.brand {
  font-family: "Times New Roman", Georgia, serif;
  font-size: clamp(2rem, 5vw, 2.6rem);
  letter-spacing: -0.005em;
  margin: 0;
  font-weight: 400;
  line-height: 1.1;
}
.brand .m { color: var(--accent); }
.brand .dot { color: var(--fg); }

.tagline {
  color: var(--muted);
  margin: 0 0 0.5rem 0;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

textarea#textInput {
  width: 100%;
  min-height: 180px;
  background: #0a0a0a;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}
textarea#textInput:focus { border-color: #555; }

.file-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--fg);
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}
.file-btn:hover { background: #151515; border-color: #333; }
.file-btn input { display: none; }

.spacer { flex: 1; }

.primary-btn {
  padding: 14px 28px;
  min-height: 48px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--r-input);
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  font-family: inherit;
  transition: transform 0.12s var(--ease), filter 0.12s var(--ease);
}
.primary-btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
.primary-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}
.primary-btn-block { width: 100%; }

/* Disclosure (Have a file? / Try a sample) — collapsed by default */
.disclosure {
  width: 100%;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.disclosure summary {
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 8px 0;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: color 0.15s;
}
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary::after {
  content: "▾";
  font-size: 11px;
  transition: transform 0.2s var(--ease);
}
.disclosure[open] summary::after { transform: rotate(180deg); }
.disclosure summary:hover { color: var(--fg); }
.disclosure > .file-row,
.disclosure > .samples-grid {
  margin-top: 12px;
}

.status {
  color: var(--muted);
  font-size: 13px;
  min-height: 18px;
  letter-spacing: 0.02em;
}

/* ---------- Sample excerpts ---------- */
.samples {
  width: 100%;
  margin-top: 1rem;
}
.samples-head {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.samples-head::before,
.samples-head::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.home-footer {
  margin-top: 1.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
}
.home-footer a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}
.home-footer a:hover { color: var(--accent); }
.samples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.sample-card {
  text-align: left;
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  cursor: pointer;
  color: var(--fg);
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.sample-card:hover {
  background: #111;
  border-color: #333;
  transform: translateY(-1px);
}
.sample-title {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 17px;
  margin-bottom: 2px;
  line-height: 1.2;
}
.sample-author {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.sample-teaser {
  color: #aaa;
  font-size: 12px;
  line-height: 1.4;
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sample-lang {
  display: inline-block;
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.08em;
}

/* ---------- Reader screen ---------- */
#reader {
  justify-content: space-between;
  padding: 0;
}

/* Top-left BACK + top-right WPM */
.top-left, .top-right {
  position: absolute;
  top: 20px;
  z-index: 10;
}
.top-left {
  left: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.top-right { right: 24px; }
/* Hide the "Classic" switch on daily/challenge runs — those are speed-only by spec. */
#reader.daily #speedToClassicBtn,
#reader.challenge #speedToClassicBtn { display: none; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: #151515; border-color: #333; }

/* The central reading area — click anywhere to play/pause */
.reader-center {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.word-frame {
  position: relative;
  width: 100%;
  max-width: 900px;
  padding: 0 2rem;
}

/* Vertical guideline down the middle (subtle) */
.word-frame::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: transparent;
  pointer-events: none;
}

/* Per the design audit, the horizontal Spritz bars are removed.
   Only a single 1px×24px tick remains, above the focal column. */
.bar { display: none; }
.bar-top { display: block; height: 0; position: relative; margin: 0 auto; }
.bar-top::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 24px;
  background: var(--bar);
  transform: translateX(-50%);
}

#wordDisplay {
  font-family: "Times New Roman", Georgia, serif;
  font-size: clamp(3rem, 7vw, 5.5rem);
  line-height: 1;
  font-weight: 400;
  letter-spacing: 0.01em;
  padding: 110px 0;
  position: relative;
  white-space: nowrap;
  user-select: none;
  width: 100%;
}

/* We absolutely position the word relative to the center line */
.word {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(0, -50%);
  white-space: nowrap;
}

.word .focal { color: var(--accent); }

/* ---------- Controls ---------- */
.reader-bottom {
  width: 100%;
  padding: 0;
}

.progress-outer {
  width: 100%;
  height: 2px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s linear;
}

/* Compact WPM control in the top-right corner */
.wpm-control {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 4px 6px;
}
.wpm-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--fg);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.wpm-btn:hover { background: #1a1a1a; }

.wpm-value {
  min-width: 78px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--fg);
}
.wpm-value .label {
  color: var(--muted);
  margin-left: 4px;
  font-size: 10px;
  letter-spacing: 0.1em;
}

/* Subtle "paused" hint that fades in when not playing */
.paused-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: #444;
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}
.paused .paused-hint { opacity: 1; }

/* When playing, fade the surrounding chrome to 12% so the word can breathe.
   Hover or focus inside the chrome restores it instantly. */
#reader:not(.paused) .top-left,
#reader:not(.paused) .top-right,
#reader:not(.paused) .help-btn,
#reader:not(.paused) .daily-finish-btn {
  opacity: 0.12;
  transition: opacity 0.4s var(--ease);
}
#reader:not(.paused):hover .top-left,
#reader:not(.paused):hover .top-right,
#reader:not(.paused):hover .help-btn,
#reader:not(.paused):hover .daily-finish-btn,
#reader:not(.paused) .top-left:focus-within,
#reader:not(.paused) .top-right:focus-within,
#reader:not(.paused) .help-btn:focus-visible,
#reader:not(.paused) .daily-finish-btn:focus-visible {
  opacity: 1;
}

/* ---------- WPM picker screen ---------- */
#wpmPicker {
  gap: 2rem;
  overflow-y: auto;
}
.picker-title {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 2rem;
  font-weight: 400;
  margin: 0;
  color: var(--fg);
}
.picker-sub {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
  margin: -1rem 0 0;
}
.wpm-big {
  display: flex;
  align-items: center;
  gap: 32px;
  margin: 1rem 0;
}
.wpm-big .value {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 5rem;
  line-height: 1;
  min-width: 220px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.wpm-big .unit {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.15em;
  margin-left: 6px;
  font-family: inherit;
  vertical-align: middle;
}
.wpm-big .big-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #0a0a0a;
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.wpm-big .big-btn:hover { background: #151515; border-color: #333; }

/* Live preview of a word flashing at the chosen WPM */
.wpm-preview {
  width: 100%;
  max-width: 420px;
  min-height: 80px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 20px;
  margin: -0.5rem 0 1rem;
}
.wpm-preview-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.wpm-preview-word {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.6rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  min-height: 1.6rem;
  user-select: none;
}
.wpm-preview-word .focal { color: var(--accent); }

.presets {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.preset-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
}
.preset-btn:hover { background: #151515; color: var(--fg); }
.preset-btn.active {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.picker-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 1rem;
}

.ghost-btn {
  padding: 12px 24px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
}
.ghost-btn:hover { background: #0a0a0a; color: var(--fg); border-color: #333; }

/* ---------- Language picker screen ---------- */
#langPicker {
  justify-content: flex-start;
  padding: clamp(4rem, 14vh, 8rem) 2rem 4rem;
  gap: 1.5rem;
  overflow-y: auto;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 640px;
  margin: 1rem 0;
}
.mode-card {
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 24px;
  text-align: left;
  cursor: pointer;
  color: var(--fg);
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 140px;
}
.mode-card:hover {
  background: #111;
  border-color: #444;
  transform: translateY(-2px);
}
.mode-card:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}
.mode-card:disabled:hover {
  background: #0a0a0a;
  border-color: var(--border);
}
.mode-name {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.6rem;
  line-height: 1.1;
}
.mode-badge {
  display: inline-block;
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 8px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.1em;
  font-family: inherit;
}
.mode-desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Challenge mode WPM display (above the word) ---------- */
.challenge-wpm {
  position: absolute;
  top: clamp(18px, 4vh, 48px);
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  display: none;
  transition: color 0.25s, letter-spacing 0.25s;
  pointer-events: none;
  white-space: nowrap;
}
#reader.challenge .challenge-wpm { display: block; }
/* Hide the top-right manual WPM control in challenge mode — the big
   display above the word is the source of truth. */
#reader.challenge .top-right { display: none; }
.challenge-wpm.flash {
  color: var(--accent);
  letter-spacing: 0.4em;
}

/* ---------- Help button + modal ---------- */
.help-btn {
  position: absolute;
  bottom: 20px;
  left: 24px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: "Times New Roman", Georgia, serif;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  z-index: 10;
}
.help-btn:hover {
  background: #151515;
  color: var(--fg);
  border-color: #333;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.modal-card {
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 32px;
  max-width: 420px;
  width: calc(100% - 40px);
  position: relative;
}
.modal-card h3 {
  margin: 0 0 16px 0;
  font-family: "Times New Roman", Georgia, serif;
  font-weight: 400;
  font-size: 1.4rem;
}
.modal-card .close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.modal-card .close:hover { background: #1a1a1a; color: var(--fg); }
.modal-card .shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: #ccc;
}
.modal-card .shortcut-row:last-child { border-bottom: none; }
.modal-card .shortcut-row .keys { display: flex; gap: 4px; }

/* ---------- Utility ---------- */
.loader-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #333;
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

kbd {
  background: #111;
  border: 1px solid #222;
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: inherit;
  color: var(--muted);
}

/* ========== DAILY CHALLENGE ========== */

/* Home screen call-to-action card — flat surface, single 1px red top edge */
.daily-cta {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 1px solid var(--accent);
  border-radius: var(--r-card);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), transform 0.15s var(--ease);
  color: var(--fg);
  font-family: inherit;
  text-align: left;
}
.daily-cta:hover {
  border-color: var(--border-2);
  border-top-color: var(--accent);
  transform: translateY(-1px);
}
.daily-cta-left { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.daily-cta-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
.daily-cta-title {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.2rem;
  line-height: 1.2;
}
.daily-cta-sub {
  font-size: 12px;
  color: var(--muted);
}
.daily-cta-arrow {
  flex: none;
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}

.daily-cta-meta {
  display: flex;
  justify-content: center;
  margin-top: -6px;
}
.link-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.link-btn:hover {
  color: var(--accent);
  background: rgba(255, 45, 58, 0.05);
}

/* Question progress bar (1/5, 2/5…) */
.q-progress {
  width: 100%;
  max-width: 640px;
  height: 4px;
  background: #111;
  border-radius: 2px;
  overflow: hidden;
}
.q-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.3s ease;
}

/* Generic daily screen wrapper (re-uses .screen) */
#dailyLangPicker, #dailyRankPicker, #dailyQuestions, #dailyResults, #dailyLeaderboard {
  justify-content: flex-start;
  padding: clamp(3rem, 10vh, 6rem) 2rem 4rem;
  gap: 1.5rem;
  overflow-y: auto;
}

.daily-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--muted);
}
.daily-header .daily-num {
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--accent);
}
.daily-header .daily-title {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.6rem;
  color: var(--fg);
  line-height: 1.2;
}
.daily-header .daily-source {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Rank cards — similar to mode-card but emphasised speed */
.rank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 640px;
}
.rank-card {
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  color: var(--fg);
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rank-card:hover {
  background: #111;
  border-color: var(--accent);
  transform: translateY(-2px);
}
.rank-card:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
.rank-card:disabled:hover {
  background: #0a0a0a;
  border-color: var(--border);
}
.rank-name {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.4rem;
}
.rank-wpm {
  font-variant-numeric: tabular-nums;
  font-size: 2.2rem;
  color: var(--accent);
  line-height: 1;
}
.rank-unit {
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted);
}
.rank-done {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}

/* Live word preview inside each rank card — loops "Ceci est la vitesse à
   400 WPM" / "This is the speed at 400 WPM" at the rank's WPM, so users
   can feel the speed before they pick. */
.rank-preview {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.1rem;
  line-height: 1;
  min-height: 1.1rem;
  margin-top: 8px;
  color: #cfcfcf;
  user-select: none;
  font-variant-numeric: tabular-nums;
}
.rank-preview .focal { color: var(--accent); }

/* Pseudo input (optional display name) */
.pseudo-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 360px;
}
.pseudo-row label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.pseudo-input {
  width: 100%;
  padding: 10px 14px;
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.pseudo-input:focus { border-color: var(--accent); }

/* Daily mode: lock the reader WPM UI */
#reader.daily .top-right { display: none; }
#reader.daily .challenge-wpm {
  display: block;
  color: var(--accent);
  letter-spacing: 0.3em;
}
.daily-finish-btn {
  position: absolute;
  bottom: 18px;
  right: 20px;
  display: none;
  z-index: 11;
}
#reader.daily .daily-finish-btn { display: block; }

/* Questions screen */
.questions-container {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.question-card {
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
}
.question-num {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.question-text {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.1rem;
  line-height: 1.4;
  margin-bottom: 14px;
}
.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.choice {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 11px 14px;
  color: var(--fg);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  transition: background 0.12s, border-color 0.12s;
}
.choice:hover:not(:disabled) { background: #151515; border-color: #333; }
.choice.selected {
  background: rgba(255, 45, 58, 0.1);
  border-color: var(--accent);
}
.choice:disabled { cursor: default; }
.choice.correct {
  background: rgba(40, 200, 60, 0.08);
  border-color: #2aa84a;
  color: #7ce08a;
}
.choice.wrong {
  background: rgba(255, 45, 58, 0.08);
  border-color: var(--accent);
  color: #ff9aa1;
}

/* Results screen */
.results-card {
  width: 100%;
  max-width: 520px;
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 28px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.score-big {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 3.6rem;
  line-height: 1;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.score-big .score-slash {
  color: var(--muted);
  font-size: 2.2rem;
  vertical-align: middle;
}
/* New: position is now the lead stat on the results card */
.results-position {
  font-family: "Times New Roman", Georgia, serif;
  font-size: clamp(2.8rem, 8vw, 3.8rem);
  line-height: 1;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
}
.results-position-of {
  color: var(--muted);
  font-size: 0.6em;
  vertical-align: 0.18em;
}
.score-sub {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.score-stats {
  display: flex;
  justify-content: center;
  gap: 28px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0 4px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: 4px 0;
}
.score-stats b { color: var(--fg); font-variant-numeric: tabular-nums; font-weight: 400; }
.score-emoji {
  font-size: 1.4rem;
  letter-spacing: 0.15em;
  line-height: 1;
  padding: 6px 0;
  font-variant-emoji: emoji;
}

.results-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.share-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 22px;
  border-radius: 6px;
  font-size: 13px;
  letter-spacing: 0.06em;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.12s, transform 0.12s;
}
.share-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.share-copied { font-size: 11px; color: #7ce08a; letter-spacing: 0.1em; text-transform: uppercase; }

/* Leaderboard */
.leaderboard {
  width: 100%;
  max-width: 640px;
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.lb-row {
  display: grid;
  grid-template-columns: 40px 1fr 70px 70px 70px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  gap: 8px;
}
.lb-row:last-child { border-bottom: none; }
.lb-row.header {
  background: #050505;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 8px 14px;
}
.lb-row.me { background: rgba(255, 45, 58, 0.07); }
.lb-pos { font-variant-numeric: tabular-nums; color: var(--muted); }
.lb-pos.top3 { color: var(--accent); font-weight: 600; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-num { font-variant-numeric: tabular-nums; text-align: right; color: #ccc; }
.lb-empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }

/* Floating "Jump to your row" pill, shown only when the user's row is offscreen */
.jump-to-me {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-pill);
  padding: 10px 18px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  z-index: 50;
  transition: transform 0.15s var(--ease), filter 0.15s var(--ease), opacity 0.2s;
}
.jump-to-me:hover { filter: brightness(1.08); transform: translate(-50%, -1px); }

@media (max-width: 500px) {
  .lb-row {
    grid-template-columns: 32px 1fr 56px 56px;
  }
  .lb-row .lb-hide-mobile { display: none; }
}

/* Error / info pills */
.daily-msg {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: #0a0a0a;
  color: #ccc;
  max-width: 520px;
  text-align: center;
}
.daily-msg.error { border-color: var(--accent); color: #ff9aa1; }

/* Segmented tabs (rank filter on leaderboard) */
.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 3px;
  gap: 2px;
  background: var(--surface);
  flex-wrap: wrap;
  align-items: center;
}
.segmented button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: var(--r-pill);
  font-size: 12px;
  letter-spacing: 0.05em;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.segmented button:hover { color: var(--fg); }
.segmented button.active {
  background: var(--fg);
  color: var(--bg);
}

/* Combined toolbar (lang + rank in one row, divider between groups) */
.seg-toolbar { gap: 4px; }
.seg-group {
  display: inline-flex;
  gap: 2px;
  align-items: center;
}
.seg-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 6px;
  flex: none;
}

/* ========== LIBEREADER (LIBRARY + CLASSIC READER) ========== */

/* Two-column row on home: textarea on the left, Library CTA on the right.
   Stacks vertically on narrow screens. */
.home-input-row {
  width: 100%;
  display: grid;
  grid-template-columns: 2.4fr 1fr;   /* library is ~29% of the row */
  gap: 12px;
  align-items: stretch;
}
.home-input-row textarea#textInput { height: 100%; }
@media (max-width: 600px) {
  .home-input-row { grid-template-columns: 1fr; }
}

/* Side-mounted Library card — slimmer padding + tighter type to match the
   reduced column width (~30% smaller than the textarea side). */
.library-cta-side {
  min-height: 180px;
  height: 100%;
  padding: 14px 16px;
}
.library-cta-side .library-cta-title { font-size: 1rem; }
.library-cta-side .library-cta-sub   { font-size: 11px; }
.library-cta-side .library-cta-arrow { font-size: 18px; }

/* Home CTA — same shape as the daily-cta but no red top edge (calmer). */
.library-cta {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), transform 0.15s var(--ease);
  color: var(--fg);
  font-family: inherit;
  text-align: left;
}
.library-cta:hover {
  border-color: var(--border-2);
  transform: translateY(-1px);
}
.library-cta-left { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.library-cta-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.library-cta-title {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.1rem;
  line-height: 1.2;
}
.library-cta-sub {
  font-size: 12px;
  color: var(--muted);
}
.library-cta-arrow {
  flex: none;
  font-size: 22px;
  color: var(--muted);
  line-height: 1;
}
.library-cta:hover .library-cta-arrow { color: var(--fg); }

/* ----- Library screen ----- */
#libraryScreen {
  justify-content: flex-start;
  padding: clamp(2rem, 5vh, 3rem) 1.5rem 4rem;
  gap: 1.2rem;
  overflow-y: auto;
}
.lib-top {
  width: 100%;
  max-width: 960px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
}
.lib-title {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.6rem;
  font-weight: 400;
  margin: 0;
  text-align: center;
}
.lib-tools {
  width: 100%;
  max-width: 960px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.lib-search {
  flex: 1;
  min-width: 180px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.lib-search:focus { border-color: var(--border-2); }

.lib-grid {
  width: 100%;
  max-width: 960px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.lib-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--fg);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  position: relative;
  min-height: 150px;
}
.lib-card:hover {
  background: #111;
  border-color: var(--border-2);
  transform: translateY(-1px);
}
.lib-card .lib-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 9px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
.lib-card .lib-card-title {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.05rem;
  line-height: 1.25;
  padding-right: 80px;
}
.lib-card .lib-card-author {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.lib-card .lib-card-meta {
  font-size: 11px;
  color: var(--muted-2);
  margin-top: auto;
}
.lib-card .lib-progress {
  width: 100%;
  height: 2px;
  background: var(--border);
  overflow: hidden;
  border-radius: 2px;
}
.lib-card .lib-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}
.lib-card .lib-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.lib-card .lib-remove {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  letter-spacing: 0.05em;
  padding: 0;
}
.lib-card .lib-remove:hover { color: var(--accent); }

.lib-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}
.lib-empty-icon { font-size: 32px; opacity: 0.4; margin-bottom: 12px; }
.lib-empty-msg { font-family: "Times New Roman", Georgia, serif; font-size: 1.2rem; color: var(--fg); }
.lib-empty-sub { font-size: 13px; margin-top: 6px; }

/* ----- Reader classique — themed via CSS variables, scoped to #readerClassic ----- */
#readerClassic {
  --rc-bg: #0d0d0d;
  --rc-fg: #e8e6e2;
  --rc-fg-muted: #888a86;
  --rc-border: #232323;
  --rc-accent: var(--accent);
  --rc-font-size: 21px;
  --rc-line-height: 1.7;
  --rc-font: "Source Serif 4", "Source Serif Pro", "Times New Roman", Georgia, serif;

  background: var(--rc-bg);
  color: var(--rc-fg);
  padding: 0;
  justify-content: stretch;
  align-items: stretch;
  flex-direction: column;
  overflow: hidden;
}
#readerClassic.theme-night  { --rc-bg: #000; --rc-fg: #fff; --rc-fg-muted: #888; --rc-border: #222; }
#readerClassic.theme-soft   { --rc-bg: #0d0d0d; --rc-fg: #e8e6e2; --rc-fg-muted: #888a86; --rc-border: #232323; }
#readerClassic.theme-sepia  { --rc-bg: #1c1612; --rc-fg: #d3cabb; --rc-fg-muted: #8b8275; --rc-border: #2a241e; }
#readerClassic.theme-paper  { --rc-bg: #f5f1e8; --rc-fg: #1a1a1a; --rc-fg-muted: #6b6b6b; --rc-border: #d8d2c2; }
#readerClassic.font-serif   { --rc-font: "Source Serif 4", "Source Serif Pro", "Times New Roman", Georgia, serif; }
#readerClassic.font-sans    { --rc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; }
#readerClassic.font-mono    { --rc-font: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.rc-top {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--rc-bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rc-border);
  z-index: 5;
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
}
#readerClassic.chrome-hidden .rc-top {
  opacity: 0.18;
  transform: translateY(-2px);
}
#readerClassic.chrome-hidden:hover .rc-top { opacity: 1; transform: none; }

.rc-icon {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  background: transparent;
  border: 1px solid var(--rc-border);
  color: var(--rc-fg);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.rc-icon:hover {
  background: color-mix(in srgb, var(--rc-fg) 8%, transparent);
}

.rc-title-wrap {
  text-align: center;
  overflow: hidden;
}
.rc-title {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rc-author {
  font-size: 10px;
  color: var(--rc-fg-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rc-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  outline: none;
  background: var(--rc-bg);
}
.rc-article {
  max-width: 64ch;
  margin: 0 auto;
  padding: 32px 24px 96px;
  font-family: var(--rc-font);
  font-size: var(--rc-font-size);
  line-height: var(--rc-line-height);
  color: var(--rc-fg);
}
.rc-article p { margin: 0 0 1em; }
.rc-article p:first-child { margin-top: 0; }

.rc-progress {
  width: 100%;
  height: 2px;
  background: var(--rc-border);
  overflow: hidden;
  flex: none;
}
.rc-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--rc-accent);
  transition: width 0.1s linear;
}

.rc-switch {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: color-mix(in srgb, var(--rc-bg) 80%, transparent);
  border: 1px solid var(--rc-border);
  color: var(--rc-fg);
  padding: 9px 14px;
  border-radius: var(--r-pill);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.06em;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 6;
  transition: background 0.15s, transform 0.15s;
}
.rc-switch:hover {
  background: var(--rc-accent);
  color: #fff;
  border-color: var(--rc-accent);
  transform: translateY(-1px);
}

/* ----- Settings sheet (slide from right) ----- */
.rc-settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease);
}
.rc-settings-overlay:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
}
.rc-settings {
  width: min(360px, 100vw);
  height: 100%;
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  padding: 18px 22px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s var(--ease);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.rc-settings-overlay:not(.hidden) .rc-settings {
  transform: translateX(0);
}
.rc-settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.rc-settings-title {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.4rem;
}
.rc-settings-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rc-settings-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.rc-settings-value {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}

.rc-theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.rc-theme-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 6px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  color: var(--fg);
  transition: border-color 0.15s, transform 0.15s;
}
.rc-theme-card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.rc-theme-card.active { border-color: var(--accent); }
.rc-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid;
}
.rc-theme-name {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.rc-theme-card.active .rc-theme-name { color: var(--fg); }

.rc-colors-row {
  display: flex;
  gap: 14px;
}
.rc-colors-row label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}
.rc-colors-row input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  padding: 2px;
}

.rc-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
}
.rc-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}
.rc-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

/* Discreet "Saved to library" badge on the daily results card */
.daily-saved-badge {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-top: 4px;
  opacity: 0.85;
}
.daily-saved-badge::before { content: "✓ "; color: var(--accent); }
