/* Bottom-sheet modals (Help / Settings) */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 540px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  border-radius: 18px 18px 0 0;
  animation: sheet-up .22s ease;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--border);
}
.sheet-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
}
.sheet-body {
  padding: 16px 18px 28px;
  overflow-y: auto;
}
.sheet-body h3 { font-size: .95rem; margin: 18px 0 6px; color: var(--brand-dark); }
.sheet-body p  { font-size: .9rem; line-height: 1.5; margin-bottom: 8px; }
.sheet-body ul { font-size: .9rem; line-height: 1.5; margin: 0 0 8px 18px; }
.sheet-body li { margin-bottom: 5px; }
.menu-item:active { background: var(--brand-light); }

:root {
  --brand: #4f46e5;
  --brand-light: #eef2ff;
  --brand-dark: #3730a3;
  --correct: #16a34a;
  --correct-light: #dcfce7;
  --incorrect: #dc2626;
  --incorrect-light: #fee2e2;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.06);
  --nav-h: 60px;
  --header-h: 54px;
  --r: 14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  max-width: 540px;
  margin: 0 auto;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }

/* ── Utility ─────────────────────────────────── */
.hidden { display: none !important; }

.page-center {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  text-align: center;
  gap: 16px;
}

/* ── Header ─────────────────────────────────── */
.page-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

.page-header h1 {
  font-size: 1.125rem;
  font-weight: 700;
}

/* ── Bottom nav ─────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 540px;
  height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}

.nav-item.active { color: var(--brand); }
.nav-icon { font-size: 1.375rem; line-height: 1; }
.nav-label { font-size: 0.6875rem; font-weight: 500; }

/* ── Buttons ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 12px;
  border: none;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  min-height: 46px;
  text-decoration: none;
  color: inherit;
}

.btn:active { transform: scale(0.97); opacity: 0.9; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary  { background: var(--brand); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-ghost    { background: transparent; color: var(--brand); }
.btn-success  { background: var(--correct); color: #fff; }
.btn-danger   { background: var(--incorrect); color: #fff; }
.btn-full     { width: 100%; }
.btn-large    { padding: 16px 24px; font-size: 1.0625rem; border-radius: var(--r); }

.btn-icon {
  background: none;
  border: none;
  padding: 8px;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  text-decoration: none;
}

.btn-icon:hover { background: var(--border); }

/* ── Auth ───────────────────────────────────── */
.auth-wrap {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brand-logo { font-size: 2.25rem; font-weight: 800; color: var(--brand); letter-spacing: -0.02em; }
.brand-tagline { color: var(--muted); font-size: 0.875rem; margin-bottom: 8px; }

.auth-form {
  background: var(--surface);
  border-radius: var(--r);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form h2 { font-size: 1.125rem; margin-bottom: 4px; }

.auth-switch {
  text-align: center;
  font-size: 0.875rem;
  color: var(--muted);
  padding: 4px 0;
}

.auth-switch a { font-weight: 600; }

/* ── Forms ──────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.9375rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

input:focus, textarea:focus, select:focus { border-color: var(--brand); }
textarea { resize: vertical; min-height: 72px; }

.error-msg {
  color: var(--incorrect);
  font-size: 0.8125rem;
  padding: 4px 0;
}

/* ── Cards (list items) ─────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 10px; }

.list-card {
  background: var(--surface);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.list-card-body { flex: 1; min-width: 0; }
.list-card-title { font-weight: 600; font-size: 1rem; line-height: 1.3; }
.list-card-sub { font-size: 0.8125rem; color: var(--muted); margin-top: 3px; }

/* ── Deck-specific ──────────────────────────── */
.deck-meta {
  font-size: 0.8125rem;
  color: var(--muted);
  display: flex;
  gap: 12px;
  margin-top: 4px;
  align-items: center;
}

.mini-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.mini-bar-fill {
  height: 100%;
  background: var(--brand);
  border-radius: 2px;
  transition: width 0.4s;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-brand { background: var(--brand-light); color: var(--brand); }
.badge-success { background: var(--correct-light); color: var(--correct); }

/* ── Dashboard ──────────────────────────────── */
.main-pad { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.greeting { font-size: 1.125rem; }
.greeting strong { font-weight: 700; }

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-tile {
  background: var(--surface);
  border-radius: var(--r);
  padding: 18px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-num { display: block; font-size: 2.25rem; font-weight: 800; color: var(--brand); line-height: 1; }
.stat-lbl { display: block; font-size: 0.8125rem; color: var(--muted); margin-top: 4px; }

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quick-tile {
  background: var(--surface);
  border-radius: var(--r);
  padding: 16px 14px;
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--brand);
  text-align: center;
  text-decoration: none;
  display: block;
}

/* ── Review ─────────────────────────────────── */
.review-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.progress-track {
  flex: 1;
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
  display: flex;
}

.progress-fill {
  height: 100%;
  background: var(--brand);
  border-radius: 3px;
  transition: width 0.35s ease;
}

#progress-text {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 38px;
  text-align: right;
}

.review-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.direction-chip {
  background: var(--brand-light);
  color: var(--brand);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 20px;
}

/* ── Flashcard flip ─────────────────────────── */
.flip-wrap {
  perspective: 1200px;
  width: 100%;
  max-width: 480px;
  height: 250px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.flip-card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.flip-front,
.flip-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  text-align: center;
  gap: 10px;
}

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

.card-hint-text {
  font-size: 0.75rem;
  color: var(--muted);
  position: absolute;
  top: 14px;
}

.card-main-word {
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.card-translation {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--brand);
}

.card-example {
  font-size: 0.875rem;
  color: var(--muted);
  font-style: italic;
  max-width: 340px;
}

.card-notes {
  font-size: 0.8125rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 8px;
  padding: 6px 12px;
  max-width: 340px;
}

.answer-row {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 480px;
}

.btn-wrong {
  flex: 1;
  background: var(--incorrect-light);
  color: var(--incorrect);
  border: 2px solid var(--incorrect);
  font-size: 1.0625rem;
  min-height: 58px;
  border-radius: var(--r);
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}

.btn-right {
  flex: 1;
  background: var(--correct-light);
  color: var(--correct);
  border: 2px solid var(--correct);
  font-size: 1.0625rem;
  min-height: 58px;
  border-radius: var(--r);
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}

.btn-partial {
  flex: 1;
  background: #fef3c7;
  color: #b45309;
  border: 2px solid #f59e0b;
  font-size: 1.0625rem;
  min-height: 58px;
  border-radius: var(--r);
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}

.btn-wrong:active { transform: scale(0.97); background: var(--incorrect); color: #fff; }
.btn-right:active { transform: scale(0.97); background: var(--correct); color: #fff; }
.btn-partial:active { transform: scale(0.97); background: #f59e0b; color: #fff; }

/* When three ratings share the row (cram mode), tighten the text */
.answer-row.three .btn-wrong,
.answer-row.three .btn-partial,
.answer-row.three .btn-right { font-size: 0.85rem; padding: 0 4px; }
.answer-row.three { gap: 8px; }

.tap-prompt {
  font-size: 0.875rem;
  color: var(--muted);
}

/* ── Section headings ───────────────────────── */
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-heading h2 { font-size: 1rem; font-weight: 700; }

/* ── Panel / collapsible form ───────────────── */
.panel {
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-title {
  font-weight: 700;
  font-size: 0.9375rem;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

/* ── Toast notification ─────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 0.875rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
  max-width: calc(100vw - 40px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Spinner ────────────────────────────────── */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ────────────────────────────── */
.empty-icon { font-size: 3.5rem; }
.empty-state h2 { font-size: 1.25rem; font-weight: 700; }
.empty-state p { color: var(--muted); font-size: 0.9375rem; max-width: 260px; }

/* ── CSV hint ───────────────────────────────── */
.csv-hint {
  background: var(--brand-light);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.8125rem;
  color: var(--brand-dark);
  line-height: 1.5;
}

.csv-hint code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  background: rgba(0,0,0,.06);
  border-radius: 4px;
  padding: 1px 5px;
}
