:root {
  --bg: #f7f7f5;
  --bg-elevated: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --border: #e5e5e2;
  --accent: #2f6f4f;
  --accent-soft: #e7f2ec;
  --accent-contrast: #ffffff;
  --danger: #b3543f;
  --danger-soft: #f7e9e5;
  --shadow: 0 1px 2px rgba(20,20,20,0.04), 0 8px 24px rgba(20,20,20,0.06);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #121212;
  --bg-elevated: #1c1c1c;
  --text: #f2f2f0;
  --text-muted: #9a9a96;
  --border: #2c2c2a;
  --accent: #6fbf94;
  --accent-soft: #1e2f26;
  --accent-contrast: #0d1a12;
  --danger: #d98b76;
  --danger-soft: #2f211d;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --bg-elevated: #1c1c1c;
    --text: #f2f2f0;
    --text-muted: #9a9a96;
    --border: #2c2c2a;
    --accent: #6fbf94;
    --accent-soft: #1e2f26;
    --accent-contrast: #0d1a12;
    --danger: #d98b76;
    --danger-soft: #2f211d;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background 0.2s ease, color 0.2s ease;
}

button { font-family: inherit; }

.hidden { display: none !important; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.01em;
}
.brand-icon { font-size: 18px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: scale(0.92); }

/* Layout */
#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.view { animation: fadeIn 0.25s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Hero */
.hero { margin-bottom: 28px; }
.hero-eyebrow {
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 8px;
}
.hero-title {
  font-size: 26px;
  line-height: 1.3;
  font-weight: 800;
  margin: 0 0 16px;
  letter-spacing: -0.02em;
}
.hero-stats {
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--text-muted);
}
.hero-stats b { color: var(--text); font-weight: 700; }

/* Actions */
.deck-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { opacity: 0.9; }
.btn-ghost { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-know { background: var(--accent-soft); color: var(--accent); flex: 1; }
.btn-again { background: var(--danger-soft); color: var(--danger); flex: 1; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px;
}
.link-btn:hover { color: var(--text); }
.reset-row { text-align: center; margin-top: 36px; }

/* Deck grid */
.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.group-heading {
  grid-column: 1 / -1;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 18px 0 -2px;
}
.group-heading:first-child { margin-top: 0; }
.deck-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.deck-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.deck-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.deck-icon { font-size: 22px; }
.deck-code {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
}
.deck-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}
.deck-progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 8px;
}
.deck-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.deck-foot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

/* Study view */
.study-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.deck-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.progress-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}
.progress-count {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.card-stage {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.nav-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, transform 0.12s ease;
}
.nav-btn:hover { border-color: var(--accent); }
.nav-btn:active { transform: scale(0.92); }

.flashcard {
  flex: 1;
  min-height: 340px;
  perspective: 1400px;
  cursor: pointer;
  outline: none;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 340px;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0.15, 0.2, 1);
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px 30px;
}
.flashcard-back { transform: rotateY(180deg); background: var(--accent-soft); }

.face-label {
  position: absolute;
  top: 18px;
  left: 22px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.flashcard-back .face-label { color: var(--accent); }

.face-text {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.5;
  margin: 0;
  white-space: pre-line;
  letter-spacing: -0.01em;
}
.flashcard-back .face-text { font-size: 17px; font-weight: 500; }

.tap-hint {
  position: absolute;
  bottom: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.rate-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.rate-row .btn {
  padding: 13px 16px;
}

.key-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

/* Done view */
.done-card {
  text-align: center;
  padding: 60px 20px;
}
.done-emoji { font-size: 48px; display: block; margin-bottom: 14px; }
.done-card h2 { font-size: 24px; margin: 0 0 10px; }
.done-summary { color: var(--text-muted); margin: 0 0 26px; font-size: 14px; }
.done-card .deck-actions { justify-content: center; }

/* Mobile */
@media (max-width: 480px) {
  .hero-title { font-size: 22px; }
  .flashcard-inner { height: 300px; }
  .face-text { font-size: 17px; }
  .nav-btn { width: 34px; height: 34px; font-size: 18px; }
  .card-stage { gap: 6px; }
  .flashcard-face { padding: 30px 20px; }
}
