* { box-sizing: border-box; margin: 0; padding: 0; }

/* keep the hidden attribute authoritative over display: flex/grid rules */
[hidden] { display: none !important; }

/* graceful arrival: elements fade + slide down when they first appear */
@keyframes rise {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

:root {
  --bg: #fbfaf7;
  --ink: #201c15;
  --muted: #8a8274;
  --card: #ffffff;
  --line: #eae4d8;
  --accent: #9a5b2e;
  --accent-ink: #7c4823;
}

body {
  font-family: Georgia, 'Times New Roman', serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

body.modal-open { overflow: hidden; }

button, input, label, select { font-family: inherit; }

/* header — a quiet single line ---------------------------------------------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.8rem;
  padding: 1.1rem 2rem;
}

.site-header h1 {
  font-size: 0.95rem;
  font-weight: normal;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  opacity: 0.55;
  transition: opacity 0.2s;
}

.site-header:hover .header-right,
.header-right:focus-within { opacity: 1; }

.tabs { display: flex; gap: 0.9rem; }

.tab {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.86rem;
  cursor: pointer;
  padding: 0.15rem 0;
}

.tab.active {
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
}

.segmented { display: inline-flex; gap: 0.6rem; }

.segmented button {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.15rem 0;
}

.segmented button.active {
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
}

main {
  padding: 1rem 2rem 4rem;
  max-width: 1060px;
  margin: 0 auto;
}

#catalog-status {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  margin-bottom: 0.8rem;
}

/* buttons -------------------------------------------------------------------- */

.btn {
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.btn:hover { border-color: var(--ink); }

.btn.small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

.btn.solid { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.solid:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

.ghost-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.82rem;
  font-style: italic;
  cursor: pointer;
  padding: 0.1rem 0;
}

.ghost-btn:hover, .ghost-btn.active { color: var(--ink); }

/* dropzone — an empty room -------------------------------------------------- */

#dropzone {
  border: 1px dashed #d8cfbd;
  border-radius: 16px;
  min-height: 46vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  animation: rise 0.6s ease 0.05s both;
}

#dropzone.dragging, #dropzone:hover { border-color: var(--accent); color: var(--ink); }

#dropzone p { font-size: 1.02rem; }
#dropzone p span { font-size: 0.84rem; opacity: 0.75; }

/* workspace ------------------------------------------------------------------ */

#workspace { animation: rise 0.5s ease both; }

#step-hint {
  color: var(--muted);
  font-size: 0.88rem;
  font-style: italic;
  text-align: center;
  margin-bottom: 0.7rem;
  animation: rise 0.4s ease both;
}

#work-wrap {
  position: relative;
  max-width: 920px;
  margin: 0 auto;
}

#work-canvas {
  width: 100%;
  display: block;
  border-radius: 12px;
  cursor: crosshair;
  touch-action: none;
}

/* floating toolbar — appears when you approach the room ---------------------- */

#workspace-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 7px;
  opacity: 0;
  transition: opacity 0.2s;
}

#work-wrap:hover #workspace-actions,
#workspace-actions:focus-within { opacity: 1; }

.tool-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(24, 20, 14, 0.6);
  color: #f2ede2;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

.tool-btn:hover { background: rgba(24, 20, 14, 0.88); }

.tool-btn.active { background: var(--accent); }

.overlay-btn {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
}

.site-footer {
  text-align: center;
  padding: 2.2rem 1rem 1.6rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.site-footer a { color: var(--muted); }

/* inline confirmation bars — no floating popouts ------------------------------ */

.inline-pop {
  max-width: 920px;
  margin: 0.7rem auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.88rem;
  animation: rise 0.35s ease both;
}

.inline-pop label, .inline-pop span:not(#measure-unit) { color: var(--muted); }

.inline-pop input {
  width: 4.6rem;
  padding: 0.32rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.92rem;
}

/* room analysis — a single quiet line ----------------------------------------- */

#room-analysis {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  margin: 0.7rem auto 0;
  font-size: 0.84rem;
  animation: rise 0.5s ease 0.12s both;
}

#room-swatches { display: inline-flex; gap: 0.35rem; }

.chip {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  display: inline-block;
}

#room-character { color: var(--muted); font-style: italic; }

/* results ------------------------------------------------------------------ */

#results-section { margin-top: 2.2rem; animation: rise 0.55s ease 0.08s both; }

#results-controls { animation: rise 0.35s ease both; }

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

#match-heading {
  font-size: 0.95rem;
  font-weight: normal;
  letter-spacing: 0.06em;
  color: var(--ink);
}

#results-controls {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1.3rem;
  padding: 0.9rem 0 1.1rem;
  margin-bottom: 1rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.control label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.3rem;
  color: var(--muted);
}

.control label span { color: var(--ink); }

.control input[type="range"] { width: 140px; accent-color: var(--accent); }

.control select {
  padding: 0.28rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 0.82rem;
  color: var(--ink);
}

#results-controls .segmented { gap: 0; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }

#results-controls .segmented button {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
}

#results-controls .segmented button.active {
  background: var(--ink);
  color: var(--bg);
  border-bottom: none;
}

#tolerance-note {
  width: 100%;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

/* cards — just the art; details on approach ----------------------------------- */

#match-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.empty-note {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 1.5rem 0;
}

.card {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: #f2eee5;
  animation: rise 0.45s ease both;
}

.card:nth-child(2), .card:nth-child(6), .card:nth-child(10) { animation-delay: 0.05s; }
.card:nth-child(3), .card:nth-child(7), .card:nth-child(11) { animation-delay: 0.1s; }
.card:nth-child(4), .card:nth-child(8), .card:nth-child(12) { animation-delay: 0.15s; }

.card-img {
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-img img { width: 100%; height: 100%; object-fit: contain; }

.card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0.9rem;
  background: linear-gradient(180deg, rgba(20, 17, 12, 0.3) 0%, rgba(20, 17, 12, 0.92) 60%);
  color: #f5f1e8;
  opacity: 0;
  transition: opacity 0.18s;
}

.card:hover .card-overlay, .card:focus-visible .card-overlay { opacity: 1; }

.card-overlay h3 { font-size: 0.95rem; font-weight: normal; line-height: 1.3; }

.card-overlay .artist { font-size: 0.8rem; font-style: italic; opacity: 0.85; }

.card-overlay .dims { font-size: 0.78rem; opacity: 0.85; margin-top: 0.15rem; }

.card-overlay .reason { font-size: 0.78rem; opacity: 0.85; margin-top: 0.3rem; }
.card-overlay .reason::before { content: '— '; }

.card-overlay .cta {
  font-size: 0.78rem;
  font-style: italic;
  margin-top: 0.45rem;
  opacity: 0.9;
}

/* gallery ------------------------------------------------------------------ */

.gallery-note {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  margin-bottom: 1.3rem;
}

#gallery-grid { columns: 4 230px; column-gap: 1rem; }

.gallery-item {
  position: relative;
  break-inside: avoid;
  margin-bottom: 1rem;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
}

.gallery-item img { width: 100%; display: block; }

.gallery-item figcaption {
  position: absolute;
  inset: auto 0 0 0;
  padding: 1.6rem 0.75rem 0.7rem;
  background: linear-gradient(180deg, rgba(20, 17, 12, 0), rgba(20, 17, 12, 0.8));
  color: #f5f1e8;
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity 0.18s;
}

.gallery-item:hover figcaption { opacity: 1; }

.gallery-item figcaption strong { display: block; font-weight: normal; }

.gallery-item figcaption span { font-style: italic; font-size: 0.75rem; opacity: 0.85; }

/* inline piece bar — fades in under the room when a piece is selected -------- */

#piece-bar {
  max-width: 920px;
  margin: 0 auto;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.25s ease, padding 0.25s ease;
  padding: 0 0.2rem;
}

#piece-bar.open {
  max-height: 320px;
  opacity: 1;
  padding: 0.8rem 0.2rem 0.3rem;
}

.preview-head { font-size: 0.85rem; }

#piece-title { letter-spacing: 0.03em; }

#piece-meta { color: var(--muted); }
#piece-meta::before { content: ' — '; color: var(--muted); }
#piece-meta a { color: var(--accent-ink); }

.footer-spacer { flex: 1; }

.preview-controls {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.7rem;
  flex-wrap: wrap;
}

.control-label {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 2.6rem;
}

#piece-bar .segmented {
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

#piece-bar .segmented button {
  padding: 0.24rem 0.62rem;
  font-size: 0.76rem;
}

#piece-bar .segmented button.active {
  background: var(--ink);
  color: var(--bg);
  border-bottom: none;
}

#frame-slider { flex: 1; min-width: 140px; accent-color: var(--accent); }

#mat-width { width: 130px; accent-color: var(--accent); }

#mat-width-label { font-size: 0.8rem; color: var(--muted); font-style: italic; }

#frame-num {
  width: 3.6rem;
  padding: 0.28rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.85rem;
  text-align: center;
}

#frame-name {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  min-width: 11rem;
}

#piece-caption {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.45rem;
}

.preview-footer {
  margin-top: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
