*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #06080f;
  --surface: rgba(18, 24, 38, 0.72);
  --surface-hover: rgba(28, 36, 56, 0.88);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.18);
  --text: #eef2ff;
  --text-muted: #8b95b0;
  --accent: #5b8def;
  --accent-glow: rgba(91, 141, 239, 0.45);
  --danger: #f87171;
  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── 动态背景 ── */

.bg-scene {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(ellipse 120% 80% at 50% -30%, rgba(59, 130, 246, 0.18), transparent 55%),
    radial-gradient(ellipse 80% 60% at 100% 80%, rgba(139, 92, 246, 0.12), transparent 50%),
    radial-gradient(ellipse 60% 50% at 0% 60%, rgba(14, 165, 233, 0.1), transparent 45%),
    var(--bg);
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: float 18s var(--ease-out) infinite alternate;
}

.orb-1 {
  width: 420px;
  height: 420px;
  background: #3b82f6;
  top: -8%;
  left: -5%;
  animation-delay: 0s;
}

.orb-2 {
  width: 360px;
  height: 360px;
  background: #8b5cf6;
  bottom: -10%;
  right: -8%;
  animation-delay: -6s;
}

.orb-3 {
  width: 280px;
  height: 280px;
  background: #06b6d4;
  top: 40%;
  left: 55%;
  animation-delay: -12s;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, black 20%, transparent 75%);
}

@keyframes float {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(30px, -40px) scale(1.08); }
}

/* ── 顶栏 ── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
  background: rgba(6, 8, 15, 0.6);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(91, 141, 239, 0.25), rgba(139, 92, 246, 0.15));
  border: 1px solid var(--border-hover);
  color: var(--accent);
  box-shadow: 0 0 24px rgba(91, 141, 239, 0.2);
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 30%, #a5b4fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-sub {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.save-status {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--mono);
  transition: color 0.3s;
}

.save-status--ok {
  color: #34d399;
  text-shadow: 0 0 12px rgba(52, 211, 153, 0.5);
}

.save-status--error {
  color: var(--danger);
}

/* ── 主区域 ── */

main {
  padding: 2.5rem 2rem 4rem;
  max-width: 1280px;
  margin: 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 1.35rem;
}

/* ── 方块卡片 ── */

.tile {
  --delay: 0s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  aspect-ratio: 1;
  padding: 1.25rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  opacity: 0;
  transform: translateY(24px) scale(0.96);
  animation: tile-in 0.65s var(--ease-out) var(--delay) forwards;
  transition:
    transform 0.45s var(--ease-spring),
    border-color 0.35s,
    box-shadow 0.45s;
}

@keyframes tile-in {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.tile-glow {
  position: absolute;
  inset: -40%;
  background: radial-gradient(circle, var(--tile-color, var(--accent)) 0%, transparent 65%);
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
  z-index: 0;
}

.tile-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 40%,
    rgba(255, 255, 255, 0.12) 50%,
    transparent 60%
  );
  transform: translateX(-120%);
  transition: transform 0.7s var(--ease-out);
  pointer-events: none;
  z-index: 3;
}

.tile-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(
    145deg,
    var(--tile-color, var(--accent)),
    #1e3a5f
  );
  box-shadow:
    0 8px 24px rgba(91, 141, 239, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.45s var(--ease-spring), box-shadow 0.45s;
  z-index: 1;
}

.tile-label {
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.35;
  letter-spacing: -0.01em;
  z-index: 1;
  transition: transform 0.35s var(--ease-out);
}

.tile-url {
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 1;
  opacity: 0.85;
}

.tile-arrow {
  position: absolute;
  bottom: 0.85rem;
  right: 0.85rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  opacity: 0;
  transform: translate(-6px, 6px);
  transition: opacity 0.35s, transform 0.35s var(--ease-out);
  z-index: 2;
}

.tile:hover {
  transform: translateY(-8px) scale(1.02);
  border-color: rgba(91, 141, 239, 0.45);
  box-shadow:
    0 20px 48px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(91, 141, 239, 0.35),
    0 0 40px rgba(91, 141, 239, 0.25);
}

.tile:hover .tile-glow {
  opacity: 0.22;
}

.tile:hover .tile-shine {
  transform: translateX(120%);
}

.tile:hover .tile-icon {
  transform: scale(1.1) rotate(-3deg);
  box-shadow:
    0 12px 32px rgba(91, 141, 239, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

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

.tile:hover .tile-arrow {
  opacity: 1;
  transform: translate(0, 0);
  color: var(--tile-color, var(--accent));
}

.tile:active {
  transform: translateY(-4px) scale(1.01);
  transition-duration: 0.1s;
}

/* ── 空状态 ── */

.empty-hint {
  text-align: center;
  color: var(--text-muted);
  margin-top: 4rem;
  font-size: 0.95rem;
  animation: fade-in 0.6s var(--ease-out);
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hidden {
  display: none !important;
}

/* ── 按钮 ── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s, background 0.25s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.btn-primary {
  background: linear-gradient(135deg, #5b8def, #7c6cf0);
  color: #fff;
  box-shadow: 0 4px 20px rgba(91, 141, 239, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 6px 28px rgba(91, 141, 239, 0.5);
  transform: translateY(-1px);
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.4);
}

.btn-danger-outline:hover {
  background: rgba(248, 113, 113, 0.08);
}

/* ── 配置弹窗 ── */

.config-dialog {
  border: 1px solid var(--border-hover);
  border-radius: 20px;
  padding: 0;
  background: rgba(14, 18, 30, 0.92);
  backdrop-filter: blur(24px);
  color: var(--text);
  max-width: 560px;
  width: calc(100% - 2rem);
  box-shadow:
    0 32px 64px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  animation: dialog-in 0.35s var(--ease-out);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.config-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  animation: fade-in 0.25s;
}

.config-form {
  padding: 1.5rem;
}

.config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.config-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.btn-close {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  width: 32px;
  height: 32px;
  transition: background 0.2s, color 0.2s;
}

.btn-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.config-tip {
  margin: 0 0 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.config-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
}

.config-item {
  display: grid;
  grid-template-columns: 1fr 2fr auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.config-item input[type="text"],
.config-item input[type="url"] {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.config-item input:focus,
.field-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.15);
}

.config-item input[type="color"] {
  width: 36px;
  height: 28px;
  padding: 0;
  border: none;
  cursor: pointer;
  background: transparent;
}

.config-add h3 {
  margin: 0 0 0.75rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.field-row label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.field-row input[type="text"],
.field-row input[type="url"] {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.color-label input[type="color"] {
  width: 48px;
  height: 32px;
}

.config-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.import-label {
  display: inline-flex;
  cursor: pointer;
}

.config-footer {
  margin-top: 1rem;
  text-align: right;
}

/* ── 响应式 & 无障碍 ── */

@media (max-width: 520px) {
  .header {
    padding: 1rem;
  }

  .header-sub {
    display: none;
  }

  main {
    padding: 1.25rem 1rem 3rem;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
  }

  .config-item {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .tile {
    opacity: 1;
    transform: none;
  }
}
