/* ============================================================
   Impara — итальянский по-русски
   Дизайн-токены, база, компоненты. Mobile-first.
   ============================================================ */

:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #eef0ea;
  --ink: #1d2429;
  --muted: #5f6a72;
  --border: #e2e6dd;
  --shadow: 0 1px 2px rgba(29, 36, 41, .05), 0 4px 14px rgba(29, 36, 41, .06);

  --green: #008c45;        /* флаг: декоративные акценты */
  --green-text: #00693a;   /* зелёный текст с запасом контраста */
  --green-btn: #00753a;    /* фон основных кнопок */
  --green-soft: #e2f2e7;
  --red: #cd212a;
  --red-text: #b91c26;
  --red-soft: #fbe7e8;
  --amber-text: #92550a;
  --amber-soft: #fdf0dc;
  --blue-text: #075e88;
  --blue-soft: #e1f0f8;
  --flag-white: #f2f3ee;

  --radius: 14px;
  --radius-sm: 9px;
  --tap: 44px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --font-it: Georgia, "Times New Roman", serif;
}

[data-theme="dark"] {
  --bg: #101410;
  --surface: #191e19;
  --surface-2: #212721;
  --ink: #e8eae3;
  --muted: #9aa49b;
  --border: #2b322b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);

  --green: #35c26d;
  --green-text: #5cd68d;
  --green-btn: #1f9d55;
  --green-soft: #17301f;
  --red: #ff6b6b;
  --red-text: #ff8585;
  --red-soft: #35191b;
  --amber-text: #f0b35c;
  --amber-soft: #33260f;
  --blue-text: #6cc6ee;
  --blue-soft: #122733;
  --flag-white: #c9cec5;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101410;
    --surface: #191e19;
    --surface-2: #212721;
    --ink: #e8eae3;
    --muted: #9aa49b;
    --border: #2b322b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);

    --green: #35c26d;
    --green-text: #5cd68d;
    --green-btn: #1f9d55;
    --green-soft: #17301f;
    --red: #ff6b6b;
    --red-text: #ff8585;
    --red-soft: #35191b;
    --amber-text: #f0b35c;
    --amber-soft: #33260f;
    --blue-text: #6cc6ee;
    --blue-soft: #122733;
    --flag-white: #c9cec5;
  }
}

/* ---------- База ---------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; margin-top: 1.6em; }
h3 { font-size: 1.05rem; margin-top: 1.4em; }
p { margin: .55em 0; }

a { color: var(--green-text); }

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 100;
  background: var(--surface);
  padding: .5rem .9rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.skip-link:focus { left: 8px; }

.noscript {
  max-width: 40rem;
  margin: 2rem auto;
  padding: 1rem;
  text-align: center;
}

.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Итальянский текст */
[lang="it"] { font-style: normal; }

/* ---------- Шапка ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar::after {
  content: "";
  display: block;
  height: 3px;
  background: linear-gradient(90deg,
    var(--green) 0 33.4%,
    var(--flag-white) 33.4% 66.7%,
    var(--red) 66.7%);
  opacity: .85;
}
.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: .55rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.brand {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--ink);
  line-height: 1.15;
}
.brand-name {
  font-family: var(--font-it);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: .01em;
}
.brand-sub {
  font-size: .72rem;
  color: var(--muted);
  letter-spacing: .04em;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 21px; height: 21px; }

.icon-sun { display: none; }
html[data-theme="dark"] .icon-sun { display: block; }
html[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) .icon-sun { display: block; }
  html:not([data-theme]) .icon-moon { display: none; }
}

/* ---------- Навигация ---------- */

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 58px;
  padding: 6px 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .01em;
}
.tabs a svg { width: 23px; height: 23px; }
.tabs a[aria-current="page"] { color: var(--green-text); }
.tabs a:active { background: var(--surface-2); }

/* ---------- Контент ---------- */

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.1rem 1rem calc(84px + env(safe-area-inset-bottom));
  animation: fadein .18s ease-out;
}
main:focus { outline: none; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 768px) {
  .tabs {
    position: static;
    max-width: 760px;
    margin: .65rem auto 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .25rem;
    gap: .25rem;
    box-shadow: var(--shadow);
  }
  .tabs a {
    flex-direction: row;
    gap: 8px;
    min-height: 42px;
    border-radius: 999px;
    font-size: .86rem;
  }
  .tabs a svg { width: 18px; height: 18px; }
  .tabs a:hover { background: var(--surface-2); color: var(--ink); }
  .tabs a[aria-current="page"] {
    background: var(--green-soft);
    color: var(--green-text);
  }
  main { padding-bottom: 3rem; }
}

/* ---------- Карточки-контейнеры ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.05rem;
  margin: .8rem 0;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.card-link {
  display: block;
  text-decoration: none;
  color: var(--ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.card-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(29,36,41,.06), 0 8px 22px rgba(29,36,41,.09);
}

.callout {
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin: .9rem 0;
  border: 1px solid transparent;
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout-tip { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 30%, transparent); }
.callout-warn { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 25%, transparent); }
.callout-tip .callout-title { color: var(--green-text); }
.callout-warn .callout-title { color: var(--red-text); }
.callout-title {
  display: block;
  font-weight: 700;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .3rem;
}

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: var(--tap);
  padding: .55rem 1.15rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--green-btn);
  color: #fff;
  font-weight: 600;
  font-size: .95rem;
  text-decoration: none;
  cursor: pointer;
  transition: filter .12s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { filter: brightness(.95); }
.btn:disabled { opacity: .55; cursor: default; }

.btn-soft {
  background: var(--green-soft);
  color: var(--green-text);
}
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); filter: none; }

.btn-danger-ghost {
  background: transparent;
  color: var(--red-text);
  border: 1px solid color-mix(in srgb, var(--red) 35%, transparent);
}
.btn-danger-ghost:hover { background: var(--red-soft); filter: none; }

.btn-block { width: 100%; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin: .9rem 0 .2rem;
}

/* ---------- Озвучиваемые слова ---------- */

.w {
  display: inline;
  padding: 1px 3px;
  margin: -1px 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--green-text);
  font-weight: 600;
  font-size: inherit;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px dashed color-mix(in srgb, var(--green) 45%, transparent);
}
.w:hover { background: var(--green-soft); }

.spk {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--green-text);
  cursor: pointer;
}
.spk:hover { background: var(--green-soft); }
.spk svg { width: 19px; height: 19px; }

.tts-hint {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--muted);
  margin: .6rem 0 1rem;
}

/* ---------- Таблицы ---------- */

.tbl-wrap { overflow-x: auto; margin: .7rem -1.05rem; padding: 0 1.05rem; }
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: .94rem;
}
.tbl th {
  text-align: left;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 600;
  padding: .45rem .55rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.tbl td {
  padding: .55rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl .trx { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.tbl .snd { font-weight: 600; white-space: nowrap; }

.ex-item { display: inline-block; margin: 0 .7rem .25rem 0; }
.ex-item small { display: block; color: var(--muted); font-size: .78rem; margin-top: -2px; }

/* Пары минимальные */
.pair-row td:nth-child(2) { border-left: 1px dashed var(--border); }

/* ---------- Чипы-фильтры ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin: .8rem 0;
}
.chip {
  min-height: 38px;
  padding: .3rem .85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: .88rem;
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] {
  background: var(--green-btn);
  border-color: var(--green-btn);
  color: #fff;
  font-weight: 600;
}

/* ---------- Статистика / плитки ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .7rem;
  margin: .9rem 0;
}
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .8rem .9rem;
}
.tile-num {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.tile-label { font-size: .78rem; color: var(--muted); }
.tile-icon { font-size: 1.05rem; display: block; margin-bottom: .15rem; }

/* ---------- Прогресс-бары ---------- */

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transition: width .3s ease;
}

/* ---------- Уроки ---------- */

.lesson-item {
  display: flex;
  align-items: center;
  gap: .85rem;
}
.lesson-num {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--green-soft);
  color: var(--green-text);
  font-weight: 700;
}
.lesson-item.done .lesson-num { background: var(--green-btn); color: #fff; }
.lesson-item-title { font-weight: 600; }
.lesson-item-meta { font-size: .8rem; color: var(--muted); }
.lesson-done-badge { margin-left: auto; color: var(--green-text); font-weight: 700; }

.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: .6rem;
  margin-top: 1.2rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  min-height: var(--tap);
  color: var(--muted);
  text-decoration: none;
  font-size: .9rem;
}
.back-link:hover { color: var(--ink); }

/* ---------- Тесты в уроках ---------- */

.quiz { margin: 1rem 0; }
.quiz-q { margin: 1.1rem 0 .5rem; font-weight: 600; }
.quiz-opts { display: grid; gap: .5rem; }
.quiz-opt {
  min-height: var(--tap);
  text-align: left;
  padding: .6rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-size: .95rem;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--green); }
.quiz-opt:disabled { cursor: default; opacity: .75; }
.quiz-opt.is-correct {
  border-color: var(--green-btn);
  background: var(--green-soft);
  color: var(--green-text);
  font-weight: 600;
  opacity: 1;
}
.quiz-opt.is-wrong {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red-text);
  opacity: 1;
}
.quiz-explain {
  margin: .5rem 0 0;
  font-size: .88rem;
  color: var(--muted);
}
.quiz-audio-btn { margin-bottom: .5rem; }

/* ---------- Флеш-карточки ---------- */

.fc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .7rem;
  margin-bottom: .7rem;
  flex-wrap: wrap;
}
.fc-progress { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }

.fc-stage { perspective: 1200px; }
.fc {
  position: relative;
  width: 100%;
  min-height: 300px;
  display: grid;
  transform-style: preserve-3d;
  transition: transform .4s cubic-bezier(.2, .7, .3, 1);
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
}
.fc.flipped { transform: rotateY(180deg); }
.fc-face {
  grid-area: 1 / 1;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  text-align: center;
  padding: 1.6rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.fc-back { transform: rotateY(180deg); }
.fc-word {
  font-family: var(--font-it);
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.fc-ru { font-size: 1.35rem; font-weight: 600; }
.fc-ex { font-size: .95rem; color: var(--muted); max-width: 32rem; }
.fc-ex [lang="it"] { color: var(--green-text); font-weight: 600; }
.fc-note {
  font-size: .85rem;
  color: var(--amber-text);
  background: var(--amber-soft);
  border-radius: 8px;
  padding: .25rem .6rem;
}
.fc-flip-hint { font-size: .8rem; color: var(--muted); }

.grades {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .5rem;
  margin-top: .8rem;
}
.grade {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 58px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: .92rem;
  cursor: pointer;
  transition: filter .12s ease;
}
.grade:hover { filter: brightness(1.05); }
.grade small { font-weight: 500; font-size: .72rem; opacity: .85; }
.grade-again { background: var(--red-soft); color: var(--red-text); }
.grade-hard  { background: var(--amber-soft); color: var(--amber-text); }
.grade-good  { background: var(--green-soft); color: var(--green-text); }
.grade-easy  { background: var(--blue-soft); color: var(--blue-text); }

.deck-head {
  display: flex;
  align-items: center;
  gap: .8rem;
}
.deck-icon {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  border-radius: 13px;
  background: var(--surface-2);
}
.deck-counts {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem .9rem;
  margin-top: .55rem;
  font-size: .82rem;
  color: var(--muted);
}
.deck-counts b { color: var(--ink); font-variant-numeric: tabular-nums; }
.deck-counts .is-due b { color: var(--red-text); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-size: .85rem;
  color: var(--muted);
  cursor: pointer;
  min-height: var(--tap);
}
.toggle input { width: 18px; height: 18px; accent-color: var(--green-btn); }

/* ---------- Тренажёр спряжения ---------- */

.trainer-task {
  text-align: center;
  padding: 1.4rem 1.1rem;
}
.trainer-inf {
  font-family: var(--font-it);
  font-size: 1.9rem;
  font-weight: 700;
}
.trainer-inf .w { font: inherit; color: var(--green-text); }
.trainer-ru { color: var(--muted); margin-top: .1rem; }
.trainer-quirk {
  display: inline-block;
  margin-top: .45rem;
  font-size: .8rem;
  color: var(--amber-text);
  background: var(--amber-soft);
  padding: .2rem .6rem;
  border-radius: 8px;
}
.trainer-pron {
  display: inline-block;
  margin: .9rem 0 .4rem;
  padding: .3rem .95rem;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 700;
  font-size: 1.05rem;
}

.trainer-form { display: flex; gap: .55rem; margin-top: .6rem; }
.trainer-input {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: .5rem .85rem;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
}
.trainer-input:focus-visible { outline-offset: 0; border-color: var(--green); }

.feedback { margin-top: .8rem; font-size: 1.02rem; min-height: 1.6em; }
.feedback.ok { color: var(--green-text); font-weight: 600; }
.feedback.err { color: var(--red-text); font-weight: 600; }
.feedback .exact { display: block; font-size: .85rem; font-weight: 500; color: var(--amber-text); margin-top: .15rem; }

.session-score {
  font-size: .88rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Когнаты ---------- */

.rule {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  margin: .6rem 0;
  overflow: hidden;
}
.rule summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .8rem 1rem;
  cursor: pointer;
  min-height: var(--tap);
  font-weight: 600;
}
.rule summary::-webkit-details-marker { display: none; }
.rule summary:hover { background: var(--surface-2); }
.rule-arrow {
  display: inline-flex;
  padding: .15rem .6rem;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green-text);
  font-weight: 700;
  white-space: nowrap;
}
.rule-count { margin-left: auto; color: var(--muted); font-size: .8rem; font-weight: 500; white-space: nowrap; }
.rule-chevron { transition: transform .2s ease; color: var(--muted); flex: 0 0 auto; }
.rule[open] .rule-chevron { transform: rotate(90deg); }
.rule-body { padding: 0 1rem .9rem; }
.rule-note { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; }

/* ---------- Тост ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 60;
  background: var(--ink);
  color: var(--bg);
  padding: .6rem 1.1rem;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: min(92vw, 26rem);
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 768px) { #toast { bottom: 28px; } }

/* ---------- Пустые состояния, итоги ---------- */

.empty {
  text-align: center;
  padding: 2.2rem 1rem;
}
.empty-emoji { font-size: 2.3rem; display: block; margin-bottom: .4rem; }

.result-num {
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.streak-flame { font-size: 1.05rem; }

.divider { border: none; border-top: 1px solid var(--border); margin: 1.4rem 0; }

.footer-actions {
  margin-top: 2.2rem;
  text-align: center;
}

/* ---------- Движение: уважение к настройкам ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  .fc { transition: none; }
}
