/* Vocabulary Trainer — мобильная вёрстка.
   Верстаем от телефона: одна колонка, крупные цели нажатия, нижняя навигация
   под большой палец. Шире 560px просто центрируем ту же колонку. */

:root {
    --bg: #f0f0f5;
    --card: #ffffff;
    --ink: #1c1c1e;
    --muted: #6b6b70;
    --line: #e2e2e8;
    --good: #2DB822;
    --bad: #f4433620;
    --bad-ink: #d33;
    --accent: #2b6cb0;
    --radius: 14px;
    --tabs-h: 58px;
    --safe: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* Свои display:flex/grid сильнее атрибута hidden — возвращаем ему власть. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

body { padding-bottom: calc(var(--tabs-h) + var(--safe)); }

/* ---------- Верхняя панель ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

.topbar select {
    flex: 1;
    min-width: 0;
    padding: 9px 10px;
    font-size: 15px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    color: var(--ink);
}

.menu { position: relative; }

.menu summary {
    list-style: none;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    font-size: 22px;
    cursor: pointer;
    user-select: none;
}

.menu summary::-webkit-details-marker { display: none; }

.menu-body {
    position: absolute;
    right: 0;
    top: 46px;
    min-width: 190px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    overflow: hidden;
}

.menu-body a {
    display: block;
    padding: 13px 16px;
    color: var(--ink);
    text-decoration: none;
    border-bottom: 1px solid var(--line);
}

.menu-body a:last-child { border-bottom: none; }

/* ---------- Экран ---------- */

#screen {
    max-width: 560px;
    margin: 0 auto;
    padding: 14px 14px 20px;
}

.hint {
    color: var(--muted);
    font-size: 14px;
    margin: 10px 0;
    text-align: center;
}

.panel {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px;
    margin: 12px 0;
}

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

.btn {
    flex: 1;
    min-height: 48px;
    padding: 12px 14px;
    font-size: 16px;
    border: none;
    border-radius: 12px;
    background: var(--card);
    color: var(--ink);
    cursor: pointer;
}

.btn.small { min-height: 38px; font-size: 14px; flex: 0 0 auto; padding: 8px 14px; }
.btn.ghost { background: #e9e9ef; }
.btn.good  { background: var(--good); color: #fff; }
.btn.bad   { background: var(--bad); color: var(--bad-ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; }

.row { display: flex; gap: 10px; margin: 12px 0; }
.row.big .btn { min-height: 54px; font-size: 17px; }

.icon-btn {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    background: #e9e9ef;
}

.icon-btn.danger { background: #ff4d4d; }

.icon-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---------- Направление тренировки ---------- */

.direction { display: flex; gap: 8px; }

.chip {
    flex: 1;
    padding: 9px 8px;
    font-size: 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
}

.chip.active {
    background: var(--good);
    border-color: var(--good);
    color: #fff;
}

/* ---------- Карточка ---------- */

.card-wrap { position: relative; perspective: 1000px; margin-top: 14px; }

.card-delete { position: absolute; top: 8px; right: 8px; z-index: 5; }

.card {
    position: relative;
    width: 100%;
    min-height: 46vh;
    transform-style: preserve-3d;
    transition: transform .4s ease;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.card.flipped { transform: rotateY(180deg); }

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 18px;
    text-align: center;
    font-size: clamp(22px, 7vw, 32px);
    font-weight: 600;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 4px 14px rgba(0,0,0,.08);
    overflow: hidden;
}

.card-back { transform: rotateY(180deg); }

.card-face img {
    max-width: 100%;
    max-height: 30vh;
    border-radius: 10px;
    object-fit: cover;
}

.card-face .pos {
    font-size: 13px;
    font-weight: 400;
    color: var(--muted);
}

/* ---------- Письмо ---------- */

.write-prompt {
    background: var(--card);
    border-radius: var(--radius);
    padding: 22px 16px;
    text-align: center;
    font-size: clamp(20px, 6vw, 28px);
    font-weight: 600;
    min-height: 30vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.write-prompt img {
    max-width: 100%;
    max-height: 22vh;
    border-radius: 10px;
}

#writeInput, #userSentence, #listSearch {
    width: 100%;
    margin-top: 12px;
    padding: 14px;
    font-size: 17px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    color: var(--ink);
}

#writeInput { text-align: center; }

.write-result { min-height: 46px; text-align: center; margin-top: 10px; font-size: 16px; }
.write-result .ok  { color: var(--good); font-weight: 600; }
.write-result .no  { color: var(--bad-ink); font-weight: 600; }
.write-result .answer { display: block; font-size: 22px; margin-top: 6px; }

/* ---------- Список ---------- */

.word {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 8px;
}

.word .thumb {
    width: 46px;
    height: 46px;
    border-radius: 8px;
    object-fit: cover;
    flex: 0 0 auto;
    background: #eee;
}

.word .body { flex: 1; min-width: 0; }
.word .lemma { font-weight: 600; }

.word .tr {
    color: var(--muted);
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.word .rating { font-size: 12px; color: var(--muted); white-space: nowrap; }
.word .acts { display: flex; gap: 6px; }

/* ---------- Фразы ---------- */

.sentence-word {
    font-size: 26px;
    font-weight: 600;
    text-align: center;
    margin: 6px 0 12px;
}

#sentenceResult .verdict { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
#sentenceResult .verdict.ok { color: var(--good); }
#sentenceResult .verdict.no { color: var(--bad-ink); }
#sentenceResult .fix { background: #fff7e0; border-radius: 10px; padding: 10px; margin: 8px 0; }

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

.drill-card { text-align: center; padding: 22px 16px; }

.drill-question {
    font-size: clamp(20px, 6vw, 28px);
    font-weight: 600;
    line-height: 1.35;
    margin-top: 6px;
}

.options { display: grid; gap: 10px; margin: 14px 0; }

.option {
    min-height: 54px;
    padding: 14px;
    font-size: 17px;
    text-align: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    color: var(--ink);
    cursor: pointer;
}

.option:active { transform: translateY(1px); }
.option.right { background: var(--good); border-color: var(--good); color: #fff; }
.option.wrong { background: #f44336; border-color: #f44336; color: #fff; }

.drill-feedback { min-height: 28px; text-align: center; font-size: 16px; margin-top: 4px; }
.drill-feedback.ok { color: var(--good); font-weight: 600; }
.drill-feedback.no { color: var(--bad-ink); }

.done-figure {
    font-size: 52px;
    font-weight: 700;
    text-align: center;
    color: var(--good);
    line-height: 1.1;
}

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

.tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding-bottom: var(--safe);
}

.tab {
    flex: 1;
    min-height: var(--tabs-h);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: none;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
}

.tab span:first-child { font-size: 19px; line-height: 1; }
.tab.active { color: var(--good); }

/* ---------- Модальное окно ---------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: flex-end;
}

.modal-body {
    width: 100%;
    max-height: 85vh;
    overflow: auto;
    background: var(--bg);
    border-radius: 18px 18px 0 0;
    padding: 14px 14px calc(14px + var(--safe));
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.image-grid figure { margin: 0; }

.image-grid img {
    width: 100%;
    height: 104px;
    object-fit: cover;
    border-radius: 10px;
    cursor: pointer;
    background: #ddd;
}

.image-grid figcaption {
    font-size: 10px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.example { text-align: left; margin-bottom: 10px; }
.example .tr { color: var(--muted); font-size: 14px; }

/* ---------- Оценка прямо на карточке ---------- */

/* На телефоне хватает свайпа и широких кнопок внизу, поэтому здесь скрыты.
   Показываются с 560px, где есть мышь и тянуться вниз неудобно. */
.rate-on-card {
    display: none;
    position: absolute;
    bottom: 14px;
    z-index: 5;
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
    opacity: .55;
    transition: opacity .15s ease, transform .15s ease;
}

.rate-on-card:hover { opacity: 1; transform: translateY(-2px); }
.rate-on-card.bad  { left: 14px;  background: #f44336; }
.rate-on-card.good { right: 14px; background: var(--good); }

.rate-on-card svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@media (min-width: 560px) {
    .card { min-height: 320px; }

    /* на десктопе оценка живёт на карточке, дублирующий ряд внизу не нужен */
    .rate-on-card { display: grid; place-items: center; }
    .rate-row { display: none; }
}

/* иконка на светлой кнопке — контур тёмный, иначе белое по светло-серому */
.icon-btn svg.dark { stroke: var(--ink); }

/* ---------- Платные возможности ---------- */

.panel.locked { text-align: center; padding: 26px 18px; }
.lock-icon { font-size: 34px; margin-bottom: 8px; }
.panel.locked b { display: block; margin-bottom: 8px; }

.plan-badge {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #e9e9ef;
    color: var(--muted);
    white-space: nowrap;
}

.plan-badge.premium { background: var(--good); color: #fff; }

#premiumNote {
    width: 100%;
    margin-top: 14px;
    padding: 12px;
    font-size: 15px;
    border: 1px solid var(--line);
    border-radius: 12px;
    resize: vertical;
}

/* ---------- Кнопка «добавить слово» ---------- */

/* Висит над нижней навигацией и доступна с любой вкладки. */
.fab {
    position: fixed;
    right: 16px;
    bottom: calc(var(--tabs-h) + var(--safe) + 16px);
    z-index: 35;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--good);
    box-shadow: 0 6px 18px rgba(0,0,0,.22);
    display: grid;
    place-items: center;
    cursor: pointer;
}

.fab:active { transform: translateY(1px); }

.fab svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: #fff;
    stroke-width: 2.4;
    stroke-linecap: round;
}

.add-hints {
    margin: 0 0 14px;
    padding-left: 20px;
    font-size: 14px;
    color: var(--muted);
    line-height: 1.7;
}

.add-hints code {
    background: #eee;
    padding: 1px 6px;
    border-radius: 5px;
    color: var(--ink);
}

#addInput {
    width: 100%;
    padding: 14px;
    font-size: 17px;
    border: 1px solid var(--line);
    border-radius: 12px;
    resize: vertical;
}

.added {
    background: var(--card);
    border-radius: 12px;
    padding: 12px;
    margin-top: 10px;
}

.added .lemma { font-weight: 600; font-size: 17px; }
.added .tr { color: var(--muted); font-size: 14px; }
.added .ex { font-size: 14px; margin-top: 6px; }
