/* Thanh điều hướng chung (lib/app-nav.ts, components/AppNav.tsx): Đảo học, khu phụ huynh, trang giới thiệu Pika AI Coach.
   CSS thuần, nạp bằng <link>: Đảo học không có Tailwind.
   - Điện thoại (< 768px): thanh dưới đáy, ngón cái bé chạm tới; chữ ngắn dưới icon.
   - Tablet, laptop (>= 768px): sidebar trái thu gọn chỉ có icon (tên hiện khi rê chuột, trình đọc màn hình đọc đủ tên); nút
     mở rộng trên cùng kéo sidebar ra có chữ, nổi trên nội dung (trang không dịch chỗ), Esc / chạm ra ngoài / bấm lại thì thu.
     Cụm tài khoản dưới cùng. Logo để ở đầu từng trang.
   Thanh có [hidden] (bé đang học bài) thì trang không chừa chỗ. Trang khác đọc --pk-nav-w (bề rộng bên
   trái) và --pk-nav-b (chiều cao dưới đáy) để dời phần tử cố định của mình.
   Màu chép từ token Kẹo Kính (styles/keo-kinh/tokens.css; mỗi mục một màu mức, nhìn màu là biết đang ở đâu), viết thẳng vì
   trang Đảo học Cổ điển không nạp token Kẹo Kính. */

:root:has(.pk-nav:not([hidden])) { --pk-nav-w: 0px; --pk-nav-b: calc(68px + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 768px) { :root:has(.pk-nav:not([hidden])) { --pk-nav-w: 80px; --pk-nav-b: 0px; } }
:root:has(.pk-nav:not([hidden])) body { padding-left: var(--pk-nav-w); padding-bottom: var(--pk-nav-b); }

.pk-nav {
  --pkn-ink: #1b2030; --pkn-muted: #555c6f; --pkn-line: rgba(198, 204, 217, .8); --pkn-focus: #0f7fa0; --pkn-primary: #0b6f8c;
  --pkn-glass: rgba(255, 255, 255, .78); --pkn-card: #fff; --pkn-tray: rgba(30, 40, 80, .07);
  --pkn-font: var(--font-baloo, "Baloo 2"), var(--font-nunito, "Nunito"), system-ui, sans-serif;
  position: fixed; z-index: 30; box-sizing: border-box; display: flex; color: var(--pkn-ink); font-family: var(--pkn-font);
  background: var(--pkn-glass); -webkit-backdrop-filter: blur(18px) saturate(1.6); backdrop-filter: blur(18px) saturate(1.6);
  -webkit-tap-highlight-color: transparent;
}
.pk-nav[hidden] { display: none !important; }
.pk-nav *, .pk-nav *::before, .pk-nav *::after { box-sizing: border-box; }
.pk-nav svg:not(.pk-ic) { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round; }
/* icon dáng mascot (lib/nav-icons.ts): màu, viền nằm sẵn trong SVG; CSS chỉ đặt cỡ. Ô đang chọn: icon to hơn một nấc */
.pk-nav .pk-ic { width: 24px; height: 24px; flex: none; overflow: visible;
  transition: transform .25s cubic-bezier(.3, 1.6, .5, 1); }
.pk-nav a { text-decoration: none; color: inherit; }
.pk-nav button { font-family: inherit; line-height: inherit; color: inherit; background: none; border: 0; margin: 0; cursor: pointer; }
.pk-nav :focus-visible { outline: 3px solid var(--pkn-focus); outline-offset: 2px; }

.pk-nav-list { display: contents; }

/* mục: ô màu (icon) + chữ. Mỗi mục một màu mức: -100 nền ô, -400 ô đang chọn, -700 chữ (icon có màu riêng) */
.pk-nav-item { --c1: #e4e6ea; --c4: #bfc4cc; --c7: #555c6f;
  position: relative; display: flex; align-items: center; min-height: 48px; border-radius: 18px; color: var(--pkn-muted);
  font-weight: 700; line-height: 1.15; transition: background-color .2s, transform .25s cubic-bezier(.3, 1.6, .5, 1); }
.pk-nav-item[data-nav="today"] { --c1: #f6e3a8; --c4: #dfb955; --c7: #8a5a12; }
.pk-nav-item[data-nav="quest"] { --c1: #e5dbff; --c4: #9775fa; --c7: #5f3dc4; }
.pk-nav-item[data-nav="home"] { --c1: #f7cdb0; --c4: #e3976a; --c7: #8c4119; }
.pk-nav-item[data-nav="coach"] { --c1: #bfddf3; --c4: #68acdb; --c7: #1d5c8c; }
.pk-nav-item[data-nav="parent"] { --c1: #bfe6cf; --c4: #6dbd91; --c7: #1f6b45; }
.pk-nav-mebtn { --c1: #f6e3a8; --c4: #dfb955; --c7: #8a5a12; }
.pk-nav-tile { display: grid; place-items: center; flex: none; border-radius: 14px; background: var(--c1); color: var(--c7);
  overflow: hidden; transition: background-color .2s, color .2s, transform .25s cubic-bezier(.3, 1.6, .5, 1); }
/* hình đại diện của bé: ô tròn có viền màu, hình lấp đầy (ô vuông nền vàng lộ góc quanh hình tròn trông như lỗi) */
.pk-nav-tile:has(> svg:not([viewBox="0 0 24 24"])) { border-radius: 999px; background: #fff; box-shadow: 0 0 0 2px var(--c4, #dfb955); }
.pk-nav-tile > svg:not([viewBox="0 0 24 24"]) { width: 100%; height: 100%; }
/* chạm vào icon / hình đại diện bên trong vẫn là chạm vào nút (hình SVG nhiều lớp không cướp chạm) */
.pk-nav-item > *, .pk-nav-toggle > * { pointer-events: none; }
.pk-nav-item:hover { background: var(--pkn-tray); }
.pk-nav-item:active .pk-nav-tile { transform: scale(.92); }
.pk-nav-item[aria-current="page"] { color: var(--c7); }
/* đang chọn (không chỉ đổi màu): ô đậm màu mức, viền trắng trong như kẹo, nhấc lên có bóng, icon to hơn, chữ đậm hơn;
   sidebar thêm vạch bên trái */
.pk-nav-item[aria-current="page"] .pk-nav-tile { background: var(--c4); color: #fff; transform: translateY(-1px);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85), 0 6px 14px -6px var(--c7); }
.pk-nav-item[aria-current="page"] .pk-ic { transform: scale(1.12); }
.pk-nav-item[aria-current="page"] .pk-nav-l, .pk-nav-item[aria-current="page"] .pk-nav-s { font-weight: 800; }
.pk-nav-l, .pk-nav-s { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-nav-l { display: none; }

/* ---------- Điện thoại: thanh dưới đáy ---------- */
@media (max-width: 767.98px) {
  .pk-nav { left: 0; right: 0; bottom: 0; height: var(--pk-nav-b, calc(68px + env(safe-area-inset-bottom, 0px)));
    padding: 6px max(6px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(6px, env(safe-area-inset-left, 0px));
    align-items: stretch; gap: 2px; border-top: 1px solid var(--pkn-line); box-shadow: 0 -12px 30px -18px rgba(20, 30, 60, .45); }
  .pk-nav-item, .pk-nav-me { flex: 1 1 0; min-width: 0; }
  /* chữ dưới icon 15px: chữ bé đọc được (luật Đảo học ≥ 15px); 320px vẫn đủ chỗ cho "Phụ huynh", tên bé dài thì "..." */
  .pk-nav-item { flex-direction: column; justify-content: center; gap: 3px; padding: 2px; font-size: 15px; text-align: center; }
  .pk-nav-me .pk-nav-item { width: 100%; height: 100%; }
  .pk-nav-tile { width: 52px; height: 32px; border-radius: 999px; }
  .pk-nav .pk-nav-tile > .pk-ic { width: 28px; height: 28px; }
  .pk-nav-item:not([aria-current="page"]) .pk-nav-tile { background: transparent; }
  .pk-nav-item:hover { background: transparent; }
  .pk-nav-mebtn .pk-nav-tile.pk-nav-avatar { width: 32px; background: var(--c1); }
  .pk-nav-s { max-width: 100%; }
}
/* 6 ô (có Vượt ải) trên điện thoại hẹp: mỗi ô ~55px, "Hôm nay", "Phụ huynh" bị cắt "…". Chữ xuống 2 dòng (vẫn 15px),
   thanh cao thêm 12px; trang đọc --pk-nav-b nên tự chừa đủ chỗ. Tên bé (ô cuối) vẫn một dòng + "…". */
@media (max-width: 479.98px) {
  :root:has(.pk-nav:not([hidden]) .pk-nav-item[data-nav="quest"]) {
    --pk-nav-b: calc(80px + env(safe-area-inset-bottom, 0px)); }
  .pk-nav:has(.pk-nav-item[data-nav="quest"]) .pk-nav-list .pk-nav-s { white-space: normal; line-height: 1.1; }
}

/* ---------- Tablet trở lên: sidebar trái, thu gọn (icon) / mở rộng (icon + chữ) ---------- */
.pk-nav-toggle { display: none; }
@media (min-width: 768px) {
  .pk-nav { top: 0; bottom: 0; left: 0; width: var(--pk-nav-w, 80px); flex-direction: column; align-items: stretch; gap: 6px;
    padding: max(14px, env(safe-area-inset-top, 0px)) 12px max(14px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    border-right: 1px solid var(--pkn-line); box-shadow: 10px 0 30px -22px rgba(20, 30, 60, .45);
    transition: width .24s cubic-bezier(.2, .8, .2, 1), box-shadow .24s; }
  .pk-nav-list { display: flex; flex-direction: column; gap: 6px; }
  .pk-nav-item { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 4px; font-size: 17px; text-align: left; }
  .pk-nav-tile { width: 48px; height: 48px; }
  .pk-nav .pk-nav-tile > .pk-ic { width: 32px; height: 32px; }
  .pk-nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 10px; bottom: 10px;
    width: 5px; border-radius: 0 999px 999px 0; background: var(--c7); }
  .pk-nav-s, .pk-nav-l { display: none; }
  .pk-nav-me { margin-top: auto; position: relative; }
  .pk-nav-me .pk-nav-item { width: 100%; }
  /* nút mở rộng: viên nhỏ trên cùng, mũi tên chỉ hướng sẽ kéo ra / thu vào */
  .pk-nav .pk-nav-toggle { display: flex; align-items: center; justify-content: center; width: 48px; height: 48px; margin: 0 4px 6px 4px;
    border-radius: 14px; background: var(--pkn-tray); color: var(--pkn-ink); }
  .pk-nav .pk-nav-toggle:hover { background: rgba(30, 40, 80, .13); }
  .pk-nav-toggle svg { transition: transform .24s; }
  .pk-nav[data-wide] { width: 240px; box-shadow: 18px 0 40px -18px rgba(20, 30, 60, .5); }
  .pk-nav[data-wide] .pk-nav-l { display: block; }
  .pk-nav[data-wide] .pk-nav-toggle svg { transform: rotate(180deg); }
  .pk-nav[data-wide] .pk-nav-item { padding-right: 12px; }
  .pk-nav[data-wide] .pk-nav-item[aria-current="page"] { background: color-mix(in srgb, var(--c1) 55%, transparent); }
}

/* màn thấp (điện thoại cầm ngang, >= 768px ngang nhưng chỉ ~360-420px cao): sidebar gọn lại cho vừa bốn mục, không bị cắt */
@media (min-width: 768px) and (max-height: 440px) {
  .pk-nav { gap: 2px; padding-top: max(8px, env(safe-area-inset-top, 0px)); padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
  .pk-nav-list { gap: 2px; }
  .pk-nav-item { padding-top: 2px; padding-bottom: 2px; }
  .pk-nav-tile { height: 40px; }
  .pk-nav .pk-nav-toggle { height: 44px; margin-bottom: 2px; }
}

/* ---------- Cụm tài khoản: bảng nhỏ (Đổi bạn, Ngôn ngữ, Đăng xuất...) ---------- */
.pk-nav-pop { position: absolute; z-index: 1; display: flex; flex-direction: column; gap: 4px; width: 300px; padding: 10px;
  background: var(--pkn-card); border-radius: 22px; color: var(--pkn-ink);
  box-shadow: 0 18px 40px -16px rgba(20, 30, 60, .5), 0 0 0 1px rgba(20, 30, 60, .06); font-family: var(--pkn-font);
  animation: pk-nav-pop .22s cubic-bezier(.3, 1.6, .5, 1); }
.pk-nav-pop[hidden] { display: none !important; }
@media (min-width: 768px) { .pk-nav-pop { left: calc(100% + 22px); bottom: 0; } }
@media (max-width: 767.98px) {
  /* thanh có backdrop-filter nên là khung chứa của bảng: đặt theo mép trên của thanh */
  .pk-nav-pop { right: max(10px, env(safe-area-inset-right, 0px)); bottom: calc(100% + 8px); width: min(300px, calc(100vw - 20px)); }
}
@keyframes pk-nav-pop { from { opacity: 0; transform: translateY(6px) scale(.97); } }
@media (prefers-reduced-motion: reduce) { .pk-nav, .pk-nav-pop, .pk-nav-item, .pk-nav-tile, .pk-nav-toggle svg { animation: none; transition: none; } }

.pk-nav-pophead { display: flex; align-items: center; gap: 10px; padding: 4px 6px 8px; }
.pk-nav-pophead .pk-nav-tile { width: 44px; height: 44px; border-radius: 14px; --c1: #f6e3a8; --c4: #dfb955; --c7: #8a5a12; }
.pk-nav-pophead strong { display: block; font-size: 17px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-nav-pophead small { display: block; font-size: 15px; font-weight: 700; color: var(--pkn-muted); }
.pk-nav-link { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 0 12px; border-radius: 14px;
  font-size: 16px; font-weight: 700; text-align: left; }
.pk-nav-link:hover { background: var(--pkn-tray); }
.pk-nav-link .pk-ic { width: 24px; height: 24px; }
.pk-nav-sep { height: 1px; margin: 4px 6px; background: var(--pkn-line); }
.pk-nav-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; padding: 0 6px 0 12px;
  font-size: 15px; font-weight: 700; color: var(--pkn-muted); white-space: nowrap; }
/* chữ trong hàng (Giao diện, Cổ điển, Kẹo Kính) không xuống dòng: bảng rộng 300px vừa cả nhãn lẫn hai nút */
.pk-nav-seg { flex: none; display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--pkn-tray); }
.pk-nav-seg button { min-width: 44px; min-height: 44px; padding: 0 10px; border-radius: 999px; font-size: 15px; font-weight: 800; color: var(--pkn-muted); }
.pk-nav-seg button[aria-pressed="true"] { background: var(--pkn-card); color: var(--pkn-ink); box-shadow: 0 2px 6px -2px rgba(20, 30, 60, .35); }
.pk-nav .pk-nav-cta { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 48px; border-radius: 999px;
  background: var(--pkn-primary); color: #fff; font-size: 17px; font-weight: 800; }
.pk-nav .pk-nav-ghost { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; border-radius: 999px;
  background: var(--pkn-tray); color: var(--pkn-ink); font-size: 17px; font-weight: 800; }
.pk-nav-ask p { margin: 4px 6px 12px; font-size: 15px; line-height: 1.4; color: var(--pkn-muted); font-family: var(--font-nunito, "Nunito"), system-ui, sans-serif; }
.pk-nav-ask strong { display: block; margin-bottom: 2px; font: 800 18px/1.3 var(--pkn-font); color: var(--pkn-ink); }
.pk-nav-askbtns { display: flex; gap: 8px; }
.pk-nav-hint { margin: 2px 6px 6px; font-size: 15px; line-height: 1.4; color: var(--pkn-muted); font-family: var(--font-nunito, "Nunito"), system-ui, sans-serif; }

@media print { .pk-nav { display: none !important; } :root body { padding: 0 !important; } }
