/* ============================================================
   导航站 — 样式表
   ============================================================ */

/* ---------- 1. Reset & Base ---------- */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 24px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* 仅在 theme-ready 之后开启动画过渡 */
  transition: none;
}
.theme-ready body {
  transition: background-color 0.3s, color 0.3s;
}

img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; border: none; background: none; color: inherit; }
input, select { font: inherit; color: inherit; }
ul, ol { list-style: none; }

/* ---------- 2. Theme Variables ---------- */
:root {
  --accent: #4f6ef7;
  --accent-hover: #3b5de7;
  --accent-light: rgba(79, 110, 247, 0.08);

  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-skeleton: #e8ecf1;

  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;

  --border: #e5e7eb;
  --border-light: #f0f0f0;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 50px rgba(0,0,0,0.12);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;

  color-scheme: light;
}

[data-theme="dark"] {
  --accent: #6c8aff;
  --accent-hover: #8aa4ff;
  --accent-light: rgba(108, 138, 255, 0.12);

  --bg: #0f1117;
  --bg-card: #1a1b23;
  --bg-input: #1e1f2a;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --bg-skeleton: #252630;

  --text: #e8e8ed;
  --text-secondary: #9ca3af;
  --text-tertiary: #6b7280;

  --border: #2a2b35;
  --border-light: #22232d;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 2px 8px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.2);
  --shadow-xl: 0 20px 50px rgba(0,0,0,0.5);

  color-scheme: dark;
}

/* 无 JS 时的自动主题回退 */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --accent: #6c8aff;
    --accent-hover: #8aa4ff;
    --accent-light: rgba(108, 138, 255, 0.12);
    --bg: #0f1117;
    --bg-card: #1a1b23;
    --bg-input: #1e1f2a;
    --bg-hover: rgba(255, 255, 255, 0.05);
    --text: #e8e8ed;
    --text-secondary: #9ca3af;
    --border: #2a2b35;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
    color-scheme: dark;
  }
}

/* ---------- 3. Layout ---------- */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- 4. Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background-color 0.3s;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---------- 5. Buttons ---------- */
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon:active { transform: scale(0.95); }

/* 主题图标切换：始终只显示"下一个状态"对应的图标 */
/* light → 点击后变 dark → 显示 dark 图标 */
[data-theme="light"] .theme-icon-light,
[data-theme="light"] .theme-icon-auto { display: none; }
/* dark → 点击后变 auto → 显示 auto 图标 */
[data-theme="dark"] .theme-icon-dark,
[data-theme="dark"] .theme-icon-light { display: none; }
/* auto → 点击后变 light → 显示 light 图标 */
[data-theme="auto"] .theme-icon-dark,
[data-theme="auto"] .theme-icon-auto { display: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-secondary);
}
.btn-secondary:hover { color: var(--text); background: var(--border); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-danger-outline {
  color: var(--danger);
  background: transparent;
}
.btn-danger-outline:hover { background: rgba(239,68,68,0.08); }

.btn-close {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-tertiary);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}
.btn-close:hover { color: var(--text); }

/* ---------- 6. Hero Section ---------- */
.hero {
  text-align: center;
  padding: 48px 0 32px;
}

.clock {
  font-size: 4rem;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 1.1;
  color: var(--text);
}

.date {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.greeting {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text);
  margin-top: 12px;
}

/* ---------- 7. Search Box ---------- */
.search-wrap {
  position: relative;
  margin-top: 28px;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-full);
  padding: 4px 4px 4px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-light);
}

.search-icon {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 12px;
  font-size: 1rem;
  outline: none;
  color: var(--text);
  min-width: 0;
}
.search-input::placeholder {
  color: var(--text-tertiary);
}

.btn-search {
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 24px;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, transform 0.1s;
}
.btn-search:hover { background: var(--accent-hover); }
.btn-search:active { transform: scale(0.96); }

/* 搜索框抖动动画 */
.search-box.shake {
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ---------- 8. Engine Chips ---------- */
.engine-chips {
  display: flex;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 6px;
  margin-top: 14px;
}

.engine-chip {
  padding: 5px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.engine-chip:hover { color: var(--text); border-color: var(--text-tertiary); }
.engine-chip.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------- 9. Suggestions Dropdown ---------- */
.suggest-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
}

.suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  transition: background 0.1s;
}
.suggest-item:hover,
.suggest-item.active {
  background: var(--bg-hover);
}
.suggest-item .si-icon {
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.suggest-item .si-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.suggest-item .si-text mark {
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}
.suggest-item .si-tag {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* ---------- 10. Categories Grid ---------- */
.categories {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
  gap: 20px;
  padding-bottom: 40px;
}

.cat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s;
  opacity: 0;
  transform: translateY(16px);
}
.cat-card.visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease, box-shadow 0.2s, background-color 0.3s;
}
@media (hover: hover) {
  .cat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
  }
  .cat-card.visible:hover {
    transform: translateY(-2px);
  }
}

.cat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.cat-emoji {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  flex-shrink: 0;
}

.cat-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.cat-count {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  background: var(--bg-hover);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.cat-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  font-size: 1.1rem;
  transition: background 0.15s, color 0.15s;
}
.cat-add:hover { background: var(--accent-light); color: var(--accent); }

/* ---------- 11. Link Tiles ---------- */
.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.link-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.link-tile:hover { background: var(--bg-hover); }
.link-tile:active { transform: scale(0.95); }

.tile-icon-wrap {
  position: relative;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: contain;
}

.tile-letter {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

.tile-name {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.3;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 编辑模式下的操作按钮 */
.tile-actions {
  display: none;
  position: absolute;
  top: -6px;
  right: -6px;
  gap: 2px;
}

.link-tile.show-actions .tile-actions {
  display: flex;
}

.tile-action {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s;
}
.tile-action:active { transform: scale(0.9); }
.tile-action.edit { background: var(--accent); }
.tile-action.delete { background: var(--danger); }
.tile-action.edit:hover { background: var(--accent-hover); }
.tile-action.delete:hover { background: var(--danger-hover); }

/* Custom tag */
.tile-custom-tag {
  position: absolute;
  bottom: 2px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.7;
}

/* ---------- 12. Dialog ---------- */
dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow-xl);
  max-width: 440px;
  width: calc(100% - 40px);
  max-height: 90vh;
  overflow-y: auto;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.dialog-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

#link-form, #settings-form {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#link-form label, #settings-form > label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#link-form input[type="text"],
#link-form select,
#settings-form input[type="text"] {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#link-form input:focus,
#link-form select:focus,
#settings-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

#link-form select { cursor: pointer; }

.setting-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.9rem !important;
  font-weight: 400 !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  color: var(--text) !important;
}
.setting-checkbox input[type="checkbox"] {
  width: 36px;
  height: 36px;
  accent-color: var(--accent);
  cursor: pointer;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
  flex-wrap: wrap;
}

.dialog-actions-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.dialog-actions-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- 13. Toast ---------- */
#toast-root {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 22px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 1.8s forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

/* ---------- 14. Footer ---------- */
.footer {
  text-align: center;
  padding: 24px 0 40px;
  font-size: 0.78rem;
  color: var(--text-tertiary);
}

/* ---------- 15. Animations ---------- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 16. Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ---------- 17. Responsive ---------- */
@media (max-width: 768px) {
  .container { padding: 0 16px; }
  .hero { padding: 32px 0 24px; }
  .clock { font-size: 3rem; }
  .greeting { font-size: 1.1rem; }

  .categories {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .engine-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .engine-chips::-webkit-scrollbar { display: none; }

  .link-grid {
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  }

  .btn-search span { display: none; }
  .btn-search {
    width: 80px;
    height: 80px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .btn-search::after {
    content: '';
    display: block;
    width: 32px;
    height: 32px;
    background: currentColor;
    mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 20 20' fill='currentColor' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' d='M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z' clip-rule='evenodd'/%3E%3C/svg%3E") center / contain no-repeat;
    -webkit-mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 20 20' fill='currentColor' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' d='M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z' clip-rule='evenodd'/%3E%3C/svg%3E") center / contain no-repeat;
  }

  .topbar { padding: 10px 16px; }
  .topbar .logo-text { display: none; }

  .dialog-actions { flex-direction: column; align-items: stretch; }
  .dialog-actions-right { margin-left: 0; justify-content: flex-end; }
  .dialog-actions-left { justify-content: flex-start; }
}

@media (max-width: 480px) {
  .clock { font-size: 2.4rem; }
  .date { font-size: 0.85rem; }
  .greeting { font-size: 1rem; }
  .search-box { padding-left: 12px; }
  .search-input { font-size: 0.9rem; padding: 8px 8px; }
  .cat-card { padding: 14px; }
  .link-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 4px; }
  .tile-name { font-size: 0.68rem; }
}

/* ---------- 18. Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .cat-card { opacity: 1; transform: none; }
}
