/* ==========================================================================
   Lingo — base.css (WP0): biến thiết kế (tokens), font tự host, dark mode, reset, typography.
   Nguồn: design/tokens.css + phần "Reset & base" của design/components.css.
   Theme: <html data-theme="light|dark"> do server đặt từ cookie lingo-theme; không có => theo hệ thống.
   KHÔNG sửa trực tiếp từ gói khác — đề xuất qua yêu cầu thay đổi chung (08 §5).
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Fonts — tự host (OFL) trong wwwroot/fonts, tạo bằng tools/fonts/build_fonts.py
      (subset latin + latin-ext + vietnamese; Noto Sans SC = GB2312 cấp 1 + chữ trong content/zh).
      local() thử trước; thiếu file thì rơi về stack hệ thống bên dưới.
   -------------------------------------------------------------------------- */
@font-face {
  font-family: "Be Vietnam Pro";
  src: local("Be Vietnam Pro"), url("/fonts/be-vietnam-pro-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Be Vietnam Pro";
  src: local("Be Vietnam Pro Medium"), url("/fonts/be-vietnam-pro-500.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Be Vietnam Pro";
  src: local("Be Vietnam Pro SemiBold"), url("/fonts/be-vietnam-pro-600.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: local("Nunito"), url("/fonts/nunito-variable.woff2") format("woff2");
  font-weight: 600 900; font-style: normal; font-display: swap;
}
@font-face {
  /* IPA (ʃ θ ð ŋ ə ɪ ʊ) + pinyin dấu thanh (ā á ǎ à ǖ ǘ ǚ ǜ) */
  font-family: "Noto Sans";
  src: local("Noto Sans"), url("/fonts/noto-sans-ipa-400.woff2") format("woff2");
  font-weight: 400 600; font-style: normal; font-display: swap;
  unicode-range: U+0000-024F, U+0250-02AF, U+02B0-02FF, U+0300-036F, U+0370-03FF, U+1D00-1DBF, U+1E00-1EFF;
}
@font-face {
  /* Subset 3.755 chữ GB2312 cấp 1 (phủ HSK1–4) + chữ trong content/zh => ~560KB, chỉ tải khi trang có chữ Hán. */
  font-family: "Noto Sans SC";
  src: local("Noto Sans SC"), local("NotoSansSC-Regular"), url("/fonts/noto-sans-sc-hsk-400.woff2") format("woff2");
  font-weight: 400 700; font-style: normal; font-display: swap;
  unicode-range: U+3000-303F, U+4E00-9FFF, U+FF00-FFEF;
}

:root {
  /* ---------------- 2. Typography ---------------- */
  --font-display: "Nunito", "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  --font-body: "Be Vietnam Pro", "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  --font-han: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --font-pinyin: "Noto Sans", "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  --font-ipa: "Noto Sans", "Charis SIL", "Segoe UI", "Lucida Sans Unicode", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;

  /* Thang chữ (mobile); tăng 1 bậc ở >=768px bên dưới */
  --text-xs: 0.75rem;    /* 12 — chỉ cho nhãn phụ, không cho câu */
  --text-sm: 0.875rem;   /* 14 */
  --text-md: 1rem;       /* 16 — body tối thiểu */
  --text-lg: 1.125rem;   /* 18 */
  --text-xl: 1.375rem;   /* 22 — tiêu đề thẻ */
  --text-2xl: 1.75rem;   /* 28 — tiêu đề trang */
  --text-3xl: 2.25rem;   /* 36 */
  --text-word: 2.5rem;   /* 40 — từ tiếng Anh trên thẻ */
  --text-han: 4rem;      /* 64 — chữ Hán trên thẻ */
  --text-han-sm: 1.75rem;

  --leading-tight: 1.2;
  --leading-normal: 1.55;   /* tiếng Việt có dấu chồng 2 tầng => >=1.5 */
  --leading-han: 1.35;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 800;   /* Nunito ExtraBold cho tiêu đề */
  --weight-black: 900;

  /* ---------------- 3. Spacing (nhịp 4/8) ---------------- */
  --space-0: 0;
  --space-1: 0.25rem;  /* 4 */
  --space-2: 0.5rem;   /* 8 */
  --space-3: 0.75rem;  /* 12 */
  --space-4: 1rem;     /* 16 */
  --space-5: 1.25rem;  /* 20 */
  --space-6: 1.5rem;   /* 24 */
  --space-8: 2rem;     /* 32 */
  --space-10: 2.5rem;  /* 40 */
  --space-12: 3rem;    /* 48 */
  --space-16: 4rem;    /* 64 */

  --gutter: var(--space-4);
  --content-max: 40rem;      /* 640 — cột học tập */
  --content-wide: 72rem;     /* 1152 — dashboard desktop */

  /* ---------------- 4. Radius ---------------- */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;   /* input, nút */
  --radius-lg: 20px;   /* thẻ */
  --radius-xl: 28px;   /* thẻ từ vựng, modal */
  --radius-pill: 999px;

  /* ---------------- 5. Motion ---------------- */
  --dur-instant: 80ms;   /* phản hồi nhấn */
  --dur-fast: 150ms;
  --dur-base: 220ms;
  --dur-slow: 320ms;
  --dur-celebrate: 600ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.55, 0, 1, 0.45);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1); /* overshoot nhẹ — chỉ cho phần thưởng */
  --press-depth: 4px;     /* nút "khối": đáy dày 4px, nhấn lún xuống */

  /* ---------------- 6. Z-index ---------------- */
  --z-base: 0;
  --z-sticky: 10;
  --z-nav: 20;
  --z-overlay: 40;
  --z-modal: 50;
  --z-toast: 60;

  /* ---------------- 7. Icon sizes ---------------- */
  --icon-sm: 16px;
  --icon-md: 20px;
  --icon-lg: 24px;
  --icon-xl: 32px;
  --tap-min: 44px;

  /* ---------------- 8. Màu nguyên thuỷ (không dùng trực tiếp trong component) ---------------- */
  --indigo-50: #EEF0FF;  --indigo-100: #E0E3FF; --indigo-200: #C7CCFE;
  --indigo-300: #A5ADFC; --indigo-400: #818CF8; --indigo-500: #6366F1;
  --indigo-600: #4F46E5; --indigo-700: #4338CA; --indigo-800: #3730A3;
  --indigo-900: #312E81; --indigo-950: #1E1B4B;

  --green-100: #DCFCE7; --green-300: #86EFAC; --green-400: #4ADE80;
  --green-600: #16A34A; --green-700: #15803D; --green-800: #166534;
  --red-100: #FEE2E2;   --red-300: #FCA5A5;   --red-400: #F87171;
  --red-600: #DC2626;   --red-700: #B91C1C;   --red-800: #991B1B;
  --amber-100: #FEF3C7; --amber-300: #FCD34D; --amber-400: #FBBF24;
  --amber-500: #F59E0B; --amber-700: #B45309; --amber-800: #92400E;
  --orange-400: #FB923C; --orange-500: #F97316; --orange-600: #EA580C; --orange-700: #C2410C;
  --sky-400: #38BDF8;   --sky-700: #0369A1;
  --blue-300: #93C5FD;  --blue-400: #60A5FA; --blue-700: #1D4ED8;
  --purple-300: #D8B4FE; --purple-400: #C084FC; --purple-700: #7E22CE;
  --pink-300: #F9A8D4;  --pink-400: #F472B6;  --pink-700: #BE185D;
  --slate-400: #94A3B8; --slate-500: #64748B; --slate-600: #475569;

  color-scheme: light;
}

/* ==========================================================================
   9. Semantic tokens — LIGHT (mặc định)
   ========================================================================== */
:root,
[data-theme="light"] {
  --bg: #F5F6FB;
  --bg-elevated: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #EEF0F8;          /* nền phụ: tag, track tiến độ */
  --surface-3: #E3E6F2;
  --text: #1E1B4B;               /* 14.8:1 trên --bg */
  --text-muted: #555B78;         /* 6.4:1 trên --bg */
  --text-subtle: #5E6482;        /* 5.4:1 trên --bg, 5.1:1 trên --surface-2 */
  --text-inverse: #FFFFFF;
  --border: #DADEEC;
  --border-strong: #B9BFD6;      /* trang trí; viền input dùng --border-input (WCAG 1.4.11 >= 3:1) */
  --border-input: #8A90AB;       /* 3.2:1 trên trắng */
  --overlay: rgb(15 16 34 / 0.55);

  --primary: #4F46E5;            /* trắng trên nền này: 6.3:1 */
  --primary-hover: #4338CA;
  --primary-shadow: #3730A3;     /* đáy nút khối */
  --primary-soft: #EEF0FF;
  --primary-soft-text: #3730A3;
  --on-primary: #FFFFFF;
  --focus-ring: #4F46E5;

  --secondary: #FFFFFF;
  --secondary-border: #DADEEC;
  --secondary-shadow: #DADEEC;

  /* Phản hồi */
  --success: #15803D;            /* chữ/icon: 5.0:1 trên trắng */
  --success-bg: #DCFCE7;
  --success-strong: #15803D;     /* nền nút "Tiếp tục" khi đúng — chữ trắng 5.0:1 */
  --success-shadow: #14532D;
  --danger: #B91C1C;             /* 6.5:1 trên trắng */
  --danger-bg: #FEE2E2;
  --danger-strong: #DC2626;
  --danger-shadow: #991B1B;
  --warning: #92400E;
  --warning-bg: #FEF3C7;
  --info: #0369A1;
  --info-bg: #E0F2FE;

  /* Game hoá */
  --xp: #B45309;                 /* chữ XP: 5.0:1 trên trắng */
  --xp-fill: #F59E0B;            /* nền huy hiệu/ngôi sao (đi với chữ --text) */
  --streak: #C2410C;             /* chữ chuỗi ngày: 5.2:1 */
  --streak-fill: #F97316;
  --streak-bg: #FFEDD5;
  --freeze: #0369A1;             /* ngày nghỉ phép */
  --freeze-bg: #E0F2FE;
  --gold: #F59E0B; --silver: #94A3B8; --bronze: #C2410C;
  --locked: #9AA0B8;

  /* Ôn tập FSRS: Lại / Khó / Được / Dễ */
  --rate-again: #B91C1C;  --rate-again-bg: #FEE2E2;
  --rate-hard:  #92400E;  --rate-hard-bg:  #FEF3C7;
  --rate-good:  #15803D;  --rate-good-bg:  #DCFCE7;
  --rate-easy:  #1D4ED8;  --rate-easy-bg:  #DBEAFE;

  /* Thanh điệu tiếng Trung — CỐ ĐỊNH toàn app (chữ, pinyin, đồ thị, nút game) */
  --tone-1: #1D4ED8;   /* thanh 1 ā — ngang cao — xanh dương (6.7:1) */
  --tone-2: #B45309;   /* thanh 2 á — đi lên — hổ phách (5.0:1) */
  --tone-3: #7E22CE;   /* thanh 3 ǎ — xuống-lên — tím (7.6:1) */
  --tone-4: #BE185D;   /* thanh 4 à — đi xuống — hồng sẫm (6.0:1) */
  --tone-5: #555B78;   /* thanh nhẹ — xám */
  --tone-1-bg: #DBEAFE; --tone-2-bg: #FEF3C7; --tone-3-bg: #F3E8FF; --tone-4-bg: #FCE7F3; --tone-5-bg: #EEF0F8;

  /* Ngôn ngữ */
  --lang-en: #4F46E5;  --lang-en-bg: #EEF0FF;
  --lang-zh: #BE123C;  --lang-zh-bg: #FFE4E6;

  /* Shadow "clay-lite": 1 lớp mềm + viền đáy đặc cho vật nhấn được */
  --shadow-xs: 0 1px 2px rgb(30 27 75 / 0.06);
  --shadow-sm: 0 2px 6px rgb(30 27 75 / 0.07), 0 1px 2px rgb(30 27 75 / 0.05);
  --shadow-md: 0 8px 20px -6px rgb(30 27 75 / 0.14), 0 2px 6px rgb(30 27 75 / 0.06);
  --shadow-lg: 0 20px 40px -12px rgb(30 27 75 / 0.22), 0 4px 10px rgb(30 27 75 / 0.06);
  --shadow-inset: inset 0 2px 4px rgb(30 27 75 / 0.06);
  --shadow-card-base: 0 4px 0 #DADEEC;     /* "đáy" thẻ khối */

  color-scheme: light;
}

/* ==========================================================================
   10. DARK — áp khi [data-theme="dark"] hoặc theo hệ thống nếu chưa chọn
   ========================================================================== */
[data-theme="dark"] {
  --bg: #0E1020;
  --bg-elevated: #181B2E;
  --surface: #181B2E;
  --surface-2: #22263D;
  --surface-3: #2D3250;
  --text: #ECEEFB;               /* 16:1 trên --bg */
  --text-muted: #B0B5D1;         /* 9.0:1 */
  --text-subtle: #8E94B4;        /* 6.0:1 */
  --text-inverse: #0E1020;
  --border: #2F3450;
  --border-strong: #454B6E;
  --border-input: #6E759A;       /* 3.6:1 trên surface */
  --overlay: rgb(0 0 0 / 0.65);

  --primary: #818CF8;            /* nền nút, chữ tối trên: 6.6:1 */
  --primary-hover: #A5ADFC;
  --primary-shadow: #4F46E5;
  --primary-soft: #262A4F;
  --primary-soft-text: #C7CCFE;
  --on-primary: #0E1020;
  --focus-ring: #A5ADFC;

  --secondary: #22263D;
  --secondary-border: #3A4062;
  --secondary-shadow: #0A0C18;

  --success: #4ADE80;   --success-bg: #11301F; --success-strong: #4ADE80; --success-shadow: #15803D;
  --danger: #F87171;    --danger-bg: #3A1418;  --danger-strong: #F87171;  --danger-shadow: #B91C1C;
  --warning: #FCD34D;   --warning-bg: #3A2A0B;
  --info: #38BDF8;      --info-bg: #0B2A3D;

  --xp: #FBBF24;  --xp-fill: #FBBF24;
  --streak: #FB923C; --streak-fill: #FB923C; --streak-bg: #3A1F0E;
  --freeze: #38BDF8; --freeze-bg: #0B2A3D;
  --gold: #FBBF24; --silver: #CBD5E1; --bronze: #FB923C;
  --locked: #5A6080;

  --rate-again: #F87171; --rate-again-bg: #3A1418;
  --rate-hard:  #FCD34D; --rate-hard-bg:  #3A2A0B;
  --rate-good:  #4ADE80; --rate-good-bg:  #11301F;
  --rate-easy:  #60A5FA; --rate-easy-bg:  #0F2547;

  --tone-1: #60A5FA; --tone-2: #FBBF24; --tone-3: #C084FC; --tone-4: #F472B6; --tone-5: #A3A9C6;
  --tone-1-bg: #0F2547; --tone-2-bg: #3A2A0B; --tone-3-bg: #2C1647; --tone-4-bg: #3D1029; --tone-5-bg: #22263D;

  --lang-en: #A5ADFC; --lang-en-bg: #262A4F;
  --lang-zh: #FB7185; --lang-zh-bg: #3D1220;

  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-sm: 0 2px 6px rgb(0 0 0 / 0.35);
  --shadow-md: 0 8px 20px -6px rgb(0 0 0 / 0.55);
  --shadow-lg: 0 20px 40px -12px rgb(0 0 0 / 0.7);
  --shadow-inset: inset 0 2px 4px rgb(0 0 0 / 0.3);
  --shadow-card-base: 0 4px 0 #0A0C18;

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1020; --bg-elevated: #181B2E; --surface: #181B2E; --surface-2: #22263D; --surface-3: #2D3250;
    --text: #ECEEFB; --text-muted: #B0B5D1; --text-subtle: #8E94B4; --text-inverse: #0E1020;
    --border: #2F3450; --border-strong: #454B6E; --border-input: #6E759A; --overlay: rgb(0 0 0 / 0.65);
    --primary: #818CF8; --primary-hover: #A5ADFC; --primary-shadow: #4F46E5; --primary-soft: #262A4F;
    --primary-soft-text: #C7CCFE; --on-primary: #0E1020; --focus-ring: #A5ADFC;
    --secondary: #22263D; --secondary-border: #3A4062; --secondary-shadow: #0A0C18;
    --success: #4ADE80; --success-bg: #11301F; --success-strong: #4ADE80; --success-shadow: #15803D;
    --danger: #F87171; --danger-bg: #3A1418; --danger-strong: #F87171; --danger-shadow: #B91C1C;
    --warning: #FCD34D; --warning-bg: #3A2A0B; --info: #38BDF8; --info-bg: #0B2A3D;
    --xp: #FBBF24; --xp-fill: #FBBF24; --streak: #FB923C; --streak-fill: #FB923C; --streak-bg: #3A1F0E;
    --freeze: #38BDF8; --freeze-bg: #0B2A3D; --gold: #FBBF24; --silver: #CBD5E1; --bronze: #FB923C; --locked: #5A6080;
    --rate-again: #F87171; --rate-again-bg: #3A1418; --rate-hard: #FCD34D; --rate-hard-bg: #3A2A0B;
    --rate-good: #4ADE80; --rate-good-bg: #11301F; --rate-easy: #60A5FA; --rate-easy-bg: #0F2547;
    --tone-1: #60A5FA; --tone-2: #FBBF24; --tone-3: #C084FC; --tone-4: #F472B6; --tone-5: #A3A9C6;
    --tone-1-bg: #0F2547; --tone-2-bg: #3A2A0B; --tone-3-bg: #2C1647; --tone-4-bg: #3D1029; --tone-5-bg: #22263D;
    --lang-en: #A5ADFC; --lang-en-bg: #262A4F; --lang-zh: #FB7185; --lang-zh-bg: #3D1220;
    --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4); --shadow-sm: 0 2px 6px rgb(0 0 0 / 0.35);
    --shadow-md: 0 8px 20px -6px rgb(0 0 0 / 0.55); --shadow-lg: 0 20px 40px -12px rgb(0 0 0 / 0.7);
    --shadow-inset: inset 0 2px 4px rgb(0 0 0 / 0.3); --shadow-card-base: 0 4px 0 #0A0C18;
    color-scheme: dark;
  }
}

/* Desktop: chữ lớn hơn 1 bậc, gutter rộng hơn */
@media (min-width: 768px) {
  :root {
    --gutter: var(--space-6);
    --text-2xl: 2rem;
    --text-3xl: 2.75rem;
    --text-word: 3rem;
    --text-han: 5rem;
  }
}

/* Giảm chuyển động: giữ đổi màu/opacity, bỏ di chuyển & nảy */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 1ms; --dur-base: 1ms; --dur-slow: 1ms; --dur-celebrate: 1ms;
    --ease-spring: linear;
    --press-depth: 0px;
  }
}

/* ==========================================================================
   11. Reset & base (chuyển từ design/components.css §0)
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { color: var(--primary-hover); }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: var(--weight-bold); line-height: var(--leading-tight); margin: 0; letter-spacing: -0.01em; }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-xs); }
::selection { background: var(--primary-soft); color: var(--text); }

.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--space-2); top: -100px; z-index: var(--z-toast); background: var(--primary); color: var(--on-primary); padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm); }
.skip-link:focus { top: var(--space-2); }
