/* ============================================
   ТОКЕНЫ
   ============================================ */
:root {
  --ink: #20253D;
  --ink-soft: #4A5066;
  --paper: #F3EFE3;
  --paper-2: #EAE3D1;
  --brass: #B8923B;
  --teal: #2F6F68;
  --clay: #B85C46;
  --line: #D8D0BC;
  --radius: 10px;

  --font-display: 'Google Sans', system-ui, sans-serif;
  --font-hebrew: 'Google Sans', 'Arial Hebrew', sans-serif;
  --font-body: 'Google Sans', system-ui, sans-serif;
  --font-mono: 'Google Sans', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  max-width: 100%;
  overflow-x: hidden;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.he { font-family: var(--font-hebrew); }
.mono { font-family: var(--font-mono); font-size: 0.92em; color: var(--ink-soft); }

/* ============================================
   TOPBAR
   ============================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--ink);
}
.topbar-title .he { font-family: var(--font-hebrew); font-size: 1.25rem; }
.topbar-title .dot { color: var(--brass); }
.topbar-title .ru { letter-spacing: 0.06em; text-transform: lowercase; color: var(--ink-soft); font-size: 0.85rem; }
.topbar-title:hover { text-decoration: none; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lang-dropdown {
  position: relative;
}

.lang-trigger {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--ink-soft);
  transition: background 0.15s;
  line-height: 1;
}
.lang-trigger svg { width: 13px; height: 13px; }
.lang-trigger .fi { font-size: 1.15rem; line-height: 1; }
.lang-option .fi { font-size: 1.1rem; line-height: 1; flex-shrink: 0; }
label .fi { font-size: 1rem; vertical-align: middle; margin-right: 2px; }
.lang-trigger:hover { background: var(--paper-2); }

.lang-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  list-style: none;
  margin: 0;
  padding: 4px;
  z-index: 100;
  min-width: 170px;
}
.lang-menu.open { display: block; }

.lang-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.lang-option:hover { background: var(--paper-2); text-decoration: none; }
.lang-option-active { font-weight: 600; color: var(--teal); }

.admin-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  transition: background 0.15s, color 0.15s;
}
.admin-icon svg { width: 18px; height: 18px; }
.admin-icon:hover { background: var(--paper-2); color: var(--teal); text-decoration: none; }

/* ============================================
   ГЛАВНАЯ
   ============================================ */
.page-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  margin: 0 0 24px;
}

.topic-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topic-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  transition: background 0.15s;
}
.topic-card:hover { background: var(--line); text-decoration: none; }

.topic-he {
  font-family: var(--font-hebrew);
  font-size: 1.3rem;
  color: var(--brass);
  min-width: 48px;
  text-align: right;
}

.topic-name {
  flex: 1;
  font-size: 0.98rem;
}

.topic-arrow {
  color: var(--ink-soft);
  font-size: 1rem;
}

.admin-note {
  font-size: 0.82rem;
  color: var(--teal);
  margin: 0;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.98rem;
  padding: 13px 22px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--teal); text-decoration: none; }
.btn-primary:active { transform: translateY(1px); }
.btn-primary.small { padding: 9px 16px; font-size: 0.88rem; }
.btn-primary svg { width: 15px; height: 15px; }


/* ============================================
   CONTAINERS / FORMS / AUTH PAGES
   ============================================ */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 36px 28px 64px;
}
.container.narrow { max-width: 480px; }

.container h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  margin: 8px 0 24px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-bottom: 18px;
}
.back-link svg { width: 14px; height: 14px; }
.back-link:hover { color: var(--teal); text-decoration: none; }

.verb-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}

.verb-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  font-weight: 500;
}

.verb-form input,
.verb-form textarea {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}
.verb-form input.he-input { font-family: var(--font-hebrew); font-size: 1.1rem; }
.verb-form textarea { resize: vertical; }

.error {
  background: #FBE7E1;
  color: var(--clay);
  border: 1px solid var(--clay);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.9rem;
}
.success {
  background: #E4EFEC;
  color: var(--teal);
  border: 1px solid var(--teal);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.9rem;
}
.form-section-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  padding-top: 8px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

.hint { font-size: 0.88rem; color: var(--ink-soft); }
.hint-req { color: var(--clay); font-style: normal; }
.back { margin-top: 18px; font-size: 0.9rem; }

/* ============================================
   TOOLBAR / SEARCH
   ============================================ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.search-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  flex: 1 1 260px;
  max-width: 380px;
}
.search-form svg { width: 16px; height: 16px; color: var(--ink-soft); flex-shrink: 0; }
.search-form input {
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: 0.95rem;
  width: 100%;
  outline: none;
  color: var(--ink);
}
.clear-search { color: var(--ink-soft); font-size: 1.1rem; padding: 0 2px; }

/* ============================================
   TABLE
   ============================================ */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.verbs-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
  background: var(--paper);
}

.verbs-table th {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  text-align: left;
  padding: 14px 16px;
  border-bottom: 2px solid var(--brass);
  background: var(--paper-2);
}

.verbs-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 1rem;
  vertical-align: middle;
}

.verbs-table tbody tr:hover { background: rgba(47, 111, 104, 0.06); }
.verbs-table .col-he { font-size: 1.25rem; font-weight: 500; }
.verbs-table .notes { color: var(--ink-soft); font-size: 0.88rem; }
.verbs-table .empty { text-align: center; color: var(--ink-soft); padding: 32px; }

.col-actions { white-space: nowrap; width: 1%; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--paper-2); color: var(--teal); }
.icon-btn.danger:hover { color: var(--clay); }
.inline-form { display: inline; }

/* ============================================
   FLASHCARDS
   ============================================ */
.flash-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.flash-counter {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.flash-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 20px 0;
}

.flash-nav {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.flash-nav svg { width: 18px; height: 18px; }
.flash-nav:hover { background: var(--line); color: var(--teal); }
.flash-nav:disabled { opacity: 0.35; cursor: default; }
.flash-nav:disabled:hover { background: var(--paper-2); color: var(--ink-soft); }

.flashcard {
  width: 100%;
  max-width: 480px;
  height: 300px;
  perspective: 1200px;
  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); }

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}
.flashcard-front .he { font-size: 2.6rem; color: var(--ink); }
.flip-hint { font-size: 0.78rem; color: var(--ink-soft); }

.flashcard-back {
  transform: rotateY(180deg);
  background: var(--paper);
  border-color: var(--teal);
  overflow-y: auto;
}
.card-translation {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--teal);
}
.card-gender {
  display: none;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
}
.card-forms {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0;
  text-align: left;
}
.card-forms dt { font-weight: 500; white-space: nowrap; }
.card-forms dd { margin: 0; }
.card-forms dd .he { font-family: var(--font-hebrew); color: var(--ink); font-size: 1rem; }

.flash-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}

.btn-know {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--teal);
  color: var(--paper);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-know:hover { background: #255852; }
.btn-know:active { transform: translateY(1px); }
.btn-know svg { width: 15px; height: 15px; }

.all-known-msg {
  text-align: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--teal);
  margin: 40px 0;
}

/* ============================================
   STATS WIDGET
   ============================================ */
.stats-widget {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.stats-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 0.78rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.stats-badge:hover { background: var(--line); color: var(--ink); }
.stats-badge svg { width: 14px; height: 14px; flex-shrink: 0; }

.stats-panel {
  width: 260px;
  max-width: calc(100vw - 32px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,0.14);
  padding: 16px;
}

.stats-graph {
  width: 100%;
  height: 48px;
  display: block;
  margin-bottom: 14px;
}
.stats-graph rect { fill: var(--brass); }

.stats-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  margin: 0;
  font-size: 0.85rem;
}
.stats-list dt { color: var(--ink-soft); font-weight: 400; }
.stats-list dd {
  margin: 0;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink);
  text-align: right;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 640px) {
  .topbar { padding: 14px 18px; }
  .container { padding: 28px 18px 48px; }
  .flash-stage { gap: 10px; }
  .flash-nav { width: 36px; height: 36px; }
  .flashcard { height: 340px; }
  .flashcard-front .he { font-size: 2rem; }
  .stats-widget { right: 10px; bottom: 10px; }
  .stats-badge { font-size: 0.72rem; padding: 6px 10px; }

  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* Таблица → карточки на мобильном */
  .table-wrap { overflow-x: visible; border: none; }
  .verbs-table { min-width: 0; width: 100%; }
  .verbs-table thead { display: none; }
  .verbs-table, .verbs-table tbody, .verbs-table td {
    display: block;
    width: 100%;
  }
  .verbs-table tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 12px;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px 14px;
    background: var(--paper);
  }
  .verbs-table tr#empty-row {
    display: block;
    border: none;
    padding: 0;
  }
  .verbs-table td {
    display: block;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
    min-width: 0;
  }
  .verbs-table td:last-child { border-bottom: none; }
  .verbs-table td:not(.col-he):not(.col-actions) {
    grid-column: 1 / -1;
  }
  .verbs-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-family: var(--font-hebrew);
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--ink-soft);
    margin-bottom: 3px;
  }
  .verbs-table .col-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 4px;
  }
}

@media (max-width: 480px) {
  .topbar { padding: 12px 14px; gap: 8px; }
  .topbar-title { gap: 5px; font-size: 0.92rem; min-width: 0; }
  .topbar-title .he { font-size: 1rem; }
  .topbar-title .ru {
    font-size: 0.68rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-right { gap: 6px; }
  .lang-trigger { padding: 5px 7px; }
  .lang-trigger svg { width: 11px; height: 11px; }
  .admin-icon { width: 32px; height: 32px; }
  .admin-icon svg { width: 15px; height: 15px; }

  .flash-stage { flex-wrap: wrap; row-gap: 14px; }
  .flashcard { order: 1; flex: 1 1 100%; max-width: 100%; }
  .flash-prev { order: 2; }
  .flash-next { order: 3; }
}
