:root {
  --primary: #1e2a4f;
  --secondary: #c9a87c;
  --accent: #ff6b6b;
  --ink: #26241f;
  --muted: #8a8277;
  --paper: #f6f0e4;
  --paper-2: #efe6d4;
  --fabric: #fbf7ee;
  --felt: #3a3a45;
  --felt-dark: #2c2c36;
  --wood: #b98a5e;
  --wood-light: #d9ab7c;
  --wood-dark: #8f6238;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --rail-h: 54px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, 'Times New Roman', serif;
}

body {
  padding-top: calc(var(--rail-h) + var(--safe-top));
  padding-bottom: calc(116px + var(--safe-bottom));
  overscroll-behavior-y: none;
}

/* ---------- Top rail ---------- */
.rail {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--rail-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background:
    repeating-linear-gradient(90deg, var(--wood) 0 12px, var(--wood-dark) 12px 15px),
    var(--wood);
  z-index: 20;
  box-shadow: 0 3px 8px rgba(0,0,0,.25);
}
.rail-inner { position: relative; height: 26px; }
.rail-rod {
  position: absolute;
  left: 34px; right: 34px; top: 5px;
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(#d8cfc2, #a99f90);
  box-shadow: inset 0 -2px 3px rgba(0,0,0,.25), 0 1px 0 rgba(255,255,255,.5);
}
.rail-handle {
  position: absolute; top: 0;
  width: 20px; height: 14px;
  border-radius: 7px 7px 3px 3px;
  background: linear-gradient(#c2b9ab, #8e8577);
  box-shadow: inset 0 -2px 3px rgba(0,0,0,.3);
}
.rail-handle::after {
  content: '';
  position: absolute; left: 5px; right: 5px; top: 3px; height: 4px;
  border-radius: 3px;
  background: radial-gradient(circle at 50% 40%, #efead9, #b6ac9c);
}
.rail-handle.left { left: 6px; }
.rail-handle.right { right: 6px; }
.app-title {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 15px;
  letter-spacing: 1.5px;
  text-align: center;
  color: #fbf3e4;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  position: relative;
  top: -3px;
}

/* ---------- App content ---------- */
.app { padding: 14px 14px 8px; }

.tab-page { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-title {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 2px 8px;
  font-weight: normal;
}

/* ---------- Dashboard ---------- */
.dashboard { display: flex; flex-direction: column; gap: 12px; }

.felt {
  background: var(--felt);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 4px 10px rgba(0,0,0,.18);
}
.felt-row { display: flex; gap: 12px; }

.snap {
  flex: 1;
  background: radial-gradient(circle at 50% 35%, #d4d4da, #9a9aa4);
  border-radius: 12px;
  border: none;
  padding: 12px 8px 14px;
  box-shadow:
    inset 0 2px 3px rgba(255,255,255,.5),
    inset 0 -4px 6px rgba(0,0,0,.25),
    0 4px 8px rgba(0,0,0,.25);
  color: var(--primary);
  text-align: center;
  position: relative;
}
.snap::before {
  content: '';
  position: absolute; inset: 4px;
  border: 1px dashed rgba(30,42,79,.25);
  border-radius: 8px;
}
.snap-num {
  display: block;
  font-family: Georgia, serif;
  font-size: 34px;
  font-weight: bold;
  line-height: 1;
  color: var(--primary);
  text-shadow: 0 1px 0 rgba(255,255,255,.6);
}
.snap-label {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--primary);
}

.upcoming { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.mini-tag {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--fabric);
  border: 1px dashed var(--secondary);
  border-radius: 4px;
  padding: 6px 10px;
  position: relative;
  overflow: hidden;
}
.mini-tag .pin { flex: 0 0 auto; }
.mini-tag .mini-name { font-family: 'Comic Sans MS', 'Bradley Hand', cursive; font-size: 14px; flex: 1; }
.mini-tag .mini-date { font-size: 11px; color: var(--muted); }
.mini-tag .thread { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; }

.empty-dash-note { font-size: 13px; color: var(--muted); font-style: italic; text-align: center; padding: 6px 0; }

/* ---------- Fabric tag card ---------- */
.tag-card {
  position: relative;
  background: var(--fabric);
  border-radius: 6px;
  padding: 16px 14px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--secondary);
  box-shadow: 0 3px 8px rgba(0,0,0,.1);
  overflow: hidden;
}
.tag-card .zig {
  position: absolute; left: 10px; right: 10px; top: -1px;
  height: 8px;
  background:
    linear-gradient(135deg, transparent 55%, var(--secondary) 55%) 0 0/8px 8px repeat-x,
    linear-gradient(-135deg, transparent 55%, var(--secondary) 55%) 0 0/8px 8px repeat-x;
}
.tag-card .thread {
  position: absolute; left: 0; right: 0; bottom: 0; height: 7px;
}
.pin-row { position: relative; text-align: center; height: 26px; margin: -6px 0 6px; }
.pin { display: inline-block; transform: rotate(45deg); width: 9px; height: 9px; border-radius: 50%; background: #d8d8e0; box-shadow: inset 0 1px 2px rgba(255,255,255,.8), 0 0 0 1px #b9b9c4; }

.tag-name {
  font-family: 'Comic Sans MS', 'Bradley Hand', 'Segoe Print', cursive;
  font-size: 21px;
  color: var(--primary);
  margin: 0 0 6px;
  line-height: 1.15;
  word-break: break-word;
}
.tag-date { font-size: 13px; color: var(--muted); letter-spacing: .5px; }
.tag-tags { display: flex; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 11px;
  color: var(--primary);
  border: 1px solid var(--secondary);
  border-radius: 20px;
  padding: 3px 9px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.chip.weather { color: var(--primary); border-color: var(--secondary); }

.tag-actions { display: flex; gap: 8px; margin-top: 12px; }
.tag-actions .fab {
  font-family: Georgia, serif;
  font-size: 12px;
  border: 1px solid var(--secondary);
  background: var(--fabric);
  color: var(--primary);
  border-radius: 16px;
  padding: 6px 14px;
}

/* ---------- Hanger / empty state ---------- */
.empty-state { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty-state svg { opacity: .5; margin-bottom: 10px; }
.empty-state p { font-style: italic; font-size: 14px; margin: 0; }
.hanger-swing { transform-origin: 58px 40px; animation: swing 1.6s ease-in-out; }
@keyframes swing {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-8deg); }
  60% { transform: rotate(6deg); }
}

/* ---------- Week rail ---------- */
.week-scroll {
  overflow-x: auto;
  display: flex;
  gap: 12px;
  padding: 8px 2px 18px;
  -webkit-overflow-scrolling: touch;
}
.hook-slot {
  flex: 0 0 118px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--paper-2);
  border-radius: 10px;
  padding: 12px 6px 10px;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.04);
}
.hook-slot::before {
  content: '';
  width: 2px; height: 14px;
  background: #a99f90;
  position: absolute; top: 2px;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.2);
}
.hook-day {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 8px;
}
.hook-day.today { color: var(--accent); font-weight: bold; }
.hook-day.count { color: var(--primary); font-size: 10px; }

.hook-tag {
  width: 100%;
  background: var(--fabric);
  border: 1px dashed var(--secondary);
  border-radius: 4px;
  text-align: center;
  padding: 7px 4px;
  font-family: 'Comic Sans MS', 'Bradley Hand', cursive;
  font-size: 12px;
  color: var(--primary);
  line-height: 1.2;
  position: relative;
  margin-top: 4px;
  cursor: pointer;
  min-height: 44px;
  word-break: break-word;
}
.hook-tag .thread { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; }

.empty-hanger { margin-top: 6px; opacity: .4; }
.empty-hanger p { font-size: 11px; font-style: italic; margin: 3px 0 0; }

/* ---------- Outfits list ---------- */
.list-wrap { display: flex; flex-direction: column; gap: 12px; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--fabric);
  border: 1px solid var(--secondary);
  border-radius: 20px;
  padding: 8px 14px;
  margin-bottom: 4px;
}
.search input {
  border: none; background: none; outline: none;
  font-family: Georgia, serif; font-size: 15px;
  color: var(--ink); width: 100%;
}
.search input::placeholder { color: var(--muted); font-style: italic; }

.swipe-wrap { position: relative; overflow: hidden; border-radius: 6px; }
.swipe-bg {
  position: absolute; inset: 0;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 16px;
  font-size: 13px;
  letter-spacing: .5px;
}
.swipe-card {
  position: relative;
  background: var(--fabric);
  transform: translateX(0);
  transition: transform .15s ease;
  touch-action: pan-y;
  cursor: pointer;
}

/* ---------- Create / form ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(30,42,79,.55);
  display: flex;
  align-items: flex-end;
  z-index: 40;
  padding-bottom: var(--safe-bottom);
}
.overlay.hidden { display: none; }
.overlay-card {
  width: 100%;
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideup .25s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
.overlay-card h2 { font-family: Georgia, serif; color: var(--primary); margin: 0 0 14px; font-size: 20px; }

.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input[type="text"], .field input[type="date"] {
  width: 100%;
  font-family: Georgia, serif;
  font-size: 16px;
  padding: 12px 12px;
  border: 1px solid var(--secondary);
  border-radius: 8px;
  background: var(--fabric);
  color: var(--ink);
  outline: none;
}
.field input:focus { border-color: var(--primary); }
.error { display: block; color: var(--accent); font-size: 12px; margin-top: 4px; min-height: 0; }

.picker { border: none; padding: 0; margin: 0 0 14px; }
.picker .options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.opt {
  border: 1px solid var(--secondary);
  background: var(--fabric);
  color: var(--primary);
  border-radius: 20px;
  padding: 8px 14px;
  font-family: Georgia, serif;
  font-size: 14px;
  text-transform: capitalize;
}
.opt.selected { background: var(--primary); color: #fbf3e4; border-color: var(--primary); }
.opt .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.fabric-btn {
  flex: 1;
  position: relative;
  font-family: Georgia, serif;
  font-size: 16px;
  border-radius: 22px;
  padding: 13px;
  border: 1px solid var(--secondary);
  background: var(--fabric);
  color: var(--primary);
  box-shadow: 0 2px 5px rgba(0,0,0,.12);
}
.fabric-btn.hang {
  background: var(--primary);
  color: #fbf3e4;
  border-color: var(--primary);
}
.fabric-btn .loop {
  display: inline-block;
  width: 12px; height: 16px;
  border: 2px solid currentColor;
  border-radius: 8px;
  margin-right: 8px;
  vertical-align: middle;
  opacity: .8;
}
.fabric-btn:active { transform: translateY(1px); }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding-bottom: var(--safe-bottom);
  background: linear-gradient(#c99a6a, #8f6238);
  box-shadow: 0 -3px 8px rgba(0,0,0,.3);
  z-index: 30;
}
.dresser {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  padding: 0 4px 14px;
  border-top: 3px solid #6f4a27;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,.05) 0 1px, transparent 1px 60px);
}
.knob {
  position: relative;
  border: none;
  background: transparent;
  padding: 0;
  width: 68px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: Georgia, serif;
  color: var(--primary);
}
.knob-top {
  width: 34px; height: 12px;
  border-radius: 8px 8px 2px 2px;
  background: linear-gradient(#b98a5e, #7c552c);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.35), inset 0 -2px 2px rgba(0,0,0,.35);
}
.knob-face {
  width: 58px;
  border-radius: 8px 8px 14px 14px;
  background: linear-gradient(#c99a6a, #8f6238);
  color: #5b3a1a;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: .3px;
  padding: 12px 2px 14px;
  text-transform: uppercase;
  box-shadow: inset 0 2px 2px rgba(255,255,255,.3), inset 0 -4px 6px rgba(0,0,0,.25);
  margin-top: -2px;
}
.knob.active .knob-top {
  transform: translateY(-3px);
  background: linear-gradient(#d9ab7c, #9c6c38);
}
.knob.active .knob-face {
  transform: translateY(-6px);
  background: linear-gradient(#e2b98a, #a97840);
  color: #3a2410;
  box-shadow: inset 0 2px 2px rgba(255,255,255,.45), inset 0 -4px 6px rgba(0,0,0,.2), 0 6px 12px rgba(0,0,0,.35);
}
.knob.active .twill {
  display: block;
  position: absolute;
  top: 34px;
  width: 6px; height: 24px;
  background: repeating-linear-gradient(45deg, #f0e0c4 0 2px, #cbb69a 2px 4px);
  border-radius: 3px;
  box-shadow: 0 3px 5px rgba(0,0,0,.3);
  transform: translateY(-8px);
  animation: hangIn .3s ease;
}
@keyframes hangIn { from { transform: translateY(-18px); opacity: 0; } to { transform: translateY(-8px); opacity: 1; } }
.knob .twill { display: none; }