/* ============================================================
   全局
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: #f6f8fa; color: #1e293b; line-height: 1.5; min-height: 100vh;
}

button { font-family: inherit; }

/* ============================================================
   主页
   ============================================================ */
#homePage { display: flex; flex-direction: column; min-height: 100vh; }

header.home-header {
  background: #fff; border-bottom: 1px solid #e2e8f0; padding: 16px 28px;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.logo {
  font-weight: 700; font-size: 1.25rem; color: #0f172a;
  display: flex; align-items: center; gap: 8px;
}
.logo span {
  background: #6366f1; color: #fff; font-size: 0.7rem; padding: 2px 8px;
  border-radius: 999px; font-weight: 500;
}

.search-wrap { flex: 1; min-width: 200px; max-width: 420px; position: relative; }
.search-wrap input {
  width: 100%; padding: 9px 16px 9px 38px; border: 1px solid #e2e8f0; border-radius: 10px;
  font-size: 0.9rem; background: #f8fafc; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-wrap input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
  background: #fff;
}
.search-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; stroke: #94a3b8; fill: none; stroke-width: 2;
}

.header-stat { font-size: 0.82rem; color: #64748b; white-space: nowrap; }
.header-stat strong { color: #0f172a; }

.main {
  display: flex; flex: 1; max-width: 1500px; width: 100%;
  margin: 0 auto; padding: 0 24px;
}

.sidebar {
  width: 200px; flex-shrink: 0; padding: 24px 16px 24px 0;
  position: sticky; top: 73px; align-self: flex-start;
  max-height: calc(100vh - 73px); overflow-y: auto;
}
.sidebar h3 {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  color: #94a3b8; margin-bottom: 10px; font-weight: 600;
}
.cat-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.cat-list li {
  font-size: .88rem; padding: 8px 12px; border-radius: 8px;
  cursor: pointer; color: #475569;
  transition: background .15s, color .15s;
  display: flex; justify-content: space-between; align-items: center;
}
.cat-list li:hover { background: #eef2f6; color: #0f172a; }
.cat-list li.active { background: #e0e7ff; color: #4338ca; font-weight: 600; }
.cat-list li .count { font-size: .72rem; color: #94a3b8; font-weight: 400; }
.cat-list li.active .count { color: #6366f1; }

.content { flex: 1; padding: 24px 0 60px 32px; min-width: 0; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

/* ============================================================
   卡片
   ============================================================ */
.card {
  background: #fff; border-radius: 14px; border: 1px solid #e9edf2;
  overflow: hidden;
  transition: box-shadow .25s, transform .25s, border-color .25s;
  display: flex; flex-direction: column; cursor: pointer;
}
.card:hover {
  box-shadow: 0 12px 28px -8px rgba(15,23,42,.12);
  transform: translateY(-2px); border-color: #cbd5e1;
}

.card-preview {
  height: 180px; background: #f1f5f9; position: relative;
  overflow: hidden; border-bottom: 1px solid #e9edf2;
}
.card-preview iframe { width: 100%; height: 100%; border: none; display: block; }
.preview-badge {
  position: absolute; top: 10px; right: 10px;
  background: rgba(255,255,255,.85); backdrop-filter: blur(6px);
  border: 1px solid rgba(0,0,0,.04);
  font-size: .65rem; padding: 3px 8px; border-radius: 999px;
  color: #475569; font-weight: 500; pointer-events: none;
}

.card-body {
  padding: 14px 16px 16px; display: flex; flex-direction: column;
  gap: 10px; flex: 1;
}
.card-title { font-size: .95rem; font-weight: 600; color: #0f172a; }
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: .68rem; padding: 2px 8px; background: #f1f5f9;
  border-radius: 6px; color: #64748b; font-weight: 500;
}

/* ============================================================
   按钮
   ============================================================ */
.card-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 4px; }

.btn {
  font-size: .78rem; padding: 7px 12px; border-radius: 8px; border: 1px solid #e2e8f0;
  background: #fff; color: #334155; cursor: pointer; font-weight: 500;
  transition: background .15s, border-color .15s, color .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
.btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn.primary { background: #6366f1; border-color: #6366f1; color: #fff; }
.btn.primary:hover { background: #4f46e5; border-color: #4f46e5; }
.btn svg {
  width: 13px; height: 13px; fill: none;
  stroke: currentColor; stroke-width: 2; flex-shrink: 0;
}

/* ⭐ 卡片里两个按钮平分宽度 */
.card-actions .btn { flex: 1; }

/* ============================================================
   空状态
   ============================================================ */
.empty { grid-column: 1 / -1; text-align: center; padding: 80px 20px; color: #94a3b8; }
.empty p { font-size: .95rem; }

/* ============================================================
   详情页
   ============================================================ */
#detailPage { display: none; min-height: 100vh; background: #eef1f6; }

.detail-topbar {
  background: #fff; border-bottom: 1px solid #e2e8f0; padding: 14px 28px;
  display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 10;
}
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 7px 12px; font-size: .82rem; font-weight: 500; color: #475569;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.back-btn:hover { background: #e2e8f0; color: #0f172a; }
.back-btn svg {
  width: 14px; height: 14px; fill: none;
  stroke: currentColor; stroke-width: 2;
}
.detail-topbar .breadcrumb { font-size: .82rem; color: #94a3b8; }
.detail-topbar .breadcrumb strong { color: #0f172a; font-weight: 600; }

.detail-page-wrap {
  width: 80vw;
  max-width: 1800px;
  min-width: 960px;
  margin: 28px auto 60px;
}

.detail-body {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(0, 1.5fr);
  align-items: stretch;
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 24px 60px -30px rgba(15, 23, 42, 0.18),
    0 0 0 1px rgba(15, 23, 42, 0.05);
  min-height: calc(100vh - 180px);
}

/* 左侧信息区：不出现滚动条 */
.detail-info {
  background: #fff;
  border-right: 1px solid #e2e8f0;
  padding: 32px 30px 60px;
  min-width: 0;
}
.detail-info h1 {
  font-size: 1.4rem; font-weight: 700; color: #0f172a;
  letter-spacing: -0.01em; margin-bottom: 6px;
}
.detail-info .meta {
  display: flex; align-items: center; gap: 8px;
  font-size: .78rem; color: #94a3b8; margin-bottom: 14px;
}
.detail-info .meta .dot-sep { color: #cbd5e1; }
.detail-info .tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 24px; }

.info-block { margin-bottom: 26px; min-width: 0; }
.info-block h3 {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: #94a3b8; font-weight: 700; margin-bottom: 12px;
}
.info-block p.desc { font-size: .84rem; color: #475569; line-height: 1.75; }

/* 变形过程时间轴 */
.story { position: relative; }
.story-step { display: flex; gap: 14px; position: relative; padding-bottom: 18px; }
.story-step:last-child { padding-bottom: 0; }
.story-step::before {
  content: ''; position: absolute; left: 6px; top: 18px; bottom: 0;
  width: 2px; background: linear-gradient(180deg, #cbd5e1, #e2e8f0);
}
.story-step:last-child::before { display: none; }
.story-step .dot {
  width: 14px; height: 14px; border-radius: 50%; background: #6366f1;
  flex-shrink: 0; margin-top: 3px; position: relative; z-index: 1;
  box-shadow: 0 0 0 4px #e0e7ff;
}
.story-step .step-body { flex: 1; min-width: 0; }
.story-step .step-label {
  font-size: .82rem; font-weight: 600; color: #0f172a; margin-bottom: 4px;
}
.story-step .step-css {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: .72rem; color: #64748b; line-height: 1.75;
  white-space: pre-wrap; word-break: break-word;
}

/* 参数控件 */
.param-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.param-row label {
  font-size: .8rem; font-weight: 600; color: #475569;
  display: flex; justify-content: space-between;
}
.param-row label span {
  color: #6366f1; font-weight: 500;
  font-family: ui-monospace, monospace; font-size: .78rem;
}
.param-row input[type=range] {
  width: 100%; accent-color: #6366f1; height: 5px; cursor: pointer;
}
.param-row input[type=text] {
  width: 100%; padding: 7px 12px; border: 1px solid #e2e8f0;
  border-radius: 8px; font-size: .85rem; outline: none; font-family: inherit;
}
.param-row input[type=text]:focus {
  border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.param-row input[type=color] {
  width: 44px; height: 30px; border: 1px solid #e2e8f0;
  border-radius: 8px; cursor: pointer; padding: 2px; background: #fff;
}

/* 提示词 / 代码 切换标签 */
.info-tabs {
  display: flex; gap: 4px; margin-bottom: 12px;
  border-bottom: 1px solid #e9edf2;
}
.info-tab {
  padding: 8px 12px; font-size: .8rem; font-weight: 600; color: #94a3b8;
  cursor: pointer; background: none; border: none;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}
.info-tab:hover { color: #475569; }
.info-tab.active { color: #6366f1; border-bottom-color: #6366f1; }

.info-pane { display: none; min-width: 0; }
.info-pane.active { display: block; }

/* 提示词框 */
.prompt-box {
  background: #0f172a; color: #cbd5e1; border-radius: 12px; padding: 16px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: .72rem; line-height: 1.75;
  white-space: pre-wrap; max-height: 400px; overflow-y: auto;
  border: 1px solid #1e293b;
}
.prompt-box::-webkit-scrollbar { width: 8px; }
.prompt-box::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

/* ============================================================
   代码块（带行号、语法高亮、自身滚动）
   ============================================================ */
.code-block {
  background: #0f172a; border-radius: 12px; overflow: hidden;
  border: 1px solid #1e293b; min-width: 0;
}
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; background: #1e293b; border-bottom: 1px solid #334155;
}
.code-head .lang {
  font-size: .7rem; color: #94a3b8;
  font-family: ui-monospace, monospace;
  display: flex; align-items: center; gap: 8px;
}
.code-head .lang::before {
  content: ''; width: 9px; height: 9px; border-radius: 50%;
  background: linear-gradient(135deg,#f472b6,#a855f7);
}
.code-head .copy-inline {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
  color: #cbd5e1; font-size: .68rem; padding: 5px 9px; border-radius: 6px;
  cursor: pointer; transition: background .15s;
}
.code-head .copy-inline:hover { background: rgba(255,255,255,.12); color: #fff; }
.code-head .copy-inline svg {
  width: 11px; height: 11px; fill: none;
  stroke: currentColor; stroke-width: 2;
}

.code-body {
  display: flex; max-height: 400px; overflow: auto;
  background: #0f172a;
  width: 100%; min-width: 0;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: .715rem; line-height: 1.7;
  scrollbar-width: thin; scrollbar-color: #334155 #0f172a;
}
.code-body::-webkit-scrollbar { width: 8px; height: 8px; }
.code-body::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
.code-body::-webkit-scrollbar-corner { background: #0f172a; }

.code-gutter {
  flex-shrink: 0; padding: 14px 10px 14px 14px; text-align: right;
  color: #475569; user-select: none; background: #0f172a;
  border-right: 1px solid #1e293b; white-space: pre;
  font-variant-numeric: tabular-nums;
  position: sticky; left: 0; z-index: 1;
}
.code-content {
  padding: 14px 18px 14px 14px;
  white-space: pre; color: #cbd5e1;
  min-width: max-content; tab-size: 2;
}
.code-content .tok-comment { color: #64748b; font-style: italic; }
.code-content .tok-string  { color: #86efac; }
.code-content .tok-tag     { color: #f472b6; }
.code-content .tok-keyword { color: #a78bfa; font-weight: 500; }
.code-content .tok-number  { color: #fbbf24; }
.code-content .tok-punct   { color: #94a3b8; }

/* ============================================================
   右侧 Safari 预览
   ============================================================ */
.detail-preview {
  background: #f1f4f9;
  padding: 32px 36px 60px;
  display: flex; justify-content: center; align-items: flex-start;
  min-width: 0; overflow-y: auto;
  max-height: calc(100vh - 130px);
}

.safari-window {
  width: 100%; max-width: 100%;
  border-radius: 12px; overflow: hidden; background: #fff;
  box-shadow:
    0 24px 70px -24px rgba(15, 23, 42, 0.28),
    0 4px 16px -4px rgba(15, 23, 42, 0.08),
    0 0 0 1px rgba(15, 23, 42, 0.08);
}

.safari-chrome {
  background: linear-gradient(180deg, #f5f5f7 0%, #ebebed 100%);
  padding: 11px 14px 0;
  display: flex; align-items: flex-end; gap: 14px;
  border-bottom: 1px solid #d6d6d8; position: relative;
}
.safari-dots { display: flex; gap: 8px; padding-bottom: 12px; flex-shrink: 0; }
.safari-dots span {
  width: 12px; height: 12px; border-radius: 50%;
  box-shadow: inset 0 0 0 0.5px rgba(0,0,0,.08);
}
.safari-dots .dot-red    { background: #ff5f57; }
.safari-dots .dot-yellow { background: #febc2e; }
.safari-dots .dot-green  { background: #28c840; }

.safari-tabs { flex: 1; display: flex; gap: 0; min-width: 0; }
.safari-tab {
  background: #fff; border-radius: 8px 8px 0 0; padding: 8px 14px;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: #333; max-width: 260px; min-width: 0;
  margin-bottom: -1px;
  border: 1px solid #d6d6d8; border-bottom: 1px solid #fff;
  position: relative; z-index: 1;
}
.safari-tab .favicon {
  width: 12px; height: 12px; border-radius: 3px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  flex-shrink: 0;
}
.safari-tab .tab-title {
  white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; font-weight: 500;
}

.safari-toolbar {
  background: #f5f5f7; padding: 8px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid #e0e0e2;
}
.safari-toolbar .nav-btn {
  background: none; border: none;
  width: 26px; height: 26px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #a0a0a6; cursor: default; flex-shrink: 0;
}
.safari-toolbar .nav-btn svg {
  width: 15px; height: 15px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.safari-url {
  flex: 1; min-width: 0;
  background: #fff; border: 1px solid #d6d6d8; border-radius: 7px;
  padding: 5px 12px;
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: #333; justify-content: center;
}
.safari-url .lock { color: #8e8e93; display: inline-flex; }
.safari-url .lock svg {
  width: 11px; height: 11px; fill: none;
  stroke: currentColor; stroke-width: 2;
}
.safari-url .url-text {
  color: #333; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.safari-url .url-text strong { color: #0f172a; font-weight: 600; }

.safari-viewport {
  position: relative; background: #fff; height: 640px;
}
.safari-viewport iframe {
  width: 100%; height: 100%; border: none;
  display: block; background: #fff;
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: #fff; font-size: .85rem;
  padding: 11px 22px; border-radius: 10px;
  box-shadow: 0 10px 30px -6px rgba(0,0,0,.3);
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 100; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg {
  width: 16px; height: 16px; stroke: #4ade80;
  fill: none; stroke-width: 2.5;
}

/* ============================================================
   响应式
   ============================================================ */
@media (min-width: 1800px) {
  .detail-page-wrap { width: 80vw; max-width: 1800px; }
}
@media (max-width: 1400px) {
  .detail-page-wrap { width: 88vw; min-width: 0; }
}
@media (max-width: 1100px) {
  .detail-page-wrap {
    width: 100%; min-width: 0;
    margin: 20px auto 40px; padding: 0 16px;
  }
  .detail-body { grid-template-columns: 1fr; border-radius: 16px; min-height: 0; }
  .detail-info { border-right: none; border-bottom: 1px solid #e2e8f0; padding: 24px 22px 40px; }
  .detail-preview { padding: 24px 22px 40px; max-height: none; }
  .safari-viewport { height: 480px; }
}
@media (max-width: 860px) {
  .main { flex-direction: column; padding: 0 16px; }
  .sidebar { width: 100%; position: static; padding: 16px 0 0; max-height: none; }
  .cat-list { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .cat-list li {
    padding: 6px 14px; background: #fff;
    border: 1px solid #e2e8f0; border-radius: 999px;
  }
  .cat-list li.active { background: #6366f1; color: #fff; border-color: #6366f1; }
  .cat-list li.active .count { color: rgba(255,255,255,.8); }
  .cat-list li .count { display: none; }
  .content { padding: 20px 0 40px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
  header.home-header { padding: 12px 16px; gap: 12px; }
  .header-stat { display: none; }
  .detail-topbar { padding: 12px 16px; }
  .safari-viewport { height: 400px; }
}