/* CME Vietnam Engineering. Brand palette from the CME design guide:
   CME Blue #0B5FA5, Health Blue #1FA3E0, Light Blue #E8F4FB, Medical Gold #FFBC66.
   Health Blue is too light for text on white (under 3:1), so text and focus use CME Blue. */

:root {
  --cme-blue: #0b5fa5;
  --light-blue: #e8f4fb;
  --medical-gold: #ffbc66;

  --color-bg: #ffffff;
  --color-surface: var(--light-blue);
  --color-text: #1b2533;
  --color-muted: #556275;
  --color-heading: #0f2740;
  --color-brand: var(--cme-blue);
  --color-brand-hover: #084a80;
  --color-on-brand: #ffffff;
  --color-border: #d6e2ec;
  --color-code-inline: #eef3f8;

  --font-sans:
    "Lexend", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:
    ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --measure: 46rem;
  --gutter: 1.25rem;
  --radius: 0.5rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0b1622;
    --color-surface: #13243a;
    --color-text: #d8e2ec;
    --color-muted: #9aabbd;
    --color-heading: #f1f7fc;
    --color-brand: #6cc4f0;
    --color-brand-hover: #9ad6f5;
    --color-on-brand: #0b1622;
    --color-border: #22364d;
    --color-code-inline: #172a40;
  }
}

/* Base */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Column layout keeps the footer at the bottom of short pages. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  color: var(--color-heading);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-wrap: balance;
  scroll-margin-top: 1.5rem;
}

p {
  text-wrap: pretty;
}

a {
  color: var(--color-brand);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.2em;
  -webkit-tap-highlight-color: rgb(11 95 165 / 0.15);
  touch-action: manipulation;
  transition:
    color 150ms ease,
    background-color 150ms ease,
    border-color 150ms ease;
}

a:hover {
  color: var(--color-brand-hover);
}

:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 3px;
  border-radius: 2px;
}

img {
  max-width: 100%;
  height: auto;
}

.container {
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 10;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  background-color: var(--color-brand);
  color: var(--color-on-brand);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
}

.skip-link:focus-visible {
  transform: none;
}

.empty-state {
  color: var(--color-muted);
}

/* Header */

.site-header {
  border-top: 3px solid var(--medical-gold);
  border-bottom: 1px solid var(--color-border);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding-block: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  color: var(--color-heading);
  text-decoration: none;
}

.brand:hover {
  color: var(--color-brand);
}

/* The logo has a white background, so it sits on a white tile in both themes. */
.brand-mark {
  display: inline-grid;
  flex-shrink: 0;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background-color: #ffffff;
}

.brand-mark img {
  width: auto;
  height: 2.125rem;
}

.brand-name {
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-nav a {
  color: var(--color-muted);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--color-brand);
}

.site-nav a[aria-current="page"] {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--medical-gold);
  text-underline-offset: 0.45em;
}

/* Home */

.intro {
  padding-block: 3.5rem 2rem;
}

.intro-title {
  margin: 0;
  color: var(--color-brand);
  font-size: clamp(1.875rem, 4.5vw, 2.625rem);
}

.intro-text {
  max-width: 38rem;
  margin: 1rem 0 0;
  color: var(--color-muted);
  font-size: 1.1875rem;
}

.section-title {
  margin: 0;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-muted);
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Post cards */

.post-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.post-card {
  padding-block: 1.75rem;
  border-bottom: 1px solid var(--color-border);
}

.post-card-title {
  margin: 0;
  font-size: 1.375rem;
}

.post-card-title a {
  color: var(--color-heading);
  text-decoration: none;
  overflow-wrap: break-word;
}

.post-card-title a:hover {
  color: var(--color-brand);
  text-decoration: underline;
}

.post-card-excerpt {
  margin: 0.5rem 0 0;
  overflow-wrap: break-word;
}

.post-meta {
  margin: 0.375rem 0 0;
  color: var(--color-muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.post-author {
  color: var(--color-text);
  font-weight: 500;
}

/* Tags */

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.875rem 0 0;
  padding: 0;
  list-style: none;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.625rem;
  border-radius: 999px;
  background-color: var(--color-surface);
  color: var(--color-brand);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
}

.tag:hover {
  background-color: var(--color-brand);
  color: var(--color-on-brand);
}

.tag-count {
  color: inherit;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

.tag-index {
  margin-bottom: 1rem;
}

.tag-section {
  margin-top: 2.5rem;
}

.tag-section h2 {
  margin: 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

/* Posts and pages */

.post-header,
.page-header {
  padding-block: 3rem 1.5rem;
}

.post-title,
.page-title {
  margin: 0;
  font-size: clamp(2rem, 5vw, 2.75rem);
  overflow-wrap: break-word;
}

.post-lede {
  margin: 0.75rem 0 0;
  color: var(--color-muted);
  font-size: 1.1875rem;
}

.post-header .post-meta {
  margin-top: 1rem;
}

/* Markdown content. Every rule here goes through :where(.prose) so it has no more
   specificity than a bare element selector, and component classes rendered inside
   (post cards and tag chips on the tags page) keep their own styles. */
.prose {
  overflow-wrap: break-word;
}

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

:where(.prose)
  :where(p, ul, ol, blockquote, table, figure, .highlighter-rouge) {
  margin-block: 0 1.25em;
}

:where(.prose) h2 {
  margin: 2.25em 0 0.6em;
  font-size: 1.5rem;
}

:where(.prose) h3 {
  margin: 1.75em 0 0.5em;
  font-size: 1.25rem;
}

:where(.prose) h4 {
  margin: 1.5em 0 0.5em;
  font-size: 1.0625rem;
}

:where(.prose) :where(ul, ol):not([class]) {
  padding-left: 1.5em;
}

:where(.prose) :where(ul, ol):not([class]) > li + li {
  margin-top: 0.375em;
}

:where(.prose) li::marker {
  color: var(--color-muted);
}

:where(.prose) blockquote {
  margin-inline: 0;
  padding-left: 1rem;
  border-left: 4px solid var(--medical-gold);
  color: var(--color-muted);
}

:where(.prose) hr {
  margin-block: 2.5rem;
  border: 0;
  border-top: 1px solid var(--color-border);
}

:where(.prose) img {
  border-radius: var(--radius);
}

/* Wide tables scroll inside the column instead of widening the page. */
:where(.prose) table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

:where(.prose) :where(th, td) {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  text-align: left;
}

:where(.prose) th {
  background-color: var(--color-surface);
  color: var(--color-heading);
  font-weight: 600;
}

/* Code */

code,
kbd,
pre {
  font-family: var(--font-mono);
}

:not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 0.3em;
  background-color: var(--color-code-inline);
  font-size: 0.875em;
  overflow-wrap: anywhere;
}

pre {
  margin: 0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  line-height: 1.6;
  tab-size: 2;
}

/* Post footer */

.post-footer {
  margin-top: 3rem;
  padding-block: 1.5rem 3rem;
  border-top: 1px solid var(--color-border);
}

.post-footer .tag-list {
  margin-top: 0;
}

.post-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.post-nav-link {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  padding: 1rem 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-decoration: none;
}

.post-nav-link:hover {
  border-color: var(--color-brand);
}

.post-nav-next {
  grid-column: -2;
  text-align: right;
}

.post-nav-label {
  color: var(--color-muted);
  font-size: 0.8125rem;
}

.post-nav-title {
  color: var(--color-heading);
  font-weight: 600;
  overflow-wrap: break-word;
}

/* Footer */

.site-main {
  flex: 1;
  padding-bottom: 3rem;
}

.site-footer {
  border-top: 1px solid var(--color-border);
  color: var(--color-muted);
  font-size: 0.875rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-block: 1.5rem;
}

.footer-inner p {
  margin: 0;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.footer-links a {
  color: var(--color-muted);
}

.footer-links a:hover {
  color: var(--color-brand);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
