/*
 * One Dark — trang bio công khai (Flask/Jinja). Một file duy nhất, không cần build.
 * Thay cho tailwind.css + custom.css + one-dark.css cũ.
 * Tài liệu: docs/21-design-system-one-dark.md · docs/24-responsive-fold.md
 *
 * Bố cục (mobile-first):
 *   1. Điện thoại dọc ............ 1 cột, rộng tối đa 480px
 *   2. Màn hẹp (< 360px) ......... màn ngoài máy gập (~280px): thu nhỏ avatar, khoảng cách
 *   3. Điện thoại ngang .......... (landscape, cao ≤ 560px): hồ sơ cột trái gọn, nội dung phải
 *   4. Máy gập mở / tablet ....... (≥ 600px): hồ sơ cố định trái 280px, nội dung phải
 *   5. Desktop ................... (≥ 1024px): 340px + nội dung, liên kết 2 cột
 *   6. Màn hình đôi .............. (viewport-segments): hồ sơ một nửa, nội dung nửa kia, né bản lề
 */

/* ---------- Font (OFL, tự host) ---------- */
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/BeVietnamPro-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/BeVietnamPro-Medium.woff2') format('woff2'); }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 600; font-display: swap; src: url('../fonts/BeVietnamPro-SemiBold.woff2') format('woff2'); }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/BeVietnamPro-Bold.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/JetBrainsMono-Regular.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/JetBrainsMono-Medium.woff2') format('woff2'); }

/* ---------- Token One Dark ---------- */
:root {
  color-scheme: dark;
  --deep: #181a1f;
  --inset: #1b1f23;
  --panel: #21252b;
  --base: #282c34;
  --raised: #2c313a;
  --hover: #323842;
  --selected: #3e4451;
  --border: #3a3f4b;
  --border-strong: #4b5263;
  --strong: #e6e8ec;
  --soft: #d7dae0;
  --text: #abb2bf;
  --muted: #9198a3;
  --comment: #7f848e;
  --faint: #5c6370;
  --on-accent: #1b1f23;
  --blue: #61afef;
  --green: #98c379;
  --yellow: #e5c07b;
  --red: #e06c75;
  --purple: #c678dd;
  --cyan: #56b6c2;
  --orange: #d19a66;
  --blue-rgb: 97 175 239;
  --green-rgb: 152 195 121;
  --yellow-rgb: 229 192 123;
  --red-rgb: 224 108 117;
  --purple-rgb: 198 120 221;
  --cyan-rgb: 86 182 194;
  --orange-rgb: 209 154 102;
  --accent: var(--blue);
  --accent-rgb: var(--blue-rgb);
  --accent-text: var(--accent); /* màu nhấn dùng làm CHỮ trên nền base: đỏ chỉ đạt 4.38:1 → đổi sang --soft */
  --scrim: rgb(12 14 17 / 0.72);
  --shadow-pop: 0 16px 40px rgb(0 0 0 / 0.5);
  --sans: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Khoảng cách với mép an toàn (tai thỏ khi xoay ngang, thanh home) */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --gutter: 16px;
  --tap: 44px;
}

/* ---------- Giao diện do chủ trang chọn (Dashboard › Trang bio › Giao diện = site.theme) ----------
 * <html data-accent data-card data-ring> do backend bio_theme() in ra; không cần build.
 * Chữ trên nền màu nhấn dùng --on-accent (#1b1f23): cả 7 màu đều đạt ≥ 4.5:1 (thấp nhất: red 4.9:1). */
[data-accent='green']  { --accent: var(--green);  --accent-rgb: var(--green-rgb); --accent-text: var(--accent); }
[data-accent='yellow'] { --accent: var(--yellow); --accent-rgb: var(--yellow-rgb); --accent-text: var(--accent); }
[data-accent='red']    { --accent: var(--red);    --accent-rgb: var(--red-rgb); --accent-text: var(--soft); }
[data-accent='purple'] { --accent: var(--purple); --accent-rgb: var(--purple-rgb); --accent-text: var(--accent); }
[data-accent='cyan']   { --accent: var(--cyan);   --accent-rgb: var(--cyan-rgb); --accent-text: var(--accent); }
[data-accent='orange'] { --accent: var(--orange); --accent-rgb: var(--orange-rgb); --accent-text: var(--accent); }

/* ---------- Nền tảng ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  background: var(--base);
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--base);
  color: var(--text);
  font: 400 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: anywhere;
}
body.is-locked { overflow: hidden; }
img, video, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
::selection { background: var(--selected); color: var(--strong); }
:where(a, button, input, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
[x-cloak] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--selected); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Khung chung: chừa mép an toàn ở cả 4 phía */
.shell {
  width: 100%;
  margin: 0 auto;
  padding:
    calc(var(--safe-t) + 24px)
    calc(var(--safe-r) + var(--gutter))
    calc(var(--safe-b) + 32px)
    calc(var(--safe-l) + var(--gutter));
  animation: od-enter .32s ease-out both;
}
/* Chỉ trượt nhẹ, không làm mờ: nội dung luôn thấy được kể cả khi animation bị hoãn (tab nền, bot chụp ảnh) */
@keyframes od-enter { from { transform: translateY(6px); } to { transform: none; } }
body.is-leaving .shell { opacity: 0; transform: translateY(4px); transition: opacity .15s ease, transform .15s ease; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 8px;
  font: 600 14px/1 var(--sans); white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, filter .15s ease;
}
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--secondary { background: var(--raised); color: var(--soft); border: 1px solid var(--border); font-weight: 500; }
.btn--secondary:hover { background: var(--selected); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: var(--tap); height: var(--tap); border-radius: 10px;
  color: var(--text); border: 1px solid transparent;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: var(--raised); border-color: var(--border); color: var(--strong); }
.icon-btn svg { width: 20px; height: 20px; }

/* Icon SVG tô màu bằng mask (icon trong static/icons là SVG đen) */
.mask-icon {
  display: block; width: 20px; height: 20px; background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.tone-0 { --tone: var(--blue-rgb); }
.tone-1 { --tone: var(--red-rgb); }
.tone-2 { --tone: var(--yellow-rgb); }
.tone-3 { --tone: var(--green-rgb); }
.tone-4 { --tone: var(--purple-rgb); }
.tone-5 { --tone: var(--orange-rgb); }
.tone-page { --tone: var(--cyan-rgb); }

/* =====================================================================
   TRẠNG THÁI: đang tải · lỗi · chuyển trang
   ===================================================================== */
@keyframes od-shimmer { 0% { background-position: -200px 0; } 100% { background-position: calc(100% + 200px) 0; } }
@keyframes od-indeterminate { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
@keyframes od-spin { to { transform: rotate(360deg); } }

/* Khung ảnh: shimmer khi chưa tải xong (JS ở base.html gắn .is-loaded / .is-broken) */
.media { position: relative; background-color: var(--raised); overflow: hidden; }
.js .media:not(.is-loaded):not(.is-broken) {
  background-image: linear-gradient(90deg, transparent 0, rgb(255 255 255 / .06) 50%, transparent 100%);
  background-size: 200px 100%; background-repeat: no-repeat;
  animation: od-shimmer 1.3s linear infinite;
}
.media img { transition: opacity .2s ease; }
.js .media:not(.is-loaded):not(.is-broken) img { opacity: 0; }
.media.is-broken img { display: none; }
/* Ảnh hỏng: icon "ảnh" mờ ở giữa */
.media.is-broken::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 28%; max-width: 32px; aspect-ratio: 1;
  background-color: var(--faint);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Crect x='3' y='5' width='18' height='14' rx='2'/%3E%3Cpath d='M3 15l5-4 4 3 3-2 6 5M3 3l18 18'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Crect x='3' y='5' width='18' height='14' rx='2'/%3E%3Cpath d='M3 15l5-4 4 3 3-2 6 5M3 3l18 18'/%3E%3C/svg%3E") center / contain no-repeat;
}
/* Avatar hỏng: chữ cái đầu của tên thay cho icon */
.media--avatar.is-broken::after {
  content: attr(data-initial); -webkit-mask: none; mask: none; background: none;
  width: auto; height: auto; aspect-ratio: auto; max-width: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--strong); font: 600 36px/1 var(--sans);
}

/* Đang chuyển trang: vạch chạy 2px trên cùng */
body.is-leaving::before {
  content: ''; position: fixed; top: env(safe-area-inset-top, 0px); left: 0; z-index: 100;
  width: 40%; height: 2px; background: var(--accent);
  animation: od-indeterminate 1s ease-in-out infinite;
}

/* Khối chờ (skeleton) dạng dòng chữ */
.sk { display: block; height: 12px; border-radius: 4px; background-color: var(--raised);
  background-image: linear-gradient(90deg, transparent 0, rgb(255 255 255 / .06) 50%, transparent 100%);
  background-size: 200px 100%; background-repeat: no-repeat; animation: od-shimmer 1.3s linear infinite; }
.sk-lines { display: flex; flex-direction: column; gap: 14px; }
.sk--title { height: 28px; width: 70%; border-radius: 6px; margin-bottom: 8px; }
.sk--h2 { height: 18px; width: 40%; margin-top: 16px; }

/* Vòng quay + thông báo trong lightbox */
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid rgb(255 255 255 / .15); border-top-color: var(--accent); animation: od-spin .8s linear infinite; }
.lightbox__state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); font-size: 14px; pointer-events: none; }
.lightbox__state .btn { pointer-events: auto; }

/* =====================================================================
   TRANG CHỦ
   ===================================================================== */
.bio { max-width: 480px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- Thẻ hồ sơ ---------- */
.profile { display: flex; flex-direction: column; align-items: center; text-align: center; }
.profile__avatar {
  display: block; flex-shrink: 0;
  width: 96px; height: 96px; border-radius: 50%;
  background: var(--selected);
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 4px var(--base);
  margin-bottom: 16px;
}
.profile__avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile__name { color: var(--strong); font-size: 26px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
.profile__subtitle { margin-top: 6px; color: var(--muted); font-size: 14.5px; max-width: 32ch; white-space: pre-line; }
.socials {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
  margin: 20px 0 0; padding: 0; list-style: none;
}
.social {
  display: flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); border-radius: 12px;
  background: var(--raised); border: 1px solid var(--border); color: var(--text);
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.social:hover { background: var(--selected); color: var(--strong); border-color: var(--border-strong); }
.social .mask-icon { width: 20px; height: 20px; }

/* ---------- Tab Profile / Gallery ---------- */
.tabs {
  position: sticky; top: calc(var(--safe-t) + 8px); z-index: 5;
  display: flex; gap: 4px; padding: 4px;
  background: rgb(27 31 35 / 0.88);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: 12px;
}
.tab {
  flex: 1 1 0; min-height: 40px; border-radius: 8px;
  color: var(--muted); font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background-color .15s ease, color .15s ease;
}
.tab:hover { color: var(--soft); }
.tab[aria-selected='true'] { background: var(--selected); color: var(--strong); font-weight: 600; }
.tab__count { font: 500 11px/1 var(--mono); color: var(--muted); }
.tab[aria-selected='true'] .tab__count { color: var(--text); }

/* role=tablist chỉ chứa tab; nút "Thêm" nằm cạnh (axe aria-required-children) — khung .tabs giữ bố cục */
.tabs__list { display: contents; }
/* Tab dư: menu "Thêm" (mặc định) hoặc cuộn ngang — chỉ trên điện thoại dọc */
.tabs__more { display: none; position: relative; flex: 1 1 0; }
.tab--more { width: 100%; gap: 4px; min-width: 0; padding: 0 6px; }
.tab--more span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab--more.is-current { background: var(--selected); color: var(--strong); font-weight: 600; }
.tabs__menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 10; min-width: 180px;
  display: flex; flex-direction: column; padding: 4px;
  background: var(--raised); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-pop);
}
.tabs__item { display: flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 12px; border-radius: 7px; color: var(--soft); font-size: 14px; text-align: left; }
.tabs__item:hover, .tabs__item.is-current { background: var(--selected); color: var(--strong); }
.tabs__item .tab__count { margin-left: auto; }
@media (max-width: 599px) {
  .tabs--more .tab--extra { display: none; }
  .tabs--more .tabs__more { display: block; }
  .tabs--scroll { overflow-x: auto; scrollbar-width: none; -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
  .tabs--scroll::-webkit-scrollbar { display: none; }
  .tabs--scroll .tab { flex: 0 0 auto; padding: 0 14px; }
}
[role=tabpanel]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 12px; }
.md-tab { padding: 4px 2px; }
[data-tab-type] { display: flex; flex-direction: column; gap: 12px; }
[data-tab-type="gallery"] { display: block; }
[data-tab-type][x-cloak] { display: none !important; }

/* ---------- Link card ---------- */
.links { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin: 0; padding: 0; list-style: none; }
.link-card {
  display: flex; align-items: center; gap: 14px; height: 100%;
  min-height: 64px; padding: 12px 14px;
  background: var(--raised); border: 1px solid var(--border); border-radius: 12px;
  color: var(--strong);
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease;
}
.link-card:hover { background: var(--hover); border-color: var(--border-strong); }
.link-card:active { transform: scale(0.99); }
.link-card__icon {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: rgb(var(--tone) / 0.14); color: rgb(var(--tone));
}
.link-card:hover .link-card__icon { background: rgb(var(--tone) / 0.22); }
.link-card__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.link-card__title { font-weight: 600; font-size: 15px; line-height: 1.35; }
.link-card__desc {
  color: var(--text); font-size: 13px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.link-card__end { flex-shrink: 0; color: var(--muted); transition: color .15s ease, transform .15s ease; }
.link-card:hover .link-card__end { color: var(--accent); }
.link-card:hover .link-card__end--arrow { transform: translate(1px, -1px); }
.badge {
  display: inline-flex; align-items: center; flex-shrink: 0;
  font: 500 10.5px/1 var(--mono); padding: 4px 6px; border-radius: 4px;
  color: var(--cyan); background: rgb(var(--cyan-rgb) / 0.06);
}

/* ---------- Gallery ---------- */
.gallery { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin: 0 calc(-1 * var(--gutter) + 4px); }
.tile {
  position: relative; display: block; width: 100%; aspect-ratio: 3 / 4; overflow: hidden;
  background: var(--raised); border-radius: 6px;
}
.tile img, .tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform .25s ease; }
.tile:hover img { transform: scale(1.03); }
.tile:focus-visible { outline-offset: -2px; }
.tile__meta { position: absolute; left: 6px; bottom: 6px; display: flex; align-items: center; gap: 6px; pointer-events: none; }
.tile__play { width: 30px; height: 30px; border-radius: 50%; background: rgb(0 0 0 / 0.6); color: #fff; display: flex; align-items: center; justify-content: center; }
.tile__play svg { width: 14px; height: 14px; margin-left: 2px; }
.tile__dur { padding: 3px 6px; border-radius: 4px; background: rgb(0 0 0 / 0.6); color: #fff; font: 500 11px/1 var(--mono); }
/* Tab "Dự án": dùng thẻ .item của /page, thêm link xem cả trang */
#panel-projects { display: flex; flex-direction: column; gap: 12px; }
.more-link {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 4px; color: var(--accent-text); font-size: 14px; font-weight: 500;
}
.more-link svg { width: 16px; height: 16px; transition: transform .15s ease; }
.more-link:hover svg { transform: translateX(2px); }
.empty { padding: 32px 0; text-align: center; font: italic 12.5px/1.6 var(--mono); color: var(--comment); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  background: rgb(15 17 21 / 0.96);
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
.lightbox__bar { flex-shrink: 0; display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 8px 0 16px; }
.lightbox__count { flex: 1; font: 500 12px/1 var(--mono); color: var(--muted); }
.lightbox__stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 0 8px; touch-action: pan-y; }
.lightbox__stage img, .lightbox__stage video {
  position: absolute; inset: 0 8px 12px; margin: auto;
  max-width: calc(100% - 16px); max-height: calc(100% - 12px); width: auto; height: auto;
  object-fit: contain; border-radius: 6px; user-select: none; -webkit-user-drag: none;
}
.lightbox__nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgb(24 26 31 / 0.8); border: 1px solid var(--border); color: var(--strong); }
.lightbox__nav:hover { background: var(--selected); }
.lightbox__nav--prev { left: 8px; }
.lightbox__nav--next { right: 8px; }
.lightbox__caption { flex-shrink: 0; max-height: 28vh; overflow-y: auto; padding: 12px 16px 16px; color: var(--soft); font-size: 14px; }
.lightbox__caption small { display: block; margin-top: 4px; font: 500 12px/1 var(--mono); color: var(--muted); }
.lightbox__text { margin: 0; white-space: pre-wrap; }
.lightbox__more { display: block; }
.lightbox__text.is-clamped { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lightbox__more { min-height: var(--tap); padding: 0 2px; color: var(--accent); font-size: 13.5px; font-weight: 600; }

/* =====================================================================
   TRANG CON: thanh trên (page / detail)
   ===================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: calc(var(--safe-t) + 56px);
  padding: var(--safe-t) calc(var(--safe-r) + 8px) 0 calc(var(--safe-l) + 8px);
  background: rgb(33 37 43 / 0.9);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--deep);
}
.topbar__title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--strong); font-size: 16px; font-weight: 600; }
.topbar__meta { font: 500 11.5px/1 var(--mono); color: var(--muted); padding-right: 8px; white-space: nowrap; }
.read-progress { position: absolute; left: 0; bottom: -1px; height: 2px; width: 0; background: var(--accent); transition: width .1s linear; }
.topbar ~ .shell { padding-top: 20px; }

/* ---------- /page/<id> ---------- */
.page { max-width: 560px; }
.search {
  display: flex; align-items: center; gap: 10px;
  height: var(--tap); padding: 0 12px; margin-bottom: 16px;
  background: var(--inset); border: 1px solid var(--border); border-radius: 10px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / 0.18); }
.search svg { width: 16px; height: 16px; flex-shrink: 0; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--strong); font: 15px/1 var(--sans); }
.search input::placeholder { color: var(--comment); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.items { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.item {
  position: relative; display: flex; align-items: flex-start; gap: 12px; padding: 12px;
  background: var(--raised); border: 1px solid var(--border); border-radius: 12px;
  transition: background-color .15s ease, border-color .15s ease;
}
.item[hidden] { display: none; }
.item--link:hover { background: var(--hover); border-color: var(--border-strong); }

/* ---------- Kiểu thẻ (site.theme.card_style) — áp cho thẻ liên kết + thẻ mục trang ----------
 * outline (mặc định): nền nổi + viền · solid: nền đặc, không viền · minimal: không nền, chỉ gạch chân */
[data-card='solid'] .link-card, [data-card='solid'] .item { background: var(--hover); border-color: transparent; }
[data-card='solid'] .link-card:hover, [data-card='solid'] .item--link:hover { background: var(--selected); border-color: transparent; }
[data-card='solid'] .badge { background: transparent; }
[data-card='minimal'] .link-card, [data-card='minimal'] .item {
  background: transparent; border-color: transparent; border-bottom-color: var(--border); border-radius: 0;
}
[data-card='minimal'] .link-card:hover, [data-card='minimal'] .item--link:hover {
  background: rgb(var(--accent-rgb) / 0.06); border-color: transparent; border-bottom-color: var(--border-strong); border-radius: 8px;
}
[data-card='minimal'] .links { gap: 2px; }

/* ---------- Màu nhấn trên tab đang chọn + viền avatar (site.theme.avatar_ring) ---------- */
.tab[aria-selected='true'], .tab--more.is-current { box-shadow: inset 0 -2px 0 var(--accent); }
[data-ring='off'] .profile__avatar { border-color: var(--border); }
.item__overlay { position: absolute; inset: 0; z-index: 1; border-radius: inherit; }
.item__num { flex-shrink: 0; min-width: 22px; padding-top: 2px; font: 500 12.5px/1.5 var(--mono); color: var(--orange); }
.item__img { flex-shrink: 0; width: 76px; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--selected); }
.item__img img { width: 100%; height: 100%; object-fit: cover; }
.item__body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item__title { color: var(--strong); font-weight: 600; font-size: 15px; line-height: 1.35; }
.item__desc { margin-top: 2px; color: var(--text); font-size: 13px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.item__file { margin-top: 6px; font: 11px/1.4 var(--mono); color: var(--green); }
.item__actions { position: relative; z-index: 2; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px;
  border-radius: 8px; font-size: 13px; font-weight: 600;
  background: var(--accent); color: var(--on-accent);
}
.chip:hover { filter: brightness(1.08); }
.chip--ext { background: var(--selected); color: var(--soft); font-weight: 500; }
.chip--ext:hover { background: var(--border-strong); filter: none; }
.chip svg { width: 13px; height: 13px; }

/* ---------- /d/<path>: bài đọc ---------- */
.article { max-width: 720px; }
.prose { color: var(--text); font-size: 16px; line-height: 1.75; }
.prose > :first-child { margin-top: 0; }
.prose h1 { margin: 0 0 .6em; color: var(--strong); font-size: 1.65em; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
.prose h2 { margin: 1.8em 0 .5em; color: var(--strong); font-size: 1.25em; line-height: 1.35; font-weight: 600; }
.prose h2::before { content: '## '; color: var(--red); font-family: var(--mono); font-weight: 500; }
.prose h3 { margin: 1.5em 0 .4em; color: var(--soft); font-size: 1.08em; font-weight: 600; }
.prose p { margin: 0 0 1em; }
.prose ul, .prose ol { margin: 0 0 1em; padding-left: 1.4em; }
.prose li { margin: .25em 0; }
.prose li::marker { color: var(--muted); }
.prose a { color: var(--blue); border-bottom: 1px solid rgb(var(--blue-rgb) / 0.4); }
.prose a:hover { border-bottom-color: currentColor; }
.prose strong { color: var(--strong); }
.prose blockquote { margin: 0 0 1em; padding: 10px 14px; border: 1px solid rgb(var(--yellow-rgb) / 0.3); border-left: 3px solid var(--yellow); background: rgb(var(--yellow-rgb) / 0.08); color: var(--soft); border-radius: 6px; }
.prose blockquote > :last-child { margin-bottom: 0; }
.prose code { font: .88em/1.5 var(--mono); background: var(--selected); color: var(--yellow); padding: .12em .4em; border-radius: 4px; }
.prose pre { margin: 0 0 1.2em; padding: 12px 14px; overflow-x: auto; background: var(--panel); border: 1px solid var(--deep); border-radius: 8px; -webkit-overflow-scrolling: touch; }
.prose pre code { display: block; padding: 0; background: transparent; color: var(--text); font-size: 13px; line-height: 1.65; white-space: pre; }
.prose img { height: auto; border-radius: 8px; margin: 1em 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.prose table { display: block; overflow-x: auto; border-collapse: collapse; margin: 0 0 1em; font-size: .92em; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose th { background: var(--panel); color: var(--strong); }
.tk-c { color: var(--comment); font-style: italic; }
.tk-s { color: var(--green); }
.tk-k { color: var(--purple); }
.tk-n { color: var(--orange); }
.tk-f { color: var(--blue); }

/* ---------- 404 / 500 ---------- */
.error { max-width: 440px; min-height: calc(100dvh - 56px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; }
.error__code { font: 600 96px/1 var(--mono); color: var(--selected); letter-spacing: -0.04em; user-select: none; }
.error__code .hl-red { color: var(--red); }
.error__code .hl-yellow { color: var(--yellow); }
.error__title { color: var(--strong); font-size: 20px; font-weight: 600; }
.error__text { color: var(--muted); font-size: 14px; }
.error__snippet { width: 100%; margin: 8px 0 0; padding: 12px 14px; text-align: left; white-space: pre-wrap; background: var(--panel); border: 1px solid var(--deep); border-radius: 8px; font: 12.5px/1.7 var(--mono); color: var(--text); }
.error__actions { display: flex; gap: 10px; width: 100%; margin-top: 12px; }
.error__actions > * { flex: 1 1 0; min-width: 0; }
.c-purple { color: var(--purple); } .c-green { color: var(--green); } .c-red { color: var(--red); } .c-comment { color: var(--comment); font-style: italic; }

/* =====================================================================
   THÍCH ỨNG
   ===================================================================== */

/* 2. Màn rất hẹp — màn ngoài máy gập (Galaxy Z Fold ~280–344px) */
@media (max-width: 359px) {
  :root { --gutter: 12px; }
  .profile__avatar { width: 76px; height: 76px; margin-bottom: 12px; }
  .profile__name { font-size: 22px; }
  .socials { gap: 8px; }
  .link-card { gap: 12px; padding: 10px 12px; }
  .link-card__icon { width: 36px; height: 36px; }
  .link-card .badge { display: none; }
  .tab { font-size: 13px; gap: 4px; }
  .tab__count { display: none; }
  .social { width: 40px; height: 40px; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .item__img { width: 60px; }
  .error__code { font-size: 72px; }
  .error__actions { flex-direction: column; }
}

/* 3. Điện thoại ngang — chiều cao thấp: không xếp chồng hồ sơ trên nội dung */
@media (orientation: landscape) and (max-height: 560px) {
  .shell { padding-top: calc(var(--safe-t) + 16px); padding-bottom: calc(var(--safe-b) + 16px); }
  .bio {
    max-width: 1040px;
    display: grid; grid-template-columns: minmax(200px, 34%) minmax(0, 1fr);
    column-gap: 24px; row-gap: 12px; align-items: start;
  }
  .bio > * { grid-column: 2; min-width: 0; }
  .bio > .profile {
    grid-column: 1; grid-row: 1 / span 5;
    position: sticky; top: calc(var(--safe-t) + 16px);
    max-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 32px); overflow-y: auto;
    padding: 20px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--border);
  }
  .profile__avatar { width: 64px; height: 64px; margin-bottom: 10px; box-shadow: 0 0 0 3px var(--panel); }
  .profile__name { font-size: 20px; }
  .profile__subtitle { font-size: 13px; }
  .socials { margin-top: 14px; gap: 6px; }
  .social { width: 40px; height: 40px; border-radius: 10px; }
  .tabs { top: calc(var(--safe-t) + 8px); }
  .links { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); margin: 0; }
  .topbar { min-height: calc(var(--safe-t) + 48px); }
  .topbar ~ .shell { padding-top: 14px; }
  .items { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .page { max-width: 960px; }
  .error { min-height: calc(100dvh - 48px); display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 32px; text-align: left; max-width: 720px; align-content: center; justify-items: start; }
  .error__code { grid-row: 1 / span 5; font-size: 88px; align-self: center; }
  .lightbox__bar { height: 44px; }
  .lightbox__caption { display: none; }
}

/* 4. Máy gập mở (~600–1023px) và tablet dọc: hồ sơ thành cột trái cố định */
@media (min-width: 600px) and (min-height: 561px) {
  :root { --gutter: 24px; }
  .shell { padding-top: calc(var(--safe-t) + 32px); }
  .bio {
    max-width: 1120px;
    display: grid; grid-template-columns: 280px minmax(0, 1fr);
    column-gap: 28px; row-gap: 16px; align-items: start;
  }
  .bio > * { grid-column: 2; min-width: 0; }
  .bio > .profile {
    grid-column: 1; grid-row: 1 / span 5;
    position: sticky; top: calc(var(--safe-t) + 32px);
    padding: 28px 20px 24px; border-radius: 16px; background: var(--panel); border: 1px solid var(--border);
  }
  .profile__avatar { box-shadow: 0 0 0 4px var(--panel); }
  .socials { gap: 8px; }
  .social { width: 40px; height: 40px; border-radius: 10px; }
  .tabs { max-width: 440px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; margin: 0; }
  .tile { border-radius: 8px; }
  .page { max-width: 960px; }
  .items { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
  .lightbox__nav--prev { left: 16px; }
  .lightbox__nav--next { right: 16px; }
}
@media (min-width: 960px) and (min-height: 561px) {
  .links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 5. Desktop */
@media (min-width: 1024px) and (min-height: 561px) {
  .shell { padding-top: 48px; }
  .bio { grid-template-columns: 340px minmax(0, 1fr); column-gap: 48px; }
  .bio > .profile { top: 48px; padding: 36px 28px 30px; }
  .profile__avatar { width: 112px; height: 112px; }
  .profile__name { font-size: 28px; }
  .social { width: var(--tap); height: var(--tap); }
  .gallery { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
}

/* 6. Màn hình đôi / gập có bản lề (Viewport Segments API) — không đặt nội dung lên bản lề */
@media (horizontal-viewport-segments: 2) {
  .bio {
    max-width: none;
    grid-template-columns:
      calc(env(viewport-segment-width 0 0) - var(--gutter) - var(--safe-l))
      calc(env(viewport-segment-width 1 0) - var(--gutter) - var(--safe-r));
    column-gap: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0) + 2 * var(--gutter));
  }
  .bio > .profile {
    min-height: calc(100dvh - 64px); display: flex; justify-content: center;
    background: transparent; border: 0;
  }
  /* Trang con: danh sách / bài đọc nằm trọn ở màn phải */
  .shell.page, .shell.article { max-width: none; padding-left: calc(env(viewport-segment-left 1 0) + var(--gutter)); }
  .items { grid-template-columns: minmax(0, 1fr); }
  .lightbox__stage { padding-right: calc(100vw - env(viewport-segment-right 0 0)); }
  .lightbox__nav--next { right: calc(100vw - env(viewport-segment-right 0 0) + 8px); }
}
@media (vertical-viewport-segments: 2) {
  /* Tư thế "laptop" (gập ngang): hồ sơ ở nửa trên, nội dung cuộn ở nửa dưới */
  .bio { display: flex; max-width: 640px; }
  .bio > .profile {
    position: static; display: flex; justify-content: center;
    min-height: calc(env(viewport-segment-height 0 0) - var(--safe-t) - 24px);
    margin-bottom: calc(env(viewport-segment-top 0 1) - env(viewport-segment-bottom 0 0) + 24px);
    background: transparent; border: 0;
  }
  .tabs { top: calc(env(viewport-segment-top 0 1) + 8px); }
}

/* Thiết bị chỉ có chuột: hover rõ hơn; cảm ứng: bỏ hiệu ứng hover dính */
@media (hover: none) {
  .link-card:hover, .item--link:hover { background: var(--raised); border-color: var(--border); }
  .link-card:active, .item--link:active { background: var(--hover); }
  .tile:hover img { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .topbar, .tabs, .socials, .lightbox { display: none !important; }
  body { background: #fff; color: #000; }
}
