:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1c1d22;
  --muted: #5d6170;
  --border: #e2e4ec;
  --primary: #1f5fe0;
  --primary-hover: #174bb4;
  --primary-text: #ffffff;
  --new: #0f7a54;
  --new-bg: #e3f6ee;
  --warn-bg: #fff4e0;
  --warn-text: #7a4b00;
  --code-bg: #eef0f6;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 6px 24px rgb(0 0 0 / 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121317;
    --surface: #1c1e24;
    --text: #eceef3;
    --muted: #a3a8b8;
    --border: #2d3039;
    --primary: #6b97ff;
    --primary-hover: #8aaeff;
    --primary-text: #0b1020;
    --new: #5fd6a4;
    --new-bg: #143327;
    --warn-bg: #3a2c12;
    --warn-text: #ffd796;
    --code-bg: #262932;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

/* Thuộc tính hidden luôn ẩn, kể cả khi class có đặt display. */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

main { display: block; min-height: 60vh; }

/* Cân dòng: tiêu đề chia đều các dòng, đoạn văn tránh một chữ đứng lẻ ở dòng cuối. */
h1, h2, h3, .app-tagline, .post-title { text-wrap: balance; }
p, li, dd, blockquote { text-wrap: pretty; }
main:focus { outline: none; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }

a { color: var(--primary); }
a:focus-visible, button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, .chip:focus-within {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 8px;
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.12em 0.38em;
  border-radius: 5px;
  word-break: break-word;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--surface);
  padding: 8px 14px;
  border-radius: 8px;
  z-index: 20;
}
.skip-link:focus { left: 8px; }

.muted { color: var(--muted); }
.empty { padding: 32px 0; color: var(--muted); text-align: center; }

/* ---------- Header / footer ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 24px; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { font-size: 1.2rem; color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.brand img { display: block; }
.main-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.main-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
}
.main-nav a:hover { color: var(--text); background: var(--surface); }
.main-nav a[aria-current="page"] { color: var(--text); background: var(--surface); font-weight: 600; }
.header-search { margin-left: auto; }
.header-search input { width: 220px; }

input[type="search"], select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  min-height: 42px;
}
input[type="search"]::placeholder { color: var(--muted); }

.site-footer { margin-top: 48px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.92rem; }
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding-top: 24px; padding-bottom: 32px; }
.footer-inner p { margin: 0; }
.footer-inner nav { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-inner a { color: var(--muted); }

/* ---------- Sections ---------- */
.hero { padding: 64px 0 24px; text-align: center; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); line-height: 1.15; margin: 0 0 12px; letter-spacing: -0.02em; }
.lead { font-size: 1.15rem; color: var(--muted); margin: 0; }
.hero-search { display: flex; gap: 8px; max-width: 560px; margin: 28px auto 0; }
.hero-search input { flex: 1; min-height: 48px; font-size: 1.05rem; }
.notice {
  display: inline-block;
  margin-top: 20px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn-text);
}

.section { padding: 28px 20px; }
.section h1 { font-size: clamp(1.8rem, 4vw, 2.4rem); margin: 0 0 6px; letter-spacing: -0.02em; line-height: 1.2; }
.section h2 { font-size: 1.45rem; margin: 0 0 16px; letter-spacing: -0.01em; }
.section .app-name, .section .post-title { margin: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.section-head h2 { margin: 0; }
.page-lead { margin: 0 0 20px; font-size: 1.05rem; }

.breadcrumb ol { list-style: none; padding: 0; margin: 0 0 16px; display: flex; gap: 6px; font-size: 0.9rem; color: var(--muted); min-width: 0; }
.breadcrumb li { white-space: nowrap; }
.breadcrumb li:last-child { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.breadcrumb li + li::before { content: "/"; margin-right: 6px; color: var(--border); }
.breadcrumb a { color: var(--muted); }

/* ---------- Buttons, badges, chips, tags ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 18px;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: transparent; color: var(--primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); border-color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); padding-left: 10px; padding-right: 10px; }
.btn-ghost:hover { color: var(--text); }
.btn[aria-disabled="true"] { background: var(--border); color: var(--muted); pointer-events: none; }

.badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.5;
  padding: 1px 8px;
  border-radius: 999px;
  vertical-align: middle;
  letter-spacing: 0;
}
.badge-version { background: var(--border); color: var(--text); }
.badge-new { background: var(--new-bg); color: var(--new); }
.badge-draft { background: var(--warn-bg); color: var(--warn-text); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; padding: 0; border: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
}
.chip:hover { border-color: var(--primary); }
.chip[aria-pressed="true"], .chip:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.count { font-size: 0.8em; opacity: 0.75; }

.tag-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.tag {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  text-decoration: none;
}
.tag:hover { color: var(--primary); border-color: var(--primary); }
.tag-more { color: var(--primary); }
.tag-list-lg .tag { font-size: 1rem; padding: 6px 14px; background: var(--surface); }
.tag-cloud { margin: 0 0 24px; }

/* ---------- Filter / search bars ---------- */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 0 0 16px; }
.filter-search { flex: 1 1 320px; }
.filter-search input { width: 100%; }
.filter-sort { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.92rem; }
.result-count { margin: 0 0 14px; font-size: 0.92rem; }

/* ---------- App cards ----------
   Mỗi phần có vị trí và chiều cao cố định để các thẻ cạnh nhau luôn thẳng hàng. */
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 20px; }
.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.app-card:hover { border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); }
.app-head { display: flex; gap: 14px; align-items: center; min-width: 0; }
.app-head > a { flex: none; line-height: 0; }
.app-icon { width: 56px; height: 56px; border-radius: 13px; }
.app-head-text { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.app-name {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-name a { color: var(--text); text-decoration: none; }
.app-name a:hover { color: var(--primary); text-decoration: underline; }
.app-badges { display: flex; align-items: center; gap: 6px; min-height: 22px; flex-wrap: nowrap; }
.app-card .app-tagline {
  margin: 0;
  color: var(--text);
  line-height: 1.5;
  min-height: 3em;                       /* luôn chừa đủ 2 dòng */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.app-meta { margin: 0; color: var(--muted); font-size: 0.88rem; }
.app-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.app-card-actions { flex-direction: column; flex-wrap: nowrap; margin-top: auto; padding-top: 4px; }
.app-card-actions > .btn-primary { width: 100%; }
.app-actions-row { display: flex; gap: 8px; align-items: center; }
.app-actions-row .btn-secondary { flex: 1 1 auto; min-width: 0; padding-left: 12px; padding-right: 12px; }
.app-actions-row .btn-ghost { flex: none; }

/* ---------- App detail ---------- */
.update-banner {
  margin: 0 0 20px;
  padding: 16px 20px;
  border-radius: var(--radius);
  background: var(--new-bg);
  border: 1px solid color-mix(in srgb, var(--new) 40%, transparent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.update-banner p { margin: 0; }

.app-hero { display: flex; gap: 28px; align-items: center; margin: 8px 0 36px; }
.app-icon-lg { width: 128px; height: 128px; border-radius: 28px; flex: none; }
.app-hero-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.app-hero h1 { margin: 0; }
.app-hero .app-tagline { font-size: 1.15rem; margin: 0; color: var(--muted); }
.app-hero .app-actions { margin-top: 4px; }

.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start; }
.detail-main > section { margin-bottom: 28px; }
.detail-main h2 { font-size: 1.3rem; margin: 0 0 10px; }
.detail-main ul, .detail-main ol { padding-left: 22px; margin: 0; }
.detail-main li { margin: 4px 0; }
.detail-side {
  position: sticky;
  top: 88px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.side-title { font-size: 1rem !important; margin: 0 !important; }
.info-list { margin: 0; display: grid; gap: 0; }
.info-list div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.info-list div:first-child { padding-top: 0; }
.info-list dt { color: var(--muted); white-space: nowrap; }
.info-list dd { margin: 0; text-align: right; font-weight: 500; }
.info-block h3 { margin: 0 0 4px; font-size: 0.9rem; color: var(--muted); font-weight: 500; }
.info-block p { margin: 0; font-weight: 500; }
.changelog { list-style: none; padding: 0 !important; }
.changelog > li { border-left: 3px solid var(--border); padding: 0 0 16px 16px; margin: 0 !important; }
.changelog h3 { margin: 0 0 4px; font-size: 1.05rem; }
.changelog ul { margin: 0 0 6px !important; }
.sha { margin: 0; color: var(--muted); font-size: 0.78rem; }
.sha code { word-break: break-all; }
.related { margin-top: 40px; }

/* ---------- Posts ---------- */
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 20px; }
.post-list { display: grid; gap: 16px; max-width: 820px; }
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.post-cover img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.post-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.post-title { margin: 0; font-size: 1.15rem; line-height: 1.4; }
.post-title a { color: var(--text); text-decoration: none; }
.post-title a:hover { color: var(--primary); text-decoration: underline; }
.post-meta { margin: 0; color: var(--muted); font-size: 0.85rem; }
.post-summary { margin: 0; color: var(--muted); line-height: 1.55; }
.post-card .tag-list { margin-top: auto; padding-top: 6px; }
/* Dạng lưới (trang chủ, bài liên quan): giới hạn số dòng để các thẻ thẳng hàng. */
.post-grid .post-title {
  min-height: 2.8em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-grid .post-summary {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-list .post-title { font-size: 1.3rem; }

.post { max-width: 820px; }
.post-header { margin-bottom: 24px; display: flex; flex-direction: column; gap: 10px; }
.post-header h1 { margin: 0; }
.post-cover-lg { width: 100%; border-radius: var(--radius); margin-bottom: 24px; }

.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 0 0 28px;
}
.toc h2 { font-size: 1rem; margin: 0 0 8px; }
.toc ol { margin: 0; padding-left: 20px; }
.toc li { margin: 3px 0; }
.toc .toc-l3 { margin-left: 18px; list-style: circle; }

.post-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 40px; }
.post-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  font-weight: 600;
}
.post-nav .older { text-align: right; grid-column: 2; }
.post-nav span.muted { font-weight: 400; font-size: 0.88rem; }

.pagination { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 28px; }
.pagination ol { list-style: none; display: flex; gap: 6px; margin: 0; padding: 0; }
.pagination a, .pagination span[aria-current] {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  text-decoration: none;
}
.pagination span[aria-current] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }

/* ---------- Nội dung Markdown ---------- */
.prose { font-size: 1.05rem; line-height: 1.75; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose h2 { font-size: 1.5rem; margin: 2em 0 0.6em; line-height: 1.3; scroll-margin-top: 88px; }
.prose h3 { font-size: 1.2rem; margin: 1.6em 0 0.5em; scroll-margin-top: 88px; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose table, .prose pre { margin: 0 0 1.1em; }
.prose ul, .prose ol { padding-left: 1.5em; }
.prose li { margin: 0.3em 0; }
.prose img { max-width: 100%; height: auto; border-radius: 10px; }
.prose blockquote {
  margin-left: 0;
  padding: 12px 18px;
  border-left: 4px solid var(--primary);
  background: var(--surface);
  border-radius: 0 10px 10px 0;
  color: var(--muted);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose pre {
  background: var(--code-bg);
  padding: 14px 16px;
  border-radius: 10px;
  overflow-x: auto;
  line-height: 1.5;
}
.prose pre code { background: none; padding: 0; font-size: 0.9em; }
.prose table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.prose th { background: var(--surface); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.prose kbd {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85em;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
}

/* ---------- Tìm kiếm ---------- */
.search-form { margin-bottom: 8px; }
.search-results { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; max-width: 820px; }
.search-result {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.search-result img { border-radius: 11px; flex: none; }
.search-result h2 { font-size: 1.15rem; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search-result p { margin: 0; }
.search-meta { font-size: 0.88rem; margin-bottom: 4px !important; }

/* ---------- Hộp chọn phiên bản ---------- */
.versions-dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: min(80vh, 720px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
}
.versions-dialog[open] { display: flex; flex-direction: column; }
.versions-dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--border);
}
.dialog-head h2 { margin: 0 0 4px; font-size: 1.3rem; }
.dialog-head p { margin: 0; font-size: 0.92rem; }
.dialog-close {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.dialog-close:hover { background: var(--bg); }
.versions-list { list-style: none; margin: 0; padding: 8px 24px 20px; overflow-y: auto; }
.version-item { padding: 16px 0; border-bottom: 1px solid var(--border); }
.version-item:last-child { border-bottom: none; }
.version-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.version-head h3 { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.version-head .btn { margin-left: auto; min-height: 38px; padding: 6px 16px; }
.version-notes { margin: 8px 0 0; padding-left: 22px; }
.version-notes li { margin: 2px 0; }
.version-item .sha { margin-top: 6px; }
.version-empty { padding: 12px 0; }

.not-found { text-align: center; padding-top: 80px; padding-bottom: 80px; }
.not-found .app-actions { justify-content: center; }

/* ---------- Màn hình nhỏ ---------- */
@media (max-width: 860px) {
  .detail-layout { grid-template-columns: 1fr; }
  .detail-side { position: static; }
  /* Đầu trang gọn: logo, menu 1 hàng (vuốt ngang nếu dài), ô tìm kiếm; không dính khi cuộn. */
  .site-header { position: static; }
  .header-inner { gap: 8px 16px; padding-top: 10px; padding-bottom: 10px; }
  .main-nav {
    order: 3;
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -8px;
  }
  .main-nav::-webkit-scrollbar { display: none; }
  .main-nav a { white-space: nowrap; padding: 6px 10px; }
  .header-search { margin-left: auto; flex: 1 1 160px; }
  .header-search input { width: 100%; min-height: 38px; padding: 6px 12px; }
  .detail-side { top: auto; }
}
@media (max-width: 640px) {
  .app-hero { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 520px) {
  .app-grid, .post-grid { grid-template-columns: 1fr; }
  .hero-search { flex-direction: column; }
  .post-nav { grid-template-columns: 1fr; }
  .post-nav .older { grid-column: 1; }
  .app-hero { gap: 16px; }
  .app-icon-lg { width: 96px; height: 96px; border-radius: 22px; }
}
