/* ========================================
   CSS Variables & Theme System
   ======================================== */

:root {
  /* Light theme (default) */
  --bg-primary: #f0f4f8;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.72);
  --bg-card-hover: rgba(255, 255, 255, 0.92);
  --bg-header: rgba(255, 255, 255, 0.65);
  --bg-embed-header: rgba(255, 255, 255, 0.9);
  --bg-tag: rgba(0, 0, 0, 0.05);
  --bg-tag-active: #6366f1;
  --bg-search: rgba(255, 255, 255, 0.8);
  --bg-overlay: rgba(0, 0, 0, 0.4);
  --bg-status-online: #10b981;
  --bg-status-offline: #94a3b8;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-tag-active: #ffffff;
  --border-color: rgba(0, 0, 0, 0.08);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-card-hover: 0 4px 16px rgba(0,0,0,0.1), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-header: 0 1px 8px rgba(0,0,0,0.06);
  --accent: #6366f1;
  --accent-light: #818cf8;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --blur: blur(16px);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: rgba(30, 41, 59, 0.72);
  --bg-card-hover: rgba(30, 41, 59, 0.92);
  --bg-header: rgba(15, 23, 42, 0.8);
  --bg-embed-header: rgba(30, 41, 59, 0.95);
  --bg-tag: rgba(255, 255, 255, 0.08);
  --bg-tag-active: #818cf8;
  --bg-search: rgba(30, 41, 59, 0.8);
  --bg-overlay: rgba(0, 0, 0, 0.6);
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border-color: rgba(255, 255, 255, 0.08);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.15);
  --shadow-card-hover: 0 4px 16px rgba(0,0,0,0.3), 0 2px 6px rgba(0,0,0,0.2);
  --shadow-header: 0 1px 8px rgba(0,0,0,0.3);
  --accent: #818cf8;
  --accent-light: #a5b4fc;
}

/* ========================================
   Reset & Base
   ======================================== */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
  line-height: 1.6;
}

/* Background decoration */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background:
    radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(236, 72, 153, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(59, 130, 246, 0.04) 0%, transparent 60%);
  z-index: -1;
  animation: bgShift 20s ease-in-out infinite alternate;
}

@keyframes bgShift {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(-2%, -2%) rotate(3deg); }
}

a {
  color: var(--accent);
  text-decoration: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ========================================
   Header
   ======================================== */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-header);
  transition: background var(--transition);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
}

.logo-text {
  font-size: 1.35rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Theme toggle */
.theme-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tag);
  transition: all var(--transition);
  font-size: 1.2rem;
  position: relative;
  overflow: hidden;
}

.theme-toggle:hover {
  background: var(--bg-tag-active);
  transform: scale(1.05);
}

.theme-icon {
  position: absolute;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] .theme-icon.sun { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="light"] .theme-icon.moon { opacity: 0; transform: rotate(-90deg) scale(0.5); }
[data-theme="dark"] .theme-icon.sun { opacity: 0; transform: rotate(90deg) scale(0.5); }
[data-theme="dark"] .theme-icon.moon { opacity: 1; transform: rotate(0deg) scale(1); }

/* ========================================
   Main Content
   ======================================== */

.main {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 40px;
}

/* ========================================
   Filter Bar
   ======================================== */

.filter-bar {
  margin-bottom: 28px;
}

.search-box {
  position: relative;
  max-width: 520px;
  margin: 0 auto 16px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 12px 44px 12px 44px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-search);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: all var(--transition);
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--text-muted);
  background: var(--bg-tag);
  transition: all var(--transition);
}

.search-clear.visible {
  display: flex;
}

.search-clear:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

/* Category tags — hidden */
.category-tags {
  display: none;
}

.category-tag {
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--bg-tag);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.category-tag:hover {
  background: var(--border-color);
  transform: translateY(-1px);
}

.category-tag.active {
  background: var(--bg-tag-active);
  color: var(--text-tag-active);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

/* ========================================
   App Grid
   ======================================== */

.app-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  max-width: 1080px;
  margin: 0 auto;
}




/* ========================================
   App Card
   ======================================== */

.app-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-xl);
  padding: 28px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  overflow: hidden;
  animation: cardIn 0.4s ease backwards;
  /* Neumorphism-inspired layered shadow */
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.04),
    0 8px 24px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] .app-card {
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.2),
    0 8px 24px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.app-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(236, 72, 153, 0.05));
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.app-card::after {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  bottom: -1px;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,255,255,0.4), rgba(255,255,255,0.05));
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 0;
}

.app-card:hover {
  background: var(--bg-card-hover);
  box-shadow:
    0 4px 8px rgba(0, 0, 0, 0.06),
    0 16px 40px rgba(99, 102, 241, 0.12),
    0 0 0 1px rgba(99, 102, 241, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transform: translateY(-6px) scale(1.01);
  border-color: rgba(99, 102, 241, 0.25);
}

[data-theme="dark"] .app-card:hover {
  box-shadow:
    0 4px 8px rgba(0, 0, 0, 0.3),
    0 16px 40px rgba(129, 140, 248, 0.15),
    0 0 0 1px rgba(129, 140, 248, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.app-card:hover::before {
  opacity: 1;
}

.app-card:hover::after {
  opacity: 1;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Card top: icon + category badge */
.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

.card-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--bg-tag), rgba(99, 102, 241, 0.06));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  padding: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.card-icon-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-badge.online {
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent);
}

.card-badge.local {
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
}

.card-badge.static {
  background: rgba(16, 185, 129, 0.12);
  color: #10b981;
}

/* Status indicator for local apps */
.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 500;
  margin-top: 4px;
}

.status-dot::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online::before {
  background: var(--bg-status-online);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
  animation: pulse 2s ease-in-out infinite;
}

.status-dot.offline::before {
  background: var(--bg-status-offline);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Card body */
.card-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  position: relative;
  z-index: 1;
}

.card-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.55;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* Card tags */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.card-tag {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-tag);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  transition: all var(--transition);
}

/* Card footer */
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
  position: relative;
  z-index: 1;
}

.card-action {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: gap var(--transition);
}

.app-card:hover .card-action {
  gap: 8px;
}

/* ========================================
   Empty State
   ======================================== */

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.empty-hint {
  font-size: 0.85rem;
}

/* ========================================
   Embed Panel (iframe)
   ======================================== */

.embed-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.embed-panel.active {
  transform: translateY(0);
  opacity: 1;
}

.embed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-embed-header);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.embed-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.embed-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
}

.embed-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.embed-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.embed-link {
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-tag);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.embed-link:hover {
  background: var(--accent);
  color: #fff;
}

.embed-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: var(--bg-tag);
  transition: all var(--transition);
}

.embed-close:hover {
  background: #ef4444;
  color: #fff;
}

.embed-body {
  flex: 1;
  position: relative;
}

.embed-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  position: absolute;
  top: 0;
  left: 0;
}

/* ========================================
   Overlay
   ======================================== */

.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ========================================
   Footer
   ======================================== */

.footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-header);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.footer-icon {
  height: 22px;
  width: auto;
  margin-right: 8px;
  vertical-align: middle;
  border-radius: 4px;
}

/* ========================================
   Placeholder Card (建设中)
   ======================================== */

.app-card--placeholder {
  cursor: default;
  pointer-events: none;
  border-style: dashed;
  border-color: var(--text-muted);
  background: transparent;
  min-height: 240px;
  justify-content: center;
  align-items: center;
}

.app-card--placeholder::before {
  display: none;
}

.app-card--placeholder::after {
  display: none;
}

.app-card--placeholder:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--text-muted);
  background: transparent;
}

.placeholder-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.placeholder-pulse {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px dashed var(--text-muted);
  opacity: 0.5;
  animation: placeholder-spin 4s linear infinite;
}

.placeholder-text {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-align: center;
}

@keyframes placeholder-spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 900px) {
  .header-inner {
    padding: 10px 16px;
  }

  .logo-text {
    font-size: 1.15rem;
  }

  .main {
    padding: 16px 16px 32px;
  }

  .app-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    max-width: 720px;
  }

  .app-card {
    padding: 22px;
  }
}

@media (max-width: 580px) {
  .app-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    max-width: 400px;
  }

  .logo-text {
    font-size: 1rem;
  }

  .app-card {
    padding: 20px;
  }
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}
