/* ============================================================
   my-nav 样式（Bento 便当盒：顶部工具条 + 大小不一的卡片拼图）
   深浅色：默认跟随系统，html[data-theme] 为手动锁定
   主题色：--accent 由 app.js 写入
   ============================================================ */

:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --panel: #ffffff;
  --text: #1f2329;
  --sub: #5b6270;
  --muted: #98a0aa;
  --border: #e9ebef;
  --border-strong: #d9dce1;
  --hover: rgba(31, 35, 41, 0.05);
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --accent-soft-2: rgba(59, 130, 246, 0.24);
  --shadow: 0 2px 10px rgba(20, 25, 45, 0.04);
  --shadow-lift: 0 10px 26px rgba(20, 25, 45, 0.13);
  --icon-bg: #ffffff;
  --glass: rgba(255, 255, 255, 0.9);
  --bar-shadow: 0 2px 14px rgba(20, 25, 45, 0.09);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0f1116;
    --surface: #191c22;
    --panel: #191c22;
    --text: #e9eaee;
    --sub: #b3b8c1;
    --muted: #8d949f;
    --border: #262a31;
    --border-strong: #363b44;
    --hover: rgba(233, 234, 238, 0.07);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 10px 26px rgba(0, 0, 0, 0.55);
    --icon-bg: rgba(255, 255, 255, 0.92);
    --glass: rgba(22, 25, 31, 0.86);
    --bar-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  }
}

html[data-theme="dark"] {
  --bg: #0f1116;
  --surface: #191c22;
  --panel: #191c22;
  --text: #e9eaee;
  --sub: #b3b8c1;
  --muted: #8d949f;
  --border: #262a31;
  --border-strong: #363b44;
  --hover: rgba(233, 234, 238, 0.07);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-lift: 0 10px 26px rgba(0, 0, 0, 0.55);
  --icon-bg: rgba(255, 255, 255, 0.92);
  --glass: rgba(22, 25, 31, 0.86);
  --bar-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

/* hidden 属性全局最高优先，防止 display:flex 把隐藏元素顶出来 */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- 壁纸 ---------------- */

body.has-wallpaper {
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

.wall-dim {
  position: fixed;
  inset: 0;
  background: #0b0c10;
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.25s;
}

/* ---------------- 顶部工具条按钮 ---------------- */

.top-actions {
  flex: none;
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.round-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--sub);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.round-btn:hover { color: var(--text); background: var(--hover); }

body.edit-mode #editBtn { background: var(--accent); color: #fff; }

/* ---------------- 顶部工具条 ---------------- */

.hero {
  position: relative;
  /* 必须高于 .content，否则展开的引擎下拉会被下面的卡片盖住 */
  z-index: 20;
  padding: 26px 20px 0;
}

/* 标题 / 搜索引擎 / 按钮收进同一条玻璃工具条 */
.hero-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1160px;
  margin: 0 auto;
  padding: 7px 12px 7px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--glass);
  box-shadow: var(--bar-shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* 标题与搜索引擎之间的细竖线 */
.hero-div {
  flex: none;
  width: 1px;
  height: 14px;
  background: var(--border-strong);
}

/* 顶部那一行可编辑的站点标题，双击可改，存在 data.js */
.site-title {
  flex: none;
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.edit-mode .site-title {
  cursor: pointer;
  border-bottom: 1px dashed var(--border-strong);
}

body.edit-mode .site-title:hover { color: var(--accent); border-color: var(--accent); }

/* 一排搜索引擎入口，点一下直接进站 */
.engine-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.engine-link {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 11px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--sub);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}

.engine-link:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

/* 分组快捷胶囊：工具条下方一行，左对齐，点某个只显示该分组 */
.group-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 7px;
  margin: 10px auto 0;
  max-width: 1160px;
}

.chip {
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--glass);
  color: var(--sub);
  font-size: 12.5px;
  padding: 4px 13px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.15s;
}

.chip:hover { color: var(--text); border-color: var(--border-strong); }

.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

/* ---------------- 内容区（便当盒拼图） ---------------- */

.content {
  position: relative;
  z-index: 1;
  max-width: 1160px;
  margin: 0 auto;
  padding: 18px 20px 90px;
}

/* 编辑态底部有吸底操作条，多留余量，保证最后一行卡片能完整滚出来 */
body.edit-mode .content { padding-bottom: 150px; }

/* 用固定列数的网格：每张卡宽度只由自己占几格决定，
   改一张的宽窄不会把同排其它卡挤变形（最多让它们换行） */
.groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}

.panel {
  position: relative;
  grid-column: span 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
  scroll-margin-top: 20px;
}

/* 站点多的分组占两个格子，成为便当盒里的大格子 */
.panel.is-wide { grid-column: span 2; }

/* 编辑态：卡片标题栏是拖拽把手，右下角是缩放手柄 */
body.edit-mode .panel { outline: 1px dashed var(--border-strong); outline-offset: 2px; }

body.edit-mode .panel-head {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

body.edit-mode .panel-head:active { cursor: grabbing; }

/* 拖动时的占位虚影 */
.panel-ghost { opacity: 0.35; }

/* 右下角缩放手柄：往右拖变宽、往左拖变窄 */
.rz {
  display: none;
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  border-right: 2px solid var(--border-strong);
  border-bottom: 2px solid var(--border-strong);
  border-bottom-right-radius: 6px;
  touch-action: none;
}

body.edit-mode .rz { display: block; }
body.edit-mode .rz:hover { border-color: var(--accent); }

body.has-wallpaper .panel {
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
}

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

.panel-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--sub);
  flex: none;
}

.panel-head .line { flex: 1; height: 1px; background: var(--border); }

.panel-head .count { font-size: 10.5px; color: var(--muted); flex: none; }

/* 空分组提示 */
.panel-empty {
  padding: 14px 2px 6px;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------------- 图标网格 ---------------- */

.tile-grid {
  flex: 1;
  display: grid;
  /* 同一行的卡片被拉成等高，靠 align-content 把多出来的空间均分，避免底部一大片空 */
  align-content: space-evenly;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px 2px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px 6px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s, transform 0.13s;
}

.tile:hover { background: var(--hover); transform: translateY(-2px); }

/* 图标方块：固定尺寸防抖动 */
.tile-icon {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--icon-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(20, 25, 45, 0.09);
  overflow: hidden;
  transition: box-shadow 0.15s;
}

.tile:hover .tile-icon { box-shadow: 0 5px 14px rgba(20, 25, 45, 0.15); }

.tile-icon img { width: 26px; height: 26px; object-fit: contain; display: block; }

.tile-icon.is-fallback { font-size: 17px; font-weight: 500; user-select: none; }

.tile-name {
  max-width: 100%;
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- 编辑态 ---------------- */

body.edit-mode .tile { cursor: grab; }
body.edit-mode .tile:hover { transform: none; }
body.edit-mode .tile-icon { outline: 1px dashed var(--border-strong); outline-offset: 3px; }

.sortable-ghost { opacity: 0.35; }
.sortable-chosen { cursor: grabbing; }

.tile-ops {
  position: absolute;
  top: -2px;
  right: -2px;
  display: none;
  gap: 1px;
}

body.edit-mode .tile-ops { display: flex; }

.tile-op {
  width: 19px;
  height: 19px;
  border: none;
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}

.tile-op:hover { color: var(--text); }
.tile-op.del:hover { color: #e24b4a; }

.mini-btn {
  flex: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 1px 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.mini-btn:hover { color: var(--text); border-color: var(--border-strong); }
.mini-btn.danger:hover { color: #e24b4a; border-color: rgba(226, 75, 74, 0.5); background: rgba(226, 75, 74, 0.08); }

.add-tile {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.add-tile:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.panel-foot { margin-top: 10px; }

/* 新增分组按钮占满一整行 */
.add-group-wrap { grid-column: 1 / -1; display: flex; justify-content: center; padding: 2px 0 0; }

/* ---------------- 编辑底部操作栏 ---------------- */

/* 吸底通栏，像编辑器状态栏；不再是一块浮在中部的小卡片压着卡片 */
.edit-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  transform: none;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  border-radius: 0;
  padding: 10px max(20px, calc((100% - 1160px) / 2 + 20px));
  box-shadow: 0 -8px 28px rgba(20, 25, 45, 0.12);
  z-index: 150;
}

/* 提示文字靠左，两个按钮推到右侧 */
.edit-bar .btn:first-of-type { margin-left: auto; }

.edit-hint { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------------- 按钮 ---------------- */

.btn {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  padding: 7px 15px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.btn:hover { border-color: var(--border-strong); }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------------- 弹窗 ---------------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, 0.42);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.26);
}

.modal-box h3 { margin: 0 0 14px; font-size: 15px; font-weight: 500; }

.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.modal-text { font-size: 13px; color: var(--sub); margin: 0; line-height: 1.7; }

/* ---------------- 表单字段 ---------------- */

.fld { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.fld input, .fld select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.fld input:focus, .fld select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.fld input[type="color"] { padding: 3px; height: 36px; cursor: pointer; }
.fld input[type="range"] { padding: 0; accent-color: var(--accent); cursor: pointer; }

.fld.inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.fld.inline input { width: 60px; margin-top: 0; }

.fld-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.field-error { font-size: 12px; color: #e24b4a; margin: -6px 0 10px; display: none; }

/* ---------------- 设置抽屉 ---------------- */

.scrim.right { z-index: 450; }

.settings {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 350px;
  max-width: calc(100vw - 20px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 500;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -10px 0 34px rgba(0, 0, 0, 0.14);
}

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

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.settings-title { font-size: 15px; font-weight: 500; }

.settings-body { flex: 1; overflow-y: auto; padding: 16px 18px 30px; }

.set-sec { margin-bottom: 26px; }

.set-sec h3 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.set-sec h3::before {
  content: "";
  width: 4px;
  height: 13px;
  border-radius: 2px;
  background: var(--accent);
}

.set-tip { font-size: 11.5px; color: var(--muted); margin: 10px 0 0; line-height: 1.6; }

.conn-result { font-size: 12px; margin: 10px 0 0; padding: 8px 11px; border-radius: 9px; line-height: 1.6; }
.conn-result.ok { background: rgba(99, 153, 34, 0.1); color: #4f7c17; }
.conn-result.bad { background: rgba(226, 75, 74, 0.1); color: #a32d2d; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s;
}

.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--text); }

.snap-list { display: flex; flex-direction: column; gap: 8px; }

.snap-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 12px;
  color: var(--muted);
}

.snap-item .btn { padding: 4px 10px; font-size: 12px; }
.snap-empty { font-size: 12px; color: var(--muted); margin: 0; }

/* ---------------- 轻提示 ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 11px;
  padding: 9px 18px;
  font-size: 13px;
  z-index: 600;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  max-width: calc(100vw - 40px);
  text-align: center;
}

/* ---------------- 中等宽度：网格少一列 ---------------- */

@media (max-width: 1100px) {
  .groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------------- 手机端 ---------------- */

@media (max-width: 768px) {
  .hero { padding: 16px 14px 0; }

  /* 标题占第一行左边，三个圆按钮在右边；搜索引擎换到第二行 */
  .hero-bar { flex-wrap: wrap; gap: 6px 10px; padding: 8px 8px 8px 16px; border-radius: 14px; }
  .site-title { flex: 1 1 auto; font-size: 17px; max-width: none; }
  .hero-div { display: none; }
  .top-actions { order: 2; }
  .engine-row { order: 3; flex: 1 1 100%; margin-left: -10px; }

  .engine-link { height: 28px; padding: 0 10px; font-size: 12.5px; }

  /* 分组胶囊改为横向可滑动单行 */
  .group-chips {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    width: 100%;
    max-width: none;
    margin-top: 10px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .group-chips::-webkit-scrollbar { display: none; }

  .chip { flex: none; }

  .content { padding: 14px 12px 80px; }

  /* 手机端一律单列，大格子也退回一格，否则会撑出横向滚动 */
  .groups { grid-template-columns: 1fr; }
  .panel.is-wide { grid-column: span 1; }

  .panel { padding: 12px 12px; border-radius: 14px; }

  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 8px 0; }

  .tile-icon { width: 42px; height: 42px; }
  .tile-icon img { width: 25px; height: 25px; }

  .edit-bar { gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); justify-content: center; }
  .edit-bar .btn:first-of-type { margin-left: 0; }
  .edit-hint { display: none; }
  body.edit-mode .content { padding-bottom: 120px; }

  .groups { gap: 10px; }

  .round-btn { width: 30px; height: 30px; font-size: 12px; }
}
