:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3248;
  --primary: #6c63ff;
  --primary-dim: #4d45cc;
  --success: #22c55e;
  --danger: #ef4444;
  --text: #e8eaf6;
  --text-muted: #7b82a0;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
}

/* ── screens ───────────────────────────────────────────────── */

.screen { display: none; flex-direction: column; height: 100%; }
.screen.active { display: flex; }

/* ── splash ─────────────────────────────────────────────────── */

#splash-screen {
  justify-content: center;
  align-items: center;
  background: #ffffff;
}

.splash-logo {
  width: 75%;
  max-width: 360px;
  animation: splashIn 1.5s ease;
}

@keyframes splashIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── top bar ────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
}

.topbar-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--primary);
}

.topbar-logo {
  height: 50px;
  width: auto;
  object-fit: contain;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 20px;
  transition: color 0.15s;
}
.icon-btn:hover { color: var(--text); }

/* ── auth screen ────────────────────────────────────────────── */

#auth-screen {
  gap: 0;
}

.auth-logo {
  font-size: 48px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -2px;
  text-align: center;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  margin-top: -16px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-tabs {
  display: flex;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all 0.15s;
}

.auth-tab.active {
  background: var(--primary);
  color: white;
}

.input-group { display: flex; flex-direction: column; gap: 6px; }

.input-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}
.input-group input:focus { border-color: var(--primary); }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

/* ── buttons ────────────────────────────────────────────────── */

.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 20px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:active { background: var(--primary-dim); transform: scale(0.98); }

.btn-success {
  background: var(--success);
  color: white;
  flex: 1;
}
.btn-danger {
  background: var(--danger);
  color: white;
  flex: 1;
}
.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── card screen ────────────────────────────────────────────── */

#card-screen {
  padding: 0 16px;
  gap: 16px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}

.badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.badge.mood { color: #a78bfa; border-color: #4c3c84; background: #1f1440; }
.badge.tense { color: #67e8f9; border-color: #164e63; background: #061f2e; }
.badge.level { color: var(--text-muted); border-color: var(--border); background: var(--surface2); font-weight: 700; }

.card-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease;
}

#card-content {
  transition: opacity 0.22s ease, transform 0.22s ease;
  will-change: opacity, transform;
}

#card-content.swap-out {
  opacity: 0;
  transform: translateY(8px);
}

#card-content.swap-in {
  animation: cardContentIn 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes cardContentIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-meaning {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.card-infinitive {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -1px;
}

.card-divider {
  width: 40px;
  height: 2px;
  background: var(--border);
  border-radius: 2px;
}

.card-person {
  font-size: 18px;
  color: var(--text-muted);
  font-weight: 500;
}

.card-answer {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
  opacity: 0;
  transition: opacity 0.25s;
  min-height: 40px;
}

.card-answer.visible { opacity: 1; }

.card-new-badge {
  background: #1a3a1a;
  border: 1px solid #2d6a2d;
  color: #4ade80;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ── action buttons ─────────────────────────────────────────── */

.action-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.card-controls {
  min-height: 50px;
  display: flex;
}

.card-controls > * {
  width: 100%;
}

.review-buttons {
  display: flex;
  gap: 10px;
}

/* ── stats bar ──────────────────────────────────────────────── */

.stats-bar {
  display: flex;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  gap: 2px;
  font-size: 11px;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}
.stat-item:last-child { border-right: none; }

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.stat-item.due .stat-value    { color: #f97316; }
.stat-item.new .stat-value    { color: #a78bfa; }
.stat-item.done .stat-value   { color: var(--success); }
.stat-item.streak .stat-value { color: #fb923c; }
.stat-item.xp .stat-value     { color: #facc15; }

/* ── done screen ────────────────────────────────────────────── */

#done-screen {
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 32px;
}

.done-icon { font-size: 64px; }

.done-title {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.5px;
}

.done-subtitle {
  color: var(--text-muted);
  text-align: center;
  font-size: 15px;
}

/* ── stats screen ────────────────────────────────────────────── */

#stats-screen {
  padding: 0 16px 16px;
  gap: 16px;
  overflow-y: auto;
}

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

.stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stats-card-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

.stats-card-value {
  font-size: 36px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
}

.progress-bar-wrap {
  background: var(--surface2);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* ── upgrade input (reuse input-group input style) ──────────── */

.upgrade-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}
.upgrade-input:focus { border-color: var(--primary); }

/* ── level settings ─────────────────────────────────────────── */

.settings-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 4px 0;
}

.settings-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 16px;
}

.level-pills {
  display: flex;
  gap: 6px;
}

.level-pill {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 4px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  letter-spacing: 0.3px;
}

.level-pill.active {
  background: #1e1a40;
  color: #a78bfa;
  border-color: #4c3c84;
}

.level-pill.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 0 12px rgba(108, 99, 255, 0.4);
}

.level-pill:active { transform: scale(0.95); }

/* ── tense settings ─────────────────────────────────────────── */

.tense-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 4px 4px;
}

.tense-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s;
  gap: 12px;
}

.tense-row:active { opacity: 0.8; }
.tense-row.active { border-color: var(--primary); background: #1a1640; }

.tense-row-text { flex: 1; }
.tense-row-name { font-size: 15px; font-weight: 500; color: var(--text); }
.tense-row-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Toggle switch */
.toggle {
  width: 44px;
  height: 26px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 13px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle.on { background: var(--primary); border-color: var(--primary); }
.toggle.on::after { transform: translateX(18px); background: white; }

/* ── loading ────────────────────────────────────────────────── */

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: auto;
}

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

/* ── transitions ────────────────────────────────────────────── */

.fade-in { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── gamification toasts & overlays ─────────────────────────── */

.xp-toast {
    position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
    background: var(--primary); color: #fff; padding: 6px 16px;
    border-radius: 20px; font-weight: bold; animation: fadeup 2s forwards;
    pointer-events: none; z-index: 100;
}
.badge-toast {
    position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%);
    background: #7c3aed; color: #fff; padding: 8px 18px;
    border-radius: 20px; animation: fadeup 3s forwards;
    pointer-events: none; z-index: 100;
}
.levelup-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.6);
    display: flex; align-items: center; justify-content: center; z-index: 200;
}
.levelup-box {
    background: var(--surface); border-radius: 16px; padding: 32px;
    text-align: center;
}
@keyframes fadeup {
    0%   { opacity: 1; transform: translateX(-50%) translateY(0); }
    80%  { opacity: 1; }
    100% { opacity: 0; transform: translateX(-50%) translateY(-30px); }
}

/* ── screen-header (profile and similar screens) ────────────── */

.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
}

.screen-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--primary);
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 20px;
  transition: color 0.15s;
}
.back-btn:hover { color: var(--text); }

/* ── profile screen ─────────────────────────────────────────── */

.profile-body { padding: 16px; overflow-y: auto; flex: 1; }
.level-card { background: var(--card-bg, var(--surface)); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.level-number { font-size: 1.4rem; font-weight: bold; margin-bottom: 8px; }
.xp-bar-wrap { background: #333; border-radius: 8px; height: 10px; overflow: hidden; }
.xp-bar { height: 100%; background: var(--primary); transition: width .4s; }
.xp-label { font-size: .85rem; color: #aaa; margin-top: 4px; }
.streak-card { background: var(--card-bg, var(--surface)); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.badge-item { background: var(--card-bg, var(--surface)); border-radius: 10px; padding: 12px; text-align: center; }
.badge-item.locked { opacity: .35; }
.badge-item.earned { box-shadow: 0 0 0 2px var(--primary); }
.badge-icon { font-size: 2rem; }
.badge-name { font-size: .75rem; margin-top: 4px; }

/* ── path lesson bar (card screen) ───────────────────────────── */

.path-lesson-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 4px;
}
.path-lesson-progress-wrap {
  flex: 1;
  height: 6px;
  background: #2a2d3e;
  border-radius: 3px;
  overflow: hidden;
}
.path-lesson-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}
.path-lesson-bar span {
  font-size: .75rem;
  color: #aaa;
  white-space: nowrap;
  min-width: 36px;
  text-align: right;
}

/* ── path screen ─────────────────────────────────────────────── */

.path-level-ready {
  background: var(--primary); color: #fff;
  text-align: center; padding: 10px 16px;
  font-weight: bold; font-size: .95rem;
}

.path-nodes {
  padding: 16px 0 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  overflow-y: auto;
  flex: 1;
}

.path-level-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 24px 8px;
}
.path-level-divider::before,
.path-level-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #333;
}
.path-level-divider span {
  font-size: .8rem;
  font-weight: bold;
  color: #aaa;
  letter-spacing: .1em;
}

.path-node-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
}
.path-node-wrap.left  { padding-left: 20%; }
.path-node-wrap.right { padding-right: 20%; }

.path-node {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid transparent;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s;
}
.path-node:active:not(:disabled) { transform: scale(.92); }

.path-node.completed {
  background: #16a34a;
  border-color: #15803d;
  color: #fff;
}
.path-node.active {
  background: var(--primary);
  border-color: #4f46e5;
  color: #fff;
}
.path-node.active.current {
  animation: pulse-node 2s infinite;
}
.path-node.locked {
  background: #1e2130;
  border-color: #333;
  color: #555;
  cursor: default;
}

.path-node-label {
  font-size: .72rem;
  color: #aaa;
  margin-top: 6px;
  text-align: center;
  max-width: 80px;
}

@keyframes pulse-node {
  0%, 100% { box-shadow: 0 0 0 0 rgba(108, 99, 255, .5); }
  50%       { box-shadow: 0 0 0 10px rgba(108, 99, 255, 0); }
}

/* ── onboarding modal ────────────────────────────────────────── */

.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 999;
  padding: 0 0 env(safe-area-inset-bottom, 0);
}

.onboarding-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 32px 24px 28px;
  max-width: 480px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slide-up .3s ease;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.onboarding-icon {
  font-size: 48px;
  text-align: center;
}

.onboarding-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

.onboarding-text {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
  text-align: center;
}

.onboarding-text strong {
  color: var(--text);
}

.onboarding-hint {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.onboarding-hint strong {
  color: var(--text);
}

.onboarding-hint-icon {
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}
