:root {
  --red: #e8453c;
  --red-dark: #c92a21;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2024;
  --muted: #6b7280;
  --border: #e5e7eb;
  --learning: #e8590c;
  --known: #2f9e44;
  --review: #1971c2;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
  --radius: 18px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 540px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Header */
header {
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  color: #fff;
  padding: calc(18px + env(safe-area-inset-top)) 20px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
header .sub { font-size: 12.5px; opacity: 0.9; margin-top: 2px; }
.head-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.logout-btn {
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.logout-btn:active { transform: scale(0.96); }
#userbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.userbar-btn {
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.userbar-btn:active { transform: scale(0.96); }
.donate-btn { background: #ffd43b; color: #5c3b00; border-color: #ffd43b; }

/* Модальное окно */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
}
.modal h3 { font-size: 19px; margin-bottom: 6px; }

/* Приветственное окно */
.welcome-modal { text-align: center; }
.welcome-emoji { font-size: 44px; line-height: 1; margin-bottom: 6px; }
.welcome-list {
  list-style: none;
  text-align: left;
  margin: 14px 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.welcome-list li { display: flex; gap: 10px; font-size: 14px; line-height: 1.4; }
.welcome-list li span { font-size: 20px; flex: 0 0 auto; }
.modal-lead { font-size: 13.5px; color: var(--muted); margin-bottom: 14px; line-height: 1.4; }
.modal textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  background: #fff;
  color: var(--text);
}
.modal textarea:focus { outline: 2px solid var(--red); border-color: transparent; }
.crypto-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  margin-top: 4px;
}
.crypto-net { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 10px; }
.crypto-qr {
  width: 180px;
  height: 180px;
  display: block;
  margin: 0 auto 12px;
  border-radius: 8px;
  background: #fff;
}
.crypto-addr {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
  background: var(--bg);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  user-select: all;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.modal-actions .btn { flex: 0 0 auto; padding: 10px 18px; }

/* ===== Экраны входа / настройки ===== */
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  margin-top: 8px;
}
.auth-card h2 { font-size: 22px; margin-bottom: 6px; }
.auth-lead { font-size: 14px; color: var(--muted); margin-bottom: 18px; line-height: 1.45; }
.auth-card .field input { font-size: 16px; }
.auth-switch { margin-top: 16px; text-align: center; font-size: 13.5px; color: var(--muted); }
.auth-switch .link-btn { font-weight: 600; color: var(--red); }
.setup-steps { margin: 0 0 16px 18px; font-size: 14px; line-height: 1.6; color: var(--text); }
.setup-steps li { margin-bottom: 6px; }
.setup-steps code, .auth-lead code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 13px;
}

/* Stat chips */
.stats {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.stat {
  flex: 1;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s;
}
.stat:hover { background: rgba(255, 255, 255, 0.26); }
.stat .num { font-size: 19px; font-weight: 700; }
.stat .lbl { font-size: 11px; opacity: 0.92; }

/* Tabs */
nav.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 9;
}
nav.tabs button {
  flex: 1;
  border: none;
  background: none;
  padding: 13px 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
nav.tabs button.active {
  color: var(--red);
  border-bottom-color: var(--red);
}

main { flex: 1; padding: 18px 16px 40px; }

/* Переключатель базы (Моя / Готовая) */
#baseswitch:not(:empty) { padding: 12px 16px 0; }
.base-switch {
  display: flex;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.base-switch button {
  flex: 1;
  border: none;
  background: none;
  border-radius: 9px;
  padding: 9px 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.base-switch button.active { background: var(--red); color: #fff; }

/* Фильтр по теме */
.cat-filter {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--card);
  color: var(--text);
  margin-bottom: 12px;
}
.list-note {
  font-size: 12.5px;
  color: var(--muted);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 10px;
}

/* Баннер «Установить приложение» */
.install-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: calc(100% - 24px);
  max-width: 516px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 40;
}
.install-txt { flex: 1; font-size: 13.5px; line-height: 1.35; }
.install-go { flex: 0 0 auto; padding: 9px 16px; font-size: 14px; }
.install-x {
  flex: 0 0 auto;
  border: none;
  background: var(--bg);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--red); color: #fff; }
.btn-ghost { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-block { display: block; width: 100%; text-align: center; }
a.btn { text-decoration: none; }

/* ===== Study / flashcard ===== */
.study-empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}
.study-empty .big { font-size: 40px; margin-bottom: 10px; }

.deck-pick {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.deck-pick button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 12px;
  padding: 10px 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}
.deck-pick { flex-wrap: wrap; }
.deck-pick button {
  flex: 1 1 22%;
  min-width: 0;
  font-size: 12px;
  padding: 9px 4px;
}
.deck-pick button.active {
  border-color: var(--red);
  color: var(--red);
  background: #fff5f5;
}
.deck-pick .cnt {
  display: inline-block;
  font-size: 11px;
  opacity: 0.7;
  font-weight: 700;
}

/* Озвучка */
.speak-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 17px;
  cursor: pointer;
  line-height: 1;
}
.speak-btn:active { transform: scale(0.9); }

/* Копировать в свою базу (на карточке) */
.copy-mine {
  position: absolute;
  bottom: 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.copy-mine:active { transform: scale(0.96); }

/* Иконки действий в строке списка */
.row-icons { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }

.flashcard {
  perspective: 1400px;
  height: 320px;
  margin-bottom: 18px;
  cursor: pointer;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.face .cat-badge {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 20px;
}
.face .hint {
  position: absolute;
  bottom: 18px;
  font-size: 12px;
  color: var(--muted);
}
.face .word { font-size: 38px; font-weight: 700; letter-spacing: -0.5px; }
.face.back { transform: rotateY(180deg); background: #fff8f1; }
.face.back .word { font-size: 30px; color: var(--red-dark); }
.face .orig { font-size: 15px; color: var(--muted); margin-bottom: 6px; }

.answer-row { display: flex; gap: 8px; }
.answer-row .btn { flex: 1; padding: 14px 6px; font-size: 14px; color: #fff; }
.ans-dont { background: var(--learning); }
.ans-review { background: var(--review); }
.ans-know { background: var(--known); }
.progress-line { font-size: 13px; color: var(--muted); }
.study-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}
.dir-toggle {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.dir-toggle:active { transform: scale(0.96); }

/* ===== Word list ===== */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
.toolbar input, .toolbar select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--card);
  color: var(--text);
}
.toolbar input { flex: 1; }
.toolbar #fcat { flex: 1; }

.word-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.word-row .info { flex: 1; min-width: 0; }
.word-row .indo { font-size: 16px; font-weight: 700; }
.word-row .rus { font-size: 13.5px; color: var(--muted); margin-top: 1px; }
.word-row .cat { font-size: 11px; color: var(--muted); margin-top: 3px; }
.status-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.row-actions { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
.mini {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  width: 30px; height: 30px;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
}
.seg button {
  border: none;
  background: var(--card);
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.seg button.on { color: #fff; }
.seg button.on.learning { background: var(--learning); }
.seg button.on.known { background: var(--known); }
.seg button.on.review { background: var(--review); }

.list-empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ===== Add form ===== */
.form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
}
.field input:focus { outline: 2px solid var(--red); border-color: transparent; }
.form-msg { font-size: 13px; margin-top: 4px; min-height: 16px; }
.form-msg.err { color: var(--red); }
.form-msg.ok { color: var(--known); }

.import-box {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.import-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.import-sub { font-size: 13px; color: var(--muted); margin-bottom: 14px; line-height: 1.4; }

datalist { color: #000; }

.footer-actions {
  margin-top: 26px;
  display: flex;
  gap: 8px;
  font-size: 13px;
}
.link-btn {
  background: none; border: none; color: var(--muted);
  text-decoration: underline; cursor: pointer; font-size: 13px;
}

/* Описание для поисковиков (видимый футер под приложением) */
.seo-text {
  max-width: 540px;
  margin: 0 auto;
  padding: 22px 18px 40px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.seo-text h2 { font-size: 16px; color: var(--text); margin-bottom: 8px; }
.seo-text p { margin-bottom: 10px; }

/* Плавающая кнопка «Добавить слово» */
#fab {
  position: fixed;
  bottom: 22px;
  right: calc(50% - 270px + 18px);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--red);
  color: #fff;
  font-size: 32px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(232, 69, 60, 0.45);
  z-index: 20;
  transition: transform 0.12s, filter 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#fab:active { transform: scale(0.92); }
#fab.hidden { display: none; }
@media (max-width: 560px) {
  #fab { right: 18px; }
}
