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

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.8;
  color: var(--ink-cloud);
  background: var(--cloud-white);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

button {
  font: inherit;
  color: inherit;
}

p {
  margin: 0 0 1em;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.5em;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

:focus-visible {
  outline: 2px solid var(--signal-cyan);
  outline-offset: 3px;
}

/* ============ Variables ============ */
:root {
  --cloud-white: #F7FAFC;
  --mist-gray: #E8EDF2;
  --sea-blue: #3A6EA5;
  --deep-blue: #244B72;
  --signal-cyan: #37C2C9;
  --sunset-orange: #F08A3C;
  --mist-teal: #D9F2F3;
  --salt-gray: #5F6F7E;
  --ink-cloud: #15202B;
  --warm-sand: #FCE7D6;

  --font-sans: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", ui-monospace, Consolas, "Liberation Mono", monospace;

  --radius-pill: 999px;
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;

  --shadow-island: 0 18px 50px -24px rgba(36, 75, 114, 0.34);
  --shadow-panel: 0 26px 60px -30px rgba(36, 75, 114, 0.42);

  --shell-max: 1220px;
  --gutter: clamp(1rem, 4vw, 3rem);
}

/* ============ Utilities ============ */
.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 ============ */
.skip-link {
  position: fixed;
  top: -120px;
  left: 1rem;
  z-index: 220;
  padding: 0.8rem 1.35rem;
  background: var(--deep-blue);
  color: #fff;
  font-size: 0.9rem;
  border-radius: var(--radius-pill);
  text-decoration: none;
  box-shadow: var(--shadow-panel);
  pointer-events: auto;
  transition: top 180ms ease;
}

.skip-link:focus {
  top: 1rem;
}

/* ============ Reading progress ============ */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  z-index: 210;
  pointer-events: none;
  background: linear-gradient(90deg, var(--sea-blue) 0%, var(--signal-cyan) 70%, var(--sunset-orange) 100%);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 120ms linear;
}

/* ============ Header ============ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 90;
  padding: clamp(0.75rem, 2vw, 1.4rem) var(--gutter) 0;
  pointer-events: none;
}

.header-shell {
  position: relative;
  pointer-events: auto;
  max-width: var(--shell-max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0.55rem 0.5rem 1.05rem;
  background: rgba(247, 250, 252, 0.88);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(58, 110, 165, 0.12);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-island);
  transition: transform 260ms ease, box-shadow 260ms ease, padding 260ms ease, background 260ms ease;
}

.site-header.is-scrolled .header-shell {
  transform: translateY(-3px);
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
  background: rgba(247, 250, 252, 0.95);
  box-shadow: 0 24px 52px -26px rgba(36, 75, 114, 0.5);
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: none;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius-sm);
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(142deg, var(--sea-blue) 0%, var(--signal-cyan) 100%);
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.14;
}

.brand-name {
  font-size: 0.98rem;
  font-weight: 500;
  color: var(--deep-blue);
  letter-spacing: 0.01em;
}

.brand-note {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  color: var(--salt-gray);
}

/* Nav toggle */
.nav-toggle {
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  padding: 0.5rem 0.85rem 0.5rem 0.7rem;
  background: var(--mist-teal);
  border: 1px solid rgba(58, 110, 165, 0.18);
  border-radius: var(--radius-pill);
  color: var(--deep-blue);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.nav-toggle:hover {
  background: #cdecee;
}

.nav-toggle-icon {
  display: grid;
  gap: 4px;
  width: 16px;
}

.nav-toggle-bar {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 220ms ease, opacity 180ms ease;
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) {
  transform: translateY(3px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) {
  transform: translateY(-3px) rotate(-45deg);
}

.nav-toggle-label {
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

/* Nav panel */
.nav-panel {
  display: flex;
  align-items: center;
  gap: 1.15rem;
  margin-left: auto;
}

.site-nav {
  display: flex;
  align-items: center;
}

.nav-list {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-item {
  margin: 0;
}

.nav-link {
  display: inline-block;
  padding: 0.48rem 0.78rem;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  color: var(--salt-gray);
  text-decoration: none;
  white-space: nowrap;
  transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.nav-link:hover {
  color: var(--deep-blue);
  background: var(--mist-teal);
}

.nav-link[aria-current="page"] {
  color: var(--deep-blue);
  font-weight: 500;
  background: var(--mist-teal);
  box-shadow: inset 0 0 0 1px rgba(55, 194, 201, 0.5);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: none;
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.62rem 1.2rem;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--sunset-orange);
  color: var(--ink-cloud);
  box-shadow: 0 12px 26px -16px rgba(240, 138, 60, 0.9);
}

.btn-primary:hover {
  background: #e57c2e;
}

.btn-ghost {
  background: transparent;
  color: var(--sea-blue);
  border-color: rgba(58, 110, 165, 0.32);
}

.btn-ghost:hover {
  background: var(--mist-teal);
  border-color: var(--signal-cyan);
  color: var(--deep-blue);
}

.btn-blue {
  background: var(--sea-blue);
  color: #fff;
}

.btn-blue:hover {
  background: var(--deep-blue);
}

/* ============ Page shell & grids ============ */
.page-shell {
  width: 100%;
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.prose {
  max-width: 66ch;
  font-size: 1.05rem;
  line-height: 1.85;
  color: var(--ink-cloud);
}

.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: clamp(1rem, 2.2vw, 1.9rem);
}

/* ============ Breadcrumb ============ */
.breadcrumb {
  margin: clamp(1.5rem, 4vw, 2.75rem) 0 clamp(1rem, 2vw, 1.5rem);
}

.breadcrumb-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  color: var(--salt-gray);
}

.breadcrumb-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.breadcrumb-item + .breadcrumb-item::before {
  content: "/";
  color: rgba(58, 110, 165, 0.4);
}

.breadcrumb-link {
  color: var(--salt-gray);
  text-decoration: none;
  transition: color 160ms ease;
}

.breadcrumb-link:hover {
  color: var(--sea-blue);
}

.breadcrumb-current {
  color: var(--sea-blue);
}

/* ============ Chapter numbering ============ */
.chapter-no {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: clamp(1.6rem, 3.4vw, 2.4rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.02em;
  color: rgba(58, 110, 165, 0.34);
  vertical-align: super;
  transition: color 420ms ease;
}

[data-chapter].is-active .chapter-no {
  color: var(--signal-cyan);
}

/* ============ Image frames ============ */
.img-frame {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-radius: var(--radius-lg);
  aspect-ratio: 16 / 10;
  background: linear-gradient(150deg, #dce9f4 0%, #e8edf2 46%, #d9f2f3 100%);
  box-shadow: inset 0 0 0 1px rgba(58, 110, 165, 0.09);
}

.img-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image:
    radial-gradient(ellipse 56% 42% at 22% 24%, rgba(255, 255, 255, 0.86), transparent 66%),
    radial-gradient(ellipse 46% 34% at 80% 72%, rgba(55, 194, 201, 0.34), transparent 70%),
    radial-gradient(ellipse 38% 28% at 62% 16%, rgba(240, 138, 60, 0.16), transparent 72%);
}

.img-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: repeating-linear-gradient(114deg, rgba(36, 75, 114, 0.055) 0 1px, transparent 1px 9px);
  opacity: 0.55;
}

.img-frame > img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-frame--wide {
  aspect-ratio: 21 / 9;
}

.img-frame--tall {
  aspect-ratio: 4 / 5;
}

.img-frame--square {
  aspect-ratio: 1 / 1;
}

/* ============ Reveal ============ */
[data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 620ms ease, transform 620ms cubic-bezier(0.22, 1, 0.36, 1);
}

[data-reveal].is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ============ Footer ============ */
.site-footer {
  position: relative;
  overflow: hidden;
  margin-top: clamp(4rem, 9vw, 8.5rem);
  padding: clamp(2.75rem, 6vw, 5rem) var(--gutter) 1.6rem;
  background: linear-gradient(180deg, var(--cloud-white) 0%, var(--mist-gray) 100%);
  border-top: 1px solid rgba(58, 110, 165, 0.1);
}

.site-footer::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(ellipse 42% 26% at 6% 10%, rgba(58, 110, 165, 0.14), transparent 68%),
    radial-gradient(ellipse 38% 24% at 84% 18%, rgba(55, 194, 201, 0.18), transparent 70%),
    radial-gradient(ellipse 46% 26% at 52% 100%, rgba(240, 138, 60, 0.09), transparent 72%);
}

.footer-shell {
  position: relative;
  max-width: var(--shell-max);
  margin: 0 auto;
}

.footer-grid {
  display: grid;
  grid-template-columns: 1.7fr 1fr 1fr 1.5fr;
  gap: clamp(1.5rem, 3vw, 3rem);
  padding-bottom: clamp(2rem, 4vw, 3rem);
}

.footer-brand-line {
  margin: 0 0 0.35rem;
  font-size: 1.18rem;
  font-weight: 500;
  color: var(--deep-blue);
  letter-spacing: 0.01em;
}

.footer-brand-note {
  margin: 0 0 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: var(--sea-blue);
}

.footer-desc {
  margin: 0;
  max-width: 34ch;
  font-size: 0.94rem;
  line-height: 1.8;
  color: var(--salt-gray);
}

.footer-heading {
  margin: 0 0 1.05rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--sea-blue);
}

.footer-links {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.footer-link {
  display: inline-block;
  font-size: 0.92rem;
  color: var(--salt-gray);
  text-decoration: none;
  transition: color 160ms ease, transform 160ms ease;
}

.footer-link:hover {
  color: var(--deep-blue);
  transform: translateX(4px);
}

.footer-contact {
  display: grid;
  gap: 0.6rem;
  font-style: normal;
}

.footer-contact-row {
  display: grid;
  gap: 0.15rem;
  margin: 0;
}

.footer-contact-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  color: var(--sea-blue);
}

.footer-contact-value {
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--salt-gray);
  word-break: break-word;
}

.footer-note {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  line-height: 1.75;
  color: var(--salt-gray);
}

.footer-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 1.4rem;
  border-top: 1px solid rgba(58, 110, 165, 0.14);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  color: var(--salt-gray);
}

.footer-icp {
  color: var(--sea-blue);
}

/* ============ Breakpoints ============ */
@media (max-width: 1080px) {
  .nav-link {
    padding: 0.45rem 0.58rem;
    font-size: 0.85rem;
  }

  .header-actions {
    gap: 0.35rem;
  }

  .header-actions .btn {
    padding: 0.55rem 0.9rem;
    font-size: 0.84rem;
  }
}

@media (max-width: 900px) {
  .nav-toggle {
    display: inline-flex;
  }

  .nav-panel {
    position: absolute;
    top: calc(100% + 0.55rem);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.7rem;
    margin-left: 0;
    padding: 0.85rem;
    background: rgba(247, 250, 252, 0.97);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(58, 110, 165, 0.13);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-panel);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 220ms ease, transform 220ms ease, visibility 0s linear 220ms;
  }

  .nav-panel[data-open="true"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity 220ms ease, transform 220ms ease, visibility 0s;
  }

  .site-nav {
    display: block;
  }

  .nav-list {
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
  }

  .nav-link {
    display: block;
    padding: 0.7rem 0.9rem;
    font-size: 0.94rem;
  }

  .header-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding-top: 0.35rem;
    border-top: 1px solid rgba(58, 110, 165, 0.12);
  }

  .header-actions .btn {
    width: 100%;
    padding: 0.72rem 1rem;
    font-size: 0.9rem;
  }

  .footer-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .brand-note {
    font-size: 0.6rem;
  }

  .nav-toggle-label {
    display: none;
  }

  .footer-grid {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .footer-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.45rem;
  }

  .grid-12 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

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

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .site-header.is-scrolled .header-shell {
    transform: none;
  }

  [data-reveal] {
    opacity: 1;
    transform: none;
  }

  .footer-link:hover {
    transform: none;
  }
}
