:root {
  --primary: #7aaf50;
  --primary-dark: #5d8e39;
  --primary-light: #e8f5d8;
  --success: #4caf72;
  --success-light: #d6f5e3;
  --error: #e05252;
  --error-light: #fde8e8;
  --bg: #f4f9f0;
  --card: #ffffff;
  --text: #1a2416;
  --text-muted: #6b7c61;
  --border: #d8eacc;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 1px 4px rgba(0,0,0,.05), 0 6px 20px rgba(93,142,57,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ── Nav ──────────────────────────────────────────────────── */
.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(255,255,255,.92);
}

.nav a {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; gap: 3px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 10px; font-weight: 600;
  letter-spacing: .2px;
  transition: color .15s;
  padding: 4px 0;
}

.nav a.active, .nav a:hover { color: var(--primary-dark); }

.nav a svg {
  width: 24px; height: 24px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ── Page layout ─────────────────────────────────────────── */
.page {
  padding: 56px 18px max(80px, calc(env(safe-area-inset-bottom) + 70px));
  max-width: 480px; margin: 0 auto;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  border: 1px solid rgba(216,234,204,.6);
}

.card-title {
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-muted); margin-bottom: 14px;
}

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

label {
  display: block; font-size: 14px; font-weight: 600;
  color: var(--text); margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; font-family: inherit;
  color: var(--text); background: var(--card);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(122,175,80,.18);
}

/* ── Autocomplete ────────────────────────────────────────── */
.autocomplete-wrap { position: relative; }

.suggestions {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,.1);
  z-index: 200;
  overflow: hidden;
  display: none;
}
.suggestions.show { display: block; }

.suggestion-item {
  padding: 13px 16px;
  font-size: 15px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  transition: background .1s;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:active, .suggestion-item:hover { background: var(--primary-light); }
.suggestion-word { font-weight: 600; }
.suggestion-trans { font-size: 13px; color: var(--text-muted); }

.translation-preview {
  margin-top: 10px; padding: 12px 14px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  font-size: 14px; color: var(--primary-dark); font-weight: 500;
  display: none;
}
.translation-preview.show { display: block; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 600; font-family: inherit;
  border: none; cursor: pointer;
  transition: all .15s; text-decoration: none; width: 100%;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.98); opacity: .92; }

.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-secondary:hover { background: #d4edbe; }

.btn-ghost {
  background: transparent; color: var(--text-muted);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary-dark); }

.btn-danger { background: var(--error-light); color: var(--error); }
.btn-danger:hover { background: #fbcfcf; }

.btn-sm { padding: 9px 16px; font-size: 14px; width: auto; }

.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  margin-bottom: 14px; display: none;
}
.alert.show { display: block; }
.alert-error { background: var(--error-light); color: #b33a3a; }
.alert-success { background: var(--success-light); color: #2a7a4a; }

/* ── Vocab list ──────────────────────────────────────────── */
.vocab-item {
  display: flex; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--border); gap: 12px;
}
.vocab-item:last-child { border-bottom: none; padding-bottom: 0; }
.vocab-item:first-child { padding-top: 0; }

.vocab-words { flex: 1; min-width: 0; }
.vocab-source { font-weight: 700; font-size: 16px; }
.vocab-target { font-size: 14px; color: var(--text-muted); margin-top: 2px; }
.vocab-date { font-size: 11px; color: #b0c4a0; margin-top: 3px; }

.vocab-edit {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--primary-light); color: var(--primary-dark);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 16px; transition: background .15s;
}
.vocab-edit:hover { background: #d4edbe; }

.vocab-delete {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--error-light); color: var(--error);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 17px; transition: background .15s;
}
.vocab-delete:hover { background: #fbcfcf; }

/* ── Quiz ────────────────────────────────────────────────── */
.quiz-word-card {
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-radius: var(--radius); padding: 44px 28px;
  text-align: center; color: white;
  box-shadow: 0 10px 32px rgba(93,142,57,.32);
  margin-bottom: 20px;
}

.quiz-word { font-size: 38px; font-weight: 800; letter-spacing: -0.5px; line-height: 1.2; }
.quiz-word-hint { font-size: 14px; opacity: .72; margin-top: 10px; }

.quiz-result {
  border-radius: var(--radius); padding: 24px 20px;
  margin-bottom: 16px; display: none; text-align: center;
}
.quiz-result.show { display: block; }
.quiz-result.correct { background: var(--success-light); }
.quiz-result.wrong { background: var(--error-light); }

.quiz-result-icon { font-size: 44px; margin-bottom: 10px; }
.quiz-result-label { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.quiz-result.correct .quiz-result-label { color: #2a7a4a; }
.quiz-result.wrong .quiz-result-label { color: #b33a3a; }
.quiz-result-answer { font-size: 24px; font-weight: 700; color: var(--text); margin: 10px 0; }
.quiz-result-alts { font-size: 13px; color: var(--text-muted); }

/* ── Week row ────────────────────────────────────────────── */
.week-row {
  display: flex; gap: 8px; align-items: center; margin-bottom: 14px;
}
.week-row select { flex: 1; padding: 10px 14px; font-size: 14px; }
.week-row label { margin: 0; font-size: 13px; white-space: nowrap; color: var(--text-muted); font-weight: 600; }

/* ── Mode toggle ─────────────────────────────────────────── */
.mode-toggle {
  display: flex; background: var(--primary-light);
  border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px;
}
.mode-btn {
  flex: 1; padding: 10px; border: none; border-radius: 9px;
  background: transparent; font-size: 14px; font-weight: 700;
  color: var(--primary-dark); cursor: pointer; transition: all .15s;
}
.mode-btn.active { background: var(--primary); color: white; }

/* ── Auth ────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
  padding: 40px 24px max(40px, env(safe-area-inset-bottom));
  max-width: 400px; margin: 0 auto;
}

.auth-logo {
  width: 76px; height: 76px;
  background: linear-gradient(145deg, var(--primary), var(--primary-dark));
  border-radius: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 42px; font-weight: 800;
  margin: 0 auto 26px;
  box-shadow: 0 10px 28px rgba(93,142,57,.28);
  color: white;
}

.auth-title {
  font-size: 32px; font-weight: 800; text-align: center;
  margin-bottom: 6px; letter-spacing: -0.8px;
}

.auth-subtitle {
  font-size: 15px; color: var(--text-muted);
  text-align: center; margin-bottom: 36px;
}

.auth-tabs {
  display: flex; background: var(--primary-light);
  border-radius: var(--radius-sm); padding: 4px; margin-bottom: 24px;
}

.auth-tab {
  flex: 1; padding: 11px; border: none; border-radius: 9px;
  background: transparent; font-size: 15px; font-weight: 700;
  color: var(--primary-dark); cursor: pointer; transition: all .15s;
}
.auth-tab.active { background: var(--primary); color: white; }

/* ── Settings ────────────────────────────────────────────── */
.settings-section { margin-bottom: 26px; }
.settings-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text-muted);
  margin-bottom: 10px; padding: 0 4px;
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 16px; color: var(--text-muted); }
.empty-icon { font-size: 48px; margin-bottom: 14px; }
.empty-text { font-size: 15px; line-height: 1.5; }

/* ── Spinner ─────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: white; border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: max(14px, env(safe-area-inset-top)) 18px 14px;
  z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-title { font-size: 17px; font-weight: 800; letter-spacing: -.2px; }

.tag {
  display: inline-flex; align-items: center;
  background: var(--primary-light); color: var(--primary-dark);
  font-size: 12px; font-weight: 700;
  padding: 4px 12px; border-radius: 14px;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 300;
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 20px max(24px, env(safe-area-inset-bottom));
  width: 100%; max-width: 480px;
  transform: translateY(100%); transition: transform .25s cubic-bezier(.32,1,.23,1);
  max-height: 85vh; overflow-y: auto;
}
.modal-backdrop.open .modal { transform: translateY(0); }

.modal-handle {
  width: 36px; height: 4px;
  background: var(--border); border-radius: 2px;
  margin: 0 auto 18px;
}
.modal-title {
  font-size: 18px; font-weight: 800; margin-bottom: 18px;
  letter-spacing: -.2px;
}

/* ── Lang buttons (settings) ─────────────────────────────── */
.lang-btn {
  flex: 1; padding: 18px 10px; font-size: 22px;
  border-radius: 14px; border: 2px solid transparent;
  background: var(--bg); cursor: pointer; transition: all .15s;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.lang-btn span { font-size: 13px; font-weight: 700; color: var(--text); }
.lang-btn.selected { border-color: var(--primary); background: var(--primary-light); }
