:root {
  --bg: #ffffff;
  --ink: #2b2b2b;
  --muted: #9a9a9a;
  --muted2: #363636;
  --line: #dcdcdc;
  --line-hover: #bdbdbd;
  --hover: #f5f5f4;
  --green: #2f9e44;
  --green-soft: #ebfbee;
  --red: #e03131;
  --red-soft: #fff0f0;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  min-height: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 26px 22px calc(22px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---- header ---- */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 15px;
}

.level { color: var(--muted); }

.stats {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--muted);
}

.stats .mark { font-weight: 700; }
.stats .ok  { color: var(--green); }
.stats .bad { color: var(--red); }
.stats .passed { color: var(--muted); }

/* ---- progress до следующего уровня ---- */
.progress {
  margin-top: 16px;
}
.progress-track {
  height: 8px;
  background: var(--hover);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--green);
  border-radius: 999px;
  transition: width .35s ease;
}
.progress-label {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* ---- card ---- */
.card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 34px;
  padding: 40px 0;
}

.word {
  font-size: clamp(40px, 9vw, 60px);
  font-weight: 700;
  letter-spacing: -0.5px;
  text-align: center;
  line-height: 1.1;
  min-height: 1.2em;
  word-break: break-word;
}

.gloss {
  margin-top: -18px;
  font-size: clamp(24px, 6vw, 36px);
  font-weight: 700;            /* как у слова */
  letter-spacing: -0.5px;      /* как у слова */
  color: var(--muted2);
  text-align: center;
  min-height: 1em;
}

.answers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 680px;
}

.answer {
  flex: 1 1 130px;
  padding: 14px 10px;
  font-size: 17px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

/* ---- подсказки клавиатуры ---- */
kbd.key,
.keys-hint kbd {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  background: var(--hover);
  border: 1px solid var(--line);
  border-bottom-width: 2px;          /* «объём» клавиши */
  border-radius: 5px;
  padding: 3px 6px 2px;
}

.keys-hint {
  margin-top: -22px;                 /* прижать к кнопкам (gap карточки большой) */
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.keys-hint kbd { margin: 0 2px; }

/* на тачскринах физической клавиатуры нет — подсказки не показываем */
@media (hover: none), (pointer: coarse) {
  kbd.key, .keys-hint { display: none; }
  .answer { padding: 18px 10px; }
}

.answer:hover:not(:disabled) {
  background: var(--hover);
  border-color: var(--line-hover);
}

.answer:disabled { cursor: default; }

.answer.correct {
  border-color: var(--green);
  color: var(--green);
  background: #f0fbf3;
}

.answer.wrong {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-soft);
}

.hint {
  min-height: 22px;
  font-size: 15px;
  color: var(--muted);
  text-align: center;
}
.hint.correct { color: var(--green); }
.hint.wrong { color: var(--red); }

/* ---- footer ---- */
.bottom {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 14px;
  row-gap: 12px;
  font-size: 14px;
  color: var(--muted);
}

/* переключатель языка — слева, статус синхронизации и ссылки — справа */
.bottom .lang-switch { margin-right: auto; }

.links { display: flex; gap: 22px; }

.linkbtn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}
.linkbtn:hover { color: var(--ink); text-decoration: underline; }

.sync {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line);
  transition: background .2s ease;
}
.sync.ok      { background: var(--green); }
.sync.pending { background: #f0a020; }
.sync.offline { background: var(--red); }

/* ---- overlay / dialog ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.28);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.overlay[hidden] { display: none; }

.dialog {
  background: #fff;
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.dialog h2 { margin: 0; font-size: 18px; }
.dialog-sub { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }

/* ---- таблица статистики ---- */
.table-wrap {
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
}
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.stats-table th,
.stats-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.stats-table td:first-child { word-break: break-word; }   /* длинные слова переносим */
.stats-table th.num,
.stats-table td.num { text-align: right; white-space: nowrap; }
.stats-table .ok  { color: var(--green); }   /* колонка верных — зелёная, как ✓ на главной */
.stats-table .bad { color: var(--red); }     /* колонка ошибок — красная, как ✕ на главной */
.stats-table thead th {
  position: sticky;
  top: 0;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.stats-table thead th:hover { background: var(--hover); }
.stats-table tbody tr:hover { background: var(--hover); }
.stats-table tbody tr:last-child td { border-bottom: none; }
/* стрелка направления сортировки у активной колонки */
.stats-table th[aria-sort="ascending"]::after  { content: " ▲"; font-size: 9px; color: var(--muted); }
.stats-table th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; color: var(--muted); }

.json-data { margin-top: 4px; }
.json-data summary { cursor: pointer; color: var(--ink); font-size: 14px; margin-bottom: 10px; }

.danger-zone { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.danger-zone a.linkbtn { text-decoration: none; }

.dialog-foot { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; text-align: right; }

.btn-block {
  width: 100%; padding: 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; margin-top: 4px;
  transition: background .12s ease, border-color .12s ease;
}
.btn-block:hover { background: var(--hover); border-color: var(--line-hover); }
.linkbtn.danger { color: var(--red); }
.linkbtn.danger:hover { color: var(--red); text-decoration: underline; }

#data-json {
  width: 100%;
  height: 260px;
  resize: vertical;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 12px;
}
.dialog-msg { color: var(--green); font-size: 13px; }

.sync-settings { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.sync-settings summary { cursor: pointer; color: var(--ink); font-size: 14px; }
.sync-settings code { background: var(--hover); padding: 1px 5px; border-radius: 4px; }
#sync-token {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  margin-bottom: 10px;
}
