:root {
  --bg: #0b0f16;
  --panel: #0f1522;
  --text: #d6e2f0;
  --muted: #8aa0b6;
  --accent: #24f0a8;
  --accent-2: #19a398;
  --accent-soft: rgba(36, 240, 168, 0.12);
  --card: #121a29;
  --card-border: #1c2738;
  --shadow: rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  --search-bg: #0e1523;
  --input-bg: #0e1523;
  --dock-bg: rgba(14,21,35,0.7);
  --footer-text: #9bb0c5;
  --sidebar-width: 120px;
  --topbar-height: 48px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--mono);
  color: var(--text);
  background: var(--bg);
}

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

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  padding-top: var(--topbar-height);
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid #0e1422;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.sidebar nav {
  width: 100%;
  max-width: 200px;
}
.main {
  min-width: 0;
  padding-top: var(--topbar-height);
}
.category-list {
  list-style: none;
  margin: 0;
  padding: 12px;
}
.category-list li {
  margin: 6px 0;
}
.category-item {
  width: 100%;
  text-align: left;
  padding: 10px 32px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.category-item.active {
  border-color: var(--accent-2);
  background: var(--accent-soft);
  color: var(--accent);
}
.category-item:hover { border-color: var(--accent); }

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--sidebar-width);
  align-items: center;
  gap: 16px;
  padding: 0 2%;
  background: var(--panel);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid #0e1422;
  z-index: 100;
  height: var(--topbar-height);
}
.topbar-left { 
  display: flex; 
  align-items: center; 
  justify-content: flex-start; 
  gap: 10px; 
  height: 100%; 
  width: var(--sidebar-width);
}
.brand-container {
  display: flex;
  align-items: center;
  gap: 6px;
}
.topbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  max-width: min(1200px, 100%);
  margin: 0 auto;
}
.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  height: 100%;
}
.brand {
  margin: 0;
  letter-spacing: 0.2em;
  font-weight: 800;
  font-size: 30px;
  color: var(--accent);
  text-shadow: 0 0 0 transparent;
  line-height: 1;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.websearch {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--search-bg);
  border: 1px solid var(--accent-2);
  border-radius: 10px;
  padding: 4px 6px;
  height: 32px;
  position: relative;
}
.websearch:focus-within {
  border-color: var(--accent);
}
#engine-toggle.engine-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  height: 24px;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--mono);
}
.engine-menu.hidden { display: none; }
.engine-caret { font-size: 10px; }
.engine-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--panel);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 30px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 12;
}
.engine-item {
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--mono);
}
.engine-item.active,
.engine-item:hover { background: var(--accent-soft); }
#web-search:focus { outline: none; }
#web-search {
  width: min(28vw, 360px);
  padding: 4px 8px;
  height: 24px;
  border: 0;
  background: transparent;
  color: var(--text);
  outline: none;
  text-align: center;
}
#web-search::placeholder { text-align: center; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: all .15s ease;
}
.btn:hover { background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }
.btn:active, .btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}
.btn-ghost {
  border-color: #203247;
  color: var(--muted);
}
.btn:hover { background: var(--accent-soft); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  font-size: 16px;
  flex-shrink: 0;
}
.theme-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

#user-menu.hidden { display: none; }
.user-menu { position: relative; }
.user-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--accent);
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--mono);
}
.topbar-right .user-btn {
  flex-direction: row-reverse;
  text-align: right;
}
.user-btn:hover { background: var(--accent-soft); }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #1b2a3f;
}
.user-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 96px;
  width: max-content;
  background: var(--panel);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 12px 30px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 20;
}
.menu-divider {
  height: 1px;
  background: #1b2a3f;
  margin: 6px 0;
}
.user-info {
  padding: 6px;
  border-radius: 10px;
  background: rgba(18, 26, 41, 0.6);
}
.user-info-body {
  display: grid;
  gap: 8px;
  justify-items: center;
}
.user-info-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px dashed var(--card-border);
  background: #1b2a3f;
  object-fit: cover;
  cursor: pointer;
}
.user-info-body input {
  width: 100%;
  text-align: center;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #1b2a3f;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}
.user-info-actions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.admin-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.profile-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.profile-actions { display: grid; gap: 8px; }
.menu-item {
  text-align: center;
  padding: 8px 10px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-family: var(--mono);
}
.menu-item:hover { background: var(--accent-soft); }
.menu-item.danger { color: #ff6b6b; }

.content-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.sidebar-actions {
  display: grid;
  gap: 12px;
  padding: 12px;
  border-top: 1px solid #0e1422;
}
.sidebar-range {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.category-text { text-align: left; }

#bookmark-file {
  display: none;
}

.admin-only { display: none; }

.hidden { display: none !important; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: grid;
  place-items: center;
  z-index: 20;
}
.modal {
  width: min(540px, 92vw);
  background: var(--panel);
  border: 1px solid #1d2940;
  border-radius: 12px;
  box-shadow: 0 24px 60px var(--shadow);
  padding: 18px 18px 8px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.modal .head-actions { display:flex; gap:8px; }
.modal h3 {
  margin: 0 0 12px;
  font-size: 16px;
  letter-spacing: .08em;
  color: var(--accent);
}
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}
.field label {
  color: var(--muted);
  font-size: 12px;
}
.field input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #1b2a3f;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}
.field select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #1b2a3f;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}
.error {
  min-height: 18px;
  color: #ff6b6b;
  font-size: 12px;
  margin-bottom: 8px;
}
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid #162235;
}
.flex-spacer { flex: 1; }

.float-edit {
  position: fixed;
  right: 16px;
  bottom: 84px;
  z-index: 16;
}
#search {
  width: min(28vw, 320px);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #1b2a3f;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}
#search::placeholder { color: #69829d; }

.content {
  padding: 24px clamp(16px, 4vw, 32px) 64px;
  width: min(1200px, 100%);
  margin: 0 auto;
}
.empty {
  margin: 8vh auto 4vh;
  max-width: 720px;
  text-align: left;
  color: var(--muted);
  background: var(--card);
  border: 1px solid #162235;
  border-radius: var(--radius);
  padding: 24px 24px 16px;
}
.empty .tip {
  margin-top: 8px;
  color: #7fa3a1;
  font-size: 13px;
}
.groups {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}
.group {
  grid-column: span 4;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px var(--shadow);
  overflow: hidden;
}
.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
  border-bottom: 1px solid #152032;
  color: var(--muted);
}
.group-title {
  margin: 0;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: .08em;
}
.links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(168px * var(--bookmark-scale, 1)), 1fr));
  gap: 12px;
  padding: 12px 14px 16px;
}
.link-card {
  display: flex;
  align-items: center;
  gap: calc(8px * var(--bookmark-scale, 1));
  padding: calc(4px * var(--bookmark-scale, 1));
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: calc(10px * var(--bookmark-scale, 1));
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
  user-select: none;
  height: calc(80px * var(--bookmark-scale, 1));
}
.link-card:hover {
  transform: translateY(-1px);
  border-color: var(--accent-2);
  background: #101828;
}
.link-card:hover .link-title { color: var(--accent); }
.link-card .dot {
  display: none;
}
.link-card .icon {
  width: calc(72px * var(--bookmark-scale, 1));
  height: calc(72px * var(--bookmark-scale, 1));
  border-radius: calc(4px * var(--bookmark-scale, 1));
  background: transparent;
  flex: none;
}
.add-card {
  flex-direction: row;
  align-items: center;
  border-style: dashed;
  opacity: 0.85;
}
.add-card:hover { opacity: 1; }
.add-icon {
  width: var(--bookmark-size);
  height: var(--bookmark-size);
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px dashed var(--card-border);
  color: var(--muted);
  font-size: 24px;
  flex: none;
}
.add-card .meta {
  text-align: left;
}
.add-card .link-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}
.add-card .link-url { display: none; }

.color-input {
  width: 100%;
  height: 40px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid #1b2a3f;
  background: var(--input-bg);
}
.link-card .meta {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  justify-content: center;
  align-items: center;
  gap: 4px;
}
.link-title {
  font-size: calc(14px * var(--bookmark-scale, 1));
  font-weight: 700;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  max-width: 100%;
}
.link-desc {
  font-size: calc(12px * var(--bookmark-scale, 1));
  color: var(--muted);
  text-align: center;
  width: 100%;
  max-width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  max-height: calc(24px * var(--bookmark-scale, 1));
}

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 10px;
  padding: 0 12px;
  color: var(--footer-text);
  text-align: center;
  z-index: 5;
}
.footer .sep { display:none; }
.footer .link { display:none; }

@media (max-width: 1080px) {
  .group { grid-column: span 6; }
}

/* 中等尺寸窗口 - 收窄目录栏和搜索栏 */
@media (max-width: 1024px) and (min-width: 768px) {
  :root {
    --sidebar-width: 100px;
  }
  
  .sidebar .category span {
    font-size: 12px;
  }
  
  /* 缩小搜索栏 */
  .websearch {
    max-width: 300px;
  }
  
  .websearch input {
    font-size: 13px;
    padding: 8px 12px;
  }
}

/* 小尺寸窗口 - 进一步收窄目录栏，缩小搜索栏 */
@media (max-width: 800px) and (min-width: 640px) {
  :root {
    --sidebar-width: 80px;
  }
  
  .sidebar .category span {
    font-size: 11px;
  }
  
  /* 进一步缩小搜索栏 */
  .websearch {
    max-width: 200px;
  }
  
  .websearch input {
    font-size: 12px;
    padding: 6px 10px;
  }
  
  .engine-toggle {
    font-size: 11px;
  }
}

/* 窗口宽度小于640px - 隐藏搜索栏和dock栏 */
@media (max-width: 640px) {
  .websearch {
    display: none;
  }
  
  .topbar-center {
    flex: 0;
  }
  
  .topbar-right {
    margin-left: auto;
  }
  
  /* 隐藏dock栏 */
  .dock {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(100%);
    transition: all 0.3s ease;
  }
  
  /* 底部提示条 */
  .dock-toggle {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 10px;
    width: 60px;
    height: 4px;
    background: var(--accent);
    border-radius: 2px;
    opacity: 0.6;
    cursor: pointer;
    z-index: 14;
    transition: all 0.3s ease;
  }
  
  .dock-toggle:hover {
    opacity: 1;
    width: 80px;
  }
  
  /* 鼠标悬停在提示条或底部区域时显示dock栏 */
  .dock-toggle:hover + .dock,
  .dock:hover {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
  }
  
  .links { grid-template-columns: 1fr; }
  #search { width: min(56vw, 320px); }
}
@media (min-width: 1680px) {
  .group { grid-column: span 3; }
  .links { grid-template-columns: repeat(4, 1fr); }
}

/* Dock */
:root { --dock-size: 84px; --bookmark-size: 44px; }
.dock {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 44px;
  display: flex;
  align-items: flex-end;
  gap: 24px;
  padding: 10px 12px;
  border-radius: 14px;
  z-index: 15;
  min-height: calc(var(--dock-size) * 0.9);
  min-width: calc(var(--dock-size) * 4 + 24px * 3 + 24px);
  transition: all 0.3s ease;
}
.dock::after {
  content: '';
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  width: 120%;
  min-width: calc(var(--dock-size) * 4 + 24px * 3 + 24px);
  height: 32px;
  background: var(--accent);
  border-radius: 50%;
  z-index: -1;
  filter: blur(16px);
  opacity: 0.7;
}
.dock.no-shadow::after {
  display: none;
}
.dock.hidden { display: none; }
.dock-item {
  width: var(--dock-size);
  height: var(--dock-size);
  border-radius: 20%;
  overflow: hidden;
  display: grid;
  place-items: center;
  transition: transform .12s ease;
}
.dock-item:hover { transform: translateY(-4px) scale(1.06); }
.dock-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: transparent;
}

/* 主题：浅色/深色与系统 */
[data-theme="light"] {
  --bg: #ffffff;
  --panel: #fffaf5;
  --text: #1f2a33;
  --muted: #6b7b88;
  --accent: #ff6a00;
  --accent-2: #ff3d00;
  --card: #ffffff;
  --card-border: #e8edf2;
  --shadow: rgba(0, 0, 0, 0.12);
  background: var(--bg);
  --search-bg: #ffe9d5;
  --input-bg: #fff2e6;
  --dock-bg: #ffe0c2;
  --footer-text: #a4aeb8;
  --accent-soft: rgba(255, 106, 0, 0.12);
}
[data-theme="light"] .sidebar {
  background: var(--panel);
  border-right: 1px solid #edf1f5;
}
[data-theme="light"] .topbar {
  border-bottom: 1px solid #ffd4ad;
}
[data-theme="light"] .websearch {
  border-color: var(--accent-2);
}
[data-theme="light"] .field input {
  border-color: #ffd4ad;
}
[data-theme="light"] .modal {
  border-color: #ffd4ad;
}
[data-theme="light"] .modal-actions {
  border-top-color: #ffd4ad;
}
[data-theme="light"] input[type="checkbox"],
[data-theme="light"] input[type="radio"],
[data-theme="light"] input[type="range"] {
  accent-color: var(--accent);
}
[data-theme="light"] .group-header {
  border-bottom: 1px solid #edf1f5;
  color: var(--muted);
}
[data-theme="light"] .empty {
  background: var(--card);
  border: 1px solid #edf1f5;
}
[data-theme="light"] .link-card {
  background: #ffffff;
  border-color: var(--card-border);
}
[data-theme="light"] .link-card:hover {
  background: #fff1e6;
  border-color: var(--accent-2);
}
[data-theme="light"] .brand {
  text-shadow: none;
  color: var(--accent);
}
[data-theme="light"] .btn-ghost {
  border-color: #ffd4ad;
  color: var(--accent-2);
}
[data-theme="light"] .btn-ghost:hover {
  background: rgba(255, 106, 0, 0.12);
  border-color: var(--accent-2);
}
[data-theme="light"] .btn {
  box-shadow: 0 8px 18px rgba(255, 106, 0, 0.12);
}
[data-theme="light"] .dock-item:hover {
  border-color: var(--accent-2);
}
[data-theme="light"] .category-item.active {
  background: rgba(255, 106, 0, 0.18);
  border-color: var(--accent-2);
}
[data-theme="light"] .eng.active {
  background: rgba(255, 106, 0, 0.22);
}
[data-theme="dark"] {
  /* 使用默认暗色变量，已由上方定义 */
}

/* 响应式布局 - 手机适配 */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 60px;
    --topbar-height: 44px;
  }
  
  .app {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    padding-top: var(--topbar-height);
  }
  
  .sidebar {
    position: sticky;
    top: var(--topbar-height);
    height: calc(100vh - var(--topbar-height));
    border-right: 1px solid #0e1422;
    flex-direction: column;
    flex-wrap: nowrap;
    padding: 8px 4px;
    gap: 8px;
  }
  
  .sidebar .category {
    min-width: 48px;
    max-width: 48px;
    flex: none;
  }
  
  .sidebar .category span {
    font-size: 10px;
    text-align: center;
  }
  
  .content {
    padding-bottom: 60px;
  }
  
  .links {
    grid-template-columns: repeat(auto-fill, minmax(calc(100px * var(--bookmark-scale, 1)), 1fr));
    gap: 10px;
    padding: 10px 12px;
  }
  
  .link-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: calc(100px * var(--bookmark-scale, 1));
    padding: calc(8px * var(--bookmark-scale, 1));
  }
  
  .link-card .icon {
    width: calc(64px * var(--bookmark-scale, 1));
    height: calc(64px * var(--bookmark-scale, 1));
    border-radius: calc(4px * var(--bookmark-scale, 1));
    background: transparent;
    flex: none;
    margin-bottom: calc(8px * var(--bookmark-scale, 1));
  }
  
  .link-card .meta {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    justify-content: center;
    align-items: center;
    gap: 0;
  }
  
  .link-card .link-desc {
    display: none;
  }
  
  .link-card .link-title {
    font-size: calc(12px * var(--bookmark-scale, 1));
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    max-width: 100%;
  }
  
  .topbar {
    padding: 0 12px;
  }
  
  .topbar-right {
    gap: 8px;
  }
  
  .topbar-right .user {
    font-size: 12px;
  }
  
  .logo {
    font-size: 14px;
  }
  
  .search {
    max-width: 200px;
  }
  
  .search input {
    font-size: 13px;
  }
  
  .search-engines {
    gap: 6px;
  }
  
  .search-engines button {
    font-size: 11px;
    padding: 4px 8px;
  }
}

/* 小屏幕手机适配 */
@media (max-width: 480px) {
  .links {
    grid-template-columns: repeat(auto-fill, minmax(calc(80px * var(--bookmark-scale, 1)), 1fr));
    gap: 8px;
    padding: 8px 10px;
  }
  
  .link-card {
    height: calc(80px * var(--bookmark-scale, 1));
  }
  
  .link-card .icon {
    width: calc(48px * var(--bookmark-scale, 1));
    height: calc(48px * var(--bookmark-scale, 1));
  }
  
  .link-card .link-title {
    font-size: calc(10px * var(--bookmark-scale, 1));
  }
  
  .sidebar {
    padding: 6px 2px;
    gap: 6px;
  }
  
  .sidebar .category {
    min-width: 44px;
    max-width: 44px;
  }
  
  .sidebar .category span {
    font-size: 9px;
  }
}
