:root {
  --bg: #f4f7cd;
  --surface: #fbfced;
  --text: #425019;
  --muted: #71812f;
  --accent: #8d9a2e;
  --accent-dark: #768126;
  --correct: #748228;
  --correct-bg: #eef3cc;
  --wrong: #9d4b58;
  --wrong-bg: #ffe8ec;
  --border: #d5e0a5;
  --shadow: 0 4px 14px rgba(80, 102, 27, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}
.topbar__user {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar__name {
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}
.topbar__logout { margin: 0; }

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 30px 22px 64px;
}

.hidden { display: none !important; }

.lead {
  color: var(--muted);
  margin: 0 0 18px;
  font-size: 16px;
}

/* ---- Flash-сообщения ---- */
.flash {
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
}
.flash--error { background: var(--wrong-bg); color: var(--wrong); }
.flash--message { background: var(--correct-bg); color: var(--correct); }

/* ---- Формы входа/регистрации ---- */
.auth-card {
  max-width: 360px;
  margin: 40px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 26px;
  box-shadow: var(--shadow);
}
.auth-card h2 { margin: 0 0 18px; }
.field {
  display: block;
  margin-bottom: 14px;
}
.field span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}
.field input {
  width: 100%;
  font-size: 15px;
  font-family: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
}
.auth-card .primary-btn { width: 100%; }
.auth-switch {
  margin: 16px 0 0;
  font-size: 14px;
  text-align: center;
  color: var(--muted);
}
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover { color: var(--accent-dark); }

/* ---- Выбор блока ---- */
.blocks-grid {
  display: grid;
  gap: 14px;
}
.block-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.block-item:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.block-item__num {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}
.block-item__title {
  font-size: 17px;
  font-weight: 600;
}
.block-item__desc {
  font-size: 14px;
  color: var(--muted);
}
.block-item--soon {
  opacity: 0.6;
  cursor: not-allowed;
}
.block-item__badge {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 12px;
  background: var(--border);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 999px;
}
.block-item__resume {
  margin-top: 6px;
  align-self: flex-start;
  font-size: 12px;
  background: var(--correct-bg);
  color: var(--correct);
  padding: 2px 10px;
  border-radius: 999px;
}
.block-item__best {
  margin-top: 6px;
  align-self: flex-start;
  font-size: 12px;
  color: var(--muted);
}

/* ---- Тренажёр ---- */
.trainer-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  position: relative;
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 16px;
  padding: 6px 8px;
  border-radius: 8px;
}
.link-btn:hover { color: var(--accent-dark); background: rgba(141, 154, 46, 0.08); }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-size: 24px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover {
  background: var(--correct-bg);
  color: var(--accent-dark);
}
.icon-btn--stats {
  font-size: 21px;
  margin-left: auto;
}

.progress {
  flex: 1;
  min-width: 210px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.progress__bar {
  flex: 1;
  height: 12px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress__bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}
.progress__percent {
  min-width: 56px;
  text-align: right;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-dark);
}

.trainer-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-dark);
  text-align: left;
  margin: 0 0 14px;
}

.stats-popover {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
  margin: 0 0 16px;
}
.stats-popover__line {
  font-size: 16px;
  color: var(--muted);
  margin: 0 0 8px;
}
.stats-popover__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.stats-popover__actions .link-btn {
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  border-radius: 10px;
  font-weight: 700;
  padding: 8px 14px;
}
.stats-popover__actions .link-btn:hover {
  border-color: var(--accent-dark);
  background: var(--correct-bg);
  color: var(--accent-dark);
}

.word-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px;
  font-size: 50px;
  font-weight: 600;
  letter-spacing: 1px;
  min-height: 136px;
  padding: 18px;
  text-align: center;
  border-radius: 12px;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.word-box--wrong {
  background: var(--wrong-bg);
  color: var(--wrong);
  border: 1px solid rgba(157, 75, 88, 0.28);
}

.gap {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  vertical-align: middle;
  margin: 0 2px;
  position: relative;
}
.gap__options {
  display: flex;
  gap: 4px;
}
.gap__picker {
  position: relative;
  display: inline-flex;
}
.gap__menu {
  position: absolute;
  left: 50%;
  top: calc(100% + 6px);
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  max-width: min(92vw, 360px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 8;
}
.gap__picker--open .gap__menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.gap-btn {
  font-size: 24px;
  font-weight: 700;
  font-family: inherit;
  min-width: 54px;
  min-height: 52px;
  padding: 8px 10px;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.gap-btn:disabled { cursor: default; }
.gap-btn--picker {
  min-width: 54px;
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.gap-btn--menu {
  min-width: 44px;
  min-height: 52px;
  padding: 8px 10px;
}
.gap-btn--resolved {
  min-width: 18px;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  padding: 0 2px;
  cursor: default;
}
.gap-btn--correct {
  border-color: var(--correct);
  background: var(--correct-bg);
  color: var(--correct);
}
.gap-btn--wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
  color: var(--wrong);
}

.word-box__context {
  margin-left: 12px;
  color: var(--muted);
  font-weight: 600;
}

.feedback {
  border-radius: 10px;
  padding: 16px 18px;
  margin: 8px auto 0;
  max-width: 560px;
  font-size: 17px;
}
.feedback--correct { background: var(--correct-bg); color: var(--correct); }
.feedback--wrong { background: var(--wrong-bg); color: var(--wrong); }
.feedback__answer { font-weight: 600; }
.feedback__rule { color: var(--text); margin-top: 6px; }
.checked-letter {
  font-weight: 800;
  text-transform: uppercase;
}
.checked-letter--correct {
  color: #d85aa6;
}
.checked-letter--wrong {
  color: #c82437;
}

.trainer-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 28px;
}
.primary-btn {
  font-size: 18px;
  font-family: inherit;
  padding: 14px 32px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.12s ease;
}
.primary-btn:hover { background: var(--accent-dark); }

/* ---- Результаты ---- */
.result-summary {
  font-size: 18px;
  text-align: center;
}
.result-history {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.result-mistakes {
  margin: 18px 0;
  display: grid;
  gap: 8px;
}
.mistake-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 15px;
}
.mistake-row__word { font-weight: 600; }
.mistake-row__rule { color: var(--muted); font-size: 13px; }

/* ---- Блок 1: звёзды и список слов ---- */
.stars {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0 0 14px;
}
.task-mastery-stats {
  margin: 2px 0 8px;
  text-align: left;
  font-size: 15px;
  color: var(--muted);
}
.stars--small {
  gap: 2px;
  margin: 0;
  justify-content: flex-end;
}
.star {
  color: var(--border);
  font-size: 34px;
  line-height: 1;
  transition: color 0.2s ease;
}
.stars--small .star {
  font-size: 14px;
}
.star--filled {
  color: #e6b422;
}

.feedback__memorized {
  margin-top: 8px;
  font-weight: 700;
  font-size: 14px;
}

.word-list-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.word-list-head .trainer-title {
  flex: 1;
  margin: 0;
  text-align: left;
}

.word-list-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.word-list-filter input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.word-list {
  display: grid;
  gap: 8px;
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding-right: 4px;
}

.word-list__item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.word-list__item:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.word-list__item--memorized {
  border-color: #e6d48a;
  background: #fffdf5;
}
.word-list__label {
  font-weight: 600;
  word-break: break-word;
}
.word-list__stats {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.deferred-access {
  margin-top: 16px;
  display: flex;
  justify-content: center;
}

.deferred-list {
  display: grid;
  gap: 10px;
}

.deferred-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.deferred-item__phrase {
  font-weight: 600;
}

.deferred-item__meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.deferred-item__note {
  margin-top: 6px;
  font-size: 13px;
}

@media (hover: hover) and (pointer: fine) {
  .gap-btn:hover:not(:disabled) { background: var(--accent); color: #fff; }
}

@media (max-width: 768px) {
  .topbar {
    padding: 12px 14px;
    flex-wrap: wrap;
  }

  .container {
    padding: 18px 12px 44px;
  }

  .trainer-head {
    flex-wrap: wrap;
    gap: 10px;
  }

  .progress {
    min-width: 0;
    width: 100%;
  }

  .trainer-title {
    font-size: 20px;
    margin-bottom: 10px;
  }

  .word-box {
    font-size: clamp(34px, 11vw, 50px);
    min-height: 108px;
    padding: 12px 10px;
  }

  .word-box__context {
    margin-left: 8px;
    font-size: 0.42em;
  }

  .gap-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
    padding: 6px 8px;
  }

  .gap-btn--menu {
    min-width: 42px;
  }

  .primary-btn {
    width: 100%;
    padding: 12px 16px;
  }

  .trainer-controls {
    margin-top: 18px;
  }

  .word-list__item {
    grid-template-columns: 1fr auto;
    row-gap: 6px;
  }
}
