:root {
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --ink: #1f1b17;
  --muted: #6f665c;
  --line: #e4dbcf;
  --accent: #b5532f;
  --accent-soft: #f3e1d6;
  --good: #3f7a52;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 6px 18px rgba(40, 30, 20, .06);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171411; --surface: #221e1a; --ink: #f2ebe2; --muted: #a79c90;
    --line: #3a332c; --accent: #e07a52; --accent-soft: #3d2a20; --good: #7cbf8e;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
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)); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 26px; line-height: 1.15; }
h3 { font-size: 18px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.brand { font-family: var(--serif); font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -.02em; }
.brand::after { content: "."; color: var(--accent); }
.weather-chip { font-size: 13px; color: var(--muted); background: var(--surface); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px; }

.view { padding: 4px 16px 24px; max-width: 720px; margin: 0 auto; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* Tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b)); }
.tab { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
  color: var(--muted); font-size: 11px; font-weight: 500; cursor: pointer; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--ink); }
.tab.active svg { stroke: var(--accent); }
.tab-add { order: 0; }
.tab-add svg { width: 44px; height: 44px; padding: 10px; background: var(--ink); stroke: var(--bg); border-radius: 50%; stroke-width: 2.2; }
.tabbar .tab[data-tab="wardrobe"] { order: -2; }
.tabbar .tab[data-tab="add"] { order: -1; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); padding: 10px 16px; border-radius: 999px; font-weight: 500; cursor: pointer; min-height: 42px; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: #b3261e; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }

/* Chips */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px;
  font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.static { cursor: default; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.empty { text-align: center; padding: 40px 20px; }
.empty .big { font-family: var(--serif); font-size: 22px; margin-bottom: 6px; }

/* Wardrobe grid */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.tile { position: relative; aspect-ratio: 3 / 4; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; cursor: pointer; display: flex; flex-direction: column; }
.tile img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.tile .label { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }
.tile .worn { position: absolute; top: 6px; right: 6px; font-size: 10px; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 1px 6px; font-weight: 600; }
.checker { background-color: var(--surface);
  background-image: linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0; }

/* Forms */
label.field { display: block; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 5px; }
input[type=text], input[type=number], input[type=url], input[type=password], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; min-height: 42px; }
textarea { min-height: 70px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; padding: 0; }
.pick { display: flex; flex-wrap: wrap; gap: 6px; }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick label { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; }
.pick input:checked + label { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pick input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Add flow */
.preview { position: relative; height: 52vh; max-height: 520px; margin: 0 auto; border-radius: var(--radius); border: 1px solid var(--line);
  display: grid; place-items: center; overflow: hidden; width: 100%; }
.preview img { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); object-fit: contain; }
.progress { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Item detail */
.detail-img { position: relative; height: 38vh; margin: 0 auto; width: 100%; border-radius: var(--radius); }
.detail-img img { position: absolute; inset: 12px; width: calc(100% - 24px); height: calc(100% - 24px); object-fit: contain; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats div { background: var(--bg); border-radius: 10px; padding: 8px 4px; }
.stats b { display: block; font-family: var(--serif); font-size: 20px; }
.stats span { font-size: 11px; color: var(--muted); }

/* Outfit board (collage) */
.board { position: relative; aspect-ratio: 3 / 4; border-radius: var(--radius); background: var(--bg); overflow: hidden; touch-action: none; }
.board .body { position: absolute; left: 50%; top: 2%; height: 96%; transform: translateX(-50%); opacity: .95; pointer-events: none; }
.board .piece { position: absolute; transform: translate(-50%, -50%); cursor: grab; user-select: none; -webkit-user-drag: none; filter: drop-shadow(0 4px 6px rgba(0,0,0,.15)); }
.board .piece.dragging { cursor: grabbing; filter: drop-shadow(0 10px 14px rgba(0,0,0,.25)); z-index: 50 !important; }
.outfit-card .why { font-size: 14px; }
.outfit-card .tip { font-size: 13px; background: var(--accent-soft); color: var(--ink); padding: 8px 10px; border-radius: 10px; }
.outfit-card .tip b { color: var(--accent); }
.mini-strip { display: flex; gap: 6px; overflow-x: auto; }
.mini-strip img { width: 52px; height: 64px; object-fit: contain; background: var(--bg); border-radius: 8px; padding: 4px; flex: none; }

/* Onboarding */
.hero { padding: 30px 4px 10px; }
.hero h2 { font-size: 34px; }
.steps { display: flex; gap: 6px; }
.steps i { flex: 1; height: 3px; background: var(--line); border-radius: 3px; }
.steps i.on { background: var(--accent); }

/* Sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 15, 10, .45); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 720px; max-height: 90dvh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b)); }
.sheet .grab { width: 40px; height: 4px; background: var(--line); border-radius: 4px; margin: -6px auto 12px; }

.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
.hr { height: 1px; background: var(--line); margin: 18px 0; }
.link { background: none; border: 0; color: var(--accent); padding: 0; cursor: pointer; font-weight: 500; }
