/*
 * Gelasio — serif tự host, metric tương thích Georgia nên bố cục không xê dịch.
 *
 * Lý do đổi: Georgia bản Windows không có khối Latin Extended Additional
 * (U+1E00–1EFF), tức là không có ầ ệ ộ ữ… Trình duyệt dò font theo TỪNG KÝ TỰ,
 * nên "Trần" bị vẽ bằng hai font khác nhau và hở ra một khoảng ở chữ có dấu.
 * Một font mang đủ tiếng Việt là cách duy nhất để mọi máy hiện giống nhau.
 *
 * File đã cắt còn Latin + tiếng Việt, dạng biến thiên 400–700 nên chỉ một file
 * lo cả chữ thường lẫn chữ đậm. Bản nghiêng chỉ được tải khi trang có chữ nghiêng.
 */
@font-face {
  font-family: 'Gelasio';
  src: url('/fonts/gelasio.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Gelasio';
  src: url('/fonts/gelasio-italic.woff2') format('woff2');
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg: #fffdf9;
  --fg: #1a1815;
  --muted: #6b655c;
  --rule: #e6e0d6;
  --link: #9a4b1f;
  --measure: 48rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12110f;
    --fg: #ece7de;
    --muted: #9a9288;
    --rule: #2b2823;
    --link: #e0925e;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  /* Keep the scrollbar gutter on every page, otherwise short pages render
     ~15px wider than long ones and the nav jumps sideways between them. */
  scrollbar-gutter: stable;
  overflow-y: scroll;
}

body {
  margin: 0;
  padding: 4rem 1.5rem 6rem;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.65 Gelasio, ui-serif, Georgia, "Times New Roman", serif;
}

main {
  max-width: var(--measure);
  margin: 0 auto;
}

h1 {
  margin: 0 0 0.35rem;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h2 {
  margin: 3rem 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
}

p {
  margin: 0 0 1.1rem;
}

a {
  color: var(--link);
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration: none;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.92rem;
}

.masthead {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  min-height: 3.5rem;
  margin-bottom: 1.25rem;
}

.intro {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: 0 2.4rem;
  align-items: start;
}

.intro-text p:last-child {
  margin-bottom: 0;
}

.portrait-link {
  display: block;
  cursor: zoom-in;
}

.portrait {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: var(--rule);
  transition: opacity 0.2s;
}

.portrait-link:hover .portrait {
  opacity: 0.88;
}

/* Click-to-enlarge, no JavaScript: the overlay shows while it is the :target */
.lightbox {
  display: none;
}

.lightbox:target {
  display: grid;
  position: fixed;
  inset: 0;
  z-index: 50;
  place-items: center;
  padding: 1.5rem;
  /* Nếu vì lý do gì đó nội dung vẫn cao hơn khung — điện thoại đang phóng to,
     thanh địa chỉ trồi lên — thì cuộn được, chứ không mất hút. */
  overflow: auto;
  overscroll-behavior: contain;
  background: rgb(0 0 0 / 0.88);
}

.lightbox-bg {
  position: absolute;
  inset: 0;
  cursor: zoom-out;
}

.lightbox picture {
  position: relative;
  display: contents;
}

.lightbox img {
  position: relative;
  max-width: min(100%, 620px);
  max-height: 88vh;
  /* svh = khung khi thanh công cụ đang hiện. Trình duyệt cũ bỏ qua dòng này. */
  max-height: 82svh;
  width: auto;
  height: auto;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  text-decoration: none;
  opacity: 0.7;
}

.lightbox-close:hover {
  opacity: 1;
}

/* Photo gallery — an entry title opens a set of photos, one overlay per photo,
   each linking on to the next. Same :target trick as the portrait, so clicking
   through the photos still works with JavaScript switched off. */
.gallery-link {
  color: inherit;
  text-decoration-color: var(--rule);
  text-underline-offset: 3px;
  cursor: zoom-in;
}

.gallery-link:hover {
  color: var(--link);
  text-decoration-color: currentColor;
}

.gallery-count {
  margin-left: 0.5rem;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  white-space: nowrap;
}

.gallery-count::before {
  content: "· ";
}

/* When the title already links to a case study, the count opens the gallery. */
a.gallery-count {
  color: var(--muted);
  text-decoration-color: var(--rule);
  text-underline-offset: 3px;
}

a.gallery-count:hover {
  color: var(--link);
}

.gallery:target {
  place-items: center;
  padding: 1.5rem;
}

.gallery-panel {
  position: relative;
  width: min(100%, 900px);
  text-align: center;
}

.gallery-title {
  margin: 0 0 0.9rem;
  color: #fff;
  font-size: 1.15rem;
  font-weight: 600;
}

.gallery-panel figure {
  margin: 0;
}

.gallery-shot {
  display: block;
  cursor: e-resize;
}

.gallery-panel img {
  display: block;
  margin: 0 auto;
  /* .lightbox img caps a single photo at 620px — a gallery shot wants the panel. */
  max-width: 100%;
  max-height: 68vh;
  max-height: 64svh;
  width: auto;
  height: auto;
  border-radius: 8px;
  background: rgb(255 255 255 / 0.06);
}

.gallery-panel figcaption {
  margin-top: 0.7rem;
  color: rgb(255 255 255 / 0.68);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.86rem;
}

.gallery-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0.8rem 0 0;
}

.gallery-arrow {
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  text-decoration: none;
  opacity: 0.6;
  padding: 0 0.5rem;
}

.gallery-arrow:hover {
  opacity: 1;
}

.gallery-counter {
  color: rgb(255 255 255 / 0.6);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.gallery-hint {
  margin: 0.3rem 0 0;
  color: rgb(255 255 255 / 0.4);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
}

.lang {
  margin-left: auto;
  align-self: flex-start;
  flex: none;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.5rem;
  margin-bottom: 2.5rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--rule);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
}

nav a {
  color: var(--muted);
  text-decoration: none;
}

nav a:hover {
  color: var(--fg);
  text-decoration: underline;
}

nav a[aria-current="page"] {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-thickness: 1px;
}

.intro p:first-of-type {
  font-size: 1.08rem;
}

/* Work list: year on the left, everything else in one column. */
.entries {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* `> li` chứ không phải `li`: mục con trong .detail là <li> lồng bên trong,
   không được thừa hưởng lưới hai cột của mục cha. Các mục cách nhau bằng
   khoảng trắng, không kẻ ngang — đường kẻ duy nhất của trang nằm dưới nav. */
.entries > li {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0 1rem;
  padding-bottom: 1.15rem;
}

.entries > li:last-child {
  padding-bottom: 0;
}

.entries .when {
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  padding-top: 0.25rem;
}

.entries .what {
  margin: 0;
}

/* Gạch đầu dòng dưới tiêu đề, cho mục có nhiều việc rời nhau. */
.entries .detail {
  grid-column: 2;
  margin: 0.4rem 0 0;
  padding-left: 1.05rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.entries .detail li {
  padding: 0.12rem 0;
}

.entries .where {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

.links {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
}

footer {
  margin-top: 4rem;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
}

@media (max-width: 34rem) {
  body {
    padding-top: 2.5rem;
  }

  .entries > li {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  /* Đệm 1.5rem mỗi bên ăn mất 3rem của một màn 320px — thu lại cho ảnh rộng ra. */
  .lightbox:target {
    padding: 0.75rem;
  }

  .gallery-title {
    font-size: 1rem;
  }

  .entries .detail {
    grid-column: 1;
  }

  .entries .when {
    padding-top: 0;
  }
}

@media (max-width: 34rem) {
  .intro {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .portrait {
    order: -1;
    max-width: 260px;
  }
}

/* Bài viết. Trong bài, h2 quay lại làm tiêu đề mục bình thường chứ không
   phải nhãn chữ nhỏ in hoa như ở các trang khác. */
.prose h2 {
  margin: 2.5rem 0 0.75rem;
  color: var(--fg);
  font-family: Gelasio, ui-serif, Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.prose h3 {
  margin: 2rem 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.prose > :first-child {
  margin-top: 0;
}

.prose-list {
  margin: 0 0 1.1rem;
  padding-left: 1.15rem;
}

.prose-list li {
  padding: 0.15rem 0;
}

.prose blockquote {
  margin: 1.4rem 0;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  color: var(--muted);
}

.prose blockquote p {
  margin: 0;
}

/* Ảnh trong bài: ![chú thích](/photos/x.jpg) trên một dòng riêng thành figure.
   Chiều cao đặt auto để không méo, và ảnh không bao giờ rộng hơn cột chữ. */
.prose-figure {
  margin: 1.8rem 0;
}

.prose-figure img,
.prose-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  background: var(--rule);
}

.prose-img {
  margin: 1.4rem 0;
}

.prose-figure figcaption {
  margin-top: 0.5rem;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
  line-height: 1.5;
}

.prose pre {
  margin: 1.3rem 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  border-radius: 8px;
  background: var(--rule);
  font-size: 0.85rem;
  line-height: 1.55;
}

.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
}

.prose :not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--rule);
}

.prose pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.back {
  margin-top: 3rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
}

/* List 100 — numbered life list */
.list100 {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: goal;
}

.list100 li {
  counter-increment: goal;
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: 0 0.6rem;
  align-items: baseline;
  padding: 0.05rem 0;
  line-height: 1.45;
}

.list100 li::before {
  content: counter(goal);
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.progress {
  margin: 0 0 2rem;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.88rem;
}

.progress b {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
