:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(1.9rem, 1.2rem + 2.2vw, 3rem);
  --space-1: .25rem; --space-2: .5rem; --space-3: .75rem; --space-4: 1rem; --space-5: 1.25rem;
  --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem; --space-12: 3rem; --space-16: 4rem;

  --bg: #f3efe6;
  --surface: #fbf9f4;
  --surface-2: #ece6da;
  --border: #d9d1c1;
  --text: #1e231f;
  --muted: #5b5f57;
  --accent: #2f4a32;
  --accent-hover: #233826;
  --accent-soft: #dfe7d8;
  --ok: #2f6b3a;
  --close: #9a6a12;
  --over: #a3412a;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(30,35,31,.06), 0 8px 24px rgba(30,35,31,.07);
  --font-display: 'Cabinet Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Satoshi', 'Segoe UI', sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: var(--text-base); line-height: 1.5; -webkit-font-smoothing: antialiased; }
img { display: block; max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) clamp(var(--space-4), 3vw, var(--space-10)); background: var(--accent); color: #f3efe6; }
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-mark { width: 32px; height: 32px; color: #d9c79f; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: var(--text-base); letter-spacing: .01em; line-height: 1.1; }
.brand-sub { font-size: var(--text-xs); opacity: .8; }
.topbar .btn-ghost { color: #f3efe6; border-color: rgba(243,239,230,.45); background: transparent; }
.topbar .btn-ghost:hover { background: rgba(243,239,230,.12); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 44px; padding: var(--space-2) var(--space-5); border-radius: 999px; border: 1.5px solid transparent; font-weight: 700; font-size: var(--text-sm); text-decoration: none; transition: background .18s, border-color .18s, transform .18s; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fbf9f4; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #93a091; cursor: not-allowed; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-sm { min-height: 36px; padding: var(--space-1) var(--space-4); }
.btn-lg { min-height: 52px; padding: var(--space-3) var(--space-8); font-size: var(--text-base); }
.btn-grow { flex: 1; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 700; font-size: var(--text-sm); text-decoration: underline; text-underline-offset: 3px; }

/* layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 420px); gap: clamp(var(--space-5), 2.5vw, var(--space-10)); padding: clamp(var(--space-5), 3vw, var(--space-10)); max-width: 1440px; margin: 0 auto; align-items: start; }
.intro { margin-bottom: var(--space-5); max-width: 46ch; }
.intro h1 { font-family: var(--font-display); font-weight: 800; font-size: var(--text-2xl); line-height: 1.05; letter-spacing: -.01em; margin-bottom: var(--space-3); text-wrap: balance; }
.intro p { color: var(--muted); }

/* stage */
.stage { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--space-3); }
.drop { border: 2px dashed var(--border); border-radius: calc(var(--radius) - 4px); padding: clamp(var(--space-8), 6vw, var(--space-16)) var(--space-6); text-align: center; background: repeating-linear-gradient(135deg, transparent 0 14px, rgba(47,74,50,.025) 14px 28px); transition: border-color .2s, background-color .2s; }
.drop.drag, .drop.pulse { border-color: var(--accent); background-color: var(--accent-soft); }
.drop-icon { width: 52px; height: 52px; color: var(--accent); margin: 0 auto var(--space-3); }
.drop-title { font-family: var(--font-display); font-weight: 800; font-size: var(--text-lg); }
.drop-hint { color: var(--muted); font-size: var(--text-sm); margin-top: var(--space-1); }
.drop-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); margin-top: var(--space-5); }
.drop-actions label { cursor: pointer; }
.samples { padding: var(--space-4) var(--space-2) var(--space-2); }
.samples-label { font-size: var(--text-sm); color: var(--muted); }
.samples-row { display: flex; gap: var(--space-3); margin-top: var(--space-2); }
.sample { flex: 1; max-width: 200px; padding: 0; border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); text-align: left; transition: border-color .18s, transform .18s; }
.sample:hover { border-color: var(--accent); transform: translateY(-2px); }
.sample img { aspect-ratio: 4/3; object-fit: cover; width: 100%; }
.sample span { display: block; padding: var(--space-1) var(--space-3); font-size: var(--text-xs); font-weight: 700; }

.compare { position: relative; border-radius: calc(var(--radius) - 4px); overflow: hidden; background: var(--surface-2); user-select: none; }
.compare-before { width: 100%; height: auto; max-height: 72vh; object-fit: contain; margin: 0 auto; }
.compare-after-wrap { position: absolute; inset: 0; clip-path: inset(0 0 0 50%); }
.compare-after { width: 100%; height: 100%; object-fit: contain; }
.compare-range { position: absolute; inset: 0; z-index: 3; cursor: ew-resize; touch-action: pan-y; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.compare img { -webkit-user-drag: none; pointer-events: none; }
.compare.dragging .compare-handle span { transform: translate(-50%, -50%) scale(1.12); }
.compare-handle span { transition: transform .15s; }
.compare-handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; background: #fbf9f4; transform: translateX(-50%); z-index: 2; pointer-events: none; box-shadow: 0 0 8px rgba(0,0,0,.35); }
.compare-handle span { position: absolute; top: 50%; left: 50%; width: 48px; height: 48px; transform: translate(-50%, -50%); border-radius: 50%; background: #fbf9f4; box-shadow: 0 2px 10px rgba(0,0,0,.3); }
.compare-handle span::before, .compare-handle span::after { content: ''; position: absolute; top: 50%; width: 0; height: 0; border: 6px solid transparent; transform: translateY(-50%); }
.compare-handle span::before { left: 6px; border-right-color: var(--accent); }
.compare-handle span::after { right: 6px; border-left-color: var(--accent); }
.tag { position: absolute; top: var(--space-3); padding: var(--space-1) var(--space-3); border-radius: 999px; background: rgba(30,35,31,.72); color: #fbf9f4; font-size: var(--text-xs); font-weight: 700; z-index: 2; pointer-events: none; }
.tag-left { left: var(--space-3); } .tag-right { right: var(--space-3); background: var(--accent); }
.loading { position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; gap: var(--space-3); text-align: center; background: rgba(30,35,31,.55); backdrop-filter: blur(3px); color: #fbf9f4; font-weight: 700; padding: var(--space-6); }
.loading-bar { width: min(280px, 60vw); height: 6px; border-radius: 99px; background: rgba(255,255,255,.25); overflow: hidden; margin: 0 auto; }
.loading-bar span { display: block; height: 100%; width: 40%; border-radius: inherit; background: #d9c79f; animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
.stage-tools { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-2) var(--space-1); }
.stage-note { font-size: var(--text-sm); color: var(--muted); }

/* panel */
.panel { position: sticky; top: var(--space-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: calc(100vh - var(--space-8)); }
.panel-scroll { overflow-y: auto; padding: var(--space-5); display: grid; gap: var(--space-6); overscroll-behavior: contain; }
.block h2 { font-family: var(--font-body); font-weight: 700; font-size: var(--text-lg); display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.block-head h2 { margin-bottom: 0; }
.num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fbf9f4; font-size: var(--text-xs); font-weight: 700; flex: none; }
.budget-out { font-family: var(--font-display); font-weight: 800; font-size: var(--text-xl); color: var(--accent); font-variant-numeric: tabular-nums; }
.budget-scale { display: flex; justify-content: space-between; font-size: var(--text-xs); color: var(--muted); }
.label { font-size: var(--text-sm); font-weight: 700; margin: var(--space-4) 0 var(--space-2); }
.block .label:first-of-type { margin-top: 0; }

input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; margin: var(--space-2) 0 0; }

.projects { display: grid; gap: var(--space-2); }
.project { border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); transition: border-color .18s, background .18s; }
.project.on { border-color: var(--accent); background: #f6f8f2; }
.project-head { width: 100%; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); background: none; border: 0; text-align: left; }
.check { width: 22px; height: 22px; border-radius: 6px; border: 1.5px solid var(--border); flex: none; display: grid; place-items: center; background: var(--surface); }
.project.on .check { background: var(--accent); border-color: var(--accent); }
.project.on .check::after { content: ''; width: 6px; height: 11px; border: solid #fbf9f4; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px); }
.project-text { flex: 1; min-width: 0; display: grid; }
.project-name { font-weight: 700; font-size: var(--text-sm); }
.project-desc { font-size: var(--text-xs); color: var(--muted); }
.project-price { font-size: var(--text-xs); font-weight: 700; color: var(--accent); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.project-body { padding: 0 var(--space-3) var(--space-3) calc(var(--space-3) + 22px + var(--space-3)); display: grid; gap: var(--space-3); }
.ctl-top { display: flex; justify-content: space-between; font-size: var(--text-sm); }
.ctl-top output { font-weight: 700; font-variant-numeric: tabular-nums; }
.ctl-label { font-size: var(--text-sm); color: var(--muted); display: block; margin-bottom: var(--space-1); }
.ctl-top .ctl-label { margin: 0; }
.seg { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.seg button, .chip { padding: var(--space-1) var(--space-3); min-height: 34px; border-radius: 999px; border: 1.5px solid var(--border); background: var(--surface); font-size: var(--text-xs); font-weight: 700; transition: all .15s; }
.seg button.on, .chip.on { background: var(--accent); border-color: var(--accent); color: #fbf9f4; }
.seg button:hover:not(.on), .chip:hover:not(.on) { border-color: var(--accent); }
.ctl-check { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.ctl-check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); }
.swatch { display: grid; gap: var(--space-1); justify-items: center; padding: var(--space-2) var(--space-1); border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); font-size: var(--text-xs); font-weight: 700; text-align: center; line-height: 1.2; }
.swatch.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.sw { width: 100%; height: 34px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }

.panel-foot { border-top: 1px solid var(--border); padding: var(--space-4) var(--space-5) var(--space-5); background: var(--surface); border-radius: 0 0 var(--radius) var(--radius); }
.meter-row { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-3); }
.meter-label { font-size: var(--text-xs); color: var(--muted); }
.meter-total { font-family: var(--font-display); font-weight: 800; font-size: var(--text-lg); font-variant-numeric: tabular-nums; line-height: 1.2; }
.fit-pill { font-size: var(--text-xs); font-weight: 700; padding: var(--space-1) var(--space-3); border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.fit-pill.ok { background: #dcebdc; color: var(--ok); }
.fit-pill.close { background: #f4e7c8; color: var(--close); }
.fit-pill.over { background: #f3d9d1; color: var(--over); }
.meter { position: relative; height: 10px; border-radius: 99px; background: var(--surface-2); margin: var(--space-3) 0 var(--space-4); }
.meter span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent) 0 var(--lo, 60%), rgba(47,74,50,.45) var(--lo, 60%)); transition: width .25s; }
.meter span.close { background: linear-gradient(90deg, var(--close) 0 var(--lo), rgba(154,106,18,.4) var(--lo)); }
.meter span.over { background: linear-gradient(90deg, var(--over) 0 var(--lo), rgba(163,65,42,.4) var(--lo)); }
.meter i { position: absolute; top: -5px; bottom: -5px; width: 3px; border-radius: 2px; background: var(--text); transform: translateX(-50%); transition: left .25s; }
.meter i::after { content: 'Budget'; position: absolute; top: 20px; left: 50%; transform: translateX(-50%); font-size: 11px; font-style: normal; font-weight: 700; color: var(--muted); display: none; }
.foot-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.foot-error { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--over); font-weight: 500; }

/* result */
.result { margin-top: var(--space-5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(var(--space-5), 3vw, var(--space-8)); display: grid; gap: var(--space-5); }
.result-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: var(--space-4); }
.eyebrow { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.result-total { font-family: var(--font-display); font-weight: 800; font-size: var(--text-xl); font-variant-numeric: tabular-nums; }
.result-fit { font-size: var(--text-sm); font-weight: 700; }
.result-fit.ok { color: var(--ok); } .result-fit.close { color: var(--close); } .result-fit.over { color: var(--over); }
.result-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.lines { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.lines li { display: flex; justify-content: space-between; gap: var(--space-4); padding: var(--space-2) 0; border-bottom: 1px solid var(--border); font-size: var(--text-sm); }
.lines li span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cta-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-5); border-radius: var(--radius-sm); background: var(--accent); color: #f3efe6; }
.cta-box > div { flex: 1 1 280px; }
.cta-title { font-family: var(--font-display); font-weight: 800; font-size: var(--text-lg); }
.cta-text { font-size: var(--text-sm); opacity: .88; margin-top: var(--space-1); }
.cta-box .btn-primary { background: #d9c79f; color: var(--text); }
.cta-box .btn-primary:hover { background: #e6d6b2; }
.summary-details summary { cursor: pointer; font-weight: 700; font-size: var(--text-sm); color: var(--accent); }
.summary-details textarea { width: 100%; margin: var(--space-3) 0 var(--space-2); padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); font-size: var(--text-sm); resize: vertical; }
.fine { font-size: var(--text-xs); color: var(--muted); }

.site-foot { text-align: center; padding: var(--space-6) var(--space-4) var(--space-10); font-size: var(--text-xs); color: var(--muted); }

@media (max-width: 959px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .panel-scroll { overflow: visible; }
  .panel-foot { position: sticky; bottom: 0; z-index: 10; box-shadow: 0 -6px 20px rgba(30,35,31,.1); border-radius: 0 0 var(--radius) var(--radius); }
}
@media (max-width: 480px) {
  .topbar .btn { display: none; }
  .swatches { grid-template-columns: repeat(2, 1fr); }
  .project-body { padding-left: var(--space-3); }
  .cta-box .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
