:root {
  --primary: #8b5e3c;
  --primary-dark: #6f4a2e;
  --primary-light: #a97a52;
  --secondary: #f5f0eb;
  --accent: #c4a35a;
  --wood-dark: #5b3c22;
  --wood-mid: #7d5636;
  --cream: #fbf8f4;
  --ink: #3b2f24;
  --muted: #8a7a6a;
  --line: #e4d8ca;
  --casual: #7d9a75;
  --work: #4a5a7d;
  --date: #c97b8f;
  --danger: #b34a3a;
  --shadow: 0 6px 18px rgba(70, 46, 26, 0.18);
  --shadow-soft: 0 3px 10px rgba(70, 46, 26, 0.14);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--secondary);
  overflow-x: hidden;
}

/* ---- Wallpaper / closet rail scene ---- */
.rail-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 20%, rgba(196,163,90,0.10) 0, transparent 45%),
    radial-gradient(circle at 85% 75%, rgba(139,94,60,0.12) 0, transparent 50%),
    repeating-linear-gradient(45deg, #efe7dd 0 2px, #f5f0eb 2px 26px);
  overflow: hidden;
}
.rail-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.25), rgba(255,255,255,0) 30%);
}
.wallpaper-shape {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(139,94,60,0.08);
}
.wall-1 { width: 340px; height: 340px; top: -120px; right: -100px; }
.wall-2 { width: 280px; height: 280px; bottom: 120px; left: -140px; }

.rail-pole {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 72px;
  height: 100%;
  background: linear-gradient(90deg, #6a4527, #8b5e3c 45%, #9a6b45 55%, #5f3f24);
  box-shadow: 6px 0 14px rgba(70,46,26,0.25);
  opacity: 0.35;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-t)) 16px 96px;
}

/* ---- Header ---- */
.app-header { padding: 6px 2px 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(160deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  display: grid; place-items: center;
  box-shadow: var(--shadow-soft);
  border-bottom: 3px solid var(--wood-dark);
}
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.2px; color: var(--primary-dark); }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }

/* ---- Tab panels ---- */
.tab-panel { display: none; animation: fade 0.22s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- Clothesline + clothespins ---- */
.clothesline {
  position: relative;
  margin: 18px 4px 8px;
  padding: 18px 8px 26px;
  display: flex;
  justify-content: space-around;
  gap: 12px;
}
.clothesline::before {
  content: "";
  position: absolute;
  top: 8px; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--wood-mid) 12%, var(--wood-mid) 88%, transparent);
  border-radius: 3px;
}
.clothespin {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(180deg, var(--primary-light), var(--primary));
  border: 2px solid var(--wood-dark);
  border-radius: 9px;
  padding: 14px 8px 10px;
  box-shadow: var(--shadow-soft);
}
.clothespin::before {
  content: "";
  position: absolute;
  top: 8px; left: 50%; transform: translateX(-50%);
  width: 20px; height: 5px;
  background: var(--wood-dark);
  border-radius: 3px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.12);
}
.pin-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #efe2d2;
  text-align: center;
}
.pin-number {
  font-size: 34px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.28);
  line-height: 1.1;
  margin: 6px 0 4px;
}
.pin-tag {
  width: 30px; height: 20px;
  background: #d8c9a8;
  clip-path: polygon(0 0, 100% 0, 100% 85%, 50% 100%, 0 85%);
  opacity: 0.85;
}

/* ---- Quick plan button ---- */
.quick-plan {
  width: 100%;
  margin: 6px 0 4px;
  padding: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(160deg, var(--accent), #b08f47);
  color: #3b2f24;
  font-weight: 700;
  font-size: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border-bottom: 3px solid #9a7b38;
}
.quick-icon {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #3b2f24;
  color: var(--accent);
  display: grid; place-items: center;
  font-size: 18px; line-height: 1;
}
.quick-plan:active { transform: translateY(1px); }

/* ---- Section heads ---- */
.recent-head, .wardrobe-head { margin: 22px 2px 12px; }
.recent-head h2, .wardrobe-head h2 {
  margin: 0; font-size: 16px; color: var(--primary-dark);
  letter-spacing: 0.3px;
}
.wardrobe-head p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

/* ---- Hanger + garment card ---- */
.hanger-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  overflow: hidden;
  margin-bottom: 10px;
  user-select: none;
}
.hanger-art {
  flex-shrink: 0;
  width: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hanger-hook {
  width: 12px; height: 14px;
  border: 3px solid var(--wood-mid);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}
.hanger-body {
  width: 40px; height: 22px;
  background: linear-gradient(180deg, var(--primary-light), var(--primary));
  border: 2px solid var(--wood-dark);
  border-radius: 22px 22px 4px 4px;
  position: relative;
}
.garment {
  margin-top: 4px;
  width: 36px;
  height: 40px;
  border-radius: 6px 6px 3px 3px;
  position: relative;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,0.06);
}
.garment::after {
  content: "";
  position: absolute;
  left: 5px; right: 5px; bottom: 4px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.35);
}
.garment-oc{ background: var(--casual); }
.garment-wk{ background: var(--work); }
.garment-dt{ background: var(--date); }
.garment-na{ background: #9c8f7d; }

.hanger-info { flex: 1; min-width: 0; }
.hanger-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hanger-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.occasion-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  letter-spacing: 0.3px;
}
.badge-oc{ background: var(--casual); }
.badge-wk{ background: var(--work); }
.badge-dt{ background: var(--date); }
.badge-na{ background: #9c8f7d; }

.hanger-items {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* woven label */
.woven-label {
  display: inline-block;
  margin-top: 8px;
  font-size: 10px;
  letter-spacing: 0.3px;
  color: #4b3d2f;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.18) 0 1px, transparent 1px 3px),
    #e6d9bd;
  border: 1px solid #c9b88f;
  border-radius: 3px;
  padding: 2px 6px;
}

/* ---- Swipe action ---- */
.swipe-wrap { position: relative; border-radius: 14px; margin-bottom: 10px; overflow: hidden; }
.swipe-delete {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 22px;
  background: var(--danger);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.swipe-delete .swipe-btn {
  background: rgba(0,0,0,0.12);
  border-radius: 8px;
  padding: 10px 14px;
}
.swipe-item {
  position: relative;
  background: var(--cream);
  transition: transform 0.18s ease;
  will-change: transform;
}
.swipe-item .hanger-card { margin-bottom: 0; box-shadow: none; }

/* ---- Search + chips ---- */
.search-wrap { margin: 2px 0 14px; }
.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  box-shadow: var(--shadow-soft);
}
.search-icon {
  width: 14px; height: 14px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  position: relative; flex-shrink: 0;
}
.search-icon::after {
  content: "";
  position: absolute;
  width: 7px; height: 2px;
  background: var(--muted);
  transform: rotate(45deg);
  right: -6px; bottom: -2px;
  border-radius: 2px;
}
.search-box input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  padding: 13px 0;
  font-size: 15px;
  color: var(--ink);
}
.filter-chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: var(--cream);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ---- Form ---- */
.form-card {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow-soft);
}
.form-card h2 { margin: 0 0 16px; font-size: 18px; color: var(--primary-dark); }
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary-dark);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}
.field input, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font-size: 15px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.error { color: var(--danger); font-size: 11px; margin: 4px 0 0; min-height: 0; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }
.btn-save {
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(160deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.save-icon {
  width: 14px; height: 14px;
  border: 2px solid #fff;
  border-top: none; border-right: none;
  transform: rotate(-45deg);
  margin-top: -3px;
}
.btn-cancel {
  border: 1px solid var(--line);
  background: var(--secondary);
  color: var(--muted);
  border-radius: 14px;
  padding: 14px 20px;
  font-size: 14px;
  cursor: pointer;
}
.btn-save:active, .btn-cancel:active { transform: translateY(1px); }

/* ---- Wardrobe rail ---- */
.wardrobe-rail {
  position: relative;
  background: linear-gradient(180deg, #eae0d2, #d9cbb5);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px 12px 16px;
  min-height: 240px;
  box-shadow: var(--shadow-soft);
}
.wardrobe-rail::before {
  content: "";
  position: absolute;
  top: 12px; left: 12px; right: 12px;
  height: 4px;
  background: linear-gradient(90deg, #6a4527, #8b5e3c, #6a4527);
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.rail-row {
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.wardrobe-item { cursor: pointer; text-align: center; width: 84px; }
.wardrobe-item .hanger-body { margin: 0 auto; }
.wardrobe-item .garment { margin: 5px auto 0; width: 34px; height: 46px; }
.wardrobe-name {
  margin-top: 8px;
  font-size: 11px;
  color: var(--primary-dark);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Empty states ---- */
.empty-state { text-align: center; padding: 40px 20px; }
.empty-hanger { font-size: 40px; margin: 0 0 8px; }
.empty-state h3 { margin: 0 0 6px; color: var(--primary-dark); }
.empty-state p { margin: 0; color: var(--muted); font-size: 14px; }
.hidden { display: none !important; }

/* ---- Detail sheet ---- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.sheet.open { display: flex; }
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(40,26,14,0.5);
  animation: fade 0.2s;
}
.sheet-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: var(--cream);
  border-radius: 22px 22px 0 0;
  padding: 10px 22px calc(28px + var(--safe-b));
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle {
  width: 44px; height: 5px;
  background: var(--line);
  border-radius: 3px;
  margin: 6px auto 18px;
}
.sheet-card h2 { margin: 0 0 6px; font-size: 20px; color: var(--primary-dark); }
.detail-block { margin-top: 16px; }
.detail-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 4px;
}
.detail-block p { margin: 0; font-size: 15px; line-height: 1.5; }
.detail-meta {
  margin-top: 16px;
  display: flex; gap: 14px;
  font-size: 12px; color: var(--muted);
}
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn-edit {
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.btn-del {
  flex: 1;
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  border-radius: 14px;
  padding: 14px;
  font-weight: 700;
  cursor: pointer;
}

/* ---- Bottom tab bar ---- */
.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  padding-bottom: var(--safe-b);
}
.fabric-strip {
  position: absolute;
  top: -8px; left: 0; right: 0;
  height: 10px;
  background:
    repeating-linear-gradient(45deg, #b58b5f 0 6px, #a77d52 6px 12px);
  border-radius: 4px 4px 0 0;
  opacity: 0.9;
}
.tab-inner {
  position: relative;
  display: flex;
  justify-content: space-around;
  align-items: center;
  max-width: 520px;
  margin: 0 auto;
  padding: 14px 6px 8px;
  background: linear-gradient(180deg, #cfa570, #b98b5a);
  border-top: 3px solid #9a7b48;
  box-shadow: 0 -4px 14px rgba(70,46,26,0.25);
}
.tab-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  color: #4a3624;
}
.tab-hanger {
  width: 26px; height: 34px;
  display: block;
  position: relative;
  transition: transform 0.2s ease, filter 0.2s ease;
  transform-origin: top center;
}
.tab-hanger::before {
  content: "";
  position: absolute;
  top: 0; left: 50%; transform: translateX(-50%);
  width: 7px; height: 11px;
  border: 2px solid currentColor;
  border-bottom: none;
  border-radius: 5px 5px 0 0;
}
.tab-hanger::after {
  content: "";
  position: absolute;
  top: 9px; left: 50%; transform: translateX(-50%);
  width: 24px; height: 14px;
  background: currentColor;
  border-radius: 13px 13px 3px 3px;
}
.tab-btn .tab-label { font-size: 10px; font-weight: 600; letter-spacing: 0.2px; }
.tab-btn.active { color: #fff; }
.tab-btn.active .tab-hanger {
  transform: rotateX(18deg) translateY(-2px);
  filter: drop-shadow(0 3px 3px rgba(0,0,0,0.35));
}
.tab-btn.active .tab-label { text-shadow: 0 1px 2px rgba(0,0,0,0.25); }
.tab-btn:not(.active) { color: #6b4d2f; }
.tab-btn:not(.active) .tab-hanger { filter: brightness(0.55) saturate(0.6); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: calc(110px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: #3b2f24;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  white-space: nowrap;
  max-width: 90%;
}
.toast.show { animation: fade 0.2s; }