/* ═══════════════════════════════════════════════════════════════
   DESIGN SYSTEM — Học Ngoại Ngữ
   Shared CSS cho toàn bộ website
   ═══════════════════════════════════════════════════════════════ */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Noto+Sans+KR:wght@400;500;700&display=swap');

/* ═══ 1. CSS CUSTOM PROPERTIES ═══ */
:root {
  /* ── Primary ── */
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: #EEF2FF;
  --primary-soft: #C7D2FE;

  /* ── Accent (override per page) ── */
  --accent: #4F46E5;
  --accent-light: #EEF2FF;

  /* ── Semantic ── */
  --success: #10B981;
  --success-light: #D1FAE5;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --danger: #EF4444;
  --danger-light: #FEE2E2;

  /* ── Surfaces ── */
  --bg-body: #EEF2FF;
  --bg-panel: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-input: #F8FAFC;
  --bg-hover: #F1F5F9;

  /* ── Text ── */
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --text-inverse: #FFFFFF;

  /* ── Borders ── */
  --border: #E2E8F0;
  --border-strong: #CBD5E1;

  /* ── Shadows (tinted, not pure black) ── */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.07), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
  --shadow-focus: 0 0 0 3px rgba(79, 70, 229, 0.18);
  --shadow-accent-focus: 0 0 0 3px rgba(var(--accent-rgb, 79, 70, 229), 0.18);

  /* ── Radius ── */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* ── Typography ── */
  --font-sans: 'Inter', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-serif: 'Noto Serif KR', 'Georgia', serif;

  /* ── Font Sizes ── */
  --text-xs: 0.75rem;    /* 12px */
  --text-sm: 0.8125rem;  /* 13px */
  --text-base: 0.9375rem;/* 15px */
  --text-md: 1rem;       /* 16px */
  --text-lg: 1.125rem;   /* 18px */
  --text-xl: 1.25rem;    /* 20px */
  --text-2xl: 1.5rem;    /* 24px */
  --text-3xl: 1.875rem;  /* 30px */
  --text-4xl: 2.25rem;   /* 36px */

  /* ── Spacing ── */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* ── Transitions ── */
  --ease-out: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 150ms;
  --dur-normal: 250ms;
  --dur-slow: 400ms;

  /* ── Z-index scale ── */
  --z-base: 1;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal-backdrop: 300;
  --z-modal: 400;
  --z-toast: 500;
}

/* ═══ DARK MODE ═══ */
body.dark-mode {
  --primary: #4255ff;
  --primary-hover: #5d6eff;
  --primary-light: #1b1a47;
  --primary-soft: #2e3856;
  --accent: #4255ff;
  --accent-light: #1b1a47;
  --success: #18ae79;
  --success-light: #0d3c2c;
  --warning: #ffb020;
  --warning-light: #4c3200;
  --danger: #ff5454;
  --danger-light: #4c1111;
  --bg-body: #0a092d;
  --bg-panel: #121238;
  --bg-card: #2e3856;
  --bg-input: #1b1a47;
  --bg-hover: #212c4d;
  --text-primary: #ffffff;
  --text-secondary: #cbd5e1;
  --text-muted: #939bb4;
  --text-inverse: #0a092d;
  --border: #1d1d42;
  --border-strong: #2e3856;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.45);
}

/* ═══ 2. CSS RESET & BASE ═══ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-body);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, video, svg { display: block; max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ═══ 3. TYPOGRAPHY ═══ */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
}

h1 { font-size: var(--text-3xl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-2xl); letter-spacing: -0.015em; }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); font-weight: 600; }
h6 { font-size: var(--text-base); font-weight: 600; }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-primary-color { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* ═══ 4. LAYOUT ═══ */
.ds-container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 var(--sp-5);
}

.ds-container--narrow { max-width: 680px; }
.ds-container--wide { max-width: 1080px; }

.ds-flex { display: flex; }
.ds-flex-col { display: flex; flex-direction: column; }
.ds-flex-center { display: flex; align-items: center; justify-content: center; }
.ds-flex-between { display: flex; align-items: center; justify-content: space-between; }
.ds-flex-wrap { display: flex; flex-wrap: wrap; }
.ds-gap-1 { gap: var(--sp-1); }
.ds-gap-2 { gap: var(--sp-2); }
.ds-gap-3 { gap: var(--sp-3); }
.ds-gap-4 { gap: var(--sp-4); }
.ds-gap-6 { gap: var(--sp-6); }

.hidden { display: none !important; }

/* ═══ 5. TOPBAR / NAVIGATION ═══ */
.ds-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(255, 255, 255, 0.88);
}
body.dark-mode .ds-topbar {
  background: rgba(30, 41, 59, 0.88);
}

.ds-topbar__title {
  font-size: var(--text-lg);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.ds-topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.ds-topbar__user {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  background: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
}

.ds-nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--dur-normal) var(--ease-out);
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
}
.ds-nav-link:hover {
  color: var(--primary);
  background: var(--primary-light);
}
.ds-nav-link.active {
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 600;
}

/* ═══ 6. BUTTONS ═══ */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.5;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--dur-normal) var(--ease-out);
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
}

.ds-btn:active {
  transform: scale(0.97);
}

.ds-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Primary */
.ds-btn--primary {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}
.ds-btn--primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

/* Accent */
.ds-btn--accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.ds-btn--accent:hover:not(:disabled) {
  filter: brightness(0.92);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

/* Secondary */
.ds-btn--secondary {
  background: var(--primary-light);
  color: var(--primary);
  border-color: transparent;
}
.ds-btn--secondary:hover:not(:disabled) {
  background: var(--primary-soft);
}

/* Outline */
.ds-btn--outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}
.ds-btn--outline:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* Ghost */
.ds-btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.ds-btn--ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Danger */
.ds-btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.ds-btn--danger:hover:not(:disabled) {
  background: #DC2626;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

/* Danger Outline */
.ds-btn--danger-outline {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.ds-btn--danger-outline:hover:not(:disabled) {
  background: var(--danger-light);
}

/* Icon button */
.ds-btn--icon {
  padding: var(--sp-2);
  min-width: 36px;
  min-height: 36px;
  border-radius: var(--radius-sm);
}

/* Size variants */
.ds-btn--sm {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-xs);
  border-radius: var(--radius-xs);
}
.ds-btn--lg {
  padding: var(--sp-3) var(--sp-6);
  font-size: var(--text-md);
  border-radius: var(--radius-md);
}

/* Pill */
.ds-btn--pill { border-radius: var(--radius-full); }

/* ═══ 7. CARDS ═══ */
.ds-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-md);
  transition: all var(--dur-normal) var(--ease-out);
}

.ds-card:hover {
  box-shadow: var(--shadow-lg);
}

.ds-card--interactive:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-soft);
}

.ds-card--flat {
  box-shadow: none;
  border: 1px solid var(--border);
}

.ds-card--accent {
  border-left: 3px solid var(--accent);
}

/* ═══ 8. FORM INPUTS ═══ */
.ds-input,
.ds-textarea,
.ds-select {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease-out);
  outline: none;
  line-height: 1.5;
}

.ds-input:focus,
.ds-textarea:focus,
.ds-select:focus {
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
  background: var(--bg-panel);
}

.ds-input::placeholder,
.ds-textarea::placeholder {
  color: var(--text-muted);
}

.ds-textarea {
  min-height: 80px;
  resize: vertical;
}

.ds-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.ds-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}

.ds-form-group {
  margin-bottom: var(--sp-4);
}

/* ═══ 9. TABS ═══ */
.ds-tabs {
  display: flex;
  gap: var(--sp-1);
  background: var(--bg-input);
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ds-tab {
  flex: 1;
  padding: var(--sp-2) var(--sp-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--dur-normal) var(--ease-out);
  white-space: nowrap;
  text-align: center;
}

.ds-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.ds-tab.active {
  background: var(--bg-panel);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ═══ 10. TOAST NOTIFICATIONS ═══ */
.ds-toast-container {
  position: fixed;
  top: var(--sp-5);
  right: var(--sp-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  pointer-events: none;
  max-width: 380px;
  width: calc(100% - var(--sp-10));
}

.ds-toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--bg-panel);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  pointer-events: auto;
  animation: dsToastIn 0.35s var(--ease-spring) forwards;
  overflow: hidden;
  position: relative;
}

.ds-toast::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.ds-toast--success::before { background: var(--success); }
.ds-toast--error::before { background: var(--danger); }
.ds-toast--warning::before { background: var(--warning); }
.ds-toast--info::before { background: var(--primary); }

.ds-toast__icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
}

.ds-toast__content {
  flex: 1;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-primary);
}

.ds-toast__close {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: var(--text-md);
  padding: 2px;
  line-height: 1;
  transition: color var(--dur-fast) var(--ease-out);
}
.ds-toast__close:hover { color: var(--text-primary); }

.ds-toast.removing {
  animation: dsToastOut 0.3s var(--ease-out) forwards;
}

@keyframes dsToastIn {
  from { opacity: 0; transform: translateX(30px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes dsToastOut {
  from { opacity: 1; transform: translateX(0) scale(1); max-height: 200px; margin-bottom: 0; }
  to   { opacity: 0; transform: translateX(30px) scale(0.95); max-height: 0; margin-bottom: calc(var(--sp-3) * -1); padding-top: 0; padding-bottom: 0; }
}

/* ═══ 11. MODAL / CONFIRM DIALOG ═══ */
.ds-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--sp-4);
  opacity: 0;
  visibility: hidden;
  transition: all var(--dur-normal) var(--ease-out);
}

.ds-modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.ds-modal {
  background: var(--bg-panel);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  transform: translateY(20px);
  transition: transform var(--dur-slow) var(--ease-spring);
  padding: var(--sp-6);
}

.ds-modal-backdrop.open .ds-modal {
  transform: translateY(0);
}

.ds-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-5);
}

.ds-modal__title {
  font-size: var(--text-lg);
  font-weight: 700;
}

.ds-modal__close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--text-xl);
  color: var(--text-muted);
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease-out);
  line-height: 1;
}
.ds-modal__close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.ds-modal__body { margin-bottom: var(--sp-5); }

.ds-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
}

/* Confirm dialog specific */
.ds-confirm-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xl);
  margin-bottom: var(--sp-4);
}

.ds-confirm-icon--danger { background: var(--danger-light); }
.ds-confirm-icon--warning { background: var(--warning-light); }
.ds-confirm-icon--info { background: var(--primary-light); }

.ds-confirm-message {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: var(--sp-6);
}

/* ═══ 12. PROGRESS BAR ═══ */
.ds-progress {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.ds-progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent, var(--primary)));
  border-radius: var(--radius-full);
  transition: width var(--dur-slow) var(--ease-out);
  min-width: 0;
}

.ds-progress--lg { height: 10px; }
.ds-progress--sm { height: 4px; }

/* ═══ 13. BADGES ═══ */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  line-height: 1.5;
}

.ds-badge--primary { background: var(--primary-light); color: var(--primary); }
.ds-badge--success { background: var(--success-light); color: var(--success); }
.ds-badge--warning { background: var(--warning-light); color: #92400E; }
.ds-badge--danger { background: var(--danger-light); color: var(--danger); }
.ds-badge--neutral { background: var(--bg-input); color: var(--text-secondary); }
.ds-badge--accent { background: var(--accent-light); color: var(--accent); }

/* ═══ 14. LOADING / SKELETON ═══ */
.ds-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: dsSpin 0.7s linear infinite;
}
.ds-spinner--sm { width: 20px; height: 20px; border-width: 2px; }
.ds-spinner--lg { width: 44px; height: 44px; border-width: 4px; }

@keyframes dsSpin {
  to { transform: rotate(360deg); }
}

.ds-skeleton {
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--border) 50%, var(--bg-input) 75%);
  background-size: 200% 100%;
  animation: dsShimmer 1.5s infinite ease-in-out;
  border-radius: var(--radius-sm);
}

.ds-skeleton--text {
  height: 14px;
  margin-bottom: var(--sp-2);
  width: 80%;
}
.ds-skeleton--text:last-child { width: 60%; }

.ds-skeleton--title {
  height: 22px;
  width: 50%;
  margin-bottom: var(--sp-3);
}

.ds-skeleton--card {
  height: 120px;
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-4);
}

.ds-skeleton--avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
}

.ds-skeleton--btn {
  height: 36px;
  width: 100px;
  border-radius: var(--radius-sm);
}

@keyframes dsShimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Loading overlay */
.ds-loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 250, 252, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
}
body.dark-mode .ds-loading-overlay {
  background: rgba(15, 23, 42, 0.85);
}

/* ═══ 15. COMMUNITY SECTION BANNER ═══ */
.ds-community-banner {
  background: linear-gradient(135deg, var(--primary), #7C3AED);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  color: #fff;
  margin-bottom: var(--sp-4);
}
body.dark-mode .ds-community-banner {
  background: linear-gradient(135deg, #312E81, #4C1D95);
}
.ds-community-banner h3 { color: #fff; }
.ds-community-banner .ds-input {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.2);
  color: #fff;
}
.ds-community-banner .ds-input::placeholder { color: rgba(255,255,255,0.6); }
.ds-community-banner .ds-input:focus {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.4);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.15);
}

/* ═══ 16. STATS CARDS ═══ */
.ds-stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

.ds-stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  text-align: center;
  transition: all var(--dur-normal) var(--ease-out);
}
.ds-stat-card:hover {
  box-shadow: var(--shadow-md);
}

.ds-stat-card__value {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}
.ds-stat-card__label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 500;
  margin-top: var(--sp-1);
}

/* ═══ 17. SEARCH INPUT ═══ */
.ds-search {
  position: relative;
}
.ds-search__icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: var(--text-md);
}
.ds-search .ds-input {
  padding-left: 36px;
}

/* ═══ 18. EMPTY STATE ═══ */
.ds-empty {
  text-align: center;
  padding: var(--sp-12) var(--sp-6);
  color: var(--text-muted);
}
.ds-empty__icon {
  font-size: 48px;
  margin-bottom: var(--sp-4);
  opacity: 0.6;
}
.ds-empty__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}
.ds-empty__desc {
  font-size: var(--text-sm);
  max-width: 300px;
  margin: 0 auto;
}

/* ═══ 19. FILTER CHIPS ═══ */
.ds-chips {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

.ds-chip {
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-panel);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--dur-normal) var(--ease-out);
  white-space: nowrap;
}
.ds-chip:hover {
  border-color: var(--primary-soft);
  color: var(--primary);
  background: var(--primary-light);
}
.ds-chip.active {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}

/* ═══ 20. STREAK BANNER ═══ */
.ds-streak-banner {
  background: linear-gradient(135deg, #F59E0B, #EF4444);
  border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5);
  color: #fff;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}
.ds-streak-banner__icon { font-size: 36px; }
.ds-streak-banner__days {
  font-size: var(--text-3xl);
  font-weight: 800;
  line-height: 1;
}
.ds-streak-banner__label {
  font-size: var(--text-sm);
  opacity: 0.9;
}

/* ═══ 21. FLASHCARD ═══ */
.ds-flashcard-wrapper {
  perspective: 800px;
  cursor: pointer;
  margin: var(--sp-6) auto;
  max-width: 500px;
}

.ds-flashcard {
  position: relative;
  width: 100%;
  min-height: 220px;
  transition: transform 0.6s var(--ease-spring);
  transform-style: preserve-3d;
}

.ds-flashcard.is-flipped { transform: rotateY(180deg); }

.ds-flashcard__face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-8);
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: var(--text-xl);
  text-align: center;
  line-height: 1.5;
  word-break: break-word;
}

.ds-flashcard__back {
  transform: rotateY(180deg);
  background: var(--primary-light);
  border-color: var(--primary-soft);
}

.ds-flashcard__label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--sp-2);
}

.ds-flashcard__speak {
  position: absolute;
  top: 15px;
  right: 15px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 16px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--dur-fast);
}

.ds-flashcard__speak:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
  transform: scale(1.08);
}

/* ═══ 22. SCROLL ANIMATIONS ═══ */
.ds-fade-up {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}
.ds-fade-up.in-view {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger children */
.ds-stagger > .ds-fade-up:nth-child(1) { transition-delay: 0ms; }
.ds-stagger > .ds-fade-up:nth-child(2) { transition-delay: 60ms; }
.ds-stagger > .ds-fade-up:nth-child(3) { transition-delay: 120ms; }
.ds-stagger > .ds-fade-up:nth-child(4) { transition-delay: 180ms; }
.ds-stagger > .ds-fade-up:nth-child(5) { transition-delay: 240ms; }
.ds-stagger > .ds-fade-up:nth-child(6) { transition-delay: 300ms; }

/* ═══ 23. RESPONSIVE ═══ */
@media (min-width: 640px) {
  .ds-modal-backdrop {
    align-items: center;
    padding: var(--sp-6);
  }
  .ds-modal {
    border-radius: var(--radius-lg);
  }
}

@media (max-width: 768px) {
  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }

  .ds-topbar {
    padding: var(--sp-3) var(--sp-4);
  }
  .ds-topbar__title {
    font-size: var(--text-md);
  }
  .ds-container {
    padding: 0 var(--sp-4);
  }
}

@media (max-width: 480px) {
  .ds-container {
    padding: 0 var(--sp-3);
  }
  .ds-stats-bar {
    grid-template-columns: repeat(2, 1fr);
  }
  .ds-toast-container {
    right: var(--sp-3);
    left: var(--sp-3);
    max-width: none;
    width: auto;
  }
  .ds-btn--lg {
    padding: var(--sp-3) var(--sp-4);
    font-size: var(--text-sm);
  }
}

/* ═══ 24. MISC UTILITIES ═══ */
.ds-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

.ds-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ds-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* focus-visible for accessibility */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Ensure minimum touch targets */
button, [role="button"], a {
  min-height: 32px;
}

/* Print styles */
@media print {
  .ds-topbar, .ds-toast-container, .ds-modal-backdrop, .ds-footer { display: none !important; }
  body { background: #fff; }
}

/* ═══ 24. FOOTER ═══ */
.ds-footer {
  text-align: center;
  padding: var(--sp-6) var(--sp-5);
  margin: var(--sp-10) var(--sp-4) var(--sp-6);
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.7;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur-normal) var(--ease-out), box-shadow var(--dur-normal) var(--ease-out);
}
.ds-footer:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-xl);
}
.ds-footer p {
  margin: 0;
}
.ds-footer p + p {
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px dashed var(--border);
}
.ds-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  transition: color var(--dur-fast);
}
.ds-footer a:hover {
  text-decoration: underline;
  color: var(--primary-hover);
}

/* Khối credit nhà phát triển - khung gradient bo góc, viền sáng nổi bật */
.ds-footer-credit {
  margin-top: var(--sp-5);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #1E1B4B 0%, #2E1065 55%, #1E1B4B 100%);
  border: 1px solid rgba(129, 140, 248, 0.45);
  box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.08), var(--shadow-md);
  color: #E2E8F0;
  font-size: var(--text-sm);
  line-height: 1.9;
}
.ds-footer-credit__title {
  font-weight: 700;
  color: #F1F5F9;
}
.ds-footer-credit__title a {
  color: #93C5FD;
  font-weight: 700;
  text-decoration: none;
}
.ds-footer-credit__title a:hover {
  text-decoration: underline;
}
.ds-footer-credit__contact {
  margin-top: var(--sp-1);
  color: #CBD5E1;
  font-size: var(--text-xs);
}
.ds-footer-credit__contact a {
  color: #93C5FD;
  font-weight: 600;
  text-decoration: none;
}
.ds-footer-credit__contact a:hover {
  text-decoration: underline;
}
.ds-footer-credit__contact .sep {
  margin: 0 var(--sp-2);
  color: #4C5B7A;
}

/* ═══ 25. PORTAL LAYOUT (QUIZLET STYLE) ═══ */
.portal-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg-body);
}

.portal-sidebar {
  width: 240px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: var(--sp-6) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-sticky);
  transition: transform var(--dur-normal) var(--ease-out);
}

.portal-sidebar-brand {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: var(--sp-2);
}

.portal-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.portal-sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: all var(--dur-fast);
  width: 100%;
}

.portal-sidebar-nav .nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.portal-sidebar-nav .nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.portal-main {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.portal-topbar {
  height: 70px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.portal-topbar-left {
  display: flex;
  align-items: center;
  gap: 15px;
  flex: 1;
  max-width: 500px;
}

.portal-topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

/* Global Search Autocomplete styles */
.global-search-container {
  position: relative;
  width: 100%;
}

.global-search-input-wrapper {
  position: relative;
  width: 100%;
}

.global-search-input-wrapper input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: all var(--dur-fast);
}

.global-search-input-wrapper input:focus {
  border-color: var(--primary);
  background: var(--bg-panel);
  box-shadow: 0 0 0 3px rgba(66, 85, 255, 0.15);
}

.global-search-input-wrapper::before {
  content: '🔍';
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.6;
}

.global-search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  max-height: 350px;
  overflow-y: auto;
  display: none;
}

.global-search-item {
  padding: 12px 18px;
  cursor: pointer;
  transition: background var(--dur-fast);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.global-search-item:last-child {
  border-bottom: none;
}

.global-search-item:hover {
  background: var(--bg-hover);
}

.global-search-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.global-search-item-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}

.global-search-item-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* Horizontal scroll for Fresh Finds */
.fresh-finds-container {
  margin-bottom: var(--sp-8);
}

.fresh-finds-scroll {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  padding: 10px 0 20px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.fresh-finds-scroll::-webkit-scrollbar {
  height: 8px;
}
.fresh-finds-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.fresh-finds-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

.set-card-mini {
  flex: 0 0 280px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all var(--dur-normal) var(--ease-out);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 150px;
  box-shadow: var(--shadow-sm);
}

.set-card-mini:hover {
  transform: translateY(-4px);
  border-color: var(--primary-soft);
  box-shadow: var(--shadow-md);
}

.set-card-mini-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.4;
  word-break: break-word;
}

.set-card-mini-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.set-card-mini-creator {
  font-weight: 600;
  color: var(--text-secondary);
}

/* Responsive sidebar trigger */
.sidebar-trigger {
  display: none;
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-primary);
}

.portal-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-sticky) - 1);
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease-out);
}

@media (max-width: 900px) {
  .portal-sidebar {
    transform: translateX(-100%);
  }
  .portal-sidebar.open {
    transform: translateX(0);
  }
  .portal-main {
    margin-left: 0;
  }
  .sidebar-trigger {
    display: block;
  }
  .portal-topbar {
    padding: 0 var(--sp-4);
    gap: var(--sp-3);
  }
  .portal-topbar-left {
    max-width: none;
  }
  .portal-sidebar-backdrop.open {
    display: block;
    opacity: 1;
  }
  /* FIX: iOS Safari tự động zoom trang khi focus vào input/textarea/select
     có font-size < 16px, và không tự thu nhỏ lại sau khi rời ô nhập.
     Ép font-size tối thiểu 16px cho các ô nhập trên mobile để tránh zoom. */
  .ds-input, .ds-textarea, .ds-select,
  input[type="text"], input[type="search"], input[type="email"],
  input[type="password"], input[type="number"], input[type="tel"],
  textarea, select {
    font-size: 16px !important;
  }
}

@media (max-width: 480px) {
  .portal-topbar {
    padding: 0 var(--sp-3);
    height: 60px;
  }
  .portal-topbar-right .ds-btn {
    padding: 6px 10px !important;
    font-size: 12px !important;
  }
  .global-search-input-wrapper input {
    font-size: 13px;
  }
}