/* FitCheck — "old money" / quiet-luxury theme
   Ivory paper · racing green · antique gold · Cormorant Garamond + Jost */

:root {
  --paper:    #f2ecdd;   /* warm ivory ground */
  --paper-2:  #eae1cc;   /* card cream */
  --paper-3:  #e2d7bd;   /* inset / input */
  --ink:      #23201a;   /* warm near-black */
  --ink-soft: #6d6350;   /* muted taupe, secondary text */
  --green:    #1f3a2f;   /* racing / forest green */
  --green-deep:#152a20;
  --gold:     #a8863f;   /* antique gold */
  --gold-br:  #c9a95e;   /* brighter brass */
  --wine:     #7a2f2f;   /* oxblood, danger */
  --line:     #cdbf9c;   /* soft tan hairline */
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Jost', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  background-image:
    radial-gradient(120% 80% at 50% -10%, rgba(201,169,94,.10), transparent 60%),
    radial-gradient(120% 90% at 50% 110%, rgba(31,58,47,.08), transparent 55%);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.55;
  padding-bottom: 132px;
  -webkit-font-smoothing: antialiased;
}
/* film-grain / laid-paper texture over everything */
body::after {
  content: ''; position: fixed; inset: 0; z-index: 9998; pointer-events: none;
  opacity: .045; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
h1, h2, h3 { margin: 0; font-family: var(--serif); font-weight: 600; letter-spacing: .005em; }
a { color: var(--green); text-underline-offset: 3px; text-decoration-color: var(--gold); }
button { font: inherit; cursor: pointer; }
strong { font-weight: 600; color: var(--ink); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 26px 8px; max-width: 1240px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 14px; }
.crest {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--serif); font-weight: 600; font-size: 25px;
  color: var(--gold-br); background: var(--green);
  border: 1px solid var(--gold);
  box-shadow: inset 0 0 0 3px var(--green), inset 0 0 0 4px rgba(201,169,94,.45);
}
.wordmark h1 { font-size: 24px; color: var(--green); font-weight: 600; line-height: 1; }
.tagline {
  margin: 5px 0 0; color: var(--ink-soft);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .28em; font-weight: 400;
}
.iconbtn {
  background: var(--paper-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 3px;
  width: 40px; height: 40px; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color .2s, color .2s;
}
.iconbtn:hover { border-color: var(--gold); color: var(--green); }

/* ---------- decorative rule ---------- */
.rule-band {
  max-width: 1240px; margin: 2px auto 4px; padding: 0 30px;
  display: flex; align-items: center; gap: 16px;
}
.rule-band::before, .rule-band::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: .55;
}
.rule-motif { color: var(--gold); font-size: 11px; letter-spacing: .3em; }

/* ---------- banner ---------- */
.banner {
  max-width: 1020px; margin: 12px auto; padding: 12px 18px;
  background: #efe4cf; border: 1px solid var(--gold); border-left-width: 3px;
  color: #6a5320; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.hidden { display: none !important; }

/* ---------- layout ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 6px 26px; display: flex; gap: 26px; align-items: flex-start; }
.rail { width: 288px; flex: none; display: flex; flex-direction: column; gap: 22px; }
.board { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 22px; }
section { margin: 0; }
.sec-head { margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); position: relative; }
.sec-head::after { content: ''; position: absolute; left: 0; bottom: -1px; width: 64px; height: 1px; background: var(--gold); }
.sec-head h2 { font-size: 21px; color: var(--ink); display: flex; align-items: center; gap: 10px; letter-spacing: .01em; }
.step {
  font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 13px;
  color: var(--gold); background: var(--paper-2);
  border: 1px solid var(--line); border-radius: 50%;
  min-width: 28px; height: 28px; padding: 0 5px;
  display: inline-grid; place-items: center;
}
.hint { color: var(--ink-soft); font-family: var(--serif); font-style: italic; font-size: 13px; margin: 5px 0 0; max-width: 62ch; line-height: 1.35; }
.hint strong { font-style: normal; }

/* ---------- grids & tiles ---------- */
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
.tile {
  position: relative; padding: 0;
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 3px; aspect-ratio: 3 / 4; overflow: hidden;
  box-shadow: 0 1px 0 rgba(255,255,255,.5) inset, 0 8px 20px -14px rgba(60,45,20,.7);
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.selectable:hover { border-color: var(--gold); transform: translateY(-2px); }
.tile.selected { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 10px 22px -12px rgba(120,90,30,.6); }
.tile .check {
  position: absolute; top: 8px; left: 8px;
  background: var(--gold); color: var(--green-deep);
  border-radius: 50%; width: 22px; height: 22px; font-size: 12px;
  display: none; align-items: center; justify-content: center;
}
.tile.selected .check { display: inline-flex; }
.tile .del {
  position: absolute; top: 8px; right: 8px;
  background: rgba(21,26,20,.7); color: var(--paper);
  border: none; border-radius: 3px; min-width: 24px; height: 24px; padding: 0 7px; font-size: 12px;
  opacity: 0; transition: opacity .15s;
}
.tile:hover .del, .tile .del.armed { opacity: 1; }
.tile .del.armed { background: var(--wine); }
.tile .name {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 12px 6px 5px; font-family: var(--serif); font-style: italic; font-size: 11px; color: var(--paper);
  background: linear-gradient(transparent, rgba(21,26,20,.82));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.tile.add {
  border-style: dashed; border-color: var(--line); background: transparent;
  color: var(--ink-soft); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-family: var(--serif); font-style: italic; font-size: 10.5px; line-height: 1.15; text-align: center; padding: 4px;
}
.tile.add:hover { color: var(--green); border-color: var(--gold); }
.tile.add .plus { font-size: 22px; line-height: 1; font-style: normal; color: var(--gold); }

/* ---------- categories ---------- */
#categories { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 16px; }
.cat { margin: 0; }
.cat .grid { grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 7px; }
.cat-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px; }
.cat-head h3 { font-size: 15px; color: var(--ink); font-weight: 600; }
.cat-head .count, .cat-head .picked { font-family: var(--sans); font-size: 10.5px; text-transform: uppercase; letter-spacing: .16em; }
.cat-head .count { color: var(--ink-soft); }
.cat-head .picked { color: var(--gold); margin-left: auto; }

/* ---------- hair ---------- */
.hair-presets { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.hair-preset {
  background: var(--paper-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 2px; padding: 6px 11px;
  font-family: var(--sans); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  transition: border-color .2s, background .2s, color .2s;
}
.hair-preset:hover { border-color: var(--gold); }
.hair-preset.selected { background: var(--green); color: var(--gold-br); border-color: var(--green-deep); }
#hair-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }

/* ---------- lookbook ---------- */
.grid.looks { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
.look-tile { cursor: pointer; }
.look-tile .name { font-size: 12px; }
.empty {
  grid-column: 1 / -1; color: var(--ink-soft);
  font-family: var(--serif); font-style: italic; font-size: 17px;
  border: 1px dashed var(--line); border-radius: 4px; padding: 26px; text-align: center;
}

/* ---------- reveal on load ---------- */
.reveal { opacity: 0; transform: translateY(16px); animation: rise .8s cubic-bezier(.2,.7,.2,1) forwards; }
#you-section { animation-delay: .05s; }
#wardrobe-section { animation-delay: .16s; }
#hair-section { animation-delay: .27s; }
#lookbook-section { animation-delay: .38s; }
@keyframes rise { to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .reveal { animation: none; opacity: 1; transform: none; } }

/* ---------- outfit bar ---------- */
.outfit-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--green);
  background-image: linear-gradient(180deg, #234234, var(--green));
  border-top: 1px solid var(--gold);
  color: var(--paper);
  padding: 13px 20px calc(13px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 30px -20px rgba(0,0,0,.6);
}
.outfit-inner { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; flex: 1; min-width: 180px; }
.chip {
  background: var(--paper-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 2px; padding: 3px 10px; font-size: 12px; letter-spacing: .02em;
  display: inline-flex; align-items: center; gap: 7px;
  max-width: 210px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.outfit-bar .chip { background: rgba(242,236,221,.08); border-color: rgba(201,169,94,.42); color: var(--paper); }
.chip .x { cursor: pointer; color: var(--gold-br); }
.chip .x:hover { color: #e7c987; }
.outfit-bar .chip.placeholder { border-style: dashed; color: rgba(242,236,221,.6); background: transparent; }
.cap-note { align-self: center; color: var(--gold-br); font-size: 10.5px; letter-spacing: .06em; opacity: .85; font-style: italic; }
.notes {
  background: rgba(242,236,221,.94); border: 1px solid var(--gold); color: var(--ink);
  border-radius: 2px; padding: 9px 13px; font-family: var(--sans); font-size: 13px; width: 230px;
}
.notes::placeholder { color: var(--ink-soft); }
.model-badge {
  color: var(--gold-br); font-size: 10px; letter-spacing: .16em; text-transform: uppercase;
  border: 1px solid rgba(201,169,94,.42); padding: 5px 9px; border-radius: 2px; background: transparent;
}
.btn {
  background: var(--paper-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 2px; padding: 10px 18px;
  font-family: var(--sans); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .12em;
  transition: border-color .2s, background .2s, color .2s;
}
.btn:hover { border-color: var(--gold); color: var(--green); }
.btn.small { padding: 6px 11px; font-size: 10.5px; }
.btn.primary {
  background: linear-gradient(180deg, var(--gold-br), var(--gold));
  color: var(--green-deep); border: 1px solid var(--gold); font-weight: 600; letter-spacing: .14em;
  box-shadow: 0 2px 10px -4px rgba(120,90,30,.7);
}
.btn.primary:hover { filter: brightness(1.06); color: var(--green-deep); border-color: var(--gold); }
.btn.primary:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.danger { color: var(--wine); border-color: #b98a7a; background: var(--paper-2); }
.btn.danger:hover { border-color: var(--wine); color: var(--wine); }
.gen-status { display: inline-flex; align-items: center; gap: 9px; font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--paper); }
.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(242,236,221,.3); border-top-color: var(--gold-br);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(21,28,23,.6); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--paper); border: 1px solid var(--gold); border-radius: 5px;
  padding: 22px; width: min(480px, 100%); max-height: 92vh; overflow: auto;
  box-shadow: 0 40px 90px -34px rgba(15,20,15,.8), inset 0 0 0 1px rgba(201,169,94,.18);
}
.modal-card.viewer { width: min(680px, 100%); }
.modal-card header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.modal-card header h3 { font-size: 25px; color: var(--green); }
.modal-card .field { display: block; margin: 14px 0; font-size: 13px; color: var(--ink-soft); }
.modal-card .field > span { display: block; margin-bottom: 7px; }
.modal-card .note { background: var(--paper-3); border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: 3px; padding: 12px 14px; line-height: 1.5; color: var(--ink-soft); font-size: 13px; }
.modal-card .note strong { color: var(--green); }
.modal-card input, .modal-card select {
  width: 100%; background: var(--paper-3); color: var(--ink);
  border: 1px solid var(--line); border-radius: 3px; padding: 11px 13px; font-family: var(--sans); font-size: 14px;
}
.modal-card input:focus, .modal-card select:focus { outline: none; border-color: var(--gold); }
.keyrow { display: flex !important; gap: 8px; align-items: center; }
.keyrow input { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.spacer { flex: 1; }
.test-result { font-size: 13px; font-family: var(--serif); font-style: italic; }
.test-result.ok { color: var(--green); }
.test-result.err { color: var(--wine); }
#viewer-img { width: 100%; max-height: 62vh; object-fit: contain; border-radius: 3px; background: var(--paper-3); border: 1px solid var(--line); }
.viewer-meta { margin: 12px 0 2px; display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.viewer-meta .when { color: var(--ink-soft); font-family: var(--sans); font-size: 11px; letter-spacing: .06em; width: 100%; }

/* ---------- toasts ---------- */
#toasts {
  position: fixed; bottom: 122px; left: 50%; transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(460px, calc(100% - 30px));
}
.toast {
  background: var(--paper); border: 1px solid var(--gold); color: var(--ink);
  border-radius: 3px; padding: 11px 17px; font-size: 13.5px; font-family: var(--serif); font-style: italic;
  box-shadow: 0 14px 34px -16px rgba(30,25,10,.7); animation: pop .2s ease-out;
}
.toast.err { border-color: var(--wine); color: var(--wine); background: #f2e6df; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */
/* stack the rail + board into one column, keeping the I→II→III→IV workflow order */
@media (max-width: 900px) {
  main { flex-direction: column; gap: 20px; align-items: stretch; }
  .rail, .board { display: contents; }
  #you-section { order: 1; }
  #wardrobe-section { order: 2; }
  #hair-section { order: 3; }
  #lookbook-section { order: 4; }
  #categories { grid-template-columns: repeat(auto-fill, minmax(198px, 1fr)); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .grid.looks { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
}
@media (max-width: 560px) {
  body { padding-bottom: 148px; }
  .topbar { padding: 14px 16px 8px; }
  .wordmark h1 { font-size: 22px; }
  main { padding: 6px 14px; }
  .sec-head h2 { font-size: 19px; }
  #categories { grid-template-columns: 1fr; }

  /* each section's tiles become a horizontal slider instead of piling into rows */
  .grid {
    display: flex; flex-wrap: nowrap; align-items: flex-start;
    overflow-x: auto; gap: 8px; padding-bottom: 6px;
    scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
  }
  .grid > * { flex: 0 0 92px; scroll-snap-align: start; }
  .cat .grid > * { flex: 0 0 80px; }
  .grid.looks > * { flex: 0 0 120px; }
  .grid > .empty { flex: 1 0 100%; }
  .hair-presets { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .hair-preset { flex: 0 0 auto; }

  /* compact the generate bar so it stops covering the lookbook */
  .outfit-bar { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .outfit-inner { gap: 8px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .model-badge { display: none; }
  .notes { order: 2; flex: 1 1 110px; width: auto; min-width: 90px; padding: 8px 10px; }
  .outfit-inner .btn.primary { order: 3; }
  .gen-status { order: 2; }
  #toasts { bottom: 158px; }

  /* result viewer as a bottom sheet — the image gets the room, not the chrome */
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { border-radius: 14px 14px 0 0; padding: 14px 16px 18px; max-height: 92vh; }
  .modal-card.viewer { width: 100%; }
  .modal-card header { margin-bottom: 10px; padding-bottom: 8px; }
  .modal-card header h3 { font-size: 20px; }
  #viewer-img { max-height: 68vh; }
  .viewer-meta { margin: 8px 0 2px; }
  .tile .del { opacity: 1; }
}
