:root {
  --bg: #F5F1EA;
  --card: #FFFFFF;
  --ink: #1E1C19;
  --muted: #6F6A62;
  --line: #E4DED4;
  --soft: #EDE7DD;
  --accent: #33402F;
  --accent-ink: #FFFFFF;
  --accent-soft: #E1E6DA;
  --danger: #A3402F;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(30, 28, 25, .05), 0 4px 16px rgba(30, 28, 25, .05);
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412; --card: #1F1D1A; --ink: #F1ECE3; --muted: #A39D92; --line: #2E2B27; --soft: #282521;
    --accent: #BFCCAE; --accent-ink: #151412; --accent-soft: #2B3227; --danger: #E08670;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--sans); }
body { min-height: 100dvh; padding-bottom: calc(76px + var(--safe-b)); }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 18px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.topbar h1 { font: 600 24px/1.1 var(--serif); margin: 0; letter-spacing: -.01em; }
.icon-btn { background: none; border: 0; padding: 8px; margin: -8px; color: var(--ink); border-radius: 50%; cursor: pointer; }
.icon-btn:active { background: var(--soft); }

main { padding: 4px 16px 24px; max-width: 640px; margin: 0 auto; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + var(--safe-b));
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500; }
.tabbar svg { width: 23px; height: 23px; }
.tabbar a.active { color: var(--ink); }
.tabbar a.active svg { stroke-width: 2.2; }

/* generic */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
h2 { font: 600 20px/1.2 var(--serif); margin: 6px 0 12px; }
h3 { font: 600 16px/1.25 var(--sans); margin: 0 0 6px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.banner { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 11px 16px; border-radius: 999px; font-weight: 600; cursor: pointer;
  min-height: 44px; text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 4px; margin: 0 -16px 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips.static { overflow: visible; flex-wrap: wrap; margin: 0; padding: 0; }

/* weather */
.weather { display: flex; align-items: center; gap: 10px; }
.weather .ico { font-size: 28px; }
.weather .temp { font: 600 22px/1 var(--serif); }

/* outfit */
.piece { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.piece:first-child { border-top: 0; }
.piece .meta { flex: 1; min-width: 0; }
.piece .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.piece .cat { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.thumb {
  width: 56px; height: 56px; border-radius: 12px; flex: 0 0 auto; overflow: hidden; background: var(--soft);
  display: grid; place-items: center; position: relative; border: 1px solid var(--line);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .glyph { font-size: 22px; filter: saturate(0) contrast(.8); opacity: .8; }
.swatch-thumb { width: 100%; height: 100%; display: grid; place-items: center; }
.reason { font: 500 16px/1.4 var(--serif); margin: 4px 0 12px; }
.swap { border: 1px solid var(--line); background: var(--card); width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--ink); }
.swap:active { background: var(--soft); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.12); vertical-align: -1px; }

.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 12px; }

/* closet grid */
.search { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; position: relative; text-align: left; padding: 0; }
.tile .img { aspect-ratio: 1; background: var(--soft); display: grid; place-items: center; overflow: hidden; }
.tile .img img { width: 100%; height: 100%; object-fit: cover; }
.tile .label { padding: 6px 8px 8px; font-size: 12px; font-weight: 500; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile.laundry { opacity: .55; }
.badge { position: absolute; top: 6px; left: 6px; background: var(--card); border-radius: 999px; font-size: 10px; padding: 2px 7px; font-weight: 600; border: 1px solid var(--line); }
.fab {
  position: fixed; right: 18px; bottom: calc(86px + var(--safe-b)); z-index: 15; width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: 0; font-size: 30px; line-height: 1; box-shadow: 0 6px 20px rgba(0,0,0,.2); cursor: pointer;
}
.empty { text-align: center; padding: 36px 16px; }
.empty .big { font: 600 20px/1.3 var(--serif); margin-bottom: 6px; }

/* week */
.day { padding: 14px 16px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.day-head .d { font: 600 18px/1.2 var(--serif); }
.events { margin: 6px 0 2px; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.events li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 10px; }
.slot-head { display: flex; align-items: center; gap: 8px; }
.slot-head select { flex: 1; }
.strip { display: flex; gap: 8px; overflow-x: auto; margin: 10px 0 6px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.strip .thumb { width: 64px; height: 64px; cursor: pointer; }
.strip .thumb .cap { position: absolute; bottom: 0; left: 0; right: 0; font-size: 9px; background: rgba(0,0,0,.45); color: #fff; text-align: center; padding: 1px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.why { font-size: 12px; color: var(--muted); }

/* forms */
label.f { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 16px;
}
textarea.input { min-height: 70px; resize: vertical; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
select.compact { padding: 7px 30px 7px 10px; font-size: 14px; border-radius: 10px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 10px 4px; font-size: 13px; font-weight: 500; cursor: pointer; border-left: 1px solid var(--line); }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--ink); color: var(--bg); }
.colour-row { display: flex; gap: 10px; align-items: center; }
.colour-row input[type=color] { width: 52px; height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 3px; background: var(--card); flex: 0 0 auto; }
.detected { display: flex; gap: 14px; align-items: center; padding: 12px; border-radius: 14px; background: var(--soft); }
.detected .big-swatch { width: 54px; height: 54px; border-radius: 12px; border: 1px solid rgba(0,0,0,.1); flex: 0 0 auto; }
.detected .t { font: 600 18px/1.2 var(--serif); }
.preview { width: 100%; max-height: 300px; object-fit: contain; border-radius: 14px; background: var(--soft); }

/* sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 6px 18px calc(20px + var(--safe-b)); animation: up .25s cubic-bezier(.2,.8,.2,1);
  max-width: 640px; margin: 0 auto;
}
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 12px; }
.sheet-actions { position: sticky; bottom: calc(-20px - var(--safe-b)); background: var(--bg); padding: 12px 0 calc(8px + var(--safe-b)); margin-top: 14px; display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.option { display: flex; gap: 14px; align-items: center; width: 100%; text-align: left; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); margin-bottom: 10px; cursor: pointer; }
.option .o-ico { font-size: 24px; width: 40px; height: 40px; display: grid; place-items: center; background: var(--soft); border-radius: 12px; }
.option b { display: block; }

.check { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: 0 0 auto; }

details.acc { border: 1px solid var(--line); border-radius: 14px; background: var(--card); margin-bottom: 10px; }
details.acc summary { list-style: none; padding: 14px; font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; }
details.acc summary::-webkit-details-marker { display: none; }
details.acc summary::after { content: "+"; color: var(--muted); font-weight: 400; font-size: 20px; line-height: 1; }
details.acc[open] summary::after { content: "–"; }
details.acc .acc-body { padding: 0 14px 14px; }

.stars { display: inline-flex; gap: 2px; }
.stars button { background: none; border: 0; font-size: 20px; padding: 2px; cursor: pointer; color: var(--line); }
.stars button.on { color: #C8962E; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 500;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100% - 32px); text-align: center;
}

.spinner { width: 20px; height: 20px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 30px; color: var(--muted); }

.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login .logo { width: 72px; height: 72px; margin: 0 auto 16px; }
