:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #2b2b2b;
  --muted: #8a8a8a;
  --navy: #2b3a55;
  --accent: #e07a5f;
  --line: #eae4da;
  --shadow: 0 4px 16px rgba(43, 58, 85, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: #d24d4d; font-size: 14px; min-height: 18px; margin: 8px 0 0; }

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select { font-family: inherit; font-size: 15px; }

/* ---------- 登录 ---------- */
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--card); border-radius: 24px;
  box-shadow: var(--shadow); padding: 40px 28px; text-align: center;
}
.login-card .logo { font-size: 56px; }
.login-card h1 { margin: 8px 0 4px; font-size: 24px; color: var(--navy); }
.login-card input {
  width: 100%; margin-top: 24px; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: 12px; outline: none; text-align: center; letter-spacing: 2px;
}
.login-card input:focus { border-color: var(--accent); }

/* ---------- 顶栏 / 底部导航 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 18px 12px;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.ghost-btn { color: #cbd3e0; font-size: 14px; padding: 6px 10px; border-radius: 8px; }
.ghost-btn:active { background: rgba(255,255,255,0.1); }

main { padding: 16px 16px 96px; max-width: 560px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card);
  display: flex; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 8px; color: var(--muted); font-size: 12px;
}
.tab .tab-ico { font-size: 20px; }
.tab.active { color: var(--accent); font-weight: 600; }

.fab {
  position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 74px); z-index: 21;
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 30px; line-height: 1; box-shadow: 0 6px 18px rgba(224, 122, 95, 0.45);
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(0.94); }

/* ---------- 衣橱网格 ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 14px; -webkit-overflow-scrolling: touch; }
.filters .chip { flex: 0 0 auto; }

.chip {
  padding: 7px 14px; border-radius: 20px; background: var(--card); border: 1px solid var(--line);
  color: #555; font-size: 13px; white-space: nowrap;
}
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.item-card {
  position: relative; background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.item-card .thumb { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; background: #efeae1; }
.item-card .info { padding: 10px 12px 12px; }
.item-card .name { font-size: 14px; font-weight: 600; margin: 0 0 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-card .meta { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.1); flex: 0 0 auto; }
.item-card .del {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(0,0,0,0.45); color: #fff; font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.item-card .del:active { background: rgba(0,0,0,0.7); }

.empty-tip { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 15px; line-height: 1.6; }

/* ---------- 面板 ---------- */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.field-label { font-size: 13px; color: var(--muted); margin: 12px 0 8px; }
.field-label:first-child { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 按钮 ---------- */
.btn-primary {
  background: var(--accent); color: #fff; border-radius: 12px; padding: 12px 18px;
  font-size: 15px; font-weight: 600;
}
.btn-primary:active { opacity: 0.88; }
.btn-primary:disabled { background: #d8cfc5; }
.btn-lg { width: 100%; margin-top: 18px; padding: 15px; font-size: 16px; }

/* ---------- 搭配结果 ---------- */
#match-result { margin-top: 16px; }
.lookbook { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.lookbook .note { font-size: 14px; color: #555; background: #fbf4ee; border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; line-height: 1.5; }
.stack { display: flex; flex-direction: column; }
.piece {
  position: relative; background: #faf8f4; border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; display: flex; align-items: center; gap: 12px; margin-bottom: 10px;
}
.piece:last-child { margin-bottom: 0; }
.piece img { width: 54px; height: 54px; border-radius: 10px; object-fit: cover; flex: 0 0 auto; background: #efeae1; }
.piece .p-info { flex: 1; min-width: 0; }
.piece .p-name { font-size: 14px; font-weight: 600; }
.piece .p-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.piece .layer-badge {
  position: absolute; top: -9px; left: 12px; font-size: 11px; padding: 2px 10px; border-radius: 10px;
  background: var(--navy); color: #fff;
}
/* 外套叠在内搭上面，体现层次 */
.piece.layer-outer { margin-top: 14px; box-shadow: 0 -4px 12px rgba(43,58,85,0.12); }
.piece.layer-accessory { background: #fbf9f5; }
.lookbook .save-row { display: flex; gap: 10px; margin-top: 16px; }
.lookbook .save-row .btn-primary { flex: 1; margin-top: 0; }
.lookbook .save-row .ghost-btn { color: var(--muted); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }

/* ---------- 我的搭配列表 ---------- */
.outfit-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; }
.outfit-card .head { display: flex; align-items: center; justify-content: space-between; }
.outfit-card .tag { font-size: 13px; color: var(--navy); font-weight: 600; }
.outfit-card .date { font-size: 12px; color: var(--muted); }
.outfit-card .note { font-size: 13px; color: #555; margin: 8px 0 10px; line-height: 1.5; }
.outfit-card .thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.outfit-card .thumbs img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: #efeae1; }
.outfit-card .del { font-size: 20px; color: var(--muted); padding: 2px 8px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 0 0 calc(env(safe-area-inset-bottom) + 12px);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 8px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.close-btn { font-size: 26px; color: var(--muted); line-height: 1; padding: 2px 6px; }
.modal-body { padding: 8px 20px 4px; }
.modal-foot { padding: 16px 20px 0; }
.modal-foot .btn-primary { width: 100%; }

.photo-picker {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--card); border: 2px dashed var(--line); border-radius: 16px; padding: 22px;
  color: var(--muted); font-size: 14px; cursor: pointer; margin-bottom: 10px;
}
.photo-picker img { max-width: 100%; max-height: 220px; border-radius: 12px; object-fit: contain; }
#recognize-status { text-align: center; padding: 8px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.field input[type="text"], .field select {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); outline: none;
}
.field input[type="text"]:focus, .field select:focus { border-color: var(--accent); }
.color-row { display: flex; gap: 8px; }
.color-row input[type="text"] { flex: 1; }
.color-row input[type="color"] { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 2px; background: var(--card); }

/* ---------- 提示与加载 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 100;
  background: rgba(43,43,43,0.92); color: #fff; padding: 11px 18px; border-radius: 12px;
  font-size: 14px; max-width: 80%; text-align: center;
}
.loading {
  position: fixed; inset: 0; z-index: 99; background: rgba(255,255,255,0.7);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  font-size: 14px; color: var(--navy);
}
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid #e3dcd2; border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
