*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC",
    sans-serif;
  user-select: none;
  background: #0a0a0f;
}

/* ── CSS Custom Properties (set dynamically by JS) ── */
:root {
  --sb-width: 520px;
  --sb-height: 48px;
  --sb-pad: 24px;
  --sb-radius: 50px;
  --sb-bg: rgba(255, 255, 255, 0.1);
  --sb-bg-hover: rgba(255, 255, 255, 0.14);
  --sb-font-size: 16px;
  --sb-input-opacity: 0.92;
  --clk-color: #fff;
  --clk-opacity: 1;
}

/* ── Background ── */
#bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  transition: background-image 0.5s ease;
}
#bg-layer::before {
  content: "";
  position: absolute;
  width: 300%;
  height: 300%;
  top: -100%;
  left: -100%;
  background: linear-gradient(
    135deg,
    #0f0c29,
    #302b63,
    #24243e,
    #302b63,
    #0f0c29
  );
  animation: gradientFlow 12s ease infinite;
  will-change: transform;
}
#bg-layer.uploaded::before {
  display: none;
}
#bg-layer.uploaded {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
@keyframes gradientFlow {
  0% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-33.33%, -33.33%);
  }
  100% {
    transform: translate(0, 0);
  }
}

/* ── Search Bar ── */
#search-bar {
  position: fixed;
  z-index: 5;
  background: var(--sb-bg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--sb-radius);
  width: var(--sb-width);
  height: var(--sb-height);
  padding: 0 var(--sb-pad);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
  transition:
    box-shadow 0.35s ease,
    background 0.35s ease;
  display: block;
}
#search-bar:hover {
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
  background: var(--sb-bg-hover);
}
#search-bar.hidden {
  display: none;
}
#search-input {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: rgba(255, 255, 255, 0.96);
  padding: 0;
  font-family: inherit;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-shadow:
    0 0 2px rgba(0, 0, 0, 0.9),
    0 1px 2px rgba(0, 0, 0, 0.75),
    0 0 7px rgba(0, 0, 0, 0.5);
  -webkit-text-stroke: 0.6px rgba(0, 0, 0, 0.45);
  caret-color: rgba(255, 255, 255, 0.85);
  font-size: var(--sb-font-size);
  line-height: var(--sb-height);
  opacity: var(--sb-input-opacity);
  transition: opacity 0.35s ease;
}
#search-bar:hover #search-input,
#search-input:focus {
  opacity: 1;
}

/* ── Drag Button ── */
.drag-btn {
  touch-action: none;
  position: absolute;
  left: 50%;
  bottom: -30px;
  transform: translateX(-50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  cursor: grab;
  opacity: 1 !important;
  z-index: 1;
  transition: background 0.25s ease;
  background: rgba(255, 255, 255, 0.2);
}
.drag-btn:hover {
  background: rgba(255, 255, 255, 0.6) !important;
}
.drag-btn:active {
  cursor: grabbing;
}

/* ── Clock ── */
#clock {
  position: fixed;
  z-index: 4;
  font-weight: 300;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  display: none;
}
#clock.show {
  display: block;
}
#clock .clock-inner {
  line-height: 1;
  pointer-events: none;
  opacity: var(--clk-opacity);
  color: var(--clk-color);
}

/* ── Gear ── */
#gear-btn {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 20;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.15;
  transition:
    opacity 0.35s ease,
    background 0.3s ease;
}
#gear-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}

/* ── Settings Panel ── */
#settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 15;
  width: 320px;
  height: 100vh;
  background: rgba(18, 16, 36, 0.82);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  padding: 64px 20px 20px;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#settings-panel.open {
  transform: translateX(0);
}
#panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 14;
  background: transparent;
  display: none;
}
#panel-overlay.show {
  display: block;
  pointer-events: none;
}
.panel-title {
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
select {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='rgba(255,255,255,.35)' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
select option {
  background: #1a1a2e;
  color: #eee;
}
.collapse-section {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding: 6px 0;
}
.collapse-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.6px;
  transition: color 0.2s;
}
.collapse-header:hover {
  color: rgba(255, 255, 255, 0.65);
}
.collapse-header .arrow {
  display: inline-block;
  transition: transform 0.25s ease;
  font-size: 10px;
}
.collapse-header .arrow.open {
  transform: rotate(90deg);
}
.collapse-body {
  overflow: hidden;
  max-height: 800px;
  transition:
    max-height 0.3s ease,
    opacity 0.2s ease;
  opacity: 1;
}
.collapse-body.closed {
  max-height: 0 !important;
  opacity: 0;
  padding: 0;
}
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px 0 6px 4px;
}
.setting-row:last-child {
  padding-bottom: 8px;
}
.setting-row .row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.setting-row .row-header label {
  color: rgba(255, 255, 255, 0.65);
  font-size: 12px;
}
.setting-row .row-header .val {
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}
.setting-row input[type="range"] {
  width: 100%;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  margin: 3px 0;
}
.setting-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition: background 0.2s;
}
.setting-row input[type="range"]::-webkit-slider-thumb:hover {
  background: rgba(255, 255, 255, 0.45);
}
.setting-row input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  border: none;
}
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0 8px 4px;
}
.toggle-row label {
  color: rgba(255, 255, 255, 0.45);
  font-size: 12px;
}
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  transition: background 0.25s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  transition:
    transform 0.25s,
    background 0.25s;
}
.toggle-switch input:checked + .toggle-slider {
  background: rgba(120, 140, 255, 0.4);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
  background: rgba(180, 190, 255, 0.8);
}
.btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.45);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition:
    background 0.2s,
    color 0.2s;
  text-align: center;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
.btn input[type="file"] {
  display: none;
}
.sep {
  height: 1px;
  background: rgba(255, 255, 255, 0.05);
  margin: 4px 0;
}
.btn-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 4px 0;
}
.sec-label {
  color: rgba(255, 255, 255, 0.45);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 1px;
  margin: 10px 0 4px 0;
}
.bg-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
  max-height: 180px;
  overflow-y: auto;
}
.bg-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background 0.2s,
    border-color 0.2s;
}
.bg-item:hover {
  background: rgba(255, 255, 255, 0.06);
}
.bg-item.active {
  border-color: rgba(120, 140, 255, 0.3);
  background: rgba(120, 140, 255, 0.08);
}
.bg-item .bg-thumb {
  width: 32px;
  height: 24px;
  border-radius: 4px;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.bg-item .bg-thumb.vt {
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.3);
}
.bg-item .bg-name {
  flex: 1;
  color: rgba(255, 255, 255, 0.4);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bg-item .bg-del {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.2);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition:
    color 0.2s,
    background 0.2s;
}
.bg-item .bg-del:hover {
  color: rgba(255, 80, 80, 0.6);
  background: rgba(255, 80, 80, 0.08);
}
.bg-empty {
  color: rgba(255, 255, 255, 0.15);
  font-size: 12px;
  text-align: center;
  padding: 12px 0;
}
.tpl-save-row {
  display: flex;
  gap: 6px;
  padding: 4px 0;
}
.tpl-save-row input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
.tpl-save-row input:focus {
  border-color: rgba(255, 255, 255, 0.2);
}
.tpl-save-row button {
  white-space: nowrap;
  padding: 8px 12px;
  font-size: 12px;
}
.tpl-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 2px 0;
  max-height: 200px;
  overflow-y: auto;
}
.tpl-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background 0.2s,
    border-color 0.2s;
}
.tpl-item:hover {
  background: rgba(255, 255, 255, 0.06);
}
.tpl-item .tpl-name {
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
}
.tpl-item .tpl-del {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.2);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition:
    color 0.2s,
    background 0.2s;
}
.tpl-item .tpl-del:hover {
  color: rgba(255, 80, 80, 0.6);
  background: rgba(255, 80, 80, 0.08);
}
.tpl-empty {
  color: rgba(255, 255, 255, 0.15);
  font-size: 12px;
  text-align: center;
  padding: 10px 0;
}
#hint {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  color: rgba(255, 255, 255, 0.08);
  font-size: 12px;
  letter-spacing: 0.5px;
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
}
#hint.show {
  opacity: 1;
}
#settings-panel::-webkit-scrollbar {
  width: 4px;
}
#settings-panel::-webkit-scrollbar-track {
  background: transparent;
}
#settings-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
}
#settings-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}
@media (max-width: 600px) {
  #settings-panel {
    width: 100vw;
  }
}

.dragging {
  will-change: transform;
}

/* 拖拽把手自适应：贴底时翻到上方，空间不足时收进组件内 */
.handle-top .drag-btn {
  bottom: auto;
  top: -30px;
}
.handle-in .drag-btn {
  bottom: 6px;
}
.dragging .drag-btn {
  opacity: 1 !important;
}

#search-bar,
#clock {
  transform-origin: 0 0;
}

#snap-guide {
  position: fixed;
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
  background: rgba(126, 178, 255, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  z-index: 60;
}
#snap-guide.on {
  opacity: 1;
}

.reset-one {
  margin-left: 6px;
  width: 18px;
  height: 18px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #8fa4c0;
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}
.reset-one:hover {
  opacity: 1;
  color: #cfe0ff;
  transform: rotate(-40deg);
}
.reset-one svg {
  width: 11px;
  height: 11px;
}

.lab-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0;
}
.reset-one {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  line-height: 1;
  vertical-align: middle;
  border: 0;
  background: transparent;
  color: #9fb2ca;
  font-size: 9px;
  cursor: pointer;
  padding: 0;
  margin-left: 5px;
  opacity: 0.7;
  transition:
    opacity 0.15s,
    transform 0.15s;
}
.reset-one:hover {
  background: rgba(126, 178, 255, 0.18);
  border-color: rgba(126, 178, 255, 0.5);
  color: #cfe0ff;
}
.hint-i {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  font-size: 9px;
  line-height: 1;
  color: #9fb2ca;
  cursor: help;
  margin-left: 5px;
}
.hint-i:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: 150%;
  transform: translateX(-50%);
  width: 170px;
  white-space: normal;
  text-align: center;
  background: rgba(16, 20, 30, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #cfdcef;
  font-size: 11px;
  line-height: 1.5;
  padding: 6px 8px;
  border-radius: 7px;
  z-index: 99;
}

#reset-search svg,
#reset-clock svg,
#reset-bg svg {
  width: 12px;
  height: 12px;
  vertical-align: -2px;
  margin-right: 5px;
}

.btn svg {
  width: 12px;
  height: 12px;
  vertical-align: -2px;
  margin-right: 5px;
}

#gear-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* ── 无障碍：按钮化后的重置 + 键盘可见焦点 ── */
/* 只做按钮化的必要重置：不碰 font/color，否则会盖掉 .collapse-header 自己的 12px 与白色 45% */
#gear-btn {
  border: 0;
  padding: 0;
  cursor: pointer;
}
.collapse-header {
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}
.clock-inner {
  text-align: center;
}
#gear-btn:focus-visible,
.collapse-header:focus-visible,
.drag-btn:focus-visible,
.btn:focus-visible,
select:focus-visible,
input[type="range"]:focus-visible,
#tpl-name:focus-visible {
  outline: 2px solid #7fb2ff;
  outline-offset: 2px;
  border-radius: 6px;
}

/* ── 减少动效：系统开启「减少动画」时不做过渡与漂移 ── */
@media (prefers-reduced-motion: reduce) {
  #bg-layer,
  #bg-layer::before,
  .collapse-body,
  .collapse-header .arrow,
  .toggle-slider,
  .toggle-slider::before,
  #settings-panel,
  #panel-overlay {
    transition: none !important;
    animation: none !important;
  }
}

/* ── 时间组件：日期/农历副行（跟主字号缩放） ── */
.clock-inner .clk-time {
  display: block;
}
.clock-inner .clk-sub {
  display: block;
  font-size: 0.2em;
  font-weight: 400;
  letter-spacing: 0.06em;
  margin-top: 0.45em;
  opacity: 0.85;
}

/* ── 移动端视口兜底：地址栏收放时 100vh 与可视高度不同步，
     露出的 body 深色会被看成"一条黑色背景从下往上浮" ── */
html {
  height: 100%;
  background: #0f0c29;
}
body {
  height: 100vh;
  height: 100dvh;
  min-height: 100%;
  background: #0f0c29;
}
#bg-layer {
  background-color: #0f0c29;
}

/* 拖拽中的组件提到最上层，避免把手被另一层盖住 */
#clock.dragging,
#search-bar.dragging {
  z-index: 30;
}

/* ── 手机端：只放大滑块触控目标（其它控件不动） ── */
@media (max-width: 600px) {
  .setting-row input[type="range"] {
    height: 6px;
  }
  .setting-row input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }
  .setting-row input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }
}
