:root {
  --bg: #f7f3ee;
  --card: #ffffff;
  --ink: #2b2623;
  --muted: #7b716a;
  --line: #e7dfd6;
  --accent: #8a5a44;
  --accent-ink: #ffffff;
  --drop: #e9d9cc;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Naskh Arabic", sans-serif;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

h1, h2 { margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin-bottom: 12px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

img { -webkit-user-drag: none; user-select: none; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; max-width: 1100px; margin: 0 auto;
}
.topbar h1 { font-size: 1.25rem; }

.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 6px 14px; font: inherit; cursor: pointer;
}

/* ---------- Layout ---------- */
.layout {
  max-width: 1100px; margin: 0 auto; padding: 0 16px 40px;
  display: grid; gap: 20px;
  grid-template-columns: 1fr 400px;
  grid-template-areas:
    "wardrobe stage"
    "wardrobe outfit";
  grid-template-rows: auto 1fr;
  align-items: start;
}
.stage-card { grid-area: stage; }
.wardrobe   { grid-area: wardrobe; }
.outfit     { grid-area: outfit; }

.stage-card, .wardrobe, .outfit {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}

/* ---------- Stage ---------- */
.model-switch { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.model-switch button {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 999px; padding: 6px 16px; font: inherit; cursor: pointer;
}
.model-switch button[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}

.stage {
  position: relative; margin: 0 auto;
  aspect-ratio: 768 / 1376; height: min(68vh, 620px); max-width: 100%;
  background: #cfcfc9;
  border-radius: 12px; overflow: hidden;
  outline: 2px dashed transparent; outline-offset: -2px;
  transition: outline-color .15s, background-color .15s;
}
.stage.drop-active { outline-color: var(--accent); background: var(--drop); }

.stage img { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#layers img { transition: opacity .2s; }
#layers img[hidden] { display: none; }

.stage-hint {
  position: absolute; left: 8px; right: 8px; bottom: 10px; margin: 0;
  text-align: center; font-size: .8rem; color: #4a4642; pointer-events: none;
  transition: opacity .2s;
}
.stage-hint.gone { opacity: 0; }

.stage-actions { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  flex: 1; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  border-radius: 12px; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- Wardrobe ---------- */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; }
.tabs button {
  flex: none; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 999px; padding: 6px 14px; font: inherit; cursor: pointer;
}
.tabs button[aria-selected="true"] {
  background: var(--ink); color: var(--bg); border-color: var(--ink);
}

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

.tile {
  position: relative; display: block; width: 100%; text-align: start;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px; font: inherit; color: inherit; cursor: grab; user-select: none;
}
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile[aria-pressed="true"] { border-color: var(--accent); background: #f3e6dc; }
.tile .thumb {
  display: block; width: 100%; aspect-ratio: 1; object-fit: contain;
  background: #fff; border-radius: 10px;
}
.tile .name { display: block; margin-top: 8px; font-size: .88rem; font-weight: 600; }
.tile .meta { display: block; font-size: .78rem; color: var(--muted); }
.tile .badge {
  position: absolute; top: 8px; inset-inline-end: 8px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; font-size: .7rem; padding: 2px 8px;
}
.tile .badge[hidden] { display: none; }

.ghost-drag {
  position: fixed; z-index: 100; width: 96px; height: 96px; object-fit: contain;
  pointer-events: none; opacity: .9; transform: translate(-50%, -60%);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .25));
}

/* ---------- Outfit summary ---------- */
.outfit-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.outfit-list .empty { color: var(--muted); font-size: .9rem; }
.outfit-item { display: flex; align-items: center; gap: 10px; }
.outfit-item img { width: 48px; height: 48px; object-fit: contain; background: #fff; border-radius: 8px; border: 1px solid var(--line); }
.outfit-item .info { flex: 1; min-width: 0; }
.outfit-item .info strong { display: block; font-size: .9rem; }
.outfit-item .info span { font-size: .78rem; color: var(--muted); }
.outfit-item a, .outfit-item button {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 10px; padding: 6px 10px; font: inherit; font-size: .8rem;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.outfit-item a.buy { background: #25a05a; border-color: #25a05a; color: #fff; }
.total { margin: 14px 0 0; font-weight: 650; text-align: end; }

/* ---------- Footer ---------- */
.foot { max-width: 1100px; margin: 0 auto; padding: 0 16px 28px; text-align: center; font-size: .85rem; }
.foot a { color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: .88rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Mobile: stage stays visible while you browse ---------- */
@media (max-width: 820px) {
  .layout { display: flex; flex-direction: column; align-items: stretch; gap: 14px; padding: 0 12px 40px; }
  .stage-card {
    position: sticky; top: 0; z-index: 10; padding: 10px;
    box-shadow: 0 6px 18px rgba(60, 40, 30, .08);
  }
  .model-switch { margin-bottom: 8px; }
  .stage { height: 42vh; }
  .stage-actions { margin-top: 8px; }
  .btn { padding: 8px 12px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
}
