:root {
  --bg: #FAF9F6;                           /* тёплый off-white, не чистый белый */
  --surface: #FFFFFF;                       /* карточки приподняты над фоном */
  --ink: #1B1A17;                           /* почти чёрный, тёплый */
  --muted: #8A877E;                         /* тёплый серый — подписи, плейсхолдеры */
  --ghost: rgba(120, 118, 110, 0.32);       /* непечатанный текст */
  --ghost-strong: rgba(90, 88, 80, 0.58);
  --accent: #F26A21;                        /* тёплый оранжевый */
  --accent-soft: rgba(242, 106, 33, 0.12);
  --error: #E0533B;
  --line: #ECEAE3;                          /* границы, разделители */
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --font: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ---------- БРЕНД ---------- */
.brand {
  font-size: 42px;
  font-weight: 600;
  letter-spacing: -1.5px;
}
.brand.small { font-size: 22px; }
.brand .dot { color: var(--accent); }

/* печатная машинка у логотипа */
#brand-anim {
  display: flex; align-items: center; justify-content: center;
  min-height: 52px;
}
.brand-caret {
  display: inline-block;
  width: 4px; height: 0.92em;
  margin-left: 5px;
  background: var(--accent);
  border-radius: 2px;
  animation: caret 1.05s steps(1, start) infinite;
}
#brand-anim.typing .brand-caret { animation: none; opacity: 1; }
.brand-sub {
  margin-top: 8px;
  color: var(--ghost-strong);
  font-weight: 400;
  font-size: 15px;
}

/* ---------- АВТОРИЗАЦИЯ ---------- */
.auth-screen { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.auth-tabs {
  display: flex;
  gap: 4px;
  margin: 32px 0 20px;
  background: rgba(0,0,0,0.04);
  padding: 4px;
  border-radius: 12px;
}
.auth-tab {
  flex: 1; padding: 10px;
  border: none; background: transparent;
  border-radius: 9px;
  font-family: inherit; font-size: 14px; font-weight: 500;
  color: var(--ghost-strong); cursor: pointer;
  transition: all 0.25s ease;
}
.auth-tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-form .field-label { font-size: 13px; font-weight: 600; color: var(--muted, #888); margin: 6px 0 -2px; text-align: left; }
.auth-form input {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-family: inherit; font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.auth-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.auth-error { color: var(--error); font-size: 13px; min-height: 16px; text-align: left; padding-left: 4px; }

/* ---------- КНОПКИ ---------- */
.btn-primary {
  padding: 14px 18px;
  border: none; border-radius: 12px;
  background: var(--accent); color: #fff;
  font-family: inherit; font-size: 15px; font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 20px var(--accent-soft); background: #ff8c33; }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  padding: 10px 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--ghost-strong);
  font-family: inherit; font-size: 14px; cursor: pointer;
  transition: all 0.2s ease;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--ghost); }

.btn-back {
  border: none; background: transparent;
  font-family: inherit; font-size: 15px; color: var(--ghost-strong);
  cursor: pointer; padding: 6px 0;
  transition: color 0.2s ease;
}
.btn-back:hover { color: var(--accent); }

.user-chip {
  font-size: 14px; font-weight: 500;
  padding: 6px 14px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 20px;
}

/* ---------- ГЛАВНОЕ МЕНЮ ---------- */
.menu-screen { display: flex; flex-direction: column; }
.menu-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px 32px;
}
.menu-center {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px;
  animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.menu-title { font-size: 40px; font-weight: 600; letter-spacing: -1px; }
.menu-title span { color: var(--accent); }
.menu-sub { margin-top: 10px; color: var(--ghost-strong); font-size: 16px; }
.menu-sub b { color: var(--ink); }
.btn-play { margin-top: 28px; font-size: 18px; padding: 16px 64px; border-radius: 14px; }
.btn-arcade {
  margin-top: 14px;
  padding: 13px 40px; border-radius: 14px;
  border: 1.5px solid var(--accent); background: transparent; color: var(--accent);
  font-family: inherit; font-size: 16px; font-weight: 600; cursor: pointer;
  transition: all 0.2s ease;
}
.btn-arcade:hover { background: var(--accent-soft); transform: translateY(-1px); }
.menu-links { margin-top: 28px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }

/* переключатель языка (над приветствием) */
.menu-center .lang-switch { margin-bottom: 26px; }
.lang-switch {
  display: inline-flex; gap: 4px;
  background: rgba(0,0,0,0.04); padding: 3px; border-radius: 10px;
}
.lang-opt {
  padding: 7px 16px; border: none; background: transparent; border-radius: 8px;
  font-family: inherit; font-size: 13px; font-weight: 600; letter-spacing: 0.5px;
  color: var(--ghost-strong); cursor: pointer; transition: all 0.25s ease;
}
.lang-opt.active { background: var(--surface); color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

/* ---------- ВЕРХНЯЯ ПАНЕЛЬ ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--line);
}
.level-badge { font-size: 14px; color: var(--ghost-strong); }
.level-badge b { color: var(--accent); }
.stats-mini { display: flex; gap: 20px; font-size: 14px; color: var(--ghost-strong); font-variant-numeric: tabular-nums; }
.stats-mini b { color: var(--ink); font-weight: 600; }

/* аркадный таймер */
.arcade-clock {
  font-size: 26px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 84px; text-align: right;
}
.arcade-clock.low { color: var(--error); animation: pulse 0.5s ease infinite; }

/* всплывашка «+5s» */
.bonus-pop {
  position: absolute; top: 18%; left: 50%;
  transform: translateX(-50%);
  font-size: 34px; font-weight: 700; color: var(--accent);
  opacity: 0; pointer-events: none;
}
.bonus-pop.show { animation: bonus 0.9s cubic-bezier(0.16, 1, 0.3, 1); }

/* ---------- ОБЛАСТЬ ПЕЧАТИ (по центру) ---------- */
.game-screen { display: flex; flex-direction: column; }
.typing-stage {
  flex: 1; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 32px;
}
.text-wrap { width: 100%; max-width: 760px; }

.text-display {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 500;
  line-height: 1.9;
  letter-spacing: 0;
  text-align: center;
  user-select: none;
  outline: none;
  cursor: text;
}
.text-display .char {
  color: var(--ghost);
  transition: color 0.25s ease;
  position: relative;
}
/* правильно введённая буква — плавно становится оранжевой (заливка вправо) */
.text-display .char.done { color: var(--accent); }
.text-display .char.wrong {
  color: var(--error);
  background: rgba(229, 72, 77, 0.10);
  border-radius: 4px;
}

/* мигающий блочный курсор как в терминале */
.text-display .char.current::before {
  content: '';
  position: absolute;
  left: -1px; right: -1px; top: 8%; bottom: 8%;
  background: var(--accent);
  border-radius: 3px;
  opacity: 0.22;
  animation: blink 1.1s steps(1, start) infinite;
}
/* пока человек печатает — курсор не мигает, ровно горит */
.text-display.typing .char.current::before { animation: none; opacity: 0.22; }
/* пробел сохраняется и даёт перенос строки (слово не рвётся) */
.text-display .char.space { white-space: pre-wrap; }

/* полоса прогресса — «заливка вправо» */
.progress {
  margin-top: 36px;
  height: 3px;
  background: rgba(0,0,0,0.05);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s ease;
}

.hidden-input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.hint { margin-top: 40px; font-size: 14px; color: var(--ghost-strong); font-weight: 400; }

/* ---------- ВЫБОР УРОВНЯ ---------- */
.levels-screen { display: flex; flex-direction: column; }
.levels-main {
  flex: 1; display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 24px;
}
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  width: 100%; max-width: 720px;
  animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.level-tile {
  display: flex; flex-direction: column; gap: 8px;
  padding: 18px 18px 20px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); cursor: pointer; text-align: left;
  font-family: inherit;
  transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.level-tile:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 8px 20px var(--accent-soft); }
.level-tile.locked { cursor: not-allowed; opacity: 0.55; }
.level-tile.locked:hover { transform: none; border-color: var(--line); box-shadow: none; }
.level-tile.current-lvl { border-color: var(--accent); background: var(--accent-soft); }
.lvl-n { font-size: 20px; font-weight: 600; }
.lvl-n small { color: var(--ghost-strong); font-weight: 400; font-size: 13px; margin-left: 6px; }
.lvl-preview {
  font-size: 13px; color: var(--ghost-strong);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- ЛИЧНЫЙ КАБИНЕТ ---------- */
.profile-screen { display: flex; flex-direction: column; }
.profile-main {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 24px;
  animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.profile-avatar {
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 600;
  margin-bottom: 18px;
}
.profile-name { font-size: 30px; font-weight: 600; letter-spacing: -0.5px; }
.profile-stats {
  margin-top: 40px;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px;
  width: 100%; max-width: 420px;
}
.pstat {
  background: rgba(0,0,0,0.025);
  border-radius: 14px;
  padding: 22px;
  text-align: center;
}
.pstat span { display: block; font-size: 32px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.pstat small { color: var(--ghost-strong); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }

/* ---------- МОДАЛКИ ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 20;
  animation: fade 0.25s ease;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px; width: 100%; max-width: 440px;
  animation: rise 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-card h2 { font-weight: 600; font-size: 24px; margin-bottom: 24px; }
.result-stats { display: flex; justify-content: space-around; margin-bottom: 28px; }
.result-stats div { text-align: center; }
.result-stats span { display: block; font-size: 32px; font-weight: 600; color: var(--accent); }
.result-stats small { color: var(--ghost-strong); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.result-actions button { white-space: nowrap; }
#result-modal .modal-card, #arcade-modal .modal-card { max-width: 500px; }

/* ---------- РЕЙТИНГ ---------- */
.board-card { max-width: 760px; }
.board-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.board-head h2 { margin: 0; }
.board-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.board-col { min-width: 0; }
.board-col-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; letter-spacing: .02em;
  color: var(--muted); text-transform: uppercase;
  padding: 0 4px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.board-col-ic { font-size: 15px; }
.board-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
@media (max-width: 600px) {
  .board-cols { grid-template-columns: 1fr; gap: 28px; }
}
.board-row { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-radius: 12px; background: rgba(0,0,0,0.025); }
.board-row.me { background: var(--accent-soft); }
.board-rank { font-weight: 600; font-size: 15px; width: 28px; color: var(--ghost-strong); }
.board-rank.top { color: var(--accent); }
.board-name { flex: 1; font-weight: 500; }
.board-score { font-variant-numeric: tabular-nums; font-weight: 600; }
.board-score small { color: var(--ghost-strong); font-weight: 400; font-size: 12px; margin-left: 4px; }
.board-empty { text-align: center; color: var(--ghost-strong); padding: 24px; }

/* ---------- АНИМАЦИИ ---------- */
@keyframes blink { 0%, 49% { opacity: 0.22; } 50%, 100% { opacity: 0; } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes bonus {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.8); }
  25% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -30px) scale(1); }
}
@keyframes caret { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 600px) {
  .text-display { font-size: 24px; }
  .topbar { padding: 16px; }
  .stats-mini { gap: 12px; font-size: 13px; }
  .menu-links { flex-wrap: wrap; justify-content: center; }
  .profile-stats { grid-template-columns: 1fr; }
}
