:root {
  --doc-sidebar-width: 320px;
}

.doc-page {
  min-height: 100dvh;
}

.doc-page .page-shell {
  overflow: visible;
}

.doc-page mark {
  background: rgba(246, 199, 110, 0.65);
  border-radius: 6px;
  padding: 0 2px;
}

.doc-header-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.doc-header-title strong {
  font-size: 1rem;
  line-height: 1.1;
}

.doc-header-title span {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.1;
}

.doc-layout {
  display: grid;
  grid-template-columns: var(--doc-sidebar-width) minmax(0, 1fr);
  gap: 24px;
  padding: clamp(20px, 4vw, 36px) 0 80px;
}

.doc-sidebar {
  position: sticky;
  top: 86px;
  height: calc(100dvh - 106px);
  overflow: auto;
  border: 1px solid var(--stroke);
  background: rgba(255, 250, 243, 0.72);
  border-radius: var(--radius);
  box-shadow: 0 12px 36px rgba(30, 20, 12, 0.08);
}

.doc-sidebar-inner {
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}

.doc-search {
  position: relative;
}

.doc-search input {
  width: 100%;
  padding: 10px 40px 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  font: inherit;
}

.doc-search input::placeholder {
  color: rgba(92, 79, 69, 0.7);
}

.doc-search button {
  position: absolute;
  right: 10px;
  top: 50%;
  translate: 0 -50%;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.doc-search button:hover {
  border-color: var(--stroke);
  background: rgba(30, 25, 20, 0.04);
}

.doc-nav-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.doc-nav-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: -8px;
}

.doc-nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 4px;
}

.doc-nav-list a,
.doc-nav-list button {
  width: 100%;
  text-align: left;
  display: block;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

.doc-nav-list a:hover,
.doc-nav-list button:hover {
  border-color: var(--stroke);
  background: rgba(30, 25, 20, 0.04);
  color: var(--ink);
}

.doc-nav-list a[data-active="true"] {
  border-color: rgba(227, 91, 43, 0.35);
  background: rgba(227, 91, 43, 0.08);
  color: var(--ink);
  font-weight: 700;
}

.doc-nav-item[data-level="2"] a {
  padding-left: 18px;
}

.doc-nav-item[data-level="3"] a {
  padding-left: 26px;
  font-size: 0.92rem;
}

.doc-card {
  border: 1px solid var(--stroke);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 2.5vw, 34px);
  overflow: hidden;
}

.doc-content {
  max-width: 84ch;
  margin: 0 auto;
  overflow-wrap: anywhere;
}

.doc-content h1 {
  font-size: clamp(1.8rem, 2.3vw, 2.2rem);
  margin-top: 42px;
}

.doc-content h1:first-child {
  margin-top: 0;
}

.doc-content h2 {
  font-size: clamp(1.45rem, 2vw, 1.85rem);
  margin-top: 34px;
}

.doc-content h3 {
  font-size: 1.15rem;
  margin-top: 24px;
}

.doc-content p {
  margin: 0 0 14px;
}

.doc-content ul,
.doc-content ol {
  margin: 0 0 18px;
  padding-left: 1.35rem;
}

.doc-content li {
  margin: 0 0 8px;
}

.doc-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.doc-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95em;
  background: rgba(42, 157, 143, 0.12);
  border: 1px solid var(--stroke);
  padding: 0.12em 0.38em;
  border-radius: 10px;
}

.doc-content pre {
  margin: 12px 0 22px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--stroke);
  background: rgba(255, 250, 243, 0.78);
  overflow: auto;
}

.doc-content pre code {
  background: transparent;
  border: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.95em;
}

.doc-content strong {
  font-weight: 700;
}

.doc-content .table-wrap {
  margin: 22px 0 26px;
}

.doc-content .compare p {
  margin: 0;
}

.doc-figure {
  margin: 22px 0 26px;
}

@media (min-width: 900px) {
  .doc-figure:not(.doc-figure-grid) {
    width: 60%;
    margin-left: auto;
    margin-right: auto;
  }

  .doc-content p .doc-image-link {
    width: 60%;
    margin-left: auto;
    margin-right: auto;
  }
}

.doc-figure.doc-figure-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.doc-image-link {
  display: block;
  border-radius: 18px;
  border: 1px solid rgba(65, 52, 43, 0.18);
  background: rgba(255, 255, 255, 0.9);
  overflow: hidden;
  box-shadow: 0 14px 30px rgba(30, 20, 12, 0.1);
  cursor: zoom-in;
}

.doc-image-link img {
  width: 100%;
  height: auto;
  display: block;
}

.doc-block {
  position: relative;
  scroll-margin-top: 104px;
}

.doc-permalink {
  display: none !important;
}

.doc-content :target {
  outline: 2px solid rgba(227, 91, 43, 0.45);
  outline-offset: 10px;
  border-radius: 14px;
}

.doc-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 12, 0.5);
  backdrop-filter: blur(3px);
  z-index: 25;
}

.doc-lightbox {
  position: fixed;
  isolation: isolate;
  border: none;
  width: min(1100px, 96vw);
  max-width: 96vw;
  height: min(86dvh, 860px);
  inset: 0;
  margin: auto;
  padding: 14px;
  background: rgba(25, 19, 14, 0.28);
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.doc-lightbox:not([open]) {
  display: none;
}

.doc-lightbox::backdrop {
  background: rgba(20, 16, 12, 0.7);
  backdrop-filter: blur(3px);
}

.doc-lightbox-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  border-radius: 18px;
  background: rgba(15, 12, 9, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12);
  touch-action: none;
}

.doc-lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  display: block;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.35);
  will-change: transform;
  transform-origin: center center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.doc-lightbox-stage[data-zoomed="true"] img {
  cursor: grab;
}

.doc-lightbox-stage[data-zoomed="true"] img:active {
  cursor: grabbing;
}

.doc-lightbox-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.doc-lightbox-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(30, 25, 20, 0.65);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.doc-lightbox-btn:hover {
  background: rgba(30, 25, 20, 0.82);
}

.doc-lightbox-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.doc-lightbox-zoom {
  min-width: 84px;
}

.doc-lightbox-open {
  font-weight: 600;
}

.doc-lightbox-close {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 40;
  transform: translateZ(0);
  will-change: transform;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(30, 25, 20, 0.65);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.doc-lightbox-close:hover {
  background: rgba(30, 25, 20, 0.8);
}

.doc-legacy-anchor {
  display: block;
  height: 0;
  width: 0;
  scroll-margin-top: 104px;
}

.doc-only-mobile {
  display: none;
}

@media (max-width: 980px) {
  :root {
    --doc-sidebar-width: min(360px, 86vw);
  }

  .doc-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .doc-only-mobile {
    display: inline-flex;
  }

  .doc-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: auto;
    translate: -110% 0;
    transition: translate 0.22s var(--ease);
    z-index: 30;
    border-radius: 0 22px 22px 0;
  }

  .doc-lightbox {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    border-radius: 0;
    padding: calc(14px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right))
      calc(14px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  }

  .doc-lightbox-stage {
    border-radius: 16px;
  }

  .doc-sidebar[data-open="true"] {
    translate: 0 0;
  }

  .doc-content :target {
    outline-offset: 6px;
  }
}

@media (max-width: 560px) {
  .doc-header-title span {
    display: none;
  }

  .doc-layout {
    padding: 14px 0 64px;
  }

  .doc-card {
    padding: 16px;
    border-radius: 16px;
  }

  .doc-figure.doc-figure-grid {
    grid-template-columns: 1fr;
  }
}
