/* ============================================================
   Java 教程共享导航（tutorials/java-common/）
   1) 左侧：左上角三杠按钮 + 全高文章导航侧栏
   2) 右侧：页内章节导航（DeepSeek 式悬浮小窗）
   3) 底部：上一篇 / 下一篇翻页条
   依赖各页内联 :root 设计令牌（--blue / --ink / --gray / --soft / --hairline / --ease）
   ============================================================ */

html { scroll-behavior: smooth; }

/* ---------- 右侧章节导航 ---------- */
.toc {
  --toc-rows: 4;
  --toc-row-h: 1.1rem;
  --toc-gap: .65rem;
  --toc-pad-y: .75rem;
  position: fixed;
  top: 50%;
  right: 1.2rem;
  transform: translateY(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--toc-gap);
  max-height: calc(var(--toc-rows) * var(--toc-row-h)
    + (var(--toc-rows) - 1) * var(--toc-gap)
    + 2 * var(--toc-pad-y));
  overflow-y: auto;
  padding: var(--toc-pad-y) .8rem;
  background: rgba(255, 255, 255, .86);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: 0 12px 34px rgba(29, 29, 31, .08);
  scrollbar-width: thin;
  transition: max-height .35s var(--ease), background-color .3s ease;
}

.toc:empty { display: none; }

/* 上下边缘淡出遮罩：内容可滚动时出现，且贴合滚动位置 */
.toc::before,
.toc::after {
  content: '';
  align-self: stretch;
  position: sticky;
  flex-shrink: 0;
  height: calc(var(--toc-row-h) * .75);
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease;
}

.toc::before {
  top: 0;
  margin-bottom: calc(-1 * (var(--toc-row-h) * .75 + var(--toc-gap)));
  background: linear-gradient(to bottom, #ffffff, rgba(255, 255, 255, 0));
}

.toc::after {
  bottom: 0;
  margin-top: calc(-1 * (var(--toc-row-h) * .75 + var(--toc-gap)));
  background: linear-gradient(to top, #ffffff, rgba(255, 255, 255, 0));
}

.toc.toc-overflow::before,
.toc.toc-overflow::after { opacity: 1; }

.toc.toc-at-top::before,
.toc.toc-at-bottom::after { opacity: 0; }

.toc-item {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.toc-title {
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: .9rem;
  font-weight: 500;
  line-height: var(--toc-row-h);
  color: var(--ink);
  opacity: 0;
  transform: translateX(-6px);
  transition: max-width .35s var(--ease), opacity .25s ease,
              transform .3s var(--ease), color .3s ease;
}

.toc-bar {
  flex: none;
  width: 1.1rem;
  height: .32rem;
  border-radius: 999px;
  background: var(--blue);
  opacity: .55;
  margin-left: 0;
  transition: opacity .3s ease, margin-left .35s var(--ease), width .3s var(--ease);
}

.toc:hover,
.toc:focus-within,
.toc.is-open {
  background: #ffffff;
  max-height: calc(100vh - 2.4rem);
  max-height: calc(100svh - 2.4rem);
}

.toc:hover .toc-title,
.toc:focus-within .toc-title,
.toc.is-open .toc-title {
  max-width: min(240px, 50vw);
  opacity: 1;
  transform: translateX(0);
}

.toc:hover .toc-bar,
.toc:focus-within .toc-bar,
.toc.is-open .toc-bar {
  margin-left: .8rem;
  opacity: 1;
}

.toc-item:hover .toc-title,
.toc-item:focus-visible .toc-title { color: var(--blue); }

.toc-item.active .toc-title { color: var(--blue); }
.toc-item.active .toc-bar { opacity: 1; }

.toc-item:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 4px;
  border-radius: 6px;
}

/* ---------- 左侧导航：三杠按钮 + 全高侧栏 ---------- */
.app-nav-btn {
  position: fixed;
  top: 1rem;
  left: 1.2rem;
  z-index: 80;
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  color: var(--ink);
  cursor: pointer;
  transition: background-color .3s ease, color .3s ease, border-color .3s ease;
}

.app-nav-btn:hover,
.app-nav-btn.open {
  background: #ffffff;
  color: var(--blue);
}

.app-nav-btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 4px;
}

.app-nav-btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

.app-scrim {
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgba(29, 29, 31, .18);
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease, visibility 0s linear .3s;
}

body.nav-open .app-scrim {
  opacity: 1;
  visibility: visible;
  transition: opacity .3s ease, visibility 0s;
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 90;
  width: min(300px, 86vw);
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-right: 1px solid var(--hairline);
  overflow-y: auto;
  visibility: hidden;
  transform: translateX(-102%);
  transition: transform .35s var(--ease), visibility 0s linear .35s;
}

body.nav-open .app-sidebar {
  visibility: visible;
  transform: translateX(0);
  transition: transform .35s var(--ease), visibility 0s;
}

.app-sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.4rem 1.5rem 1.1rem;
  border-bottom: 1px solid var(--hairline);
}

.app-sidebar-eyebrow {
  color: var(--blue);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .28em;
  text-transform: uppercase;
}

.app-sidebar-title {
  margin-top: .3rem;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--ink);
}

.app-sidebar-close {
  flex: none;
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--soft);
  border: none;
  border-radius: 50%;
  color: var(--ink);
  cursor: pointer;
  transition: background-color .3s ease, color .3s ease;
}

.app-sidebar-close:hover {
  background: var(--blue);
  color: #ffffff;
}

.app-sidebar-close:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

.app-nav-list {
  display: flex;
  flex-direction: column;
  padding: .6rem 1rem 1.5rem;
}

.app-nav-item {
  display: block;
  padding: 1rem .8rem;
  border-bottom: 1px solid var(--hairline);
  text-decoration: none;
  color: var(--ink);
  transition: transform .3s var(--ease), color .3s ease;
}

.app-nav-item:last-child { border-bottom: none; }

.app-nav-item:hover,
.app-nav-item:focus-visible {
  color: var(--blue);
  transform: translateX(4px);
}

.app-nav-title {
  display: block;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
}

.app-nav-sub {
  display: block;
  margin-top: .35rem;
  color: var(--gray);
  font-size: .8rem;
  font-weight: 400;
  line-height: 1.5;
}

.app-nav-item.current {
  border-left: 3px solid var(--blue);
  padding-left: calc(.8rem - 3px);
}

.app-nav-item.current .app-nav-title { color: var(--blue); }

/* ---------- 底部上一篇 / 下一篇 ---------- */
.pager {
  width: 100%;
  padding-inline: clamp(1.2rem, 6vw, 4rem);
  border-top: 1px solid var(--hairline);
}

.pager-inner {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 2.2rem 0;
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
}

.pager-item {
  display: block;
  max-width: 50%;
  text-decoration: none;
  color: var(--ink);
}

.pager-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--gray);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .14em;
}

.pager-title {
  display: block;
  margin-top: .55rem;
  font-size: clamp(1.05rem, 1.3vw + .6vh, 1.4rem);
  font-weight: 600;
  line-height: 1.4;
  transition: color .3s ease;
}

.pager-arrow {
  color: var(--blue);
  transition: transform .3s var(--ease);
}

.pager-prev .pager-arrow { transform: translateX(0); }
.pager-prev:hover .pager-arrow,
.pager-prev:focus-visible .pager-arrow { transform: translateX(-5px); }

.pager-next {
  margin-left: auto;
  text-align: right;
}

.pager-next .pager-label { justify-content: flex-end; }
.pager-next .pager-arrow { transform: translateX(0); }
.pager-next:hover .pager-arrow,
.pager-next:focus-visible .pager-arrow { transform: translateX(5px); }

.pager-item:hover .pager-title,
.pager-item:focus-visible .pager-title { color: var(--blue); }

.pager-item:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 4px;
  border-radius: 8px;
}

/* ---------- 小屏适配 ---------- */
@media (max-width: 760px) {
  .toc { right: .55rem; --toc-pad-y: .65rem; padding: var(--toc-pad-y) .6rem; }
  .toc-bar { width: .9rem; }
  .app-nav-btn { top: .8rem; left: .8rem; }
}

/* 减弱动效偏好：关闭平滑滚动与过渡 */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .toc, .toc *, .toc::before, .toc::after,
  .app-nav-btn, .app-scrim, .app-sidebar, .pager * { transition: none !important; }
}
