:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-subtle: #f7f8fa;
  --border: #e5e6eb;
  --border-hover: #c9cdd4;
  --text: #1f2329;
  --text-secondary: #646a73;
  --text-muted: #8f959e;
  --accent: #3370ff;
  --accent-hover: #245bdb;
  --accent-soft: #eef4ff;
  --free-bg: #e8faf0;
  --free-text: #0a7c42;
  --paid-bg: #fff5e6;
  --paid-text: #ad5b00;
  --radius-card: 12px;
  --shadow-card: 0 1px 2px rgba(31, 35, 41, 0.04);
  --shadow-card-hover: 0 8px 24px rgba(31, 35, 41, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #3370ff 0%, #5b8cff 100%);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(51, 112, 255, 0.25);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover {
  border-color: var(--border-hover);
  background: var(--surface-subtle);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* Main layout */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 56px;
  min-height: calc(100vh - 130px);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.search-wrap {
  position: relative;
  flex: 1 1 300px;
  max-width: 440px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(51, 112, 255, 0.12);
}

.sort-tabs {
  display: inline-flex;
  background: #ebedf0;
  padding: 3px;
  border-radius: 9px;
  gap: 2px;
}

.sort-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.sort-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(31, 35, 41, 0.08);
}

/* Feishu-Drive-inspired card grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(276px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  cursor: pointer;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  border-color: rgba(51, 112, 255, 0.35);
}

.card-preview {
  position: relative;
  height: 168px;
  background: var(--surface-subtle);
  border-bottom: 1px solid #f0f1f5;
  overflow: hidden;
  padding: 12px 12px 0;
  display: flex;
  flex-direction: column;
}

.card-preview.has-cover {
  padding: 0;
}

.card-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Plan A: crisp miniature Feishu document sheet */
.mini-doc {
  background: #ffffff;
  border: 1px solid #e8eaef;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 12px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
  box-shadow: 0 2px 6px rgba(31, 35, 41, 0.04);
  overflow: hidden;
}

.mini-doc-accent {
  width: 28px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.85;
}

.mini-doc-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
  padding-right: 78px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mini-doc-summary {
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mini-doc-skills {
  margin-top: auto;
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  padding: 2px 78px 8px 0;
  overflow: hidden;
}

.mini-skill-pill {
  font-size: 10.5px;
  color: #3b5998;
  background: #f0f5ff;
  border-radius: 4px;
  padding: 2px 6px;
  max-width: 112px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-skill-more {
  flex-shrink: 0;
  max-width: none;
}

.price-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.price-badge.free {
  background: var(--free-bg);
  color: var(--free-text);
}

.price-badge.external {
  background: var(--paid-bg);
  color: var(--paid-text);
}

.source-badge {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #eceef2;
  border-radius: 4px;
  padding: 1px 6px;
}

/* Card footer (Feishu Drive layout) */
.card-body {
  padding: 12px 14px 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.doc-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

.card-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.copy-hint-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-size: 11px;
  border-radius: 6px;
  padding: 2px 7px;
  cursor: pointer;
  flex-shrink: 0;
}

.copy-hint-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.card-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.author-info {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.author-name {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-metrics {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.install-count {
  font-size: 12px;
  color: var(--text-muted);
}

.like-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 9px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.like-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.like-btn.liked {
  background: var(--accent-soft);
  border-color: rgba(51, 112, 255, 0.4);
  color: var(--accent);
  font-weight: 600;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 72px 24px;
  background: var(--surface);
  border: 1px dashed var(--border-hover);
  border-radius: 14px;
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.empty-title {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
}

.empty-desc {
  margin: 0 auto 20px;
  max-width: 440px;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 24px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  gap: 16px;
}

.footer-links a:hover {
  color: var(--accent);
}

/* Create modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: var(--surface);
  border-radius: 14px;
  max-width: 520px;
  width: 100%;
  padding: 22px 24px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.modal-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}

.modal-close:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.modal-lead {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.copy-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 10px 14px;
  margin-bottom: 16px;
}

.copy-box code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.modal-steps {
  margin: 0 0 18px;
  padding-left: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.65;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-steps strong {
  color: var(--text);
}

.modal-foot {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 60;
  background: #1f2329;
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

@media (max-width: 640px) {
  .topbar-inner {
    padding: 10px 14px;
  }
  .container {
    padding: 14px 14px 40px;
  }
}
