@font-face { font-family: "Instrument Sans"; src: url("../fonts/instrument-sans.woff") format("woff"); font-weight: 400 700; font-stretch: 75% 100%; font-display: swap; }
@font-face { font-family: "Instrument Serif"; src: url("../fonts/instrument-serif.woff") format("woff"); font-display: swap; }
@font-face { font-family: "Instrument Serif"; font-style: italic; src: url("../fonts/instrument-serif-italic.woff") format("woff"); font-display: swap; }

:root {
  --linen: #f1eee8;     /* backdrop, matches the 3D studio */
  --paper: #fbfaf7;
  --ink: #22201d;
  --muted: #7a7067;
  --line: #e2dbd0;
  --soft: #efeae2;
  --umber: #8a5a36;     /* selection accent */
  --bar-h: 64px;
  --panel-w: 400px;
  --r: 12px;
  --ease: cubic-bezier(.2,.7,.2,1);
  font-family: "Instrument Sans", system-ui, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--linen); overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--umber); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.app { position: fixed; inset: 0; }

/* ---------- top bar ---------- */
.bar { background: linear-gradient(var(--linen) 55%, rgba(241,238,232,0)); position: absolute; left: 0; right: 0; top: 0; height: calc(var(--bar-h) + 16px); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; z-index: 3; pointer-events: none; }
.brand { display: flex; align-items: baseline; gap: 12px; pointer-events: auto; }
.mark { width: 26px; height: 26px; align-self: center; }
.mark rect { fill: var(--ink); stroke: none; }
.mark path { stroke: var(--ink); stroke-width: 2.6; stroke-linecap: square; }
.name { font-family: "Instrument Serif", serif; font-size: 30px; letter-spacing: -.01em; line-height: 1; }
.tag { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.lead-time { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-right: var(--panel-w); }
.lead-time i { width: 7px; height: 7px; border-radius: 50%; background: #6f8a5c; box-shadow: 0 0 0 3px rgba(111,138,92,.18); }

/* ---------- stage ---------- */
.stage { position: absolute; inset: 0; }
.canvas { position: absolute; inset: 0; }
.canvas canvas { display: block; outline: none; touch-action: none; }
.tools { position: absolute; left: 28px; right: calc(var(--panel-w) + 28px); bottom: 24px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: rgba(251,250,247,.86); border: 1px solid var(--line); backdrop-filter: blur(10px); }
.seg button { border: 0; background: none; padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg button:hover { color: var(--ink); }
.seg button[aria-checked="true"] { background: var(--ink); color: #fff; }
.tool { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(251,250,247,.86); backdrop-filter: blur(10px); font-size: 13px; font-weight: 500; }
.tool svg { width: 18px; height: 18px; }
.tool.icon { width: 38px; padding: 0; justify-content: center; }
.tool[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.spec-chip { position: absolute; left: 22px; top: calc(var(--bar-h) + 2px); font-size: 13px; color: var(--muted); display: flex; gap: 12px; align-items: baseline; padding: 4px 12px 6px; border-radius: 12px; background: rgba(241,238,232,.78); backdrop-filter: blur(8px); z-index: 2; }
.spec-chip b { font-family: "Instrument Serif", serif; font-weight: 400; font-size: 26px; color: var(--ink); letter-spacing: -.01em; }
.dim-labels { position: absolute; inset: 0; pointer-events: none; }
.dim-labels span { position: absolute; transform: translate(-50%, -50%); background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- panel ---------- */
.panel { position: absolute; right: 16px; top: 16px; bottom: 16px; width: calc(var(--panel-w) - 32px); background: var(--paper); border-radius: 18px; border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(34,32,29,.05), 0 24px 60px rgba(60,44,28,.12); display: flex; flex-direction: column; overflow: hidden; z-index: 4; }
.grip { display: none; }
.steps { display: grid; grid-template-columns: repeat(5, 1fr); padding: 10px 10px 0; border-bottom: 1px solid var(--line); }
.steps button { border: 0; background: none; padding: 8px 2px 12px; font-size: 12.5px; font-weight: 500; color: var(--muted); position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.steps button .n { font-family: "Instrument Serif", serif; font-style: italic; font-size: 20px; line-height: 1; color: #b5aa9c; }
.steps button[aria-selected="true"] { color: var(--ink); }
.steps button[aria-selected="true"] .n { color: var(--umber); }
.steps button[aria-selected="true"]::after { content: ""; position: absolute; left: 20%; right: 20%; bottom: -1px; height: 2px; background: var(--ink); border-radius: 2px; }
.body { flex: 1; overflow-y: auto; padding: 4px 22px 22px; scrollbar-width: thin; }
.step h2 { font-family: "Instrument Serif", serif; font-weight: 400; font-size: 32px; letter-spacing: -.015em; margin: 16px 0 12px; line-height: 1; }
.step h2 em { color: var(--umber); }
.lead { margin: -4px 0 14px; color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.field { margin-top: 20px; }
.label { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 10px; }
.label span { letter-spacing: 0; text-transform: none; font-weight: 500; font-size: 13px; color: var(--muted); }
.label .muted { font-size: 12.5px; }

.tiles { display: grid; gap: 8px; }
.tiles.six { grid-template-columns: repeat(3, 1fr); }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.tiles.two { grid-template-columns: repeat(2, 1fr); }
.tile { border: 1px solid var(--line); background: #fff; border-radius: var(--r); padding: 12px 8px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--ink); transition: border-color .15s, box-shadow .15s; position: relative; }
.tile svg { width: 34px; height: 24px; stroke-width: 1.5; color: #4c453e; }
.tile:hover { border-color: #cbbfae; }
.tile[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink) inset; }
.tile small { color: var(--muted); font-weight: 400; font-size: 11.5px; text-align: center; line-height: 1.3; }
.tile .price { position: absolute; top: 7px; right: 8px; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.frame-tile { padding: 10px 10px 10px; align-items: stretch; text-align: left; }
.frame-tile img { width: 100%; aspect-ratio: 16/10; object-fit: contain; background: var(--soft); border-radius: 8px; }
.frame-tile b { font-weight: 600; font-size: 13.5px; margin-top: 2px; }
.frame-tile small { text-align: left; }

.sliders { margin-top: 18px; display: grid; gap: 14px; }
.slider { display: block; }
.sl-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.sl-head b { font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.sl-head output { font-family: "Instrument Serif", serif; font-size: 20px; font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: linear-gradient(var(--ink), var(--ink)) 0 / var(--fill, 50%) 100% no-repeat, var(--line); }
input[type=range]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 3px; background: var(--ink); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8.5px; border-radius: 50%; background: #fff; border: 1.5px solid var(--ink); box-shadow: 0 2px 6px rgba(34,32,29,.18); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 1.5px solid var(--ink); }
.note { margin: 14px 0 0; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.note svg { width: 18px; height: 18px; }

.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px 6px; }
.sw { border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); line-height: 1.2; text-align: center; }
.sw i { width: 46px; height: 46px; border-radius: 50%; background-size: cover; background-position: center; box-shadow: inset 0 0 0 1px rgba(34,32,29,.14); position: relative; }
.sw i::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 1.5px solid transparent; }
.sw:hover i::after { border-color: #cbbfae; }
.sw[aria-checked="true"] { color: var(--ink); font-weight: 600; }
.sw[aria-checked="true"] i::after { border-color: var(--ink); }
.rows { display: grid; gap: 6px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 11px 14px; }
.row b { font-weight: 600; font-size: 14px; display: block; }
.row small { color: var(--muted); font-size: 12.5px; }
.row .amt { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.row[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink) inset; }

.spec { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 4px 0 0; font-size: 13.5px; }
.spec dt { color: var(--muted); }
.spec dd { margin: 0; text-align: right; font-weight: 600; }
.lines { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.lines td { padding: 9px 0; border-top: 1px solid var(--line); }
.lines td:last-child { text-align: right; white-space: nowrap; padding-left: 10px; }
.lines tr.sum td { border-top: 1.5px solid var(--ink); font-weight: 700; font-size: 15px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.actions .wide { grid-column: 1 / -1; }
.fine { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 14px 0 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: 14px; font-weight: 600; transition: background .15s, transform .1s; }
.btn svg { width: 18px; height: 18px; }
.btn:hover { border-color: #cbbfae; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #000; }
.foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 22px 8px; border-top: 1px solid var(--line); background: #fff; }
.total { display: grid; line-height: 1.05; }
.total span { font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.total strong { font-family: "Instrument Serif", serif; font-weight: 400; font-size: 34px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
#btnNext { min-width: 150px; }
.credits { border: 0; background: #fff; color: var(--muted); font-size: 11.5px; text-decoration: underline; text-underline-offset: 2px; padding: 0 0 10px; }

/* loader / busy / toast / dialogs */
.loader { position: fixed; inset: 0; z-index: 20; background: var(--linen); display: grid; place-content: center; justify-items: center; gap: 14px; transition: opacity .6s; }
.loader.done { opacity: 0; pointer-events: none; }
.mark.big { width: 56px; height: 56px; }
.loader-name { font-family: "Instrument Serif", serif; font-size: 36px; }
.loader-bar { width: 200px; height: 2px; background: var(--line); overflow: hidden; border-radius: 2px; }
.loader-bar i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .25s; }
.loader-text { font-size: 13px; color: var(--muted); }
.busy { position: fixed; inset: 0; z-index: 15; display: grid; place-items: center; background: rgba(241,238,232,.35); }
.busy i { width: 32px; height: 32px; border-radius: 50%; border: 2.5px solid rgba(34,32,29,.15); border-top-color: var(--ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 16px); z-index: 30; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s var(--ease); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.dlg { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px)); color: var(--ink); box-shadow: 0 30px 80px rgba(34,32,29,.3); }
.dlg::backdrop { background: rgba(34,32,29,.35); }
.dlg form { padding: 22px 24px 20px; }
.dlg h3 { margin: 0 0 6px; font-family: "Instrument Serif", serif; font-weight: 400; font-size: 28px; }
.dlg p { margin: 0 0 12px; font-size: 13.5px; color: var(--muted); }
.dlg pre { margin: 0; max-height: 46vh; overflow: auto; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 12px; line-height: 1.5; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.credit-list { padding-left: 18px; margin: 4px 0 0; font-size: 13.5px; line-height: 1.5; }
.credit-list li { margin-bottom: 8px; }
.credit-list a { color: var(--umber); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- phones: bottom sheet ---------- */
@media (max-width: 860px) {
  :root { --sheet: 52vh; --bar-h: 52px; }
  .bar { padding: 0 16px; }
  .name { font-size: 24px; }
  .tag, .lead-time { display: none; }
  .stage { bottom: calc(var(--sheet) - 16px); }
  .spec-chip { left: 16px; top: var(--bar-h); }
  .spec-chip b { font-size: 21px; }
  .tools { left: 12px; right: 12px; bottom: 26px; gap: 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tools .tool span { display: none; }
  .tool { width: 36px; height: 36px; padding: 0; justify-content: center; flex: none; }
  .seg { flex: none; }
  .seg button { padding: 7px 10px; font-size: 12.5px; }
  .panel { left: 0; right: 0; bottom: 0; top: auto; width: auto; height: var(--sheet); border-radius: 20px 20px 0 0; border-bottom: 0; transition: height .3s var(--ease); }
  .panel.tall { height: 86vh; }
  .grip { display: block; padding: 8px 0 0; touch-action: none; cursor: grab; }
  .grip span { display: block; width: 40px; height: 4px; border-radius: 4px; background: #d8cfc3; margin: 0 auto; }
  .steps { padding: 0 6px; }
  .body { padding: 0 16px 16px; }
  .step h2 { font-size: 27px; margin-top: 12px; }
  .foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  .total strong { font-size: 28px; }
  .credits { display: none; }
  .toast { bottom: calc(var(--sheet) + 12px); }
}
