:root {
  color-scheme: dark;
  --page-width: min(1120px, 100%);
  --toolbar-height: 58px;
  --accent: #28dcff;
  --bg: #03060c;
  --surface: rgba(7, 12, 24, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --muted: rgba(255, 255, 255, 0.58);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: auto;
  background:
    radial-gradient(circle at 50% 0%, rgba(12, 86, 153, 0.15), transparent 32rem),
    var(--bg);
  color: #fff;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.reading-progress {
  position: fixed;
  z-index: 100;
  inset: 0 0 auto;
  height: 2px;
  background: rgba(255, 255, 255, 0.08);
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #0d5dff, #24e5df);
  box-shadow: 0 0 14px rgba(36, 229, 223, 0.7);
  transition: width 100ms linear;
}

.viewer-toolbar {
  position: fixed;
  z-index: 90;
  top: 14px;
  left: 50%;
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr);
  align-items: center;
  width: min(1180px, calc(100vw - 28px));
  min-height: var(--toolbar-height);
  padding: 8px 10px 8px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(18px) saturate(1.25);
  transform: translateX(-50%);
  transition: opacity 180ms ease, transform 180ms ease;
}

.viewer-toolbar.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -130%);
}

.identity {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: max-content;
  color: #fff;
  text-decoration: none;
}

.identity-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.identity-role {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
}

.chapter-nav {
  display: flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.chapter-link {
  padding: 8px 10px;
  border-radius: 9px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
  transition: color 160ms ease, background 160ms ease;
}

.chapter-link:hover,
.chapter-link.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.viewer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

.icon-button,
.text-button {
  min-width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.055);
  color: rgba(255, 255, 255, 0.84);
  cursor: pointer;
}

.icon-button {
  font-size: 18px;
}

.text-button {
  padding: 0 9px;
  font-size: 11px;
}

.icon-button:hover,
.text-button:hover {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
}

#zoom-value {
  width: 44px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.portfolio-shell {
  width: var(--page-width);
  margin: 0 auto;
  padding: 0 0 8vh;
  transition: width 180ms ease;
}

.portfolio-page {
  width: 100%;
  background: #05080e;
}

.portfolio-page img,
.portfolio-page picture {
  display: block;
}

.portfolio-page img {
  width: 100%;
  height: auto;
  border: 0;
}

.chapter-start {
  scroll-margin-top: calc(var(--toolbar-height) + 28px);
}

.back-to-top {
  position: fixed;
  z-index: 80;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(9, 16, 31, 0.86);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.32);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.back-to-top:hover {
  transform: translateY(-2px);
}

.noscript-note {
  position: fixed;
  z-index: 120;
  right: 16px;
  bottom: 16px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #fff;
  color: #111;
  font-size: 13px;
}

@media (max-width: 900px) {
  body {
    overflow-x: hidden;
  }

  .viewer-toolbar {
    top: 8px;
    display: block;
    width: calc(100vw - 20px);
    min-height: 0;
    padding: 5px;
    border-radius: 13px;
  }

  .chapter-nav {
    width: 100%;
    margin: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .chapter-nav::-webkit-scrollbar {
    display: none;
  }

  .chapter-link {
    flex: 1 0 auto;
    text-align: center;
  }

  .identity,
  .viewer-actions {
    display: none;
  }

  .chapter-start {
    scroll-margin-top: 58px;
  }
}

@media (max-width: 560px) {
  :root {
    --page-width: 100%;
  }

  .portfolio-shell {
    max-width: 100%;
  }

  .viewer-toolbar {
    border-radius: 12px;
  }

  .chapter-link {
    padding: 7px 8px;
    font-size: 11px;
  }

  .back-to-top {
    width: 40px;
    height: 40px;
  }
}

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

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .viewer-toolbar,
  .reading-progress,
  .back-to-top {
    display: none;
  }

  .portfolio-shell {
    width: 100%;
  }
}
