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

@font-face {
  font-family: "Buixots";
  src:
    url("fonts/Buixots.woff2") format("woff2"),
    url("fonts/Buixots.woff") format("woff");
}

:root {
  --bg: #f3f0eb;
  --surface: #ffffff;
  --border: #ddd9d2;
  --text: #1a1917;
  --muted: #8a857e;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --err: #dc2626;
  --err-soft: #fef2f2;
  --amber: #f26a0f;
  --amber-soft: #fff0e4;
  --radius: 20px;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.07);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ── */
.topbar {
  max-width: 820px;
  margin: 0 auto;
  padding: 18px 22px 8px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.brand-title {
  font-family: "Inter", system-ui, sans-serif;
  color: var(--text);
  font-size: clamp(2.25rem, 6vw, 2.5rem);
  text-decoration: none;
  opacity: 0.82;
  line-height: 1.05;
  flex-shrink: 0;
}

.app-subtitle {
  text-align: right;
  line-height: 1.25;
  padding-bottom: 4px;
}

.app-subtitle .sub-en {
  display: inline;
  font-family: "Inter", system-ui, sans-serif;
  font-size: clamp(1.1rem, 3vw, 1.35rem);
  text-transform: uppercase;
  color: var(--text);
  opacity: 0.7;
  letter-spacing: 0.04em;
  vertical-align: -3px;
}

.app-subtitle .sub-zh {
  display: inline;
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
  color: var(--muted);
  letter-spacing: 0.15em;
}

/* ── Layout ── */
.main {
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 20px 48px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Mode tabs (3 big buttons) ── */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.mode-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 16px 10px 14px;
  border-radius: 18px;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow);
  min-height: 84px;
  position: relative;
  overflow: hidden;
}

.mode-tab:hover {
  border-color: #bbb4ab;
}

.mode-tab-glyph {
  font-size: 32px;
  line-height: 1;
  color: var(--muted);
  transition: color 0.15s, transform 0.2s;
  display: block;
  font-weight: 400;
}

.mode-tab-en {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.1px;
  line-height: 1.1;
}

.mode-tab-zh {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

/* Words mode active */
.mode-tab[data-mode="words"].active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 4px 18px rgba(37, 99, 235, 0.15);
}
.mode-tab[data-mode="words"].active .mode-tab-glyph,
.mode-tab[data-mode="words"].active .mode-tab-en { color: var(--accent); }
.mode-tab[data-mode="words"].active .mode-tab-glyph { transform: scale(1.1); }

/* Paragraphs mode active */
.mode-tab[data-mode="paragraphs"].active {
  border-color: var(--ok);
  background: var(--ok-soft);
  box-shadow: 0 4px 18px rgba(22, 163, 74, 0.15);
}
.mode-tab[data-mode="paragraphs"].active .mode-tab-glyph,
.mode-tab[data-mode="paragraphs"].active .mode-tab-en { color: var(--ok); }
.mode-tab[data-mode="paragraphs"].active .mode-tab-glyph { transform: scale(1.1); }

/* Timer mode active */
.mode-tab[data-mode="timer"].active {
  border-color: var(--amber);
  background: var(--amber-soft);
  box-shadow: 0 4px 18px rgba(242, 106, 15, 0.22);
}
.mode-tab[data-mode="timer"].active .mode-tab-glyph,
.mode-tab[data-mode="timer"].active .mode-tab-en { color: var(--amber); }
.mode-tab[data-mode="timer"].active .mode-tab-glyph { transform: scale(1.1); }

/* ── Secondary controls bar ── */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.ctrl-select,
.ctrl-btn {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  height: 38px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  outline: none;
  transition: border-color 0.15s, color 0.15s, background 0.15s, opacity 0.15s;
}

.ctrl-select {
  border: 1.5px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  padding: 0 34px 0 15px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%232563eb' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.ctrl-select:focus { border-color: var(--accent); }

.ctrl-btn {
  border: 1.5px solid transparent;
  padding: 0 17px;
  background: var(--accent);
  color: #fff;
}
.ctrl-btn:hover { opacity: 0.87; }

.ctrl-btn.secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--muted);
}
.ctrl-btn.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.ctrl-btn.active-toggle {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Main card ── */
.typing-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 22px 22px;
  box-shadow: var(--shadow);
}

/* ── Timer bar ── */
.timer-bar-wrap {
  display: none;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 16px;
}
.timer-bar-wrap.visible { display: block; }

.timer-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: var(--ok);
}

/* ── Hanzi display ── */
.typing-area {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  padding: 10px 0 14px;
}

.typing-area--word {
  font-size: clamp(54px, 14vw, 88px);
  min-height: 116px;
  letter-spacing: 0.05em;
  gap: 4px;
  color: var(--text);
}

.typing-area--para {
  font-size: clamp(19px, 3.2vw, 25px);
  line-height: 1.95;
  min-height: 148px;
  gap: 0;
  color: #49453f;
}

/* ── Pinyin ── */
.pinyin-display {
  text-align: center;
  font-size: 14.5px;
  color: var(--muted);
  line-height: 1.7;
  min-height: 22px;
  word-break: break-word;
  letter-spacing: 0.4px;
  padding-bottom: 16px;
  transition: opacity 0.2s;
}
.pinyin-display.pinyin-hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── Input row + submit button ── */
.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.submit-btn {
  display: none;
}

@media (hover: none), (max-width: 768px) {
  .submit-btn {
    display: block;
    flex-shrink: 0;
    padding: 0 18px;
    border: 2px solid var(--accent);
    border-radius: 13px;
    background: var(--accent);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
  }
  .submit-btn:active { opacity: 0.75; }
}

/* ── Input field ── */
#inputField {
  display: block;
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 13px;
  padding: 13px 17px;
  font-size: 21px;
  font-family: inherit;
  outline: none;
  background: #faf8f5;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
#inputField:focus {
  border-color: var(--accent);
  background: var(--surface);
}
#inputField.incorrect {
  border-color: var(--err);
  background: var(--err-soft);
}

/* ── Helper row ── */
.helper-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 9px;
  font-size: 12.5px;
  color: var(--muted);
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Feedback ── */
.feedback {
  min-height: 20px;
  text-align: center;
  font-size: 13.5px;
  font-weight: 700;
  margin-top: 9px;
  letter-spacing: 0.15px;
}
.feedback.correct  { color: var(--ok); }
.feedback.incorrect { color: var(--err); }
.feedback.timeout  { color: var(--amber); }

/* ── Progress ── */
.progress-wrap { margin-top: 13px; }
#progressBarContainer {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
#progressBar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.3s ease;
  border-radius: 999px;
}
#progressText {
  margin-top: 5px;
  text-align: right;
  font-size: 11.5px;
  color: var(--muted);
}

/* ── Stats bar ── */
.stats-bar {
  background: var(--surface);
  border-radius: 16px;
  padding: 12px 6px;
  display: flex;
  box-shadow: var(--shadow);
}
.stat-item {
  flex: 1;
  text-align: center;
  border-right: 1px solid var(--border);
  padding: 0 6px;
}
.stat-item:last-child { border-right: none; }
.stat-label {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--muted);
  margin-bottom: 2px;
}
.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

/* ── Character states ── */
.word-char { display: inline-block; }
.letter    { display: inline; }
.letter.space { margin-right: 3px; }

.word-char.correct, .letter.is-right { color: var(--ok); }
.letter.is-active {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}
.letter.incorrect {
  color: var(--err);
  background: var(--err-soft);
  border-radius: 2px;
}

/* ── Paragraph pinyin-above-char (ruby display) ── */
.typing-area--para {
  align-items: flex-end;
  row-gap: 10px;
}

.letter.py-char {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.letter.py-char .py-rt {
  font-size: 0.48em;
  color: var(--accent);
  opacity: 0.72;
  line-height: 1.6;
  letter-spacing: 0.01em;
  font-family: system-ui, sans-serif;
  white-space: nowrap;
}

.letter.py-char .py-hanzi {
  line-height: 1.15;
}

.letter.punc {
  display: inline;
  line-height: 1.15;
}

/* Color states for py-char */
.letter.py-char.is-right .py-hanzi  { color: var(--ok); }
.letter.py-char.is-right .py-rt     { color: var(--ok); }
.letter.py-char.incorrect .py-hanzi { color: var(--err); background: var(--err-soft); border-radius: 2px; }
.letter.py-char.incorrect .py-rt    { color: var(--err); }
.letter.py-char.incorrect           { background: none; }

/* is-active override for py-char */
.letter.py-char.is-active {
  text-decoration: none;
}
.letter.py-char.is-active .py-hanzi {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}
.letter.py-char.is-active .py-rt {
  color: var(--accent);
}

/* Pinyin hidden */
.typing-area.py-hidden .py-rt {
  visibility: hidden;
}

/* ── Modal ── */
@keyframes boing {
  0%   { transform: scale(0.45) translateY(40px); opacity: 0; }
  62%  { transform: scale(1.06) translateY(-6px); opacity: 1; }
  80%  { transform: scale(0.96) translateY(2px); }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  z-index: 999;
  padding: 16px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: 24px;
  padding: 28px 26px 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
  animation: boing 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* Modal hero */
.modal-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1.5px solid var(--border);
}
.modal-hero-char {
  font-size: 60px;
  line-height: 1;
  color: var(--accent);
  flex-shrink: 0;
}
.modal-hero-text { text-align: left; }
.modal-hero-text h2 {
  font-size: 19px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}
.modal-hero-sub {
  font-size: 13px;
  color: var(--muted);
}

/* Mode cards */
.modal-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-bottom: 14px;
}
.modal-card {
  background: var(--bg);
  border-radius: 14px;
  padding: 13px 11px 12px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.15s;
  display: flex;
  flex-direction: column;
}
.modal-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}
.modal-card:hover,
.modal-card.words-c:hover  { border-color: var(--accent); background: var(--accent-soft); }
.modal-card.para-c:hover   { border-color: var(--ok);     background: var(--ok-soft); }
.modal-card.timer-c:hover  { border-color: var(--amber);  background: var(--amber-soft); }

.modal-card-icon {
  font-size: 26px;
  margin-bottom: 7px;
  line-height: 1;
  display: block;
  color: var(--accent);
}
.modal-card.para-c .modal-card-icon  { color: var(--ok); }
.modal-card.timer-c .modal-card-icon { color: var(--amber); }

.modal-card h3 {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}
.modal-card p {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
  text-align: left;
  margin: 0;
  flex: 1;
}
.modal-card-cta {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}
.modal-card:hover .modal-card-cta { opacity: 1; }

/* Tip row */
.modal-tip {
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  background: var(--bg);
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 0;
  line-height: 1.5;
}
.modal-tip strong { color: var(--text); }

/* Modal button (result overlay only) */
.modal-btn {
  display: block;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: opacity 0.15s, transform 0.1s;
}
.modal-btn:hover   { opacity: 0.88; }
.modal-btn:active  { transform: scale(0.98); }

/* Result overlay */
#resultOverlay .modal-box { text-align: center; }
#resultOverlay h2 { font-size: 22px; font-weight: 800; margin-bottom: 12px; }
#resultOverlay #resultText { font-size: 15px; color: var(--muted); margin-bottom: 14px; }

/* ── Lives display ── */
.lives-display {
  display: none;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}
.lives-display.visible { display: flex; }

.life {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--err);
  transition: opacity 0.35s, transform 0.35s;
}
.life.lost {
  opacity: 0.18;
  transform: scale(0.7);
}

/* ── Countdown ── */
@keyframes countPulse {
  0%   { transform: scale(1.5); opacity: 0.4; }
  100% { transform: scale(1);   opacity: 1; }
}
.countdown-num {
  font-size: clamp(72px, 18vw, 96px);
  font-weight: 900;
  color: var(--accent);
  animation: countPulse 0.55s cubic-bezier(0.34, 1.3, 0.64, 1) both;
  line-height: 1;
}
.countdown-go {
  color: var(--ok);
  font-size: clamp(48px, 12vw, 64px);
}

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 22px 16px;
  font-size: 12.5px;
  color: var(--muted);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .topbar {
    padding: 13px 14px 6px;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
  .app-subtitle { text-align: left; }
  .main { padding: 8px 10px 36px; }
  .app-shell { gap: 8px; }
  .mode-tab { min-height: 72px; padding: 12px 8px 10px; border-radius: 14px; }
  .mode-tab-glyph { font-size: 26px; }
  .mode-tab-en { font-size: 12.5px; }
  .mode-tab-zh { font-size: 11px; }
  .typing-card { padding: 16px 14px 18px; border-radius: 16px; }
  .ctrl-select, .ctrl-btn { font-size: 12.5px; height: 34px; }
  .ctrl-select { padding: 0 30px 0 13px; }
  .ctrl-btn { padding: 0 13px; }
  .typing-area--word { font-size: clamp(46px, 18vw, 72px); min-height: 96px; }
  .typing-area--para { font-size: 18px; min-height: 130px; }
  #inputField { font-size: 18px; padding: 11px 15px; }
  .stat-value { font-size: 19px; }
  .modal-box { padding: 22px 18px 20px; border-radius: 20px; }
  .modal-cards { grid-template-columns: 1fr; gap: 7px; }
  .modal-hero-char { font-size: 46px; }
}

/* Practice text cannot be selected, so it cannot be copied */
.typing-area, .pinyin-display, .typing-area *, .pinyin-display * {
  -webkit-user-select: none;
  user-select: none;
}

/* Bilingual labels: Chinese first and larger, English smaller underneath */
.sm { font-size: .72em; font-weight: 500; opacity: .75; letter-spacing: 0; }
.mode-tab-zh { font-size: 15px; font-weight: 700; }
.mode-tab-en { font-size: 11px; font-weight: 500; opacity: .75; }

/* Controls: New is quiet and sits on the right */
.controls-bar { justify-content: flex-start; }
.ctrl-btn.quiet {
  margin-left: auto;
  background: transparent;
  border: 1.5px dashed var(--border);
  color: var(--muted);
  font-weight: 500;
}
.ctrl-btn.quiet:hover { border-color: var(--accent); color: var(--accent); opacity: 1; }

/* Level chips: five buttons, the active one highlighted */
.level-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.level-chip { font-family: inherit; height: 34px; padding: 0 12px; border-radius: 999px; border: 1.5px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.level-chip:hover { border-color: var(--accent); color: var(--accent); }
.level-chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.level-chip .lv-zh { font-weight: 700; }

/* English paragraphs read as running text, one line flow */
.typing-area--para { display: block; text-align: left; line-height: 1.9; }
.typing-area--para .letter { display: inline; }

/* ── Round 2 (English) ── */
@font-face { font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("fonts/inter-latin-wght-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 200 900; font-display: swap; src: url("fonts/source-serif-4-latin-opsz-normal.woff2") format("woff2"); }

/* Wider page */
.topbar, .main { max-width: 1000px; }

/* Grade buttons: blue when chosen */
.level-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* New is unavailable while a paragraph is half typed, so progress is not lost */
.ctrl-btn:disabled { opacity: .35; cursor: not-allowed; }

/* Paragraph: a fixed window; finished lines scroll up and fade out, like an old typewriter */
.para-window {
  height: 11rem;
  overflow: hidden;
  position: relative;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22%, #000 70%, transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 22%, #000 70%, transparent 100%);
}
.para-window .typing-area { position: relative; transition: transform .35s ease; }
.typing-area--para { font-family: "Inter", system-ui, sans-serif; font-size: 1.45rem; line-height: 1.8; }
html.serif-text .typing-area--para { font-family: "Source Serif 4", Georgia, serif; }

/* Font check */
.font-check { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.font-check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; cursor: pointer; }
.font-check:has(input:checked) { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* Message at the end of a round */
.teacher-notice { margin: 14px 0 0; font-size: 14px; color: var(--muted); line-height: 1.5; }

/* ── Round 3 (English) ── */
/* Plain sans serif, no extra letter spacing (the Chinese spacing was carried over by mistake) */
body, .typing-area--para, .typing-area--para .letter, .typing-area--para .punc {
  letter-spacing: 0;
  word-spacing: normal;
  text-transform: none;
}
.typing-area--para { font-family: "Inter", system-ui, sans-serif; font-weight: 400; font-size: clamp(1.6rem, 1.1rem + 1.3vw, 2.2rem); line-height: 1.7; }
html.serif-text .typing-area--para { font-family: "Source Serif 4", Georgia, serif; }

/* Four lines visible. Lines leave by the top, fading only at the top edge */
.para-window {
  height: 15rem;
  padding-inline: 2.5rem;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 28%, #000 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 28%, #000 100%);
}

/* The sans / serif check applies to words and paragraphs alike */
.typing-area, .typing-area .letter, .typing-area .word-char { font-family: "Inter", system-ui, sans-serif; letter-spacing: 0; }
html.serif-text .typing-area, html.serif-text .typing-area .letter, html.serif-text .typing-area .word-char { font-family: "Source Serif 4", Georgia, serif; }

/* The paragraph window (fixed height, top fade) is only used in paragraph mode */
.para-window { height: auto; overflow: visible; padding-inline: 0; -webkit-mask-image: none; mask-image: none; }
.para-window.is-para { height: 15rem; overflow: hidden; padding-inline: 2.5rem; -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 28%, #000 100%); mask-image: linear-gradient(to bottom, transparent 0, #000 28%, #000 100%); }

/* Words and Timer: the word sits in the middle of the same space the paragraphs use */
.typing-area--word { min-height: 15rem; }

/* No fade: finished lines simply leave by the top edge */
.para-window.is-para { -webkit-mask-image: none; mask-image: none; }

/* Checks sit on the right, just before New */
.checks { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.ctrl-btn.quiet { margin-left: 0; }
/* Less rounded controls */
.ctrl-btn, .level-chip, .font-check { border-radius: 10px; }

/* All checks look the same: white box, blue when on (the Chinese app had a generic label style over them) */
.checks .font-check { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1; }
.checks .font-check input { margin: 0; width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.checks .font-check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Level chips: number and name the same size, name in bold like the Chinese app */
.level-chip { font-size: 13.5px; }
.level-chip .lv-zh { font-size: 13.5px; font-weight: 700; }

/* Shown after a finished paragraph until the next one starts */
.done-notice { margin: 12px auto 0; max-width: 40rem; padding: 12px 16px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 14.5px; font-weight: 600; line-height: 1.5; text-align: center; }
.done-notice[hidden] { display: none; }

/* Paragraph popup: room around the text and the button, and a visible close cross */
#doneOverlay .modal-box { position: relative; padding: 36px 32px 30px; }
#doneOverlay p { margin: 14px 0 26px; line-height: 1.55; color: var(--ink-2); }
#doneOk { display: block; margin-top: 4px; padding: 13px 24px; font-size: 16px; }
.done-x { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid var(--border); background: var(--surface); color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; }
.done-x:hover { border-color: var(--accent); color: var(--accent); }

/* Paragraph popup: results and the yes or no question */
#doneOverlay .done-result { font-size: 15px; font-weight: 600; color: var(--accent); margin: 10px 0 14px; }
#doneOverlay .done-question { margin: 0 0 22px; }
#doneOverlay .done-actions { display: flex; gap: 10px; flex-wrap: wrap; }
#doneOverlay .done-actions .modal-btn { flex: 1 1 200px; }

/* Round results: cards */
.result-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 6px 0 18px; }
.result-stats:has(.result-card:nth-child(5)) { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.result-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 18px 8px; border-radius: 12px; background: var(--accent-soft); border: 1.5px solid var(--accent); }
.result-value { font-size: 30px; font-weight: 700; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.result-label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
@media (max-width: 600px) {
  .result-stats, .result-stats:has(.result-card:nth-child(5)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-value { font-size: 26px; }
}

/* Round results: room between the notice and the Play again button */
#resultOverlay .modal-box { padding-bottom: 30px; }
#resultOverlay .teacher-notice { margin: 16px 0 26px; }
#closeOverlay { display: block; margin: 0 auto; padding: 13px 26px; font-size: 16px; }

/* Paragraph popup: cards and buttons */
#doneOverlay .done-result { margin: 8px 0 20px; }
#doneOverlay .done-result .result-stats { margin: 0; }
#doneOverlay .done-actions { display: flex; gap: 12px; flex-wrap: wrap; }
#doneOverlay .done-actions .modal-btn { flex: 1 1 200px; height: 50px; padding: 0 22px; border-radius: 12px; font-size: 15px; font-weight: 700; letter-spacing: .01em; }
#doneOverlay #doneNo { background: var(--accent); color: #fff; border: 1.5px solid var(--accent); box-shadow: 0 6px 16px rgba(37, 99, 235, .25); }
#doneOverlay #doneNo:hover { filter: brightness(.94); }
#doneOverlay #doneYes { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); }
#doneOverlay #doneYes:hover { background: var(--accent-soft); }
#doneOverlay .done-question { font-size: 14.5px; }
