:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --sunken: #ece7df;
  --ink: #1f2421;
  --muted: #6b6a66;
  --line: #ddd6cb;
  --accent: #9c4f2c;
  --accent-ink: #ffffff;
  --warn: #b7791f;
  --danger: #b3261e;
  --ok: #2f7d4f;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171716;
    --surface: #222220;
    --sunken: #2c2b28;
    --ink: #eeebe5;
    --muted: #a19d95;
    --line: #3a3833;
    --accent: #d9875c;
    --accent-ink: #1b120c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 1.15rem; margin: 0; letter-spacing: .02em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: var(--bg); text-decoration: none; font-weight: 600; font-size: .9rem;
}
.signed-out .tabbar, .signed-out .health { display: none; }
.health { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.health.ok { background: var(--ok); }
.health.bad { background: var(--danger); }

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

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); text-decoration: none; font-size: .75rem;
}
.tabbar a.active { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }

/* chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: .9rem; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .count { opacity: .6; margin-left: 4px; }

/* closet grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.card {
  position: relative; display: block; background: var(--surface); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; color: inherit; border: 1px solid var(--line);
}
.card .img { aspect-ratio: 1; background: var(--sunken); display: grid; place-items: center; }
.card img { width: 100%; height: 100%; object-fit: contain; }
.card .meta { padding: 8px 10px 10px; font-size: .85rem; }
.card .meta .sub { color: var(--muted); font-size: .78rem; }
.swatches { display: flex; gap: 3px; margin-top: 4px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgb(0 0 0 / .15); }
.badge {
  position: absolute; top: 8px; right: 8px; font-size: .7rem; padding: 3px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
}
.badge.review { background: var(--warn); color: #fff; border-color: transparent; }
.badge.error { background: var(--danger); color: #fff; border-color: transparent; }
.badge.care { right: auto; left: 8px; background: var(--accent); color: var(--accent-ink); border-color: transparent; }

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

/* outfits */
.outfits { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.outfit { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.outfit-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tile { position: relative; display: block; aspect-ratio: 1; background: var(--sunken); border-radius: 10px; overflow: hidden; }
.tile img { width: 100%; height: 100%; object-fit: contain; }
.tile span {
  position: absolute; left: 6px; bottom: 6px; font-size: .68rem; padding: 1px 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--muted);
}
.outfit-meta { font-size: .85rem; color: var(--muted); min-width: 0; }
.outfit-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.votes { display: flex; gap: 6px; flex: none; }
.votes svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.votes [aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.outfit.dismissed { opacity: .45; }
.reason { margin: 10px 2px 0; font-size: .92rem; }
.why { margin-top: 6px; font-size: .78rem; color: var(--muted); }
.why summary { cursor: pointer; }
h2.section { font-size: 1rem; margin: 18px 0 10px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
h2.section .hint { font-weight: 400; }
select.occasion { width: auto; min-width: 180px; margin-bottom: 4px; }
.empty b { color: var(--ink); }

/* gaps */
.recs { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.rec { display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.swatch.big { width: 36px; height: 36px; flex: none; border-radius: 10px; }
.rec-body { flex: 1; min-width: 0; display: grid; gap: 4px; }
.rec-head { display: flex; justify-content: space-between; gap: 8px; }
.rec-num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.bar { height: 6px; background: var(--sunken); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.rescues { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.mini { display: inline-block; width: 36px; height: 36px; border-radius: 8px; background: var(--sunken); overflow: hidden; flex: none; }
.mini img { width: 100%; height: 100%; object-fit: contain; }
.orphans { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.orphan { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; font-size: .9rem; }
.orphan .mini { width: 56px; height: 56px; }
.capsule { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.capsule li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); min-height: 52px; }
.capsule li:first-child { border-top: 0; }
.capsule .check { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; font-size: .8rem; flex: none; }
.capsule .owned .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.capsule .cap-name { flex: 1; }
.capsule li:not(.owned) .cap-name { color: var(--muted); }
.cap-items { display: flex; gap: 4px; }
.capsule .hidden-piece .cap-name { text-decoration: line-through; opacity: .7; }
.capsule .hidden-piece .check { border-style: dashed; }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-size: .85rem; padding: 6px 4px; cursor: pointer; flex: none; }
.link-btn.danger { color: var(--danger); }

/* account */
form.login { display: grid; gap: 14px; max-width: 380px; margin: 10vh auto 0; }
form.login h2 { margin: 0 0 4px; }
.users li { flex-wrap: wrap; }
.inline-form { display: flex; gap: 8px; flex: 1 1 100%; }
.inline-form input { flex: 1; min-width: 0; }
.inline-form .btn { padding: 8px 14px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
code { font-size: .85em; background: var(--sunken); padding: 1px 5px; border-radius: 5px; }

/* add */
.add-actions { display: grid; gap: 12px; margin: 8px 0 20px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { padding: 22px; font-size: 1.1rem; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
.btn input[type=file] { display: none; }
.uploads { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.uploads li {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px;
}
.uploads img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; }
.uploads .name { flex: 1; min-width: 0; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads progress { width: 80px; }
.hint { color: var(--muted); font-size: .85rem; }

/* detail */
.detail-img {
  background: var(--sunken); border-radius: var(--radius); aspect-ratio: 1; max-height: 50vh; width: 100%;
  display: grid; place-items: center; overflow: hidden; margin-bottom: 12px;
}
.detail-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.back { display: inline-block; color: var(--muted); text-decoration: none; margin: 4px 0 10px; }
.notice { border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: .9rem; }
.notice.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.notice.info { background: var(--sunken); }

form.tags { display: grid; gap: 14px; }
.field label, .field .label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
select, textarea, input[type=text], input[type=password] {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
textarea { resize: vertical; min-height: 44px; }
.segmented { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button { border: 0; border-right: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 10px 0; font: inherit; cursor: pointer; }
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.formality-label { font-size: .8rem; color: var(--muted); margin-top: 4px; }

.color-list { display: grid; gap: 8px; }
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row .swatch { width: 28px; height: 28px; flex: none; }
.color-row select { flex: 1; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px; width: 40px; height: 40px; font-size: 1rem; cursor: pointer; flex: none; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 8px; }
.actions .primary { flex: 1 1 100%; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 10;
}
.danger-text { color: var(--danger); }

/* wear & care */
.care { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px 12px; margin-bottom: 18px; }
.care h2.section { margin: 12px 0 0; }
.care-status { margin: 0; font-size: .9rem; }
.care-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .9rem; }
.care-line input { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.care-line input[type=number] { width: 4.5em; }
.history summary { cursor: pointer; font-size: .9rem; }
.history ul { list-style: none; padding: 0; margin: 8px 0 0; max-height: 240px; overflow-y: auto; }
.history li { display: flex; align-items: center; gap: 10px; padding: 2px 0; font-size: .9rem; }
.history li span:first-child { flex: 1; }
