:root {
  --bg: #f4efe7;
  --surface: #fffdf9;
  --surface-2: #ebe4d8;
  --ink: #2a2520;
  --muted: #7a7065;
  --line: #ddd3c4;
  --accent: #b5643a;
  --accent-ink: #fffaf3;
  --danger: #a8322d;
  --shadow: 0 1px 2px rgb(40 30 20 / .06), 0 6px 18px rgb(40 30 20 / .07);
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --surface: #25221e;
    --surface-2: #322e29;
    --ink: #efe8dd;
    --muted: #a59a8c;
    --line: #3d3832;
    --accent: #d98a5c;
    --accent-ink: #1b1916;
    --danger: #e0716a;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 18px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--sans); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .82em; font-weight: 400; }
.error { color: var(--danger); min-height: 1.2em; margin: .4rem 0 0; }

.brand { font: 600 1.45rem/1 var(--serif); letter-spacing: -.01em; margin: 0; }
.brand em { color: var(--accent); }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .55rem 1.05rem; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: .3rem .7rem; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: default; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem 1.5rem; text-align: center; }
.login-card .brand { font-size: 2.2rem; }
.login-card form { display: grid; gap: .6rem; margin-top: 1.5rem; text-align: left; }
.login-card input { padding: .75rem .9rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); letter-spacing: .12em; font-size: 1.1rem; text-align: center; text-transform: uppercase; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1rem; padding: .7rem 16px; padding-top: max(.7rem, env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: .25rem; margin: 0 auto; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.tabs button { border: 0; background: none; padding: .38rem .9rem; border-radius: 999px; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.tab-page { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 6rem; }
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; row-gap: .5rem; }
  .tabs { order: 3; width: 100%; justify-content: stretch; }
  .tabs button { flex: 1; }
  #logout { margin-left: auto; }
}

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

/* closet grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; } }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; cursor: pointer; border: 0; padding: 0; text-align: left; display: flex; flex-direction: column; }
.card img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; display: block; background: var(--surface-2); }
.card .meta { display: flex; align-items: center; gap: .45rem; padding: .5rem .65rem; font-size: .86rem; min-width: 0; }
.card .meta span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: .85rem; height: .85rem; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .18); }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty p:first-child { color: var(--ink); font: 1.2rem var(--serif); }
.fab { position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 2rem; line-height: 1; box-shadow: var(--shadow); cursor: pointer; }

/* outfit filters */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .6rem .8rem; background: var(--surface); padding: .9rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.filters label { display: grid; gap: .2rem; font-size: .8rem; color: var(--muted); }
.filters select { padding: .45rem .5rem; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font-size: .95rem; }
.filters .check { display: flex; align-items: center; gap: .4rem; font-size: .92rem; color: var(--ink); align-self: end; padding-bottom: .4rem; }
.pin-bar { display: flex; align-items: center; gap: .6rem; margin-top: .8rem; padding: .5rem .7rem; background: var(--surface-2); border-radius: 12px; }
.pin-bar img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; }
.pin-bar span { flex: 1; }
.actions { display: flex; justify-content: center; margin: 1rem 0; }

/* outfit cards */
.outfits { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.outfit { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: .7rem; display: flex; flex-direction: column; gap: .6rem; }
.outfit-foot { display: flex; align-items: center; gap: .5rem; }
.outfit-foot .dots { display: flex; gap: .2rem; }
.outfit-foot .kind { flex: 1; font-size: .85rem; color: var(--muted); }
.heart { border: 0; background: none; font-size: 1.35rem; cursor: pointer; color: var(--accent); padding: 0 .2rem; }

/* dialog */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(560px, 100vw - 16px); max-height: calc(100dvh - 16px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
dialog::backdrop { background: rgb(20 15 10 / .45); }
#item-form { padding: 1rem 1.1rem; display: grid; gap: .9rem; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { font: 600 1.3rem var(--serif); margin: 0; }
.photo-pick { display: grid; justify-items: center; gap: .6rem; }
.photo-pick img { max-width: 100%; max-height: 260px; border-radius: 12px; object-fit: contain; background: var(--surface-2); }
.photo-pick img:not([src]) { display: none; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; margin-bottom: .45rem; padding: 0; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: .45rem; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .18); position: relative; }
.swatch[aria-pressed="true"] { outline: 2.5px solid var(--ink); outline-offset: 2px; }
.swatch.suggested::after { content: ""; position: absolute; right: -3px; top: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.field { display: grid; gap: .3rem; font-weight: 600; }
.field input { font-weight: 400; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.dlg-foot { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
.dlg-foot #item-delete { margin-right: auto; }

/* photo step */
.preview-box { position: relative; width: 100%; display: grid; place-items: center; min-height: 0; }
.preview-box img { background: var(--tile); }
.busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: .6rem; background: color-mix(in srgb, var(--surface) 75%, transparent); border-radius: 12px; font-weight: 600; min-height: 120px; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.photo-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; justify-content: center; }
.check { display: flex; align-items: center; gap: .4rem; cursor: pointer; }
.photo-pick p { margin: 0; text-align: center; }

/* type picker */
.type-groups { display: grid; gap: .55rem; }
.type-group { display: grid; gap: .3rem; }
.type-group h3 { margin: 0; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.swatch.none { background: repeating-linear-gradient(45deg, var(--surface) 0 4px, var(--surface-2) 4px 8px); }

/* cut-outs sit on a soft tile so white garments still read */
:root { --tile: #ece6dc; }
@media (prefers-color-scheme: dark) { :root { --tile: #3a352f; } }
.card img, .pin-bar img { background: var(--tile); }
.card img.cut { object-fit: contain; padding: 6%; }

/* filters: "more" */
.filters .more { grid-column: 1 / -1; }
.filters summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
.more-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .6rem .8rem; margin-top: .6rem; }

/* ---------------------------------------------------------------- phones */
.photo-buttons { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
/* iOS zooms into any field under 16px */
input, select, textarea { font-size: 16px !important; }
@media (pointer: coarse) {
  .chip { padding: .55rem .95rem; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 36px; }
  .heart { min-width: 44px; min-height: 44px; }
  .swatches { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
}
@media (max-width: 560px) {
  /* the add-piece form becomes a full-screen sheet with Save always in reach */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  #item-form { min-height: 100%; padding-bottom: 0; }
  .dlg-head { position: sticky; top: 0; z-index: 2; background: var(--surface); margin: -1rem -1.1rem 0; padding: max(.8rem, env(safe-area-inset-top)) 1.1rem .6rem; border-bottom: 1px solid var(--line); }
  .dlg-foot { position: sticky; bottom: 0; background: var(--surface); margin: 0 -1.1rem; padding: .7rem 1.1rem max(.7rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
  .photo-pick img { max-height: 42dvh; }
  .outfits { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters label:first-child { grid-column: 1 / -1; }
}

/* in-app camera: covers the whole screen while open */
.camera { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.camera video { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.camera video.mirror { transform: scaleX(-1); }
.cam-tip { position: absolute; top: max(1rem, env(safe-area-inset-top)); left: 0; right: 0; margin: 0; text-align: center; color: #fff; font-size: .9rem; text-shadow: 0 1px 3px #000; }
.cam-bar { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem max(1.2rem, env(safe-area-inset-bottom)); background: #000; }
.cam-btn { color: #fff; min-width: 72px; }
.shutter { width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff; background: #fff; box-shadow: inset 0 0 0 4px #000; cursor: pointer; }
.shutter:active { transform: scale(.94); }

/* ---------------------------------------------------------------- outfit flat-lay */
.flatlay { display: grid; grid-template-columns: 1fr 1.35fr 1fr; gap: .4rem; background: var(--tile); border-radius: 12px; padding: .5rem; }
.flatlay .slot { min-width: 0; border-radius: 10px; overflow: hidden; display: grid; place-items: center; border: 0; padding: 0; background: transparent; }
.flatlay .slot img { width: 100%; height: 100%; object-fit: contain; display: block; background: transparent; }
.flatlay .slot img:not(.cut) { object-fit: cover; border-radius: 10px; }
.flatlay .area-outer { grid-area: outer; align-self: start; aspect-ratio: 3 / 5; }
.flatlay .area-top { grid-area: top; aspect-ratio: 1; }
.flatlay .area-bottom { grid-area: bottom; aspect-ratio: 1; }
.flatlay .area-dress { grid-area: dress; }
.flatlay .area-shoes { grid-area: shoes; aspect-ratio: 2 / 1; }
.flatlay .area-bag { grid-area: bag; align-self: center; aspect-ratio: 1; }
.flatlay .area-acc { grid-area: acc; aspect-ratio: 1; }
.flatlay.editable .slot { cursor: pointer; }
.flatlay .slot.empty { border: 2px dashed var(--line); color: var(--muted); align-content: center; gap: .1rem; background: color-mix(in srgb, var(--surface) 40%, transparent); }
.flatlay .slot.empty span { font-size: 1.6rem; line-height: 1; }
.flatlay .slot.empty small { font-size: .78rem; }

/* ---------------------------------------------------------------- crea */
.create-layout { display: grid; gap: 1.2rem; }
@media (min-width: 900px) {
  .create-layout { grid-template-columns: minmax(340px, 440px) 1fr; align-items: start; }
  .create-preview { position: sticky; top: 80px; }
}
.create-preview { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: .8rem; display: grid; gap: .7rem; }
.verdict p { margin: 0; }
.verdict ul { margin: .35rem 0 0; padding-left: 1.2rem; color: var(--danger); font-size: .92rem; }
.stars { color: var(--accent); letter-spacing: .05em; }
.create-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.create-actions #create-save { margin-left: auto; }
.create-pickers { display: grid; gap: 1rem; }
.picker h3 { margin: 0 0 .4rem; font: 600 1.05rem var(--serif); }
.strip { display: flex; gap: .5rem; overflow-x: auto; padding: .2rem .1rem .5rem; scroll-snap-type: x proximity; }
.pick { flex: none; width: 92px; height: 112px; border-radius: 12px; border: 2px solid transparent; background: var(--tile); padding: 0; cursor: pointer; overflow: hidden; scroll-snap-align: start; }
.pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pick img.cut { object-fit: contain; padding: 8%; }
.pick[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface) inset; }
.pick.none { width: 72px; color: var(--muted); font-size: .85rem; background: var(--surface); border: 1px dashed var(--line); }
.pick.none[aria-pressed="true"] { border: 2px solid var(--ink); color: var(--ink); }
.outfit-foot .btn.small { padding: .25rem .6rem; }
@media (max-width: 560px) {
  .tabs button { padding: .38rem .4rem; font-size: .92rem; }
  .create-actions .btn { flex: 1; justify-content: center; }
  .create-actions #create-save { flex-basis: 100%; margin-left: 0; }
}

/* palette filter swatches */
.palette-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .35rem; }
.dot.big { width: 1.4rem; height: 1.4rem; }

/* pick a color by tapping the photo */
legend { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; width: 100%; }
.pick-btn { margin-left: auto; font-weight: 400; }
.pick-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#item-preview.picking { cursor: crosshair; outline: 3px solid var(--accent); outline-offset: 3px; }
.pick-marker { position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px #000, 0 2px 6px rgb(0 0 0 / .4); pointer-events: none; }
.pick-hint { margin: 0; font-weight: 600; color: var(--accent); text-align: center; }

.filters label { min-width: 0; }
.filters select { width: 100%; min-width: 0; }
.palette-desc { flex-basis: 100%; }

/* brand */
.closet-bar { display: flex; gap: .6rem; align-items: start; }
.closet-bar .chips { flex: 1; min-width: 0; }
#brand-filter { flex: none; max-width: 42%; padding: .4rem .5rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.card .brand { padding: 0 .65rem .5rem; margin-top: -.3rem; font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
