:root {
  --bg: #10120f;
  --panel: #181b16;
  --panel-2: #20251d;
  --ink: #f2ead7;
  --muted: #aaa58f;
  --accent: #b1362f;
  --accent-2: #768b43;
  --border: #393d31;
  --good: #7fa86b;
  --bad: #d36a5f;
  --shadow: rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #222717, var(--bg) 42%);
  color: var(--ink);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}
body.is-loading main,
body.is-loading .hero,
body.is-loading .tabs,
body.is-loading .bottom-nav {
  visibility: hidden;
}

.ru-text {
  font-family: "PT Serif", Georgia, "Times New Roman", serif;
}

.hero {
  padding: 34px clamp(18px, 4vw, 56px);
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  color: var(--accent-2);
  letter-spacing: .16em;
  text-transform: uppercase;
  font-size: .78rem;
  margin: 0 0 8px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 5vw, 4rem); margin-bottom: 8px; }
.subtitle { color: var(--muted); max-width: 720px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 10px;
}
.stats div {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  text-align: center;
  min-width: 96px;
}
.stats strong { display: block; font-size: 1.8rem; }
.stats span { color: var(--muted); font-size: .8rem; }

.tabs {
  display: flex;
  gap: 8px;
  padding: 14px clamp(18px, 4vw, 56px);
  padding-top: calc(14px + env(safe-area-inset-top));
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: rgba(16,18,15,.85);
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: rgba(16,18,15,.96);
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  justify-content: space-around;
  gap: 4px;
  backdrop-filter: blur(8px);
}
.bottom-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: .72rem;
  min-height: 52px;
  padding: 6px 4px;
  border-radius: 12px;
}
.bottom-tab.active {
  color: var(--ink);
  background: rgba(177,54,47,.18);
}
.bottom-icon {
  font-size: 1.15rem;
  line-height: 1;
}

button, select, input {
  font: inherit;
}

button, select {
  border: 1px solid var(--border);
  background: var(--accent);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  transition: filter .15s ease, opacity .15s ease;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary, select, .tab { background: var(--panel-2); }
.tab, .bottom-tab { background: var(--panel-2); }
.tab {
  flex: 0 0 auto;
  white-space: nowrap;
}
.tab.active { background: var(--accent); }

main { padding: 26px clamp(18px, 4vw, 56px) 60px; }
.panel { display: none; }
.active-panel { display: block; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.025));
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 14px 40px var(--shadow);
  margin-bottom: 18px;
}
.muted, .hint { color: var(--muted); }
.hint { min-height: 1.4em; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.form-stack { display: grid; gap: 10px; }
.link-row { flex-wrap: wrap; align-items: center; }

input {
  width: 100%;
  background: #0d0f0c;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
}
.big-input { font-size: 1.1rem; margin: 10px 0; }

.chips { display: flex; gap: 10px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: rgba(118,139,67,.18);
  color: #dce7bb;
  border-radius: 999px;
  padding: 8px 10px;
  font-size: .9rem;
}
.chip-btn {
  cursor: pointer;
  transition: background .15s ease;
}
.chip-btn:hover { background: rgba(118,139,67,.32); }

.result {
  margin-top: 14px;
  border-radius: 16px;
  padding: 14px;
  background: rgba(255,255,255,.035);
  border: 1px solid var(--border);
  min-height: 24px;
}
.result:empty { display: none; }
.result.hidden { display: none; }
.correct {
  border-color: var(--good);
  color: #d9f2ce;
  animation: pulse-good .45s ease;
}
.wrong {
  border-color: var(--bad);
  color: #ffd5cf;
  animation: shake .4s ease;
}

@keyframes pulse-good {
  0% { box-shadow: 0 0 0 0 rgba(127,168,107,.5); }
  100% { box-shadow: 0 0 0 12px rgba(127,168,107,0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.vocab-list, .lesson-list {
  display: grid;
  gap: 12px;
}
.vocab-item, .lesson-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}
.vocab-item strong { font-size: 1.35rem; display: block; }
.meta { color: var(--muted); font-size: .84rem; margin-top: 8px; }

.study-loop-checklist {
  list-style: none;
  padding: 0;
  margin: 0;
  color: var(--muted);
  line-height: 2;
}
.study-loop-checklist label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.study-loop-checklist input { width: auto; }
.study-loop-progress { margin-top: 10px; }

.phone-url {
  font-size: 1.05rem;
  word-break: break-all;
  margin: 10px 0;
  flex: 1;
}
.phone-url a { color: #dce7bb; }
.phone-note code { color: var(--ink); font-size: .9rem; }

.chat-log {
  min-height: 300px;
  max-height: 420px;
  overflow: auto;
  background: #0d0f0c;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
}
.chat-prompts { margin-bottom: 12px; }
.msg {
  padding: 11px 13px;
  border-radius: 14px;
  margin: 10px 0;
  white-space: pre-wrap;
}
.msg.user { background: rgba(177,54,47,.22); margin-left: 10%; }
.msg.bot { background: rgba(118,139,67,.18); margin-right: 10%; }
.chat-row { align-items: stretch; }
.chat-row button { min-width: 90px; }

.session-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin: 12px 0;
}
.session-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .92rem;
}
.session-toggle input { width: auto; }
.session-stats { font-variant-numeric: tabular-nums; }
.session-progress {
  height: 6px;
  background: rgba(255,255,255,.08);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
}
.session-progress.hidden { display: none; }
.session-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .25s ease;
}

.flashcard-panel h2 { margin-bottom: 0; }
.flashcard-toolbar { margin-bottom: 18px; flex-wrap: wrap; gap: 14px; }
.flashcard-filters { flex-wrap: wrap; }
.flashcard-filters select { min-width: 140px; width: 100%; }
.flashcard-actions { justify-content: center; flex-wrap: wrap; margin: 8px 0; }

.flashcard-stage {
  display: flex;
  justify-content: center;
  margin: 8px 0 12px;
  perspective: 1200px;
  touch-action: pan-y;
}

.flashcard {
  width: min(100%, 520px);
  min-height: 280px;
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.flashcard:focus-visible {
  box-shadow: 0 0 0 3px rgba(118,139,67,.45);
  border-radius: 24px;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  min-height: 280px;
  transform-style: preserve-3d;
  transition: transform .45s ease;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 28px 24px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  backface-visibility: hidden;
  box-shadow: 0 18px 44px var(--shadow);
}
.flashcard-back {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, rgba(118,139,67,.18), rgba(255,255,255,.02));
}
.flashcard-label {
  position: absolute;
  top: 16px;
  left: 18px;
  color: var(--muted);
  font-size: .78rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.flashcard-text {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  line-height: 1.25;
  max-width: 100%;
  word-break: break-word;
}
.flashcard-meta {
  position: absolute;
  bottom: 16px;
  left: 18px;
  right: 18px;
  color: var(--muted);
  font-size: .84rem;
}
.flashcard-hint { text-align: center; margin: 0 0 14px; }
.flashcard-nav { justify-content: center; flex-wrap: wrap; gap: 12px; }
.flashcard-nav button { flex: 1 1 120px; max-width: 180px; }
.flashcard-counter {
  min-width: 90px;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.vocab-pagination {
  justify-content: center;
  margin-top: 16px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
  transition: opacity .3s ease, visibility .3s ease;
}
.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255,255,255,.12);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-container {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  right: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px var(--shadow);
  animation: toast-in .25s ease;
}
.toast.success { border-color: var(--good); }
.toast.error { border-color: var(--bad); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.more-links { margin-top: 0; }

.ru-input-wrap {
  display: grid;
  gap: 8px;
}
.ru-keyboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.ru-phonetic-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .88rem;
  cursor: pointer;
}
.ru-phonetic-label input { width: auto; }
.ru-osk-toggle {
  font-size: .88rem;
  min-height: 38px;
  padding: 8px 12px;
}
.ru-osk {
  display: grid;
  gap: 6px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.ru-osk.hidden { display: none; }
.ru-osk-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.ru-osk-key {
  min-width: 36px;
  min-height: 48px;
  padding: 4px 6px;
  font-size: 1rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--ink);
  cursor: pointer;
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1.1;
}
.ru-osk-latin {
  font-size: .62rem;
  color: #7eb8e8;
  font-family: system-ui, sans-serif;
  text-transform: lowercase;
}
.ru-osk-cyr {
  font-family: "PT Serif", Georgia, serif;
  font-size: 1.05rem;
}
.ru-osk-symbols .ru-osk-key {
  min-width: 32px;
  font-size: .95rem;
}
.ru-osk-key:hover { filter: brightness(1.08); }
.ru-osk-special { margin-top: 4px; }
.ru-osk-space {
  flex: 1 1 120px;
  min-width: 100px;
}
.ru-osk-wide {
  min-width: 64px;
}

.game-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  margin-top: 16px;
}
.game-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  padding: 18px;
  min-height: 140px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  transition: filter .15s ease, border-color .15s ease;
}
button.game-tile:hover {
  filter: brightness(1.06);
  border-color: var(--accent-2);
}
.game-tile-soon {
  opacity: .55;
  cursor: default;
  pointer-events: none;
}
.game-tile-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}
.game-tile-desc {
  font-size: .9rem;
  color: var(--muted);
  line-height: 1.45;
  flex: 1;
}
.game-tile-score {
  font-size: .82rem;
}
.game-panel.hidden { display: none; }
.hidden { display: none !important; }

.speed-timer-bar {
  height: 8px;
  background: rgba(255,255,255,.08);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0;
}
.speed-timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 1s linear;
}
.speed-stats {
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}

.memory-filters {
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.memory-filters select {
  flex: 1 1 140px;
  min-width: 120px;
}
.memory-stats {
  text-align: center;
  font-variant-numeric: tabular-nums;
  margin-bottom: 12px;
}
.memory-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  max-width: 520px;
  margin: 0 auto;
}
.memory-card {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
  font-size: .78rem;
  line-height: 1.2;
  word-break: break-word;
  user-select: none;
  transition: transform .2s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.memory-card:hover:not(.matched):not(.face-up) {
  filter: brightness(1.08);
}
.memory-card.face-up {
  background: rgba(118,139,67,.22);
  border-color: var(--accent-2);
}
.memory-card.face-up.ru-side {
  font-family: "PT Serif", Georgia, serif;
  font-size: .85rem;
}
.memory-card.matched {
  visibility: hidden;
  pointer-events: none;
}
.memory-card.wrong-flash {
  animation: shake .35s ease;
  border-color: var(--bad);
}

.verb-blitz-prompt-label {
  margin: 0 0 4px;
  font-size: .88rem;
}
.verb-blitz-prompt {
  margin: 0 0 20px;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
}
.verb-blitz-choices {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}
.verb-blitz-choice {
  min-height: 64px;
  padding: 14px 12px;
  font-family: "PT Serif", Georgia, serif;
  font-size: 1.15rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-2);
  cursor: pointer;
  transition: filter .15s ease, border-color .15s ease, background .15s ease;
}
.verb-blitz-choice:hover:not(:disabled) {
  filter: brightness(1.08);
  border-color: var(--accent-2);
}
.verb-blitz-choice:disabled {
  cursor: default;
  opacity: .85;
}
.verb-blitz-choice.correct {
  background: rgba(118,139,67,.28);
  border-color: var(--accent-2);
}
.verb-blitz-choice.wrong {
  background: rgba(200,80,80,.18);
  border-color: var(--bad);
}

.verb-blitz-recap {
  margin: 18px 0 20px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255,255,255,.03);
}
.verb-blitz-recap-title {
  margin: 0 0 6px;
  font-size: 1rem;
}
.verb-blitz-recap-lead {
  margin: 0 0 14px;
  font-size: .88rem;
  line-height: 1.45;
}
.conj-table-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.conj-table-block h4 {
  margin: 0 0 4px;
  font-size: .92rem;
}
.conj-verbs {
  margin: 0 0 10px;
  font-size: .82rem;
}
.conj-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
}
.conj-table th,
.conj-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.conj-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.conj-table tbody tr:last-child td {
  border-bottom: none;
}
.conj-table .conj-plural td:first-child {
  font-weight: 600;
  color: var(--accent-2);
}
.verb-blitz-recap-note {
  margin: 14px 0 0;
  font-size: .84rem;
  line-height: 1.5;
  color: var(--muted);
}
.verb-blitz-recap-note strong {
  color: var(--ink);
}
#verbBlitzStartScreen > button {
  width: 100%;
}

@media (max-width: 820px) {
  .hero { display: block; padding-top: 24px; }
  .stats { margin-top: 18px; grid-template-columns: repeat(3, 1fr); }
  .stats strong { font-size: 1.45rem; }
  .grid.two { grid-template-columns: 1fr; }
  .row.spread { display: grid; }
  .row { flex-wrap: wrap; }
  .chat-row { display: grid; grid-template-columns: 1fr auto; }
  .flashcard-toolbar { display: grid; }
  .flashcard-filters { display: grid; width: 100%; }
  .flashcard { min-height: 52vh; }
  .flashcard-inner, .flashcard-face { min-height: 52vh; }
  .flashcard-text { font-size: clamp(1.8rem, 8vw, 2.6rem); }
  .card { padding: 18px; border-radius: 18px; }
  main { padding-top: 18px; padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
  .tabs { display: none; }
  .bottom-nav { display: flex; }
  .memory-grid { gap: 8px; }
  .memory-card { font-size: .7rem; border-radius: 12px; }
  .game-grid { grid-template-columns: 1fr; }
}
