:root {
  --bg: #ffffff;
  --surface: #f8fafc;
  --text: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --accent: #0f766e;
  --max-width: 1280px;
  --content-width: 100%;
  --toc-width: 270px;
  --gap: 40px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.7;
}

a {
  color: var(--accent);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

.header-inner {
  max-width: var(--max-width);
  min-height: 64px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  letter-spacing: -0.02em;
  font-size: 1.5rem;
}

.back-link {
  font-size: 1rem;
  text-decoration: none;
}

.content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 48px 24px 72px;
  display: grid;
  grid-template-columns: minmax(0, var(--content-width)) var(--toc-width);
  gap: var(--gap);
  align-items: start;
}

.case-study {
  min-width: 0;
}

.case-study > h1 {
  margin: 0 0 32px;
  font-size: 48px;
  line-height: 1.1;
  letter-spacing: -1px;
}

.case-study > h1 + blockquote {
  margin-top: 0;
  margin-bottom: 24px;
}

h2 {
  margin-bottom: 24px;
  margin-top: 0;
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

h3 {
  margin: 24px 0 16px;
  font-size: 24px;
  line-height: 1.3;
}

p,
ul,
ol,
blockquote,
table,
pre {
  margin-top: 0;
  margin-bottom: 16px;
}

ul,
ol {
  padding-left: 1.4rem;
}

blockquote {
  padding: 18px 22px;
  background: var(--surface);
  border-left: 4px solid var(--accent);
  color: var(--muted);
}

hr {
  margin: 48px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

img {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
  margin: 28px auto 14px;
}

table {
  width: 100%;
  border: 1px solid var(--border);
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--surface);
}

tr:last-child td {
  border-bottom: 0;
}

code {
  padding: 0.15em 0.35em;
  background: var(--surface);
  border-radius: 5px;
  font-size: 0.9em;
}

pre {
  overflow-x: auto;
  padding: 16px 18px;
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  line-height: 1.6;
}

pre code {
  padding: 0;
  background: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre;
}

.mermaid {
  width: 100%;
  margin: 28px 0 18px;
  padding: 20px;
  overflow-x: auto;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

.toc {
  position: sticky;
  top: 88px;
  width: var(--toc-width);
  max-height: calc(100vh - 112px);
  overflow: hidden;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.88rem;
}

.toc strong {
  display: block;
  margin-bottom: 10px;
}

.toc nav {
  max-height: calc(100vh - 170px);
  overflow-y: auto;
}

.toc ul {
  margin: 0;
  padding-left: 18px;
}

.toc li {
  margin: 5px 0;
}

.toc a {
  text-decoration: none;
}

.loading,
.error {
  margin: 80px auto;
  color: var(--muted);
}

.error {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 42px;
  height: 42px;
  border: 1px solid #e2e8f0;
  border-radius: 50%;
  background: white;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  z-index: 100;

  display: flex;
  align-items: center;
  justify-content: center;
}

.back-to-top img {
  width: 24px;
  height: 24px;
  display: block;
  margin: 0;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  background: #f8fafc;
}

@media (max-width: 1050px) {
  :root {
    --content-width: 1fr;
    --toc-width: 220px;
    --gap: 32px;
  }
}

@media (max-width: 800px) {
  .header-inner {
    padding: 0 16px;
  }

  .content {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .toc {
    position: static;
    width: 100%;
    max-height: none;
    overflow: visible;
    order: -1;
  }

  .toc nav {
    max-height: none;
  }

  .mermaid {
    padding: 12px;
  }

  th,
  td {
    padding: 9px 10px;
  }

  .back-to-top {
    right: 16px;
    bottom: 16px;
  }

  .case-study > h1 {
    font-size: 36px;
    line-height: 1.12;
  }

  h2 {
    font-size: 24px;
    line-height: 1.2;
  }

  h3 {
    font-size: 20px;
  }
}
