:root {
  --gap: 24px;
  --content-gap: 20px;
  --nav-width: 1024px;
  --main-width: 720px;
  --header-height: 60px;
  --footer-height: 60px;
  --radius: 8px;

  --theme: #ffffff;
  --entry: #ffffff;
  --primary: #1e1e1e;
  --secondary: #6c6c6c;
  --tertiary: #d6d6d6;
  --content: #1f1f1f;
  --code-bg: #f5f5f5;
  --border: #eeeeee;
  --accent: #2f6fde;
}

:root[data-theme="dark"] {
  --theme: #1d1e20;
  --entry: #2e2e33;
  --primary: #dadadb;
  --secondary: #9b9c9d;
  --tertiary: #414244;
  --content: #c4c4c5;
  --code-bg: #37383e;
  --border: #333333;
  --accent: #7aa2f7;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  word-break: break-word;
  background: var(--theme);
  color: var(--primary);
}

a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* ---------- Header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--theme);
}
.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: calc(var(--nav-width) + var(--gap) * 2);
  margin: 0 auto;
  height: var(--header-height);
  padding: 0 var(--gap);
  line-height: var(--header-height);
}
.logo { display: flex; align-items: center; gap: 4px; }
.logo a { font-size: 22px; font-weight: 700; }
.theme-toggle { display: grid; place-items: center; width: 32px; height: 32px; margin-left: 8px; border-radius: var(--radius); }
.theme-toggle:hover { background: var(--tertiary); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
.menu { display: flex; list-style: none; margin: 0; padding: 0; gap: 20px; font-size: 16px; }
.menu a.active { border-bottom: 2px solid currentColor; padding-bottom: 2px; }

/* ---------- Main ---------- */
.main {
  flex: 1;
  width: 100%;
  max-width: calc(var(--main-width) + var(--gap) * 2);
  margin: 0 auto;
  padding: var(--gap);
}

/* ---------- Profile (home) ---------- */
.profile {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 48px;
  padding: 32px 0 56px;
  text-align: center;
  overflow: hidden;
}
.profile-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.avatar {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 8px;
  background: var(--entry);
  display: grid;
  place-items: center;
  font-size: 52px;
  font-weight: 700;
  color: var(--secondary);
  border: 1px solid var(--border);
}
.profile h1 { margin: 0; font-size: 34px; line-height: 1.3; }
.profile .subtitle { margin: 0; font-size: 15px; color: var(--secondary); }
.social { display: flex; gap: 12px; margin: 14px 0 6px; }
.social a { display: grid; place-items: center; width: 30px; height: 30px; }
.social svg { width: 22px; height: 22px; }
.buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 10px; }
.button {
  display: inline-block;
  padding: 6px 16px;
  font-size: 15px;
  font-weight: 500;
  border-radius: var(--radius);
  background: var(--tertiary);
}
.button:hover { filter: brightness(1.1); }

/* ---------- Page header / post ---------- */
.breadcrumbs { font-size: 14px; color: var(--secondary); margin-bottom: 4px; }
.breadcrumbs a:hover { color: var(--primary); }
.page-header { margin: 16px 0 28px; }
.page-header h1 { margin: 0; font-size: 40px; line-height: 1.2; }
.page-header .meta { margin-top: 8px; font-size: 14px; color: var(--secondary); }
.page-header .lead { margin: 10px 0 0; color: var(--secondary); font-size: 17px; }

.post-content { color: var(--content); }
.post-content h2 { color: var(--primary); font-size: 26px; margin: 36px 0 12px; line-height: 1.3; }
.post-content h3 { color: var(--primary); font-size: 21px; margin: 28px 0 10px; }
.post-content p { margin: 0 0 18px; }
.post-content ul { padding-left: 22px; margin: 0 0 18px; }
.post-content li { margin-bottom: 6px; }
.post-content a { box-shadow: 0 1px 0 var(--primary); }
.post-content a:hover { box-shadow: 0 2px 0 var(--primary); }
.post-content strong { color: var(--primary); }

.specs { width: 100%; border-collapse: collapse; margin: 0 0 22px; font-size: 16px; }
.specs th, .specs td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.specs th { width: 40%; color: var(--secondary); font-weight: 500; }

.figure {
  margin: 0 0 24px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--entry);
  border: 1px solid var(--border);
}
.figure img { width: 100%; height: auto; }
.placeholder {
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  color: var(--secondary);
  font-size: 14px;
  border: 1px dashed var(--tertiary);
  border-radius: var(--radius);
  background: var(--entry);
  margin: 0 0 24px;
}
.note {
  padding: 12px 16px;
  margin: 0 0 22px;
  border-left: 3px solid var(--tertiary);
  background: var(--code-bg);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 16px;
}

/* ---------- Entry cards (lists) ---------- */
.section-title { font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: var(--secondary); margin: 36px 0 14px; font-weight: 600; }
.section-title:first-of-type { margin-top: 8px; }
.entry {
  position: relative;
  margin-bottom: var(--gap);
  padding: var(--gap);
  background: var(--entry);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: transform .1s;
}
.entry:active { transform: scale(.98); }
.entry h2 { margin: 0 0 8px; font-size: 24px; line-height: 1.3; }
.entry .summary { margin: 0; font-size: 15px; color: var(--secondary); line-height: 1.6; }
.entry .meta { margin-top: 12px; font-size: 13px; color: var(--secondary); }
.entry .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--tertiary); color: var(--primary); }
.entry-link { position: absolute; inset: 0; border-radius: var(--radius); }
.entry-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sub-list { list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 12px; }
.sub-list li { margin: 0; }
.sub-card { display: block; padding: 16px 18px; background: var(--entry); border: 1px solid var(--border); border-radius: var(--radius); }
.post-content .sub-card { box-shadow: none; }
.sub-card strong { display: block; font-size: 18px; }
.sub-card span { font-size: 15px; color: var(--secondary); }
a.sub-card:hover { border-color: var(--secondary); }

/* ---------- Pagination ---------- */
.post-nav { display: flex; gap: 12px; margin-top: 40px; }
.post-nav a { flex: 1; padding: 14px 16px; border-radius: var(--radius); background: var(--tertiary); font-size: 15px; }
.post-nav a span { display: block; font-size: 12px; color: var(--secondary); }
.post-nav .next { text-align: right; }

/* ---------- Footer ---------- */
.footer {
  max-width: calc(var(--main-width) + var(--gap) * 2);
  width: 100%;
  margin: 0 auto;
  padding: calc((var(--footer-height) - var(--gap)) / 2) var(--gap);
  text-align: center;
  font-size: 13px;
  color: var(--secondary);
}
.footer a:hover { color: var(--primary); }
.home .footer { max-width: none; background: var(--entry); }

@media (max-width: 600px) {
  :root { --gap: 16px; }
  body { font-size: 17px; }
  .logo a { font-size: 19px; }
  .menu { gap: 14px; }
  .page-header h1 { font-size: 32px; }
  .entry h2 { font-size: 21px; }
  .post-nav { flex-direction: column; }
}
.meta-line { font-size: 15px; color: var(--secondary); margin: -8px 0 10px !important; }

.cover img { aspect-ratio: 3 / 2; object-fit: cover; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0 0 8px; }
.post-content .gallery a { box-shadow: none; display: block; border-radius: var(--radius); overflow: hidden; background: var(--entry); }
.gallery img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; transition: transform .2s; }
.gallery a:hover img { transform: scale(1.03); }
.caption { font-size: 13px; color: var(--secondary); margin: 0 0 24px !important; }
@media (max-width: 600px) { .gallery { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Home carousel ---------- */
.carousel {
  width: 100%;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 8%, #000 92%, transparent);
          mask-image: linear-gradient(to right, transparent, #000 8%, #000 92%, transparent);
}
.carousel-track {
  display: flex;
  gap: 16px;
  width: max-content;
}
.carousel {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.carousel::-webkit-scrollbar { display: none; }
.slide {
  position: relative;
  flex: none;
  height: 300px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--entry);
}
.slide img { height: 100%; width: auto; transition: transform .3s; }
.slide:hover img { transform: scale(1.04); }
.slide span {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 24px 12px 10px;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .65));
  opacity: 0;
  transition: opacity .2s;
}
.slide:hover span, .slide:focus-visible span { opacity: 1; }
@media (max-width: 600px) {
  .slide { height: 220px; }
  .slide span { opacity: 1; }
}

/* ---------- Project tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 8px; }
.tile { display: block; }
.tile-img {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--entry);
  border: 1px solid var(--border);
}
.tile-img img, .tile-img video { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.tile:hover .tile-img img { transform: scale(1.04); }
.tile-empty { height: 100%; display: grid; place-items: center; text-align: center; padding: 8px; font-size: 13px; color: var(--secondary); background: var(--code-bg); }
.tile h2 { margin: 10px 2px 0; font-size: 16px; line-height: 1.3; font-weight: 600; }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: var(--radius); }
@media (max-width: 600px) {
  .tiles { gap: 10px; }
  .tile h2 { font-size: 14px; }
}
.gallery-wide { grid-template-columns: repeat(2, 1fr); }
.gallery-wide img { aspect-ratio: 16 / 9; }
.video { display: block; width: 100%; aspect-ratio: 16 / 9; border-radius: var(--radius); background: #000; margin: 0 0 24px; }

/* ---------- Home banner ---------- */
.profile-inner { width: 100%; max-width: calc(var(--main-width) + var(--gap) * 2); padding: 0 var(--gap); }
.banner {
  width: 100%;
  aspect-ratio: 4 / 1;
  object-fit: cover;
  border-radius: var(--radius);
}
.banner + .avatar,
.banner + * + .avatar { margin-top: -75px; border: 4px solid var(--theme); position: relative; }
@media (max-width: 600px) {
  .banner { aspect-ratio: 3 / 1; }
  .banner + .avatar, .banner + * + .avatar { width: 120px; height: 120px; margin-top: -60px; font-size: 42px; }
}

.section-intro { margin: -6px 0 16px; font-size: 15px; color: var(--secondary); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.badge { font-size: 13px; font-weight: 500; padding: 3px 10px; border-radius: 99px; background: var(--code-bg); border: 1px solid var(--border); color: var(--primary); }
.video-portrait { aspect-ratio: 9 / 16; max-width: 360px; margin-left: auto; margin-right: auto; margin-bottom: 8px; }
.video-portrait + .caption { text-align: center; }
