/* ── Design tokens — light ───────────────────────────────── */
:root {
  --primary:        #3B82F6;
  --primary-dark:   #2563EB;
  --primary-light:  #EFF6FF;
  --bg:             #F1F5F9;
  --card:           #FFFFFF;
  --nav-bg:         #FFFFFF;
  --text:           #0F172A;
  --text-muted:     #64748B;
  --border:         #E2E8F0;
  --success:        #10B981;
  --success-light:  #ECFDF5;
  --error:          #EF4444;
  --error-light:    #FEF2F2;
  --warning:        #F59E0B;
  --warning-light:  #FFFBEB;
  --radius:         12px;
  --radius-sm:      8px;
  --shadow:         0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg:      0 10px 15px -3px rgba(0,0,0,.10), 0 4px 6px -2px rgba(0,0,0,.05);
  --font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-korean:    'Noto Sans KR', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  --nav-h:          64px;
}

/* ── Design tokens — dark ────────────────────────────────── */
[data-theme="dark"] {
  --bg:             #0A0A0A;
  --card:           #141414;
  --nav-bg:         #0F0F0F;
  --text:           #EEEEEE;
  --text-muted:     #888888;
  --border:         #2A2A2A;
  --primary-light:  #0F2A4A;
  --success-light:  #062917;
  --error-light:    #2D0A0A;
  --warning-light:  #2D1D00;
  --shadow:         0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --shadow-lg:      0 10px 15px -3px rgba(0,0,0,.6), 0 4px 6px -2px rgba(0,0,0,.4);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background .2s, color .2s;
}
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { text-decoration: none; color: inherit; }
ul { list-style: none; }

/* ── Navigation ──────────────────────────────────────────── */
#nav-bar {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: background .2s, border-color .2s;
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
}
.nav-logo {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.nav-logo:hover { opacity: .75; }

/* dark mode toggle */
.theme-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: .8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.theme-btn:hover { background: var(--border); color: var(--text); }
.nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
}
.nav-link {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
#level-badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}
.btn-icon {
  background: none;
  border: none;
  font-size: 1.3rem;
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background .15s;
}
.btn-icon:hover { background: var(--bg); }

/* ── Main layout ─────────────────────────────────────────── */
#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}
.view { display: none; }
.view.active { display: block; }

/* ── Section headings ────────────────────────────────────── */
.section-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text);
}
.section-sub {
  font-size: .9rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card-sm { padding: 16px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  transition: filter .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-success { background: var(--success); color: #fff; }
.btn-outline {
  background: none;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Form elements ───────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  background: var(--card);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-textarea { resize: vertical; min-height: 100px; }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.toggle-wrap { display: flex; align-items: center; gap: 12px; }
.toggle { position: relative; width: 48px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 26px;
  transition: background .2s;
  cursor: pointer;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(22px); }

/* ── Dashboard ───────────────────────────────────────────── */
.dashboard-welcome {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 24px;
}
.dashboard-welcome span { color: var(--primary); }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 6px;
}
.stat-label { font-size: .85rem; color: var(--text-muted); font-weight: 500; }
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.action-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.action-card h3 { font-size: 1.05rem; font-weight: 700; }
.action-card p { font-size: .88rem; color: var(--text-muted); flex: 1; }

/* ── Sets list ───────────────────────────────────────────── */
.sets-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.tab-btn {
  padding: 8px 18px;
  border: none;
  border-radius: 6px;
  background: none;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.tab-btn.active { background: var(--card); color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }
.sets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.set-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  position: relative;
}
.set-card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.set-card-name { font-size: 1rem; font-weight: 700; margin-bottom: 6px; }
.set-card-meta { font-size: .82rem; color: var(--text-muted); }
.set-card-actions {
  position: absolute;
  top: 12px; right: 12px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .15s;
}
.set-card:hover .set-card-actions { opacity: 1; }
.set-card-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: .75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 8px;
}
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.category-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, transform .1s;
}
.category-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.category-emoji { font-size: 2.2rem; margin-bottom: 10px; }
.category-name { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.category-count { font-size: .82rem; color: var(--text-muted); }

/* ── Create Set form ─────────────────────────────────────── */
.word-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.word-row .form-input { margin: 0; }
.word-list { margin-bottom: 12px; max-height: 280px; overflow-y: auto; }

/* ── Daily Review ────────────────────────────────────────── */
.review-config {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 40px 20px;
  text-align: center;
}
.review-config h2 { font-size: 1.6rem; font-weight: 700; }
.review-config p { color: var(--text-muted); }
.count-buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.count-btn {
  padding: 10px 22px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: .95rem;
  font-weight: 600;
  transition: border-color .15s, background .15s;
}
.count-btn.selected, .count-btn:hover { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

/* ── Flashcard ───────────────────────────────────────────── */
#flashcard-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 20px 0;
}
.flashcard-progress-bar {
  width: 100%;
  max-width: 640px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.flashcard-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width .4s;
}
.flashcard-counter {
  font-size: .88rem;
  color: var(--text-muted);
  font-weight: 600;
}
.flashcard {
  width: 100%;
  max-width: 640px;
  min-height: 280px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  text-align: center;
  position: relative;
  transition: border-color .2s;
}
.flashcard.correct { border-color: var(--success); background: var(--success-light); }
.flashcard.wrong   { border-color: var(--error);   background: var(--error-light); }
.flashcard-prompt { font-size: .82rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 16px; }
.flashcard-word {
  font-size: 2.8rem;
  font-weight: 800;
  font-family: var(--font-korean);
  line-height: 1.2;
  margin-bottom: 8px;
}
.flashcard-romanization { font-size: .95rem; color: var(--text-muted); margin-bottom: 16px; }
.flashcard-answer-reveal {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--success);
  margin-top: 12px;
  font-family: var(--font-korean);
}
.flashcard-input {
  width: 100%;
  max-width: 640px;
}
.flashcard-input input {
  width: 100%;
  padding: 14px 20px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.3rem;
  font-family: var(--font-korean);
  text-align: center;
  outline: none;
  transition: border-color .15s;
  background: var(--card);
}
.flashcard-input input:focus { border-color: var(--primary); }
.flashcard-input input.correct { border-color: var(--success); background: var(--success-light); }
.flashcard-input input.wrong   { border-color: var(--error);   background: var(--error-light); }
.rating-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 640px;
}
.rating-btn {
  flex: 1;
  min-width: 100px;
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 700;
  background: var(--card);
  transition: all .15s;
}
.rating-btn.again { border-color: var(--error); color: var(--error); }
.rating-btn.again:hover { background: var(--error-light); }
.rating-btn.hard { border-color: var(--warning); color: var(--warning); }
.rating-btn.hard:hover { background: var(--warning-light); }
.rating-btn.good { border-color: var(--primary); color: var(--primary); }
.rating-btn.good:hover { background: var(--primary-light); }
.rating-btn.easy { border-color: var(--success); color: var(--success); }
.rating-btn.easy:hover { background: var(--success-light); }
.audio-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background .15s;
  color: var(--primary);
}
.audio-btn:hover { background: var(--primary-light); }
.review-complete {
  text-align: center;
  padding: 60px 20px;
}
.review-complete h2 { font-size: 2rem; font-weight: 800; margin-bottom: 12px; }
.review-complete p { color: var(--text-muted); margin-bottom: 32px; }

/* ── Stories ─────────────────────────────────────────────── */
.stories-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.story-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  cursor: pointer;
  transition: border-color .15s;
}
.story-card:hover { border-color: var(--primary); }
.story-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; }
.story-meta { font-size: .82rem; color: var(--text-muted); display: flex; gap: 16px; margin-bottom: 12px; }
.story-preview { font-size: .9rem; color: var(--text-muted); line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.story-content {
  font-family: var(--font-korean);
  font-size: 1rem;
  line-height: 1.9;
  color: var(--text);
  white-space: pre-wrap;
}
.story-content .known-word {
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 600;
}
.story-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ── Profile ─────────────────────────────────────────────── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}
.profile-avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  flex-shrink: 0;
}
.profile-name { font-size: 1.4rem; font-weight: 700; }
.profile-since { font-size: .85rem; color: var(--text-muted); margin-top: 2px; }
.xp-bar {
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
  margin: 8px 0;
}
.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60A5FA);
  border-radius: 5px;
  transition: width .5s;
}
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.achievement {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  font-size: .82rem;
}
.achievement.unlocked { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.achievement-icon { font-size: 1.8rem; margin-bottom: 4px; }

/* ── Modals ──────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.45);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  position: relative;
}
.modal-lg { max-width: 720px; }
.modal-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 24px; }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none;
  font-size: 1.4rem; color: var(--text-muted);
  line-height: 1; padding: 4px 8px; border-radius: 6px;
  transition: background .15s;
}
.modal-close:hover { background: var(--bg); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; flex-wrap: wrap; }

/* ── Import section ──────────────────────────────────────── */
.import-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.import-tab {
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all .15s;
}
.import-tab.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

/* ── Toast ───────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 1000;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn .25s ease;
  max-width: 320px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--error); }
.toast.warning { background: var(--warning); color: var(--text); }
@keyframes slideIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }

/* ── Empty states ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: .9rem; margin-bottom: 20px; }

/* ── Spinner ─────────────────────────────────────────────── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Generating overlay ──────────────────────────────────── */
.generating {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}
.generating h3 { font-size: 1rem; font-weight: 600; margin-top: 12px; }

/* ── Word row in set view ────────────────────────────────── */
.word-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.word-table th { text-align: left; padding: 8px 12px; font-size: .78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--border); }
.word-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.word-table tr:last-child td { border-bottom: none; }
.word-korean { font-family: var(--font-korean); font-weight: 600; font-size: 1rem; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .nav-links { display: none; }
  #app { padding: 20px 16px 60px; }
  .flashcard-word { font-size: 2rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .modal { padding: 20px; }
  .rating-buttons { gap: 6px; }
  .rating-btn { font-size: .8rem; padding: 10px 4px; }
}

/* ── Utility ─────────────────────────────────────────────── */
.flex   { display: flex; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }

/* ── Auth modal ──────────────────────────────────────────── */
.auth-tabs { display: flex; margin-bottom: 24px; border-bottom: 2px solid var(--border); }
.auth-tab {
  flex: 1; padding: 10px; text-align: center;
  border: none; background: none;
  font-size: .95rem; font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
  cursor: pointer;
  white-space: nowrap;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.auth-divider {
  text-align: center; color: var(--text-muted);
  font-size: .82rem; margin: 16px 0;
  position: relative;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  position: absolute; top: 50%;
  width: 40%; height: 1px;
  background: var(--border);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }
.auth-user-btn {
  display: flex; align-items: center; gap: 8px;
  background: none; border: 1.5px solid var(--border);
  border-radius: 20px; padding: 5px 12px 5px 8px;
  font-size: .85rem; font-weight: 600;
  color: var(--text); cursor: pointer;
  transition: background .15s;
}
.auth-user-btn:hover { background: var(--bg); }
.auth-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--primary-light);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; flex-shrink: 0;
}

/* ── Font-korean helper ──────────────────────────────────── */
.font-korean { font-family: var(--font-korean); }

/* ── Try dots ────────────────────────────────────────────── */
.try-dots { display: flex; gap: 5px; align-items: center; }
.try-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background .2s;
}
.try-dot.used { background: var(--error); }

/* ── Flashcard feedback line ─────────────────────────────── */
.fc-feedback {
  font-size: .9rem;
  font-weight: 600;
  min-height: 22px;
  transition: color .2s;
}
.fc-feedback.correct { color: var(--success); }
.fc-feedback.wrong   { color: var(--error); }
.fc-feedback.hint    { color: var(--warning); }

/* ── Set progress bar ────────────────────────────────────── */
.set-progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px 0 6px;
  overflow: hidden;
}
.set-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: 2px;
  transition: width .4s;
}

/* ── Daily goal bar ──────────────────────────────────────── */
.daily-goal-label {
  display: flex;
  justify-content: space-between;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.daily-goal-track {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.daily-goal-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: 4px;
  transition: width .4s;
}

/* ── Weekly / 14-day chart ───────────────────────────────── */
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 80px;
}
.chart-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}
.chart-bar {
  width: 100%;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  min-height: 3px;
  position: relative;
  transition: height .3s;
}
.chart-bar-val {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .65rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.chart-label {
  font-size: .65rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}
.chart-14 { height: 100px; }

/* ── Stats rows ──────────────────────────────────────────── */
.stat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.stat-row-label { font-size: .85rem; font-weight: 600; min-width: 80px; }
.stat-row-track {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.stat-row-fill { height: 100%; border-radius: 4px; transition: width .4s; }
.stat-row-val  { font-size: .85rem; font-weight: 700; min-width: 32px; text-align: right; }

/* ── Achievement badges ──────────────────────────────────── */
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.achievement-badge {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  cursor: default;
  transition: border-color .15s, transform .1s;
}
.achievement-badge.unlocked {
  border-color: var(--primary);
  background: var(--primary-light);
}
.achievement-badge.locked { opacity: .45; }
.achievement-badge.unlocked:hover { transform: translateY(-2px); }
.achievement-icon { font-size: 1.6rem; margin-bottom: 4px; }
.achievement-name { font-size: .72rem; font-weight: 700; color: var(--text); }

/* ── Achievement toast ───────────────────────────────────── */
.achievement-toast {
  position: fixed;
  bottom: 80px; right: 24px;
  background: var(--card);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .88rem;
  font-weight: 600;
  z-index: 2000;
  transform: translateX(120%);
  transition: transform .35s cubic-bezier(.34,1.56,.64,1);
}
.achievement-toast.visible { transform: translateX(0); }

/* ── Level-up popup ──────────────────────────────────────── */
.level-up-popup {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.8);
  background: var(--card);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 40px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  z-index: 2000;
  opacity: 0;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .3s;
}
.level-up-popup.visible { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ── Sentence practice ───────────────────────────────────── */
.sentence-practice-wrap { max-width: 680px; margin: 0 auto; }
.sentence-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}
.sentence-card {
  padding: 28px 32px;
  margin-bottom: 16px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
}
.sentence-prompt-text {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--font-korean);
  line-height: 1.5;
  color: var(--text);
}

/* ── Auth Gate (full-screen) ─────────────────────────────── */
.auth-gate {
  position: fixed; inset: 0; z-index: 900;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.auth-gate.hidden { display: none !important; }

.auth-gate-inner {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
  width: 100%;
  max-width: 440px;
}
/* Prevent label wrapping inside auth gate forms */
.auth-gate-inner .form-group label { white-space: nowrap; }
.auth-gate-logo {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
  text-align: center;
  margin-bottom: 4px;
}
.auth-gate-tagline {
  font-size: .88rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 28px;
}
.auth-gate-tabs {
  margin-bottom: 28px;
}
.auth-gate-links {
  text-align: center;
  font-size: .85rem;
  color: var(--text-muted);
}
.auth-gate-links a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.auth-gate-links a:hover { text-decoration: underline; }

/* ── Nav auth dropdown ───────────────────────────────────── */
.nav-right { position: relative; }

.nav-auth-menu {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: 8px 0;
  z-index: 200;
}
.nav-auth-menu-name {
  font-size: .88rem;
  font-weight: 700;
  padding: 8px 16px 2px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-auth-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 9px 16px;
  font-size: .88rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background .12s;
}
.nav-auth-menu-item:hover { background: var(--bg); }

/* ── Local-mode banner ───────────────────────────────────── */
.local-mode-banner {
  background: var(--warning-light);
  color: var(--warning);
  border-bottom: 1px solid var(--warning);
  text-align: center;
  padding: 8px 16px;
  font-size: .82rem;
  font-weight: 500;
}
.local-mode-banner code { background: rgba(0,0,0,.08); padding: 1px 5px; border-radius: 4px; font-size: .8rem; }

/* ── Timed mode countdown ────────────────────────────────── */
.fc-timer-wrap { display: flex; align-items: center; gap: 12px; padding: 0 4px; }
.fc-timer-bar { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.fc-timer-fill { height: 100%; background: var(--success); border-radius: 3px; }
.fc-timer-text { font-size: .85rem; font-weight: 700; color: var(--text-muted); min-width: 32px; text-align: right; }
.fc-timer-text.warning { color: var(--warning); }
.fc-timer-text.danger  { color: var(--error); }

/* ── Speed mode bar ──────────────────────────────────────── */
.speed-mode-bar {
  background: linear-gradient(135deg, #F59E0B, #EF4444);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 18px 10px;
  margin-bottom: 12px;
}
.speed-mode-inner { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.speed-label { font-weight: 700; font-size: .85rem; letter-spacing: .05em; opacity: .9; }
.speed-timer { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.speed-score { font-weight: 700; font-size: 1rem; }
.speed-timer-bar { height: 4px; background: rgba(255,255,255,.3); border-radius: 2px; overflow: hidden; }
.speed-timer-fill { height: 100%; background: #fff; border-radius: 2px; }

/* ── Multi-select ────────────────────────────────────────── */
.set-card-selected { border-color: var(--primary) !important; background: var(--primary-light) !important; box-shadow: 0 0 0 2px var(--primary) !important; }
.set-select-check {
  position: absolute; top: 12px; right: 12px;
  width: 26px; height: 26px;
  border: 2px solid var(--primary); border-radius: 50%;
  background: var(--card);
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 700; color: var(--primary);
}
.set-card-selected .set-select-check { background: var(--primary); color: #fff; }
.multi-select-bar {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff;
  padding: 14px 24px; border-radius: 50px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 16px;
  z-index: 300; white-space: nowrap;
}

/* ── Folders ─────────────────────────────────────────────── */
.folder-section { margin-bottom: 28px; }
.folder-header {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 12px;
}
.folder-icon { font-size: 1.1rem; }
.folder-name { font-weight: 700; font-size: 1rem; flex: 1; }
.folder-move-select {
  padding: 4px 8px; font-size: .78rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg); color: var(--text);
  cursor: pointer; outline: none; max-width: 100px;
}
.folder-move-select:focus { border-color: var(--primary); }

/* ── Leaderboard ─────────────────────────────────────────── */
.leaderboard-table { display: flex; flex-direction: column; gap: 6px; }
.leaderboard-row {
  display: grid; grid-template-columns: 44px 1fr auto 90px;
  align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--bg); border-radius: var(--radius-sm);
  font-size: .88rem;
}
.leaderboard-row-mine { background: var(--primary-light); color: var(--primary); font-weight: 700; }
.leaderboard-rank { font-size: 1.1rem; text-align: center; }
.leaderboard-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-score { font-weight: 700; color: var(--primary); text-align: right; }
.leaderboard-date { font-size: .75rem; color: var(--text-muted); text-align: right; }

/* ── Mistake Analysis ────────────────────────────────────── */
.mistake-pattern-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.mistake-pattern-row:last-child { border-bottom: none; }
.mistake-chars {
  font-family: var(--font-korean); font-size: 1.05rem; font-weight: 700;
  color: var(--error); min-width: 72px;
}
.mistake-bar-wrap { flex: 1; background: var(--border); border-radius: 3px; height: 6px; }
.mistake-bar-fill { height: 100%; background: var(--error); border-radius: 3px; }
.mistake-count { font-size: .82rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }

/* ── Set search bar ───────────────────────────────────────── */
.sets-search-wrap {
  margin-bottom: 16px;
}
.sets-search-wrap .form-input[type="search"] {
  width: 100%;
  max-width: 480px;
  border-radius: 24px;
  padding-left: 16px;
}
