:root {
  --cols: 6;
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.72);
  --glass: rgba(20, 26, 40, 0.34);
  --glass-strong: rgba(16, 21, 34, 0.78);
  --stroke: rgba(255, 255, 255, 0.16);
  --accent: #6d8cff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--fg);
  font-family: "Segoe UI", "Microsoft YaHei UI", "PingFang SC", system-ui, -apple-system, sans-serif;
  background: #0b1020;
  -webkit-font-smoothing: antialiased;
}

#bg-layer {
  position: fixed;
  inset: -40px;
  z-index: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: filter 0.28s ease, background-color 0.3s ease, opacity 0.3s ease;
  will-change: filter;
}

#bg-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: radial-gradient(120% 120% at 50% 0%, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.55) 100%);
  background-color: #000;
  mix-blend-mode: normal;
  pointer-events: none;
  transition: opacity 0.28s ease;
  opacity: 0.15;
}

#app {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px 30px 18px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.top-actions { display: flex; gap: 10px; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: var(--glass);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  transition: transform 0.15s ease, background 0.2s ease;
  font-size: 15px;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.16); transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.96); }
#btn-settings svg { transition: transform 0.4s ease; }
#btn-settings:hover svg { transform: rotate(45deg); }

/* ---------- hero ---------- */
.hero {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: clamp(28px, 9vh, 120px);
  gap: 6px;
}

.greeting {
  font-size: 15px;
  color: var(--muted);
  letter-spacing: 2px;
  min-height: 20px;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.35);
}

.clock {
  font-size: clamp(52px, 9vw, 96px);
  font-weight: 200;
  letter-spacing: 2px;
  line-height: 1.02;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 6px 30px rgba(0, 0, 0, 0.35);
}

.date {
  font-size: 15px;
  color: var(--muted);
  letter-spacing: 1px;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.3);
}

.search {
  margin-top: 22px;
  width: min(620px, 82vw);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px 0 8px;
  height: 52px;
  border-radius: 999px;
  position: relative;
  z-index: 50;
  background: rgba(18, 23, 36, 0.42);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow: var(--shadow);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.search:focus-within {
  background: rgba(20, 26, 40, 0.62);
  border-color: rgba(140, 165, 255, 0.55);
  transform: translateY(-1px);
}
.search input {
  flex: 1 1 auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  font-size: 16px;
  font-family: inherit;
  min-width: 0;
}
.search input::placeholder { color: rgba(255, 255, 255, 0.5); }

/* 搜索引擎选择按钮 */
.engine-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 38px;
  padding: 0 8px 0 7px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s ease;
}
.engine-btn:hover { background: rgba(255, 255, 255, 0.2); }
.engine-btn img { width: 18px; height: 18px; border-radius: 5px; object-fit: contain; display: block; }
.engine-btn .caret { opacity: 0.7; }

/* 搜索引擎下拉菜单 */
.engine-menu {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 40;
  width: 300px;
  max-width: 86vw;
  padding: 8px;
  border-radius: 16px;
  background: rgba(12, 17, 28, 0.985);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  display: flex;
  flex-direction: column;
  text-align: left;
}
.engine-menu[hidden] { display: none; }
.engine-list { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }

.engine-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: #e8ecff;
  font-size: 14px;
  position: relative;
  user-select: none;
  text-align: left;
}
.engine-item:hover { background: rgba(255, 255, 255, 0.1); }
.engine-item.active { background: rgba(109, 140, 255, 0.22); }
.engine-item.dragging { opacity: 0.4; }
.engine-item.drop-target { background: rgba(109, 140, 255, 0.3); outline: 1px dashed rgba(160, 180, 255, 0.85); }
.engine-item img { width: 18px; height: 18px; border-radius: 5px; object-fit: contain; flex: 0 0 auto; }
.engine-item .nm { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.engine-item .tools { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s ease; }
.engine-item:hover .tools { opacity: 1; }
.engine-item .tools button {
  width: 22px; height: 22px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(16, 21, 34, 0.92);
  color: #fff; cursor: pointer;
}
.engine-item .tools svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.engine-item .eng-del:hover { background: #d84a4a; border-color: #d84a4a; }
.engine-item .eng-edit:hover { background: var(--accent); border-color: var(--accent); }

.engine-menu-foot { border-top: 1px solid rgba(255, 255, 255, 0.1); margin-top: 6px; padding-top: 6px; }
.engine-menu-foot button {
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #cdd6ff;
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.engine-menu-foot button:hover { background: rgba(255, 255, 255, 0.1); }

.dlg-hint { margin: -4px 0 12px; font-size: 12px; color: rgba(255, 255, 255, 0.45); }

/* ---------- shortcuts ---------- */
.shortcuts {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* 上下留白供悬停按钮越界显示，避免被滚动容器裁切 */
  overflow-y: auto;
  overflow-x: hidden;
  margin-top: clamp(18px, 4.5vh, 48px);
  padding: 26px 16px 22px;
  scrollbar-width: thin;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 6), 96px);
  gap: 20px 18px;
  justify-content: center;
  align-content: start;
}

.tile {
  position: relative;
  width: 96px;
  height: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  padding: 12px 6px 8px;
  border-radius: 16px;
  text-decoration: none;
  color: #fff;
  transition: background 0.18s ease, transform 0.18s ease;
  cursor: pointer;
  user-select: none;
}
.tile:hover { background: rgba(255, 255, 255, 0.13); transform: translateY(-3px); z-index: 2; }
.tile:active { transform: translateY(-1px) scale(0.98); }
.tile.dragging { opacity: 0.35; }
.tile.drop-target { background: rgba(109, 140, 255, 0.28); outline: 1px dashed rgba(160, 180, 255, 0.9); }

.tile-icon {
  width: 56px;
  height: 56px;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  display: grid;
  place-items: center;
  overflow: hidden;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.tile-icon img { width: 32px; height: 32px; object-fit: contain; display: block; }
/* 浅色/白色系图标自动加深底板，避免白图标看不见 */
.tile-icon.plate-dark { background: rgba(14, 19, 31, 0.62); border-color: rgba(255, 255, 255, 0.22); }
.tile-icon.plate-light { background: rgba(255, 255, 255, 0.16); }

.tile-title {
  max-width: 88px;
  font-size: 12.5px;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.94);
}

.tile-tools {
  position: absolute;
  top: -9px;
  right: -7px;
  z-index: 3;
  display: flex;
  gap: 5px;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}
.tile:hover .tile-tools { opacity: 1; transform: translateY(0); pointer-events: auto; }
.tile-tools button {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(16, 21, 34, 0.92);
  color: #fff;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}
.tile-tools svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.tile-tools .tile-del:hover { background: #d84a4a; border-color: #d84a4a; }
.tile-tools .tile-edit:hover { background: var(--accent); border-color: var(--accent); }

.tile.add .tile-icon {
  background: rgba(255, 255, 255, 0.08);
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.45);
  box-shadow: none;
  color: rgba(255, 255, 255, 0.85);
  font-size: 30px;
  font-weight: 200;
}
.tile.add:hover .tile-icon { background: rgba(255, 255, 255, 0.16); }
.tile.add .tile-title { color: var(--muted); }

.foot {
  flex: 0 0 auto;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.42);
  letter-spacing: 1px;
  padding-top: 4px;
}

/* ---------- dialog ---------- */
.dialog {
  border: 1px solid var(--stroke);
  border-radius: 20px;
  background: var(--glass-strong);
  color: #fff;
  padding: 24px 24px 20px;
  width: min(420px, 92vw);
  box-shadow: var(--shadow);
  backdrop-filter: blur(28px) saturate(150%);
  -webkit-backdrop-filter: blur(28px) saturate(150%);
}
.dialog::backdrop { background: rgba(4, 7, 15, 0.55); backdrop-filter: blur(3px); }
.dialog h3 { margin: 0 0 18px; font-size: 18px; font-weight: 600; }
.dlg-field { display: block; margin-bottom: 14px; }
.dlg-field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.dlg-field em { font-style: normal; opacity: 0.62; }
.dlg-field input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: 14.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
}
.dlg-field input:focus { border-color: rgba(140, 165, 255, 0.7); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

button.primary, button.ghost, button.mini {
  font-family: inherit;
  cursor: pointer;
  border-radius: 11px;
  border: 1px solid var(--stroke);
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.1s ease;
}
button.primary {
  height: 40px;
  padding: 0 22px;
  background: linear-gradient(180deg, #6d8cff, #4f6ef2);
  border-color: transparent;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:active { transform: scale(0.98); }
button.ghost {
  height: 40px;
  padding: 0 18px;
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  font-size: 14px;
}
button.ghost:hover { background: rgba(255, 255, 255, 0.14); }
button.ghost.small { height: 34px; font-size: 13px; padding: 0 14px; }
button.ghost.danger { color: #ff9c9c; border-color: rgba(255, 120, 120, 0.35); }
button.ghost.danger:hover { background: rgba(255, 90, 90, 0.16); }
button.mini {
  height: 38px;
  padding: 0 14px;
  background: rgba(109, 140, 255, 0.22);
  border-color: rgba(109, 140, 255, 0.4);
  color: #dfe6ff;
  font-size: 13px;
  white-space: nowrap;
}
button.mini:hover { background: rgba(109, 140, 255, 0.34); }

/* ---------- drawer ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(3, 6, 14, 0.45);
  backdrop-filter: blur(2px);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: 360px;
  max-width: 92vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: rgba(13, 18, 30, 0.86);
  border-left: 1px solid var(--stroke);
  backdrop-filter: blur(30px) saturate(150%);
  -webkit-backdrop-filter: blur(30px) saturate(150%);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.4);
  transform: translateX(105%);
  transition: transform 0.32s cubic-bezier(0.4, 0.1, 0.2, 1);
  visibility: hidden;
}
.drawer.open { transform: translateX(0); visibility: visible; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--stroke);
}
.drawer-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.drawer-head .icon-btn { width: 34px; height: 34px; }

.drawer-body { padding: 8px 20px 30px; overflow-y: auto; }
.drawer-body section { padding: 18px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.drawer-body section:last-child { border-bottom: 0; }
.drawer-body h3 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.segmented {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 12px;
  margin-bottom: 14px;
}
.segmented button {
  flex: 1;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}
.segmented button.active { background: rgba(109, 140, 255, 0.32); color: #fff; }

.field { display: none; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.field.active { display: flex; }

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.05);
  color: #dfe6ff;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.file-btn:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(140, 165, 255, 0.6); }

.row { display: flex; gap: 8px; }
.row input {
  flex: 1;
  min-width: 0;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.26);
  color: #fff;
  padding: 0 12px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

#bg-color { width: 100%; height: 46px; border: 1px solid var(--stroke); border-radius: 12px; background: transparent; cursor: pointer; padding: 3px; }

.gradients { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.gradients .swatch {
  height: 52px;
  border-radius: 11px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.gradients .swatch:hover { transform: translateY(-2px); }
.gradients .swatch.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(109, 140, 255, 0.6); }

.slider {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
.slider input[type="range"] { flex: 1; accent-color: var(--accent); }
.slider .val { width: 46px; text-align: right; color: #cdd6ff; font-variant-numeric: tabular-nums; }

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  color: #e6ebff;
  margin-bottom: 10px;
  cursor: pointer;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.hint { margin: 12px 0 0; font-size: 12px; color: rgba(255, 255, 255, 0.4); line-height: 1.6; }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  z-index: 60;
  max-width: 80vw;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(20, 26, 40, 0.94);
  border: 1px solid var(--stroke);
  color: #eef2ff;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateX(-50%) translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.is-hidden { display: none !important; }

@media (max-width: 720px) {
  #app { padding: 16px 16px 12px; }
  .grid { grid-template-columns: repeat(min(var(--cols, 4), 4), 84px); gap: 14px 10px; }
  .tile { width: 84px; }
  .foot { display: none; }
}
