/* Closet: a warm, editorial "rail" look. Paper, ink, one rust accent; photos do the talking. */
:root {
  --paper: #f3eee5;
  --card: #fbf8f2;
  --ink: #221d17;
  --muted: #6f665b;
  --line: #ddd3c4;
  --accent: #9b3b22;
  --accent-ink: #fff7f0;
  --warn-bg: #f1dfc6;
  --danger: #a3271b;
  --shadow: 0 1px 0 rgba(34, 29, 23, .06), 0 6px 18px -10px rgba(34, 29, 23, .25);
  --serif: "Newsreader", Georgia, serif;
  --sans: "Public Sans", system-ui, sans-serif;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1b1814; --card: #24201b; --ink: #efe8dc; --muted: #a59a8b; --line: #3a342c;
    --accent: #d9734f; --accent-ink: #1b1814; --warn-bg: #3b2f20; --danger: #e0715f;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 8px 20px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-bottom: calc(var(--tabs-h) + 24px); scroll-padding-top: 12px; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.45 var(--sans);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
}
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0 0 .4em; }
h1 { font-size: 2rem; line-height: 1.1; }
h2 { font-size: 1.35rem; }
a { color: inherit; }
img { display: block; max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.kicker { text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 600; color: var(--accent); margin: 0 0 .5rem; }
.lede { color: var(--muted); max-width: 34rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.error { color: var(--danger); }
code { background: var(--card); padding: .1em .35em; border-radius: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 44px; padding: 0 1.1rem; border-radius: 999px; border: 1px solid var(--ink);
  background: transparent; color: var(--ink); font: 600 .95rem var(--sans); text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.ghost { border-color: var(--line); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .chip:focus-visible, .tile:focus-visible, .opt input:focus-visible + span, .sw input:focus-visible + span {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: .85rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }

/* Login */
.login { min-height: 100svh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(100%, 380px); }
.login h1 { font-size: 3.2rem; margin-bottom: .2em; }
.login form { display: grid; gap: .6rem; margin-top: 1.6rem; }
.login label { font-weight: 600; font-size: .9rem; }
input[type=password], input[type=text], input[type=date], .field input, select {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  min-height: 44px; padding: 0 .8rem; width: 100%;
}
.form-error { color: var(--danger); font-size: .9rem; margin: 0; }

/* Frame */
.top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px; max-width: 1100px; margin: 0 auto;
}
.brand { font: 600 1.45rem var(--serif); text-decoration: none; }
.date { color: var(--muted); font-size: .85rem; }
main#view { max-width: 1100px; margin: 0 auto; padding: 6px 16px 0; outline: none; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; display: grid; place-items: center; align-content: center; gap: 2px;
  font-size: .72rem; font-weight: 600; text-decoration: none; color: var(--muted);
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current] { color: var(--ink); }
.tabs a[aria-current]::before { content: ""; position: absolute; top: 0; width: 28px; height: 2px; background: var(--accent); }
.badge {
  position: absolute; top: 8px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: .68rem; line-height: 18px; text-align: center;
}
@media (min-width: 900px) {
  body { padding-bottom: 32px; }
  .tabs { position: sticky; top: 0; inset: auto; height: auto; max-width: 1100px; margin: 0 auto 8px; padding: 0 16px;
          display: flex; gap: 1.6rem; border: 0; border-bottom: 1px solid var(--line); background: var(--paper); }
  .tabs a { display: flex; gap: .45rem; padding: .7rem 0; font-size: .9rem; }
  .tabs svg { width: 18px; height: 18px; }
  .tabs a[aria-current]::before { top: auto; bottom: -1px; width: 100%; }
  .badge { position: static; }
}

/* Today */
.wx { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .2rem 1rem; margin: .2rem 0 1rem; }
.wx-temp { font: 600 3.6rem/1 var(--serif); grid-row: span 2; letter-spacing: -.03em; }
.wx-text { color: var(--muted); font-size: .95rem; }
.wx-set select { width: auto; min-height: 36px; font-size: .9rem; }
.occasion { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin-bottom: 1.2rem; background: var(--card); }
.occasion button { border: 0; background: none; font: 600 .9rem var(--sans); color: var(--muted); padding: .5rem 1rem; border-radius: 999px; min-height: 38px; cursor: pointer; }
.occasion button[aria-checked="true"] { background: var(--ink); color: var(--paper); }
.outfits { display: grid; gap: 1rem; }
@media (min-width: 900px) { .outfits { grid-template-columns: repeat(3, 1fr); } }
.outfit { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 14px; transition: opacity .25s, transform .25s; }
.outfit header { display: flex; gap: .7rem; align-items: baseline; margin-bottom: .7rem; }
.outfit header p { margin: 0; color: var(--muted); font-size: .9rem; }
.num { font: italic 600 1.1rem var(--serif); color: var(--accent); }
.lay { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.lay figure { margin: 0; }
.lay img, .lay .noimg { aspect-ratio: 3 / 4; width: 100%; object-fit: cover; border-radius: 10px; background: var(--paper); }
.lay figcaption { font-size: .75rem; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.outfit footer { display: flex; gap: .5rem; margin-top: .9rem; }
.outfit.chosen { outline: 2px solid var(--accent); }
.outfit.chosen .wear::after { content: " ✓"; }
.outfit.gone { opacity: 0; transform: translateX(16px); }
.today-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.2rem; }

/* Closet */
.banner { display: block; background: var(--card); border-radius: 12px; padding: .8rem 1rem; margin-bottom: 1rem; text-decoration: none; }
.banner.warn { background: var(--warn-bg); }
.banner label { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; font-size: .9rem; }
.banner input[type=date] { width: auto; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .4rem; margin: 0 -16px 1rem; padding-inline: 16px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: .45rem .9rem; font: 500 .88rem var(--sans); min-height: 38px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip small { opacity: .65; }
.grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
.tile { display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; color: inherit; font: inherit; }
.tile img, .tile .noimg { aspect-ratio: 3 / 4; width: 100%; object-fit: cover; border-radius: 12px; background: var(--card); }
.noimg { display: grid; place-items: center; color: var(--muted); font-size: .8rem; }
.tile-meta { display: flex; justify-content: space-between; gap: .4rem; font-size: .82rem; margin-top: 5px; }
.tile-meta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta small { color: var(--muted); flex: none; }
.tile.untagged img { opacity: .75; }
.tile[aria-pressed="true"] img { outline: 3px solid var(--accent); outline-offset: -3px; }
.sticky-bar { position: sticky; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 10px); display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.sticky-bar .btn { box-shadow: var(--shadow); background: var(--card); }
.sticky-bar .btn.primary { background: var(--ink); }

/* Empty states */
.empty { background: var(--card); border-radius: 16px; padding: 1.6rem 1.2rem; text-align: left; }
.empty p { color: var(--muted); margin: 0 0 1rem; }

/* Tag form (queue + sheet) */
.tag-layout { display: grid; gap: 1rem; }
@media (min-width: 760px) { .tag-photo img { max-height: 70svh; } .tag-layout { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; } .tag-photo { position: sticky; top: 60px; } }
.tag-photo img, .sheet-photo img { width: 100%; max-height: 40svh; object-fit: contain; border-radius: 14px; background: var(--card); }
.tagform { display: grid; gap: 1rem; }
.pick { border: 0; padding: 0; margin: 0; }
.pick legend { font-weight: 600; font-size: .9rem; margin-bottom: .45rem; padding: 0; }
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 6px; }
.opt input, .sw input { position: absolute; opacity: 0; pointer-events: none; }
.opt span { display: block; height: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-weight: 600; font-size: .88rem; cursor: pointer; }
.opt small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; line-height: 1.25; margin-top: 2px; }
.opt input:checked + span { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.opt input:checked + span small { color: inherit; opacity: .75; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px 4px; }
.sw { display: grid; justify-items: center; gap: 2px; cursor: pointer; }
.sw span { width: 34px; height: 34px; border-radius: 50%; background: var(--c); border: 1px solid rgba(0, 0, 0, .18); }
.sw span.pat { background: repeating-linear-gradient(45deg, #2d4a6b 0 5px, #e9e2d3 5px 10px); }
.sw small { font-size: .68rem; color: var(--muted); }
.sw input:checked + span { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
.sw input:checked ~ small { color: var(--ink); font-weight: 600; }
.field { display: grid; gap: .35rem; font-weight: 600; font-size: .9rem; }
.check { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }

/* Item sheet */
.sheet { width: min(100% - 16px, 560px); max-height: 92svh; border: 0; border-radius: 18px; padding: 0; background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px -20px rgba(0, 0, 0, .5); }
.sheet::backdrop { background: rgba(20, 16, 12, .45); }
.sheet-body { position: relative; padding: 16px; display: grid; gap: .8rem; }
.close { position: absolute; top: 10px; right: 10px; z-index: 1; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--card); font-size: 1.5rem; cursor: pointer; color: var(--ink); box-shadow: var(--shadow); }
.sheet-actions { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }

/* Add */
.drop { position: relative; display: grid; place-items: center; gap: .2rem; padding: 2.4rem 1rem; border: 1.5px dashed var(--muted); border-radius: 16px; background: var(--card); cursor: pointer; text-align: center; margin-top: 1rem; }
.drop.over { border-color: var(--accent); background: var(--warn-bg); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-big { font: 600 1.35rem var(--serif); }
#progress { margin-top: 1.2rem; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.fails { padding-left: 1.1rem; color: var(--danger); font-size: .88rem; }

/* History */
.hist-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.day { border-top: 1px solid var(--line); padding: .9rem 0; }
.day h2 { font-size: 1.05rem; font-family: var(--sans); }
.day-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: .4rem; }
.mini { padding: 0; border: 0; background: none; cursor: pointer; }
.mini img, .mini .noimg { width: 64px; height: 84px; object-fit: cover; border-radius: 8px; background: var(--card); }
.day-row .undo { margin-left: auto; }

/* Toast */
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); z-index: 20;
  display: flex; align-items: center; gap: .4rem; white-space: nowrap;
  background: var(--ink); color: var(--paper); padding: .7rem 1rem; border-radius: 12px; font-size: .92rem; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
#toast[hidden] { display: none; }
#toast button { background: none; border: 0; color: var(--accent); font: 600 .92rem var(--sans); margin-left: .6rem; cursor: pointer; }
@media (prefers-color-scheme: dark) { #toast button { color: var(--paper); text-decoration: underline; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
