/* 用户个性化设置面板 —— 主题无关 */
:root {
  --pref-cols: 1;
  --pref-radius: 12px;
  --pref-icon-radius: 8px;
  --pref-section-bg: transparent;
  --pref-font: inherit;
}

html[data-pref-font="system"] body,
html[data-pref-font=""] body { font-family: var(--pref-font, inherit); }
html[data-pref-font="song"] body { font-family: "Songti SC","SimSun","Noto Serif SC",serif !important; }
html[data-pref-font="hei"] body { font-family: "Heiti SC","SimHei","Noto Sans SC",sans-serif !important; }
html[data-pref-font="kai"] body { font-family: "Kaiti SC","KaiTi","STKaiti",serif !important; }
html[data-pref-font="yuan"] body { font-family: "Yuanti SC","YouYuan","Nunito",sans-serif !important; }

/* 圆角 */
html[data-pref-radius="none"] { --pref-radius: 0; }
html[data-pref-radius="md"] { --pref-radius: 12px; }
html[data-pref-radius="lg"] { --pref-radius: 22px; }

/* 图标形状 */
html[data-pref-icon-shape="square"] { --pref-icon-radius: 8px; }
html[data-pref-icon-shape="circle"] { --pref-icon-radius: 999px; }

/* 板块背景 */
html[data-pref-section-bg="white"] { --pref-section-bg: #ffffff; }
html[data-pref-section-bg="gray"] { --pref-section-bg: #f0f1f3; }
html[data-pref-section-bg="warm"] { --pref-section-bg: #faf6f0; }
html[data-pref-section-bg="blue"] { --pref-section-bg: #f0f6ff; }
html[data-pref-section-bg="green"] { --pref-section-bg: #f0faf4; }
html[data-pref-section-bg="default"] { --pref-section-bg: transparent; }

html[data-pref-cols="1"] { --pref-cols: 1; }
html[data-pref-cols="2"] { --pref-cols: 2; }
html[data-pref-cols="3"] { --pref-cols: 3; }

.gt-grid, .ws-grid {
  grid-template-columns: repeat(var(--pref-cols), minmax(0, 1fr)) !important;
}
.gt-card, .ws-card { border-radius: var(--pref-radius) !important; }
.gt-card-icon, .ws-card-icon { border-radius: var(--pref-icon-radius) !important; }
.gt-sec, .ws-sec {
  background: var(--pref-section-bg);
  border-radius: calc(var(--pref-radius) + 4px);
}
html[data-pref-section-bg]:not([data-pref-section-bg="default"]) .gt-sec,
html[data-pref-section-bg]:not([data-pref-section-bg="default"]) .ws-sec {
  padding: 14px 12px 16px;
  margin-bottom: 16px;
}

/* 显示模式：字母 */
html[data-pref-icon="letter"] .gt-card-icon img,
html[data-pref-icon="letter"] .ws-card-icon img { display: none !important; }
html[data-pref-icon="letter"] .gt-card-icon,
html[data-pref-icon="letter"] .ws-card-icon {
  font-size: 0;
}
html[data-pref-icon="letter"] .gt-card-icon::after,
html[data-pref-icon="letter"] .ws-card-icon::after {
  content: attr(data-letter);
  font-size: 1.1rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

/* 收藏星标（扁平） */
.site-fav-btn {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 24px;
  height: 24px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #cbd5e1;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  padding: 0;
  line-height: 1;
}
html[data-pref-fav="1"] .site-fav-btn { display: inline-flex; }
.site-fav-btn.is-on {
  color: #f59e0b;
  border-color: #fde68a;
  background: #fffbeb;
}
.gt-card, .ws-card { position: relative; }
html[data-theme="dark"] .site-fav-btn {
  background: #1a1a1d;
  border-color: #2a2a2e;
  color: #64748b;
}
html[data-theme="dark"] .site-fav-btn.is-on {
  color: #fbbf24;
  border-color: #854d0e;
  background: #292524;
}

.site-card-hidden { display: none !important; }

/* FAB 设置按钮 */
.pref-fab-wrap {
  position: fixed;
  right: max(12px, calc(env(safe-area-inset-right) + 6px));
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.pref-fab-wrap > * { pointer-events: auto; }

/* 首次引导气泡 */
.pref-fab-tip {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(220px, 70vw);
  padding: 8px 10px 8px 12px;
  border-radius: 12px;
  background: #1e293b;
  color: #f8fafc;
  font-size: .78rem;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .22);
  animation: pref-tip-in .35s ease;
}
.pref-fab-tip[hidden] { display: none !important; }
.pref-fab-tip-x {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: rgba(255,255,255,.12);
  color: #e2e8f0;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
@keyframes pref-tip-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.pref-fab {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #3b82f6;
  cursor: pointer;
  line-height: 1;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
}
.pref-fab i {
  display: block;
  width: 26px;
  height: 26px;
  font-size: 26px;
  line-height: 26px;
  text-align: center;
  color: inherit;
  animation: pref-gear-spin 10s linear infinite;
  /* 立体感：柔光 + 轻描边感 */
  filter:
    drop-shadow(0 1px 0 rgba(255, 255, 255, .65))
    drop-shadow(0 2px 4px rgba(37, 99, 235, .28))
    drop-shadow(0 0 0.5px rgba(29, 78, 216, .35));
}
.pref-fab:hover {
  color: #2563eb;
  filter: none;
}
.pref-fab:hover i {
  filter:
    drop-shadow(0 1px 0 rgba(255, 255, 255, .7))
    drop-shadow(0 3px 6px rgba(37, 99, 235, .35));
}
.pref-fab:active {
  transform: scale(.92);
}
.pref-fab:active i { animation-play-state: paused; }
html[data-theme="dark"] .pref-fab { color: #60a5fa; }
html[data-theme="dark"] .pref-fab i {
  filter:
    drop-shadow(0 1px 0 rgba(255, 255, 255, .12))
    drop-shadow(0 2px 6px rgba(0, 0, 0, .45))
    drop-shadow(0 0 0.5px rgba(147, 197, 253, .4));
}
html[data-theme="dark"] .pref-fab:hover { color: #93c5fd; }
@keyframes pref-gear-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .pref-fab i { animation: none; }
  .pref-fab-tip { animation: none; }
}

/* 面板 */
.pref-mask {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(15,23,42,.35);
  backdrop-filter: blur(2px);
}
.pref-mask.show { display: block; }
.pref-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  width: min(400px, 94vw);
  background: #fff;
  color: #1f2937;
  border-left: 1px solid #e5e7eb;
  transform: translateX(105%);
  transition: transform .24s ease;
  display: flex;
  flex-direction: column;
}
.pref-panel.open { transform: translateX(0); }
.pref-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid #eef0f3;
  flex-shrink: 0;
}
.pref-panel-head h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.pref-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: #f3f4f6;
  cursor: pointer;
  font-size: 1.1rem;
}
.pref-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 18px 28px;
  -webkit-overflow-scrolling: touch;
}
.pref-group { padding: 16px 0; border-bottom: 1px solid #f1f3f5; }
.pref-group:last-child { border-bottom: 0; }
.pref-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .95rem;
  font-weight: 700;
  margin-bottom: 12px;
}
.pref-group-title i { font-size: 1.15rem; color: #64748b; }
.pref-tip {
  margin: 8px 0 0;
  font-size: .78rem;
  color: #94a3b8;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  line-height: 1.45;
}
.pref-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pref-opt {
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #64748b;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .82rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1.2;
  transition: border-color .15s, color .15s, background .15s;
}
.pref-opt i { font-size: .95rem; }
.pref-opt.active {
  background: rgba(45,133,240,.08);
  border-color: #2d85f0;
  color: #2d85f0;
  font-weight: 600;
}
.pref-swatches {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  padding: 8px 10px;
  border-radius: 10px;
}
.pref-swatch {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
}
.pref-swatch.active { border-color: #2d85f0; }
.pref-swatch[data-v="default"] {
  background: linear-gradient(90deg, #333 50%, #f5f5f5 50%);
}
.pref-swatch[data-v="white"] { background: #fff; }
.pref-swatch[data-v="gray"] { background: #d4d4d8; }
.pref-swatch[data-v="warm"] { background: #f5e6c8; }
.pref-swatch[data-v="blue"] { background: #bfdbfe; }
.pref-swatch[data-v="green"] { background: #bbf7d0; }

.pref-select {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  font-size: .9rem;
  color: #334155;
}
.pref-reset {
  margin-top: 18px;
  width: 100%;
  padding: 10px;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  font-size: .85rem;
}
.pref-reset:hover { border-color: #2d85f0; color: #2d85f0; }

html[data-theme="dark"] .pref-panel { background: #1c1c1f; color: #f1f5f9; }
html[data-theme="dark"] .pref-panel-head { border-color: #2e2e36; }
html[data-theme="dark"] .pref-close { background: #2a2a2e; color: #e5e7eb; }
html[data-theme="dark"] .pref-group { border-color: #2e2e36; }
html[data-theme="dark"] .pref-opt { background: #1a1a1d; border-color: #2a2a2e; color: #94a3b8; }
html[data-theme="dark"] .pref-opt.active { background: rgba(74,157,248,.14); border-color: #4a9df8; color: #4a9df8; }
html[data-theme="dark"] .pref-swatches { background: #2a2a2e; }
html[data-theme="dark"] .pref-select { background: #2a2a2e; border-color: #3f3f46; color: #e5e7eb; }
html[data-theme="dark"] .pref-reset { background: #2a2a2e; border-color: #3f3f46; color: #94a3b8; }

@media (max-width: 767px) {
  .pref-fab-wrap {
    right: max(14px, calc(env(safe-area-inset-right) + 6px));
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
}
