:root {
  --bg: #f0f2f8;
  --panel: #ffffff;
  --text: #1a1f36;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #5b5ef7;
  --brand-dark: #4346d9;
  --brand-soft: #ededfe;
  --shadow: 0 8px 24px rgba(26, 31, 54, 0.08);
  --sidebar-w: 280px;
  --header-h: 76px;
  --radius: 14px;
  --icon-bg: #f1f5f9;
  --nav-text: #475569;
  --nav-dot: #cbd5e1;
  --hover-border: #c7d2fe;
  --overlay: rgba(15, 23, 42, 0.45);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --panel: #1a1d27;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --line: #2d3140;
  --brand: #7c7ff9;
  --brand-dark: #a5a7fb;
  --brand-soft: #2a2d4a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --icon-bg: #252836;
  --nav-text: #b0b4bc;
  --nav-dot: #4a4f5e;
  --hover-border: #4a4f8a;
  --overlay: rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
}

a {
  color: inherit;
  text-decoration: none;
}

.layout {
  min-height: 100vh;
  display: flex;
}

/* ── 左侧边栏 ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s, transform 0.25s ease;
}

.sidebar-logo {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  flex-shrink: 0;
  object-fit: cover;
  display: block;
}

.logo-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.logo-text strong {
  font-size: 20px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo-text span {
  font-size: 13px;
  color: var(--brand);
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 10px 16px;
}

.nav-group {
  margin-bottom: 6px;
}

.nav-major {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-major::after {
  content: "";
  margin-left: auto;
  width: 10px;
  height: 10px;
  border-right: 2.5px solid var(--muted);
  border-bottom: 2.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.2s, border-color 0.15s;
  flex-shrink: 0;
}

.nav-group.open .nav-major::after {
  transform: rotate(45deg);
}

.nav-minors {
  display: none;
  padding: 2px 0 4px 8px;
}

.nav-group.open .nav-minors {
  display: block;
}

.nav-minors a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 12px;
  border-radius: 8px;
  color: var(--nav-text);
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
}

.nav-minors a::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--nav-dot);
  flex-shrink: 0;
  transition: background 0.15s;
}

.nav-minors a.active::before {
  background: var(--brand);
}

.nav-minors a.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  .nav-major:hover {
    background: var(--brand-soft);
    color: var(--brand);
  }

  .nav-major:hover::after {
    border-color: var(--brand);
  }

  .nav-minors a:hover {
    background: var(--brand-soft);
    color: var(--brand);
  }

  .nav-minors a:hover::before {
    background: var(--brand);
  }
}

/* ── 右侧主区 ── */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main-header {
  height: var(--header-h);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
  gap: 12px;
  transition: background 0.2s, border-color 0.2s;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex-shrink: 0;
  object-fit: cover;
  display: block;
}

.header-logo h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.header-logo p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--brand);
}

.main-content {
  flex: 1;
  padding: 24px 28px 16px;
}

.major-block {
  margin-bottom: 48px;
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.major-block:last-child {
  margin-bottom: 16px;
}

.major-title {
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 4px;
  color: var(--text);
}

.major-desc {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.subcategory-block {
  margin-bottom: 28px;
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.subcategory-block:last-child {
  margin-bottom: 0;
}

.subcategory-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.subcategory-title::before {
  content: "";
  width: 4px;
  height: 16px;
  border-radius: 4px;
  background: var(--brand);
  flex-shrink: 0;
}

.empty-state {
  padding: 20px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
  gap: 14px;
}

.tool-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s, background 0.2s;
  cursor: pointer;
}

.tool-card:hover {
  transform: translateY(-2px);
  border-color: var(--hover-border);
  box-shadow: var(--shadow);
}

.tool-card:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.tool-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.06);
  flex-shrink: 0;
  overflow: hidden;
}

[data-theme="dark"] .tool-icon {
  background: #f2f3f5;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 2px 8px rgba(0, 0, 0, 0.28);
}

.tool-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
}

.tool-info {
  flex: 1;
  min-width: 0;
}

.tool-name {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
  white-space: nowrap;
}

.tool-desc {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.main-footer {
  padding: 18px 28px 24px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 13px;
  color: var(--muted);
  transition: background 0.2s, border-color 0.2s;
}

.main-footer p {
  margin: 0 0 4px;
}

.main-footer a {
  color: var(--brand);
}

.main-footer a:hover {
  text-decoration: underline;
}

.footer-beian {
  margin: 0 0 4px;
  font-size: 13px;
}

.footer-beian a {
  color: var(--muted);
}

.footer-beian a:hover {
  color: var(--brand);
}

.footer-note {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.85;
}

/* ── 右下角悬浮按钮组 ── */
.float-actions {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.float-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--brand);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s, border-color 0.2s, transform 0.15s, opacity 0.2s, visibility 0.2s;
}

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

.float-btn:hover {
  transform: scale(1.05);
}

.back-to-top {
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  pointer-events: none;
}

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

.back-to-top.show:hover {
  transform: translateY(0) scale(1.05);
}

.theme-toggle {
  position: relative;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  position: absolute;
  transition: opacity 0.2s, transform 0.2s;
}

.theme-toggle .icon-sun {
  opacity: 1;
}

.theme-toggle .icon-moon {
  opacity: 0;
  transform: rotate(-30deg) scale(0.8);
}

[data-theme="dark"] .theme-toggle .icon-sun {
  opacity: 0;
  transform: rotate(30deg) scale(0.8);
}

[data-theme="dark"] .theme-toggle .icon-moon {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* ── 手机端汉堡菜单按钮（参考 ai-bot.cn：纯图标，无边框） ── */
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #1a1a2e;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.menu-icon {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
}

/* ── 侧边栏遮罩 ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s;
}

.sidebar-overlay.show {
  display: block;
  opacity: 1;
}

/* ── 移动端 ── */
@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-w);
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-nav {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 12px calc(16px + env(safe-area-inset-bottom, 0));
  }

  .menu-toggle {
    display: inline-flex;
  }

  .main-header {
    padding: 0 16px;
  }

  .main-content,
  .main-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .float-actions {
    right: 16px;
    bottom: 16px;
  }
}
