:root {
  --bg: #fdf3f7;
  --surface: #ffffff;
  --surface-2: #fbe7f0;
  --border: #f4d6e3;
  --text: #3a2530;
  --muted: #9d7a89;
  --accent: #d24e8b;
  --accent-soft: #fbdcea;
  --danger: #c8455e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(58, 37, 48, .05), 0 8px 24px rgba(210, 78, 139, .10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1319;
    --surface: #271a22;
    --surface-2: #33232d;
    --border: #422e3a;
    --text: #f5e6ee;
    --muted: #bf95a8;
    --accent: #f183b3;
    --accent-soft: #3a2430;
    --danger: #e87a8e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

/* Explicit theme overrides (used when a viewer toggles light/dark on the shared page) */
:root[data-theme="light"] {
  --bg: #fdf3f7;
  --surface: #ffffff;
  --surface-2: #fbe7f0;
  --border: #f4d6e3;
  --text: #3a2530;
  --muted: #9d7a89;
  --accent: #d24e8b;
  --accent-soft: #fbdcea;
  --danger: #c8455e;
  --shadow: 0 1px 2px rgba(58, 37, 48, .05), 0 8px 24px rgba(210, 78, 139, .10);
}
:root[data-theme="dark"] {
  --bg: #1c1319;
  --surface: #271a22;
  --surface-2: #33232d;
  --border: #422e3a;
  --text: #f5e6ee;
  --muted: #bf95a8;
  --accent: #f183b3;
  --accent-soft: #3a2430;
  --danger: #e87a8e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- layout ---------- */

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.top-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-right: auto;
}
.brand-icon { height: 30px; width: auto; display: block; }
.brand-word { height: 21px; width: auto; display: block; }
/* the logo is dark plum; lift it so it stays legible on the dark theme */
:root[data-theme="dark"] .brand-icon,
:root[data-theme="dark"] .brand-word { filter: brightness(1.9) saturate(1.05); }
@media (prefers-color-scheme: dark) {
  .brand-icon, .brand-word { filter: brightness(1.9) saturate(1.05); }
}
:root[data-theme="light"] .brand-icon,
:root[data-theme="light"] .brand-word { filter: none; }

/* ---------- splash ---------- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: #fdf3f7;          /* always the brand blush, independent of theme */
  transition: opacity .5s ease;
}
.splash.hide { opacity: 0; }
.splash-logo {
  width: min(240px, 55vw);
  height: auto;
  animation: splash-pop .6s ease both;
}
@keyframes splash-pop {
  from { opacity: 0; transform: scale(.92); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .splash { transition: none; }
  .splash-logo { animation: none; }
}

nav.tabs { display: flex; gap: 2px; }

nav.tabs button {
  background: none;
  border: 0;
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
}
nav.tabs button:hover { color: var(--text); }
nav.tabs button[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 120px;
}

.panel[hidden] { display: none; }

/* ---------- controls ---------- */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 15px;
  font-weight: 500;
  transition: border-color .12s, background .12s;
}
.btn:hover { border-color: var(--accent); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { filter: brightness(1.07); }

.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }

.btn.danger { color: var(--danger); border-color: transparent; background: none; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

input[type="text"], input[type="date"], input[type="search"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 18px;
}
.section-head h2 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.section-head .count { color: var(--muted); font-size: 14px; margin-right: auto; }

/* ---------- filters ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
}
.filters input[type="search"] { flex: 1 1 200px; width: auto; }
.filters select { width: auto; flex: 0 0 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--muted);
}
.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  padding: 0;
  transition: transform .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.card-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  background: rgba(20, 17, 14, .5);
  color: #fff;
  border-radius: 50%;
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  transition: opacity .12s, background .12s;
}
.card:hover .card-del,
.card:focus-within .card-del { opacity: 1; }
.card-del:hover { background: var(--danger); }
@media (hover: none) { .card-del { opacity: 1; } }

.card .thumb {
  aspect-ratio: 3 / 4;
  width: 100%;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}
.card .thumb.placeholder {
  display: grid;
  place-items: center;
  font-size: 30px;
}

.card .meta { padding: 10px 12px 12px; }
.card .meta .name {
  font-weight: 500;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card .meta .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.selectable { position: relative; }
.selectable[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }
.selectable[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  top: 8px; right: 8px;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: 13px;
}

.empty {
  text-align: center;
  padding: 64px 20px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 17px; }
.empty p { margin: 0 0 18px; }

/* ---------- modal ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(20, 17, 14, .45); backdrop-filter: blur(2px); }

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 17px; margin-right: auto; }

.modal-body { padding: 20px; overflow-y: auto; }

.modal-foot {
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.modal-foot .spacer { margin-right: auto; }

.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}
.row { display: flex; gap: 12px; }
.row > .field { flex: 1; }

/* photo picker */
.photo-drop {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  aspect-ratio: 3 / 4;
  max-height: 260px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--surface-2);
  color: var(--muted);
  text-align: center;
  padding: 20px;
  width: 100%;
  max-width: 200px;
}
.photo-drop img { width: 100%; height: 100%; object-fit: cover; }
.photo-drop.dragover { border-color: var(--accent); color: var(--accent); }

/* swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.swatch {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  padding: 0;
}
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- detail view ---------- */

.detail { display: flex; gap: 20px; }
.detail .detail-photo {
  flex: 0 0 180px;
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--surface-2);
}
.detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-content: start; }
.detail dt { color: var(--muted); font-size: 13px; }
.detail dd { margin: 0; font-size: 14px; }

.wear-log { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 16px; }
.wear-log h4 { margin: 0 0 10px; font-size: 14px; }
.wear-log ul { list-style: none; margin: 0; padding: 0; max-height: 140px; overflow-y: auto; }
.wear-log li {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.wear-log li span { margin-right: auto; }

/* ---------- outfit / trip rows ---------- */

.stack { display: flex; flex-direction: column; gap: 14px; }

.row-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.row-card header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.row-card header h3 { margin: 0; font-size: 16px; margin-right: auto; }
.row-card header .sub { color: var(--muted); font-size: 13px; }

.mini-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.mini {
  width: 62px;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.mini img { width: 100%; aspect-ratio: 3/4; object-fit: cover; display: block; }
.mini .ph { aspect-ratio: 3/4; display: grid; place-items: center; font-size: 20px; }

/* ---------- insights ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .n { font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 2px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 14px; }
.bar-row .lbl { flex: 0 0 130px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar { height: 8px; border-radius: 4px; background: var(--accent); min-width: 3px; }
.bar-row .val { color: var(--muted); font-size: 13px; }

/* ---------- misc ---------- */

.fab {
  position: fixed;
  right: 24px; bottom: 24px;
  z-index: 30;
  border-radius: 999px;
  padding: 13px 22px;
  box-shadow: var(--shadow);
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}
.fab:hover { filter: brightness(1.07); }

.toast {
  position: fixed;
  left: 50%; bottom: 28px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }

/* ---------- settings ---------- */

.icon-btn { font-size: 18px; padding: 7px 11px; line-height: 1; }

.settings-block { padding: 4px 0 20px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.settings-block:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.settings-block h4 { margin: 0 0 6px; font-size: 15px; }
.settings-block .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; line-height: 1.55; }
.settings-block code {
  background: var(--surface-2);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12px;
}

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.attach-btn { display: block; width: 100%; margin-top: 10px; }

.cat-manager { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 8px 8px 14px;
}
.cat-row > span:first-child { font-weight: 500; margin-right: auto; }
.cat-row .cat-used { color: var(--muted); font-size: 12px; }

.add-cat-row { display: flex; gap: 8px; }
.add-cat-row input { flex: 1; }

@media (max-width: 560px) {
  .top-inner { flex-wrap: wrap; gap: 10px; }
  .brand { flex: 1 0 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
  .detail { flex-direction: column; }
  .detail .detail-photo { flex: none; width: 140px; }
}

/* ---------- today & planner (Phase 1) ---------- */

.weather-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.weather-card .w-icon { font-size: 34px; line-height: 1; }
.weather-card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.day-card header { flex-wrap: wrap; row-gap: 8px; }
.day-card h3 .sub { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.day-weather { font-size: 13px; color: var(--muted); white-space: nowrap; }
.today-card { border-color: var(--accent); }

.warn {
  font-size: 12px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.dress-note { font-weight: 400; color: var(--muted); font-size: 13px; }
#dress-results .row-card header { flex-wrap: wrap; row-gap: 8px; }

.loc-hit, .outfit-pick-row { text-align: left; }
.outfit-pick-row .sub, .loc-hit .sub { color: var(--muted); font-size: 12px; }

/* ---------- look canvas & favourites (Phase 2) ---------- */

.heart {
  background: none;
  border: 0;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  padding: 2px 6px;
}
.heart.on, .heart:hover { color: var(--accent); }

#canvas-stage {
  position: relative;
  aspect-ratio: 3 / 4;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
  margin-bottom: 12px;
}
.piece {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.piece:active { cursor: grabbing; }
.piece img {
  width: 100%;
  display: block;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(58, 37, 48, .18);
  pointer-events: none;
}
.piece.selected { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 12px; }
.piece-ph {
  width: 100%;
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
  font-size: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.canvas-toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

#cv-selfie-thumb { display: flex; align-items: center; gap: 10px; min-height: 28px; }
#cv-selfie-thumb img {
  width: 54px;
  border-radius: 8px;
  border: 2px solid #fff;
  box-shadow: var(--shadow);
}

.mini.selfie { border: 2px solid var(--accent-soft); }

/* ---------- statuses, declutter, wishlist (Phase 3) ---------- */

.badges {
  position: absolute;
  top: 8px;
  left: 8px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1.4;
}

.gap-list { margin: 0; padding-left: 18px; }
.gap-list li { margin-bottom: 6px; font-size: 14px; color: var(--text); }

.dec-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 8px 8px 14px;
}
.dec-row .lbl { font-weight: 500; }
.dec-row .sub { color: var(--muted); font-size: 12px; margin-right: auto; }

.wish-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 8px 8px 12px;
}
.wish-row.done .wish-name { text-decoration: line-through; color: var(--muted); }
.wish-check {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  font-size: 14px;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
}
.wish-row.done .wish-check { background: var(--accent); color: #fff; }
.wish-main { display: flex; flex-direction: column; gap: 2px; margin-right: auto; }
.wish-main .sub { color: var(--muted); font-size: 12px; }

/* ---------- auth screen (Phase 4a) ---------- */

.auth-screen[hidden] { display: none; }
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 20px;
}
.auth-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 30px 26px;
  text-align: center;
}
.auth-logo { width: 150px; height: auto; margin-bottom: 14px; }
.auth-card h2 { margin: 0 0 18px; font-size: 20px; letter-spacing: -.02em; }
.auth-card form { text-align: left; }
.auth-msg { color: var(--muted); font-size: 13px; min-height: 18px; margin: 12px 0 4px; }
