:root {
  --bg:       #ffffff;
  --bg-2:     #f5f5f7;
  --bg-3:     #e8e8ed;
  --accent:   #f56300;
  --accent-h: #ff7200;
  --purple:   #8b3dff;
  --gradient: linear-gradient(135deg, #f56300 0%, #8b3dff 100%);
  --correct:  #34c759;
  --wrong:    #ff3b30;
  --warning:  #ff9f0a;
  --text-1:   #1d1d1f;
  --text-2:   #6e6e73;
  --text-3:   #aeaeb2;
  --border:   #d2d2d7;
  --r-s:      10px;
  --r-m:      16px;
  --r-l:      22px;
}

*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
html { height: -webkit-fill-available; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', system-ui, sans-serif;
  background: var(--bg); color: var(--text-1);
  min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  overflow-x: hidden; overscroll-behavior-y: none; -webkit-font-smoothing: antialiased;
}

/* ── HEADER ── */
.header {
  position: sticky; top: 0; z-index: 100; width: 100%;
  background: rgba(255,255,255,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.header__inner {
  max-width: 1200px; margin: 0 auto; padding: 0 22px;
  height: 44px; display: flex; align-items: center;
}
.header__logo {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; height: 44px;
}
.header__logo-text {
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: #1d1d1f; white-space: nowrap;
}
.header__back {
  background: none; border: none; font-family: inherit;
  font-size: 13px; font-weight: 500; color: var(--text-2);
  cursor: pointer; height: 44px; padding: 0 4px;
  display: flex; align-items: center; gap: 4px;
  transition: color 0.15s; white-space: nowrap;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  margin-left: auto;
}
.header__back:hover { color: var(--text-1); }

/* ── SCREENS ── */
.screen { display: none; width: 100%; max-width: 960px; padding: 0 20px 52px; animation: fadeUp 0.32s cubic-bezier(.25,.46,.45,.94); }
.screen.active { display: block; }
@keyframes fadeUp { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }

/* ── HERO ── */
.hero { padding: 52px 0 40px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; }
.hero__eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--accent); }
.hero__title   { font-size: clamp(36px,8vw,60px); font-weight: 800; letter-spacing: -2px; line-height: 1.02; }
.hero__sub     { font-size: clamp(15px,3.5vw,18px); color: var(--text-2); line-height: 1.55; max-width: 420px; font-weight: 400; }

/* ── STAT STRIP ── */
.stat-strip {
  display: grid; grid-template-columns: repeat(4,1fr);
  width: 100%; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-l); overflow: hidden;
  margin-bottom: 20px;
}
.stat-strip__item { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 18px 8px; border-right: 1px solid var(--border); }
.stat-strip__item:last-child { border-right: none; }
.stat-strip__val { font-size: clamp(15px,3.8vw,20px); font-weight: 700; color: var(--accent); white-space: nowrap; }
.stat-strip__lbl { font-size: clamp(9px,2vw,11px); color: var(--text-2); text-align: center; line-height: 1.3; font-weight: 500; }

/* ── TWO-COL ── */
.two-col { display: flex; flex-direction: column; gap: 16px; width: 100%; }
@media (min-width: 720px) {
  .two-col { flex-direction: row; align-items: flex-start; gap: 24px; }
  .two-col .col-main { flex: 3; min-width: 0; }
  .two-col .col-side { flex: 2; min-width: 0; position: sticky; top: 68px; }
}

/* ── CARD ── */
.card { width: 100%; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-m); padding: 20px; }
.card__label { display: block; font-size: 10px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-2); margin-bottom: 14px; }
.card--accent { border-color: rgba(139,61,255,0.35); box-shadow: 0 0 0 3px rgba(139,61,255,0.07), 0 0 14px rgba(245,99,0,0.06); }

/* ── BUTTONS ── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 980px; font-family: inherit; font-weight: 600;
  cursor: pointer; touch-action: manipulation; transition: background 0.18s, transform 0.12s, opacity 0.15s;
  -webkit-appearance: none; white-space: nowrap;
}
.btn--primary { background: var(--gradient); color: #fff; font-size: clamp(15px,3.5vw,16px); padding: 14px 36px; min-height: 50px; width: 100%; box-shadow: 0 4px 18px rgba(245,99,0,0.30), 0 4px 22px rgba(139,61,255,0.28); transition: box-shadow 0.2s, transform 0.12s, opacity 0.15s; }
@media (hover:hover) { .btn--primary:hover { box-shadow: 0 6px 28px rgba(245,99,0,0.40), 0 6px 32px rgba(139,61,255,0.36); opacity: 0.93; } }
.btn--primary:active { transform: scale(0.97); opacity: 0.88; }
.btn--ghost { background: var(--bg-2); color: var(--text-1); font-size: clamp(14px,3.2vw,15px); padding: 12px 28px; min-height: 44px; width: 100%; border: 1px solid var(--border); }
@media (hover:hover) { .btn--ghost:hover { background: var(--bg-3); } }
.btn--ghost:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.hidden { display: none !important; }

/* ── SECTION HEAD ── */
.section-head { padding: 36px 0 20px; display: flex; flex-direction: column; gap: 4px; }
.section-head span { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--accent); }
.section-head h2   { font-size: clamp(20px,5vw,26px); font-weight: 800; letter-spacing: -0.5px; }

/* ── STEPS / TIPS ── */
.steps { display: flex; flex-direction: column; gap: 14px; }
.step  { display: flex; align-items: flex-start; gap: 12px; }
.step__icon { width: 34px; height: 34px; flex-shrink: 0; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.step__text { display: flex; flex-direction: column; gap: 2px; padding-top: 5px; }
.step__text strong { font-size: 13px; font-weight: 600; }
.step__text span   { font-size: 12px; color: var(--text-2); line-height: 1.5; }
.tips { display: flex; flex-direction: column; gap: 8px; }
.tip  { display: flex; align-items: flex-start; gap: 9px; font-size: 12px; color: var(--text-2); line-height: 1.5; }
.tip::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex-shrink: 0; margin-top: 5px; }

/* ── SUMMARY ROWS ── */
.summary-label { font-size: 10px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-2); margin-bottom: 12px; display: block; }
.summary-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.summary-row:last-of-type { border-bottom: none; padding-bottom: 0; }
.summary-row__key { color: var(--text-2); font-weight: 500; }
.summary-row__val { color: var(--text-1); font-weight: 600; }

/* ── TIMER BAR ── */
.timer-wrap { width: 100%; height: 6px; background: var(--bg-3); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.timer-bar  { height: 100%; width: 100%; border-radius: 999px; background: var(--gradient); box-shadow: 0 0 10px rgba(245,99,0,0.45), 0 0 18px rgba(139,61,255,0.30); transition: width 1s linear, background 0.4s; }
.timer-bar.warn   { background: var(--warning); box-shadow: 0 0 10px rgba(255,159,10,0.55); }
.timer-bar.danger { background: var(--wrong);   box-shadow: 0 0 10px rgba(255,59,48,0.55); }

/* ── TEXT BOX ── */
.text-box {
  width: 100%;
  background: var(--bg); border: 1.5px solid rgba(139,61,255,0.22);
  border-radius: var(--r-l); padding: 20px 22px;
  height: 168px;
  font-size: clamp(16px,3.8vw,19px); line-height: 2;
  color: var(--text-3); text-align: left;
  overflow: hidden; white-space: normal; word-wrap: break-word;
  box-shadow: 0 0 0 3px rgba(139,61,255,0.07), 0 2px 12px rgba(0,0,0,0.04);
  user-select: none; -webkit-user-select: none;
  cursor: text;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.15s;
}
.text-box:focus, .text-box.focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245,99,0,0.12);
  outline: none;
}
.text-box.shake       { animation: shake 0.28s ease; }
.text-box.error-flash { animation: errorFlash 0.3s ease; }
@keyframes errorFlash {
  0%,100% { background: var(--bg); }
  40%     { background: rgba(255,59,48,0.09); }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-5px); }
  40%     { transform: translateX(5px); }
  60%     { transform: translateX(-3px); }
  80%     { transform: translateX(3px); }
}

/* Символы в тексте */
.ch              { color: var(--text-3); }
.ch.correct      { color: var(--correct); }
.ch.wrong        { color: var(--wrong); }
.ch.current-word { background: rgba(139,61,255,0.07); border-radius: 1px; }
.ch.cursor    {
  background: var(--accent); color: #fff;
  border-radius: 2px; padding: 0 1px;
  animation: blink 1s step-end infinite, cursorSlide 0.07s ease-out;
}
@keyframes cursorSlide {
  from { transform: translateX(-3px); opacity: 0.5; }
  to   { transform: translateX(0);    opacity: 1;   }
}
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0.25; } }

/* ── HIDDEN INPUT (мобильная клавиатура) ── */
.typing-hidden {
  position: fixed; top: 0; left: 0;
  width: 1px; height: 1px; opacity: 0;
  pointer-events: none; border: none; outline: none;
  font-size: 16px; /* предотвращает zoom на iOS */
  caret-color: transparent;
}

/* ── COMBO BREAK TOAST ── */
.combo-break {
  text-align: center; font-size: 12px; font-weight: 700;
  color: var(--wrong); padding: 5px 14px;
  background: rgba(255,59,48,0.08); border: 1px solid rgba(255,59,48,0.18);
  border-radius: 980px; width: fit-content; margin: 0 auto;
  animation: popIn 0.2s cubic-bezier(.34,1.56,.64,1);
}

/* ── COMBO ── */
.combo-display {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; font-size: 13px; font-weight: 700;
  color: var(--accent); padding: 6px 14px;
  background: rgba(245,99,0,0.08); border: 1px solid rgba(245,99,0,0.2);
  border-radius: 980px; width: fit-content; margin: 0 auto;
  animation: popIn 0.2s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn { from { transform: scale(0.7); opacity:0; } to { transform: scale(1); opacity:1; } }

/* ── WPM CHART ── */
.wpm-chart { width: 100%; overflow: hidden; }
.wpm-chart svg { width: 100%; height: auto; display: block; }

/* ── LIVE STAT CHIPS ── */
.live-stats { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; margin-top: 12px; }
.stat-chip {
  padding: 6px 12px; border-radius: 980px;
  background: var(--bg-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-2); font-weight: 500;
}
.stat-chip span { color: var(--text-1); font-weight: 700; }

/* ── DURATION PICKER ── */
.dur-picker {
  display: flex; gap: 8px; justify-content: center;
  margin-bottom: 12px;
}
.dur-btn {
  border: 1.5px solid var(--border); background: var(--bg-2);
  border-radius: 980px; padding: 8px 20px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--text-2); cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.dur-btn.active {
  border-color: var(--accent); color: var(--accent);
  background: rgba(245,99,0,0.06);
}
@media (hover:hover) { .dur-btn:hover:not(.active) { border-color: var(--text-3); color: var(--text-1); } }

/* ── RESULT DELTA ── */
.result-score-delta {
  font-size: 13px; font-weight: 600; margin-top: 2px;
}

/* ── HISTORY SECTION ── */
.history-section {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r-m); padding: 16px 18px 12px;
  margin-bottom: 16px; width: 100%;
}
.history-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.history-title { font-size: 10px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-2); }
.history-best-wrap { font-size: 12px; color: var(--text-2); }
.history-best-wrap strong { color: var(--accent); font-weight: 700; }
.history-chart { width: 100%; overflow: hidden; }
.history-chart svg { width: 100%; height: auto; display: block; }

/* ── NEW BEST BADGE ── */
.new-best-badge {
  display: inline-block; font-size: 13px; font-weight: 700;
  color: #fff; padding: 5px 16px;
  background: var(--gradient); border-radius: 980px;
  box-shadow: 0 4px 14px rgba(245,99,0,0.30);
  animation: popIn 0.35s cubic-bezier(.34,1.56,.64,1);
  margin-top: 4px;
}

/* ── RESULT ── */
.result-head { padding: 48px 0 32px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
.result-head__icon  { font-size: clamp(52px,12vw,68px); line-height: 1; }
.result-head__title { font-size: clamp(26px,6.5vw,36px); font-weight: 800; letter-spacing: -1px; }
.result-score-card  { background: var(--bg-2); border: 1.5px solid var(--accent); border-radius: var(--r-l); padding: 30px 24px; display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; }
.result-score-label { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-2); }
.result-score-big   { font-size: clamp(42px,11vw,60px); font-weight: 900; letter-spacing: -2px; color: var(--accent); line-height: 1.1; }
.result-score-sub   { font-size: 14px; color: var(--text-2); font-weight: 500; }
.result-message     { font-size: clamp(13px,3.2vw,15px); color: var(--text-2); line-height: 1.6; }
.result-actions     { display: flex; flex-direction: column; gap: 10px; width: 100%; }

/* ── RESULT GAINS ── */
.result-gains { background: var(--bg-2); border-radius: var(--r-m); overflow: hidden; border: 1px solid var(--border); width: 100%; }
.result-gains__header { font-size: 10px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-2); padding: 14px 18px 6px; }
.result-gain { display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-top: 1px solid var(--border); }
.result-gain__icon { font-size: 20px; flex-shrink: 0; line-height: 1; }
.result-gain__body { display: flex; flex-direction: column; gap: 2px; }
.result-gain__lbl  { font-size: 11px; color: var(--text-2); line-height: 1.3; }
.result-gain__val  { font-size: 20px; font-weight: 800; letter-spacing: -0.3px; color: var(--correct); }

/* ── CAPTCHA MODAL ── */
.captcha-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.captcha-modal {
  background: var(--bg); border-radius: var(--r-m);
  box-shadow: 0 16px 48px rgba(0,0,0,0.22);
  padding: 24px; width: 100%; max-width: 320px;
  border: 1px solid var(--border);
}
.captcha-title { font-size: 15px; font-weight: 700; color: var(--text-1); margin-bottom: 6px; }
.captcha-text  { font-size: 13px; color: var(--text-2); margin-bottom: 14px; line-height: 1.5; }
.captcha-input {
  width: 100%; border-radius: var(--r-s); border: 1.5px solid var(--border);
  padding: 12px 14px; font-size: 18px; font-weight: 700; outline: none;
  -webkit-appearance: none; font-family: inherit; color: var(--text-1);
  margin-bottom: 10px; text-align: center; background: var(--bg-2);
  user-select: text; -webkit-user-select: text;
}
.captcha-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(245,99,0,0.12); background: var(--bg); }
.captcha-error { font-size: 12px; color: var(--wrong); min-height: 16px; margin-bottom: 8px; }
.captcha-btn {
  width: 100%; border-radius: 980px; border: none;
  background: var(--gradient); color: #fff; font-weight: 700; font-size: 15px;
  padding: 14px 0; cursor: pointer; -webkit-appearance: none;
  min-height: 48px; touch-action: manipulation;
  box-shadow: 0 4px 14px rgba(245,99,0,0.28);
  font-family: inherit;
}

/* ── FINISH BUTTON ── */
.btn--finish {
  font-size: 12px; min-height: 36px; padding: 8px 20px;
  opacity: 0.55; transition: opacity 0.2s, transform 0.12s;
}
.btn--finish:hover { opacity: 0.85; }

/* ── COUNTDOWN ── */
.countdown-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  pointer-events: none;
}
.countdown-num {
  display: block;
  font-size: clamp(96px,28vw,140px); font-weight: 900; line-height: 1;
  background: var(--gradient);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: countPop 0.82s cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes countPop {
  0%   { transform: scale(0.35); opacity: 0; }
  45%  { transform: scale(1.12); opacity: 1; }
  70%  { transform: scale(0.96); }
  85%  { transform: scale(1);    opacity: 1; }
  100% { transform: scale(1.05); opacity: 0.15; }
}

/* ── RESPONSIVE ── */
@media (max-width: 480px) {
  .screen { padding: 0 16px 36px; }
  .stat-strip__item { padding: 14px 5px; }
}
@media (max-width: 360px) {
  .screen { padding: 0 12px 28px; }
}
@media (hover: none) { .key-hint { display: none; } }
