/* === VARIABLES === */
:root {
  --radius-xl: 2rem;
  --radius-lg: 1.5rem;
}

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  font: 400 16px/1.7 "Helvetica Neue", Helvetica, "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
}

img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; }
h1, h2, h3, p, blockquote, figure, figcaption { margin: 0; }
mark, em { font-style: normal; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* === CONTAINER WIDTH === */
body > header > div,
main,
body > section,
footer {
  width: min(1200px, calc(100% - 64px));
  margin-left: auto;
  margin-right: auto;
}

/* === HEADER === */
body > header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

body > header > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 90px;
}

body > header a:first-child,
footer > div > a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

body > header strong,
footer strong {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -0.03em;
}

body > header svg,
footer svg {
  width: 2rem;
  height: 2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Hamburger — hidden on desktop */
body > header button {
  display: none;
  padding: 0.5rem;
  border: none;
  border-radius: 0.6rem;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

body > header nav {
  display: flex;
  align-items: center;
  gap: 40px;
  font-size: 1rem;
  font-weight: 800;
}

body > header nav a {
  position: relative;
  padding: 0.4rem 0;
  transition: color 0.25s;
}

body > header nav a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 2px;
  border-radius: var(--radius-pill);
  background: var(--warn);
  transition: width 0.25s;
}

body > header nav a:hover        { color: var(--warn); }
body > header nav a:hover::after { width: 100%; }

/* === MAIN: 2-COLUMN GRID — aside LEFT (35%), article RIGHT (65%) === */
main {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(0, 1.7fr);
  gap: 48px;
  padding: 40px 0 56px;
  align-items: start;
}

/* article first in DOM (SEO) → renders in right column */
article {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* aside second in DOM → renders in left column */
aside {
  grid-column: 1;
  grid-row: 1;
  position: sticky;
  top: 110px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* === ARTICLE HEADER CARD (breadcrumb + H1 + author + abstract) === */
article > header {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 48px 56px;
  box-shadow: var(--shadow-soft);
}

/* Breadcrumb */
article > header > nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 32px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

article > header > nav a { transition: color 0.2s; }
article > header > nav a:hover { color: var(--warn); }

article > header > nav span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #c8c8c3;
}

article > header > nav strong { color: var(--accent); }

/* H1 */
h1 {
  font-size: clamp(1.8rem, 3.2vw, 2.5rem);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.03em;
  margin-bottom: 24px;
}

/* Author / time row */
article > header > p.meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin-bottom: 32px;
  color: var(--muted);
  font-size: 0.875rem;
}

article > header > p.meta > b {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 6px;
  background: var(--surface);
  border: 1px solid rgba(234, 234, 232, 0.8);
  border-radius: var(--radius-pill);
  color: var(--text);
  font-size: 0.94rem;
  box-shadow: 0 2px 10px -4px rgba(0, 0, 0, 0.06);
}

/* Author avatar via pseudo-element */
article > header > p.meta > b::before {
  content: "张晓";
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

article > header > p.meta > span:last-child { color: var(--warn); }

/* Abstract blockquote */
blockquote {
  padding-left: 16px;
  border-left: 3px solid var(--accent);
  color: var(--subtle);
  line-height: 1.75;
}

/* === ARTICLE BODY CARD (main text) === */
article > section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 48px 56px;
  box-shadow: var(--shadow-soft);
  color: #393f53;
  scroll-margin-top: 110px;
}

article > section p {
  margin-bottom: 1.8em;
  font-size: 1.125rem;
  line-height: 2.1;
  text-align: justify;
}

article > section p:first-child {
  font-size: 1.25rem;
  color: #2d3748;
}

/* H2 section headings */
article > section h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 32px 0 16px;
  font-size: 1.125rem;
  font-weight: 800;
  color: var(--text);
  scroll-margin-top: 110px;
}

article > section h2::before {
  content: "";
  flex-shrink: 0;
  width: 6px;
  height: 16px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

/* Inline highlights */
mark {
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(121, 189, 154, 0.15);
  color: var(--accent-deep);
  font-weight: 800;
}

em {
  padding: 1px 6px;
  border-radius: 4px;
  background: #fef9c3;
  color: #854d0e;
  font-weight: 800;
}

/* Tags row */
article > section > p.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 48px 0 0;
  padding-top: 28px;
  border-top: 1px dashed var(--line);
}

article > section > p.tags a {
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.82rem;
  transition: color 0.2s;
}

article > section > p.tags a:hover { color: var(--accent-deep); }

/* === ASIDE: BENTO IMAGE CARD === */
aside > figure {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.3s;
}

aside > figure:hover { box-shadow: var(--shadow-hover); }

aside > figure > button {
  display: block;
  position: relative;
  width: 100%;
  padding: 0;
  border: none;
  border-radius: 1rem;
  overflow: hidden;
  background: #dbe3ef;
  cursor: zoom-in;
  aspect-ratio: 3 / 4;
}

/* Blue inner border on image */
aside > figure > button::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 4px solid rgba(37, 99, 235, 0.9);
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
}

aside > figure > button > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s;
}

aside > figure > button:hover > img { transform: scale(1.05); }

/* Hover darkening overlay */
aside > figure > button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  transition: background 0.3s;
  z-index: 2;
}

aside > figure > button:hover::after { background: rgba(0, 0, 0, 0.1); }

/* Top-left badge */
figcaption {
  position: absolute;
  top: 28px;
  left: 28px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.95);
  font-size: 0.75rem;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

figcaption::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* === ASIDE: TOC CARD === */
aside > nav {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.3s;
}

aside > nav:hover { box-shadow: var(--shadow-hover); }

aside > nav > h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px;
  border-bottom: 1px solid #f3f3f0;
  font-size: 1rem;
  font-weight: 800;
}

aside > nav > h2::before {
  content: "";
  width: 5px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

aside > nav > a {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  color: var(--subtle);
  font-size: 0.875rem;
  border-top: 1px solid #f3f3f0;
  transition: background 0.2s, color 0.2s;
}

aside > nav > a:first-of-type { border-top: none; }
aside > nav > a:hover { background: #fafaf8; color: var(--warn); }

aside > nav > a > span {
  min-width: 20px;
  color: #a0aec0;
  font: 500 0.8rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
}

/* === RELATED ARTICLES SECTION === */
body > section {
  margin-bottom: 64px;
}

body > section > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

body > section > div:first-child h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
}

body > section > div:first-child h2::before {
  content: "";
  width: 5px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

body > section > div:first-child > a {
  font-size: 0.875rem;
  color: var(--muted);
  transition: color 0.2s;
}

body > section > div:first-child > a:hover { color: var(--accent-deep); }

body > section > div:last-child {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

body > section > div:last-child > a {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: var(--shadow-card);
  transition: transform 0.3s, box-shadow 0.3s;
}

body > section > div:last-child > a:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

body > section > div:last-child img {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 0.75rem;
  object-fit: cover;
  transition: transform 0.5s;
}

body > section > div:last-child > a:hover img { transform: scale(1.05); }

body > section > div:last-child small {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--accent-deep);
}

body > section > div:last-child small.cat-design  { color: #e06c75; }
body > section > div:last-child small.cat-practice { color: #d19a66; }

body > section > div:last-child h3 {
  font-size: 0.94rem;
  font-weight: 800;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

body > section > div:last-child time {
  font-size: 0.8rem;
  color: var(--muted);
}

/* === FOOTER === */
footer {
  margin-bottom: 48px;
  padding: 48px;
  background: var(--footer-bg);
  border-radius: var(--radius-xl);
}

footer > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

footer nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px 40px;
  font-weight: 800;
  font-size: 0.94rem;
}

footer > p {
  margin-top: 24px;
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

footer > p:last-child {
  display: flex;
  justify-content: center;
  gap: 32px;
  padding-top: 24px;
  border-top: 1px solid #c2d0cc;
}

footer a:hover { color: var(--warn); }

/* === LIGHTBOX DIALOG === */
dialog {
  width: min(92vw, 1080px);
  padding: 0;
  border: none;
  border-radius: var(--radius-lg);
  background: transparent;
  overflow: visible;
}

dialog::backdrop {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(16px);
}

/* Close button rendered as × via pseudo-elements */
dialog > button {
  position: absolute;
  top: -14px;
  right: -14px;
  z-index: 2;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.8);
  color: transparent;
  font-size: 0;
  cursor: pointer;
  transition: background 0.2s;
}

dialog > button::before,
dialog > button::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 2px;
  background: #555;
  border-radius: 2px;
}

dialog > button::before { transform: translate(-50%, -50%) rotate(45deg); }
dialog > button::after  { transform: translate(-50%, -50%) rotate(-45deg); }
dialog > button:hover   { background: #fff; }

dialog > img {
  display: block;
  width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 20px 60px -15px rgba(0, 0, 0, 0.15);
  background: #fff;
}

body.modal-open { overflow: hidden; }

/* === RESPONSIVE: TABLET (≤ 1024px) === */
@media (max-width: 1024px) {
  body > header > div { min-height: 70px; }

  main {
    grid-template-columns: minmax(240px, 1fr) minmax(0, 1.5fr);
    gap: 32px;
    padding: 32px 0 48px;
  }

  article > header,
  article > section { padding: 32px 36px; }
}

/* === RESPONSIVE: MOBILE (≤ 768px) === */
@media (max-width: 768px) {
  body > header > div,
  main,
  body > section,
  footer {
    width: min(100% - 24px, 1200px);
  }

  /* Show hamburger */
  body > header button { display: inline-flex; }

  /* Collapsed nav dropdown */
  body > header nav {
    position: absolute;
    top: calc(100% - 4px);
    left: 12px;
    right: 12px;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 12px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid var(--line);
    border-radius: 1.2rem;
    box-shadow: var(--shadow-hover);
  }

  body > header nav.is-open { display: flex; }
  body > header nav a { padding: 0.8rem 0.4rem; }
  body > header nav a::after { display: none; }

  /* ── Mobile reorder via display:contents ───────────────────
     Flatten article & aside so children become direct flex
     items of main and can be ordered independently:
     header(1) → image(2) → body text(3) → TOC(4)
  ────────────────────────────────────────────────────────── */
  main {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px 0 40px;
  }

  article { display: contents; }
  aside   { display: contents; }

  article > header {
    order: 1;
    display: block;
    padding: 24px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
  }

  aside > figure {
    order: 2;
    display: block;
  }

  article > section {
    order: 3;
    display: block;
    padding: 24px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
  }

  aside > nav {
    order: 4;
    display: block;
  }

  /* Text size adjustments */
  article > section p             { font-size: 1rem; line-height: 1.9; }
  article > section p:first-child { font-size: 1.1rem; }

  /* Related articles: single column */
  body > section > div:last-child  { grid-template-columns: 1fr; }
  body > section > div:first-child { flex-direction: column; align-items: flex-start; }

  /* Footer */
  footer              { padding: 32px 20px; }
  footer > div        { flex-direction: column; align-items: flex-start; }
  footer > p:last-child { flex-wrap: wrap; gap: 12px 24px; }
}
