:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --radius: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: rgba(246, 246, 244, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 700; font-size: 17px; }
.topbar-nav { display: flex; gap: 6px; align-items: center; }
.topbar-nav a {
  color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 999px; font-size: 14px;
}
.topbar-nav a.active { background: var(--ink); color: #fff; }
.link-btn { background: none; border: 0; font-size: 15px; cursor: pointer; padding: 6px; }

main { padding: 12px 14px 40px; max-width: 760px; margin: 0 auto; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.gap { gap: 8px; }
.flex1 { flex: 1; }

/* 工具条 */
.toolbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
#search {
  width: 100%; padding: 10px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-size: 14px; outline: none;
}
#search:focus { border-color: var(--accent); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); color: var(--muted); user-select: none;
}
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

.summary { font-size: 12px; color: var(--muted); margin: 4px 2px 8px; }

/* 卡片与网格 */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 15px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.item-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: transform 0.08s ease;
}
.item-card:active { transform: scale(0.98); }
.thumb {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 44px; background: #efeeec;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-meta { padding: 8px 10px 10px; }
.item-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; }
.badge {
  display: inline-block; padding: 1px 6px; border-radius: 6px; font-size: 11px;
  background: #f1efec; color: var(--muted);
}
.badge.retired { background: #fef3c7; color: #92400e; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }

/* 底部抽屉 */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-mask { position: absolute; inset: 0; background: rgba(0,0,0,0.35); }
.sheet-body {
  position: relative; width: 100%; max-height: 86vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}
@media (min-width: 720px) {
  .sheet { align-items: center; justify-content: center; }
  .sheet-body { max-width: 520px; border-radius: 18px; }
}
.sheet-grip { width: 40px; height: 4px; background: var(--line); border-radius: 4px; margin: 0 auto 12px; }

/* 详情 */
.gallery { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; }
.gallery .g-img {
  flex: none; width: 132px; height: 132px; border-radius: 10px; overflow: hidden; background: #efeeec;
  display: flex; align-items: center; justify-content: center; font-size: 40px;
}
.gallery img { width: 100%; height: 100%; object-fit: cover; }
.kv { display: grid; grid-template-columns: 76px 1fr; gap: 6px 10px; font-size: 13px; margin: 10px 0; }
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; }
.stats-line { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 10px 0; }

/* 按钮 */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; font-size: 14px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn:disabled { opacity: 0.5; }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 8px; }

/* 拆解编辑器 */
.photo-wrap { position: relative; border-radius: 10px; overflow: hidden; background: #111; }
.photo-wrap img { display: block; width: 100%; }
.region-box {
  position: absolute; border: 2px solid #22d3ee; background: rgba(34, 211, 238, 0.15);
  border-radius: 4px; display: flex; align-items: flex-start; justify-content: flex-start; cursor: pointer;
}
.region-box .num {
  background: #22d3ee; color: #083344; font-size: 11px; font-weight: 700;
  border-radius: 4px; padding: 1px 5px; margin: -2px 0 0 -2px;
}
.candidate {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff;
}
.candidate.flash { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.candidate .head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.candidate .head .n {
  width: 22px; height: 22px; border-radius: 6px; background: #22d3ee; color: #083344;
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none;
}
.tag-switch { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tag-switch button {
  border: 0; background: #fff; padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--muted);
}
.tag-switch button.on { background: var(--ink); color: #fff; }

/* 表单 */
.form { display: grid; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field input[type=text], .field select, .field textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: #fff;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.checks { display: flex; gap: 6px; flex-wrap: wrap; }
.checks label {
  display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; cursor: pointer;
}
.checks label.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.checks input { display: none; }
.checks label input:checked + span { color: inherit; }

.session-item {
  display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 8px; cursor: pointer; background: #fff;
}
.session-item .s-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: #efeeec; flex: none; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); z-index: 99;
  background: rgba(28,25,23,0.92); color: #fff; font-size: 13px; padding: 9px 16px;
  border-radius: 999px; max-width: 86vw; text-align: center; opacity: 0; transition: opacity 0.15s;
  pointer-events: none;
}
#toast.show { opacity: 1; }

/* 穿着时间线 */
.wear-entry {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  background: #fff; display: flex; flex-direction: column; gap: 4px;
}
.wear-entry .wear-items { font-size: 14px; font-weight: 500; }
.badge.plan { background: #dbeafe; color: #1d4ed8; }
.badge.worn { background: #dcfce7; color: #15803d; }

/* 穿搭方案：角色条与衣物缩略图按实际叠穿结构展示 */
.outfits-list { display: grid; gap: 12px; }
.outfit-card p { line-height: 1.6; white-space: pre-wrap; }
.outfit-role-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.outfit-role-strip span { border-bottom: 2px solid var(--accent); padding: 4px 8px; font-size: 12px; }
.outfit-pieces { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.outfit-piece { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.outfit-photo { width: 100%; aspect-ratio: 1; background: var(--bg); border-radius: 10px; overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.outfit-photo img { width: 100%; height: 100%; object-fit: contain; }
.outfit-notices { padding: 10px 0; color: #854d0e; font-size: 13px; line-height: 1.6; }
.outfit-notices summary { cursor: pointer; }
.outfit-picker { display: grid; gap: 8px; max-height: 42vh; overflow: auto; }
.outfit-pick { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.outfit-pick label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.outfit-pick select { flex: 0 0 80px; padding: 8px; }
#outfit-body textarea { width: 100%; min-height: 72px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; gap: 6px; }
  .topbar-nav { width: 100%; justify-content: space-between; }
  .topbar-nav a { padding: 6px 8px; font-size: 13px; }
  #outfits-list + * { min-width: 0; }
  body[data-page="outfits"] h2 { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }

/* 穿搭原图与独立单品图 */
.outfit-cover { display:block; width:100%; height:300px; object-fit:contain; background:var(--bg,#f5f3ef); border-radius:12px; margin-bottom:16px; }
.outfit-originals { display:flex; gap:12px; overflow-x:auto; margin:16px 0; align-items:flex-start; }
.outfit-originals > img, .outfit-originals > div { flex:0 0 auto; max-width:100%; }
.outfit-originals img { display:block; width:auto; max-width:100%; height:360px; object-fit:contain; border-radius:10px; background:#f4f2ef; }
.outfit-originals > div img { height:200px; }
.outfit-piece a { color:inherit; text-underline-offset:3px; }
.candidate-image { display:flex; align-items:center; flex-wrap:wrap; gap:10px; margin:12px 0; }
.candidate-image img { width:100px; height:100px; object-fit:contain; background:#f7f5f1; border-radius:8px; }
.image-upload { margin:12px 0 20px; }
.source-photos { margin:20px 0; }
.source-photos summary { cursor:pointer; }
.gallery .g-img { position:relative; display:flex; flex-direction:column; align-items:stretch; justify-content:flex-start; width:160px; height:auto; min-height:160px; font-size:13px; }
.g-img > .badge { display:block; margin:4px; }
.gallery .g-img > img { display:block; flex:none; width:160px; height:160px; object-fit:contain; }
.source-photos .g-img > img { height:260px; }
@media(max-width:600px) { .outfit-originals img { height:300px; } .outfit-cover { height:260px; } }
