:root {
  --ink: #1a1228;
  --ink-soft: #2a1b3d;
  --paper: #f3eef8;
  --muted: #b7a8c9;
  --accent: #9b6dff;
  --accent-soft: #c4a8ff;
  --line: rgba(196, 168, 255, 0.35);
  --bar-h: 64px;
  /* 分割线上浅、线下深（上下对换后） */
  --bar-bg: #2a2038;
  --page-bg: #302642;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Noto Serif SC", "Songti SC", serif;
  color: var(--paper);
  background: var(--ink);
}

.atmosphere {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 18% 8%, rgba(155, 109, 255, 0.28), transparent 42%),
    radial-gradient(ellipse at 88% 18%, rgba(196, 168, 255, 0.16), transparent 40%),
    linear-gradient(165deg, #241536 0%, #160f22 48%, #1f1630 100%);
  z-index: -1;
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
  opacity: 0.3;
  pointer-events: none;
}

.corner-portrait {
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 0;
  width: auto;
  height: min(58vh, 420px);
  max-width: min(46vw, 320px);
  opacity: 0.35;
  pointer-events: none;
  user-select: none;
  object-fit: contain;
  object-position: right bottom;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  min-height: var(--bar-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 0.75rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bar-bg);
  /* 必须 visible，否则应用下拉会被裁切，看起来像颜色溢出 */
  overflow: visible;
}

.brand {
  position: relative;
  z-index: 5;
  justify-self: start;
  font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-soft);
  text-decoration: none;
  line-height: 1;
}

.nav {
  position: relative;
  z-index: 1;
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.1rem 0.15rem;
  max-width: 100%;
}

.account-btn {
  position: relative;
  z-index: 5;
  justify-self: end;
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(42, 27, 61, 0.72);
  color: var(--accent-soft);
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.account-btn svg {
  width: 22px;
  height: 22px;
  display: block;
  pointer-events: none;
}

.account-btn:hover {
  background: rgba(155, 109, 255, 0.22);
  border-color: rgba(196, 168, 255, 0.55);
  color: var(--paper);
}

.account-btn.is-pulse {
  transform: scale(0.96);
}

.nav-link,
.nav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.98rem;
  text-decoration: none;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s ease, background 0.2s ease;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.nav-link:hover,
.nav-btn:hover,
.nav-link.is-active,
.nav-item.open > .nav-btn {
  color: var(--paper);
}

.nav-item {
  position: relative;
}

.caret {
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4.5px solid currentColor;
  vertical-align: middle;
  transition: transform 0.2s ease;
}

.nav-item.open .caret {
  transform: rotate(180deg);
}

.submenu {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 50%;
  min-width: 11rem;
  padding: 0.4rem;
  border: 1px solid var(--line);
  background: #2a1b3d;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, 6px);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
  z-index: 300;
}

.nav-item.open > .submenu,
.nav-item:hover > .submenu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.submenu a {
  display: block;
  padding: 0.7rem 0.85rem;
  color: var(--paper);
  text-decoration: none;
  font-size: 0.95rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.submenu a:hover {
  background: rgba(155, 109, 255, 0.18);
  color: var(--accent-soft);
}

.submenu .empty,
.submenu .disabled {
  display: block;
  padding: 0.7rem 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.shell {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - var(--bar-h));
  width: min(1040px, calc(100% - 2.5rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

@media (max-width: 768px) {
  :root {
    --bar-h: auto;
  }

  .atmosphere {
    background:
      radial-gradient(ellipse at 18% 55%, rgba(155, 109, 255, 0.12), transparent 42%),
      radial-gradient(ellipse at 88% 70%, rgba(196, 168, 255, 0.08), transparent 40%),
      linear-gradient(180deg, var(--page-bg) 0%, #241a34 45%, #1f1630 100%);
  }

  .corner-portrait {
    /* 按高度适配，保证全身入画，避开 Safari 底栏 */
    height: min(48vh, 300px);
    max-width: min(62vw, 240px);
    bottom: env(safe-area-inset-bottom, 0);
    right: 0;
  }

  .atmosphere::after {
    opacity: 0.18;
  }

  .topbar {
    padding: 0.5rem 0.55rem;
    column-gap: 0.35rem;
    background: var(--bar-bg);
    border-bottom-color: rgba(196, 168, 255, 0.22);
    overflow: visible;
  }

  html, body {
    background: var(--page-bg);
  }

  .brand {
    font-family: "Songti SC", "STSong", "Noto Serif SC", "SimSun", serif;
    font-size: 1.28rem;
    font-weight: 700;
    letter-spacing: 0.04em;
  }

  .nav-link,
  .nav-btn {
    font-size: 0.84rem;
    padding: 0.36rem 0.38rem;
  }

  .nav-btn {
    gap: 0.14rem;
    padding-right: 0.28rem;
  }

  .account-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
  }

  .account-btn svg {
    width: 18px;
    height: 18px;
  }

  /* 手机端只用点击展开，避免 hover 残留半截菜单 */
  .nav-item:hover > .submenu {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .nav-item.open > .submenu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    min-width: 10rem;
    left: 50%;
    right: auto;
  }

  .shell {
    width: min(1040px, calc(100% - 1.5rem));
    padding: 1.25rem 0 2rem;
  }
}
