/* =========================================================
   PolyPixl 3D · Configurador 3D — Sofá Modular
   ========================================================= */

:root {
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-ui: "Manrope", system-ui, sans-serif;

  --accent: #ff7e26;
  --accent-2: #ffbc50;
  --accent-rgb: 255, 126, 38;

  --ink: #1d1c1a;
  --ink-dim: rgba(29, 28, 26, 0.62);
  --ink-faint: rgba(29, 28, 26, 0.38);
  --line: rgba(29, 28, 26, 0.08);
  --glass: rgba(252, 251, 249, 0.66);
  --glass-strong: rgba(252, 251, 249, 0.86);
  --shadow: 0 30px 80px -30px rgba(40, 30, 20, .28), 0 2px 10px rgba(40, 30, 20, .05);

  --panel-w: 372px;
  --radius: 20px;
  --ease: cubic-bezier(.22, .8, .22, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #e9e6e1;
  font-family: var(--font-ui);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { opacity: .3; cursor: default; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Fundo ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 70% 60% at 40% 42%, #fbfaf8 0%, #efece7 45%, #d9d5ce 100%);
}
.backdrop::after { /* grão sutil anti-banding */
  content: ""; position: absolute; inset: 0; opacity: .35; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 .07 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

#viewer { position: fixed; inset: 0; z-index: 1; touch-action: none; }
#viewer canvas { display: block; outline: none; }
#viewer.grab canvas { cursor: grab; }
#viewer.grabbing canvas { cursor: grabbing; }
#viewer.rotate canvas { cursor: ew-resize; }

#labels { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.dim-label {
  position: absolute; left: 0; top: 0;
  padding: 4px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em; font-variant-numeric: tabular-nums;
  color: var(--ink); background: rgba(255,255,255,.82);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px -6px rgba(40,30,20,.25);
  white-space: nowrap;
  transition: opacity .4s var(--ease);
  will-change: transform;
}
#labels.off .dim-label { opacity: 0 !important; }

/* ---------- Loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at center, #fbfaf8 0%, #e4e0da 80%);
  transition: opacity 1s var(--ease), visibility 1s;
}
#loader.hidden { opacity: 0; visibility: hidden; }
.loader-inner { width: 240px; text-align: center; }
.loader-logo { width: 220px; height: auto; display: block; margin: 0 auto 34px; animation: breathe 2.2s ease-in-out infinite; }
@keyframes breathe { 0%,100% { opacity: .5; transform: scale(.98); } 50% { opacity: 1; transform: scale(1); } }
.loader-bar { height: 2px; background: rgba(0,0,0,.07); border-radius: 2px; overflow: hidden; }
.loader-bar span { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.loader-text { margin-top: 14px; font-size: 10px; letter-spacing: .26em; text-transform: uppercase; color: var(--ink-faint); }

/* ---------- Topo ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: calc(var(--panel-w) + 40px);
  z-index: 10; padding: 30px 40px;
  display: flex; align-items: flex-start; justify-content: space-between;
  pointer-events: none;
  animation: fadeDown 1.2s .3s var(--ease) both;
}
.brand { display: flex; align-items: flex-end; gap: 16px; pointer-events: auto; }
.brand-logo { height: 32px; width: auto; display: block; }
.brand-sub { font-size: 10px; letter-spacing: .28em; text-transform: uppercase; color: var(--ink-dim); padding-bottom: 6px; padding-left: 16px; border-left: 1px solid rgba(0,0,0,.15); }
.model-title { text-align: right; }
.model-title h1 { font-family: var(--font-display); font-weight: 400; font-size: 38px; line-height: 1; }
.model-title h1 em, .panel-head h2 em { font-style: italic; color: var(--accent); }
.eyebrow { display: block; font-size: 10px; letter-spacing: .32em; text-transform: uppercase; color: var(--ink-dim); margin-bottom: 8px; }

@keyframes fadeDown { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

/* ---------- Painel ---------- */
.panel {
  position: fixed; top: 20px; right: 20px; bottom: 20px;
  width: var(--panel-w); z-index: 20;
  display: flex; flex-direction: column;
  background: var(--glass);
  backdrop-filter: blur(28px) saturate(150%);
  -webkit-backdrop-filter: blur(28px) saturate(150%);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: slideIn 1.1s .2s var(--ease) both;
}
.sheet-grip { display: none; }
.panel-head { padding: 28px 28px 18px; }
.panel-head h2 { font-family: var(--font-display); font-weight: 400; font-size: 32px; line-height: 1.05; }
.panel-lead { margin-top: 10px; font-size: 12.5px; line-height: 1.6; color: var(--ink-dim); }

.sections { flex: 1; overflow-y: auto; padding: 4px 28px 20px; scrollbar-width: thin; scrollbar-color: rgba(0,0,0,.12) transparent; }
.section { padding: 18px 0 20px; border-top: 1px solid var(--line); animation: fadeUp .9s calc(.5s + var(--i) * .1s) var(--ease) both; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; min-height: 28px; }
.section-title > span { font-size: 10.5px; font-weight: 700; letter-spacing: .24em; text-transform: uppercase; }
.section-title small { font-size: 11px; color: var(--ink-faint); }

/* módulos */
.module-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.module-card {
  position: relative; display: flex; flex-direction: column; align-items: center;
  padding: 8px 6px 11px; border-radius: 14px;
  background: rgba(255,255,255,.55);
  border: 1px solid rgba(0,0,0,.05);
  cursor: grab; touch-action: none;
  transition: transform .45s var(--spring), box-shadow .35s var(--ease), background .3s;
}
.module-card:hover { transform: translateY(-3px); background: #fff; box-shadow: 0 14px 30px -14px rgba(40,30,20,.35); }
.module-card:active { cursor: grabbing; transform: scale(.97); }
.module-card .thumb { width: 100%; aspect-ratio: 4/3; display: grid; place-items: center; }
.module-card .thumb img { width: 100%; height: 100%; object-fit: contain; opacity: 0; transform: scale(.9); transition: opacity .7s var(--ease), transform .7s var(--ease); pointer-events: none; }
.module-card .thumb img.ready { opacity: 1; transform: none; }
.module-card .name { font-size: 12px; font-weight: 600; margin-top: 2px; }
.module-card .meta { font-size: 10px; color: var(--ink-faint); margin-top: 2px; letter-spacing: .03em; }
.module-card .plus {
  position: absolute; top: 7px; right: 7px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; background: var(--ink); color: #fff;
  opacity: 0; transform: scale(.6); transition: all .35s var(--spring);
}
.module-card .plus svg { width: 11px; height: 11px; stroke-width: 2.2; }
.module-card:hover .plus { opacity: 1; transform: none; }

/* tecidos */
.fabric-list { display: grid; gap: 8px; }
.fabric {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 9px 12px 9px 9px; border-radius: 14px;
  background: rgba(255,255,255,.4); border: 1px solid transparent;
  transition: background .3s, border-color .3s, transform .4s var(--spring);
}
.fabric:hover { background: rgba(255,255,255,.8); }
.fabric.active { background: #fff; border-color: rgba(0,0,0,.08); box-shadow: 0 10px 24px -14px rgba(40,30,20,.3); }
.fabric .sw {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  background-size: 180%; background-position: center;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08), 0 4px 10px -4px rgba(0,0,0,.25);
  transition: transform .45s var(--spring);
}
.fabric.active .sw { transform: scale(1.06) rotate(-4deg); }
.fabric .fx { flex: 1; }
.fabric .fn { display: block; font-size: 13px; font-weight: 600; }
.fabric .fd { display: block; font-size: 11px; color: var(--ink-faint); margin-top: 2px; }
.fabric .chk { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; opacity: 0; transform: scale(.4); transition: all .4s var(--spring); }
.fabric .chk svg { width: 11px; height: 11px; stroke-width: 2.6; }
.fabric.active .chk { opacity: 1; transform: none; }
.fabric.mixed .chk { opacity: .35; transform: scale(.7); background: var(--ink); }

/* segmentado */
.seg { position: relative; display: flex; padding: 3px; border-radius: 999px; background: rgba(0,0,0,.05); }
.seg button { position: relative; z-index: 1; padding: 5px 11px; font-size: 10.5px; font-weight: 600; letter-spacing: .02em; color: var(--ink-dim); transition: color .3s; }
.seg button.active { color: var(--ink); }
.seg .seg-pill { position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 3px; border-radius: 999px; background: #fff; box-shadow: 0 2px 8px -2px rgba(0,0,0,.18); transition: transform .45s var(--spring), width .45s var(--spring); }

/* composições */
.preset-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.preset {
  position: relative; display: flex; flex-direction: column; align-items: stretch; text-align: left;
  padding: 6px 6px 11px; border-radius: 16px;
  background: rgba(255,255,255,.45); border: 1px solid rgba(0,0,0,.04);
  transition: background .3s, transform .45s var(--spring), box-shadow .35s var(--ease), border-color .3s;
  animation: cardIn .6s calc(var(--k, 0) * 45ms) var(--ease) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
.preset:hover { background: #fff; transform: translateY(-3px); box-shadow: 0 16px 30px -16px rgba(40,30,20,.35); }
.preset:active { transform: scale(.97); }
.preset .pthumb {
  position: relative; aspect-ratio: 16 / 10; border-radius: 11px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #fdfcfa 0%, #efebe5 100%);
}
.preset .pthumb img { width: 100%; height: 100%; object-fit: contain; display: block; opacity: 0; transform: scale(.94); transition: opacity .6s var(--ease), transform .7s var(--ease); }
.preset .pthumb img.ready { opacity: 1; transform: none; }
.preset:hover .pthumb img.ready { transform: scale(1.05); }
.preset .pn { display: block; font-size: 12.5px; font-weight: 600; margin: 9px 4px 0; }
.preset .pd { display: block; font-size: 10.5px; color: var(--ink-faint); margin: 2px 4px 0; font-variant-numeric: tabular-nums; }
.preset .pcheck {
  position: absolute; top: 12px; right: 12px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: #fff;
  opacity: 0; transform: scale(.4); transition: all .4s var(--spring);
}
.preset .pcheck svg { width: 11px; height: 11px; stroke-width: 2.6; }
.preset.active { background: #fff; border-color: rgba(var(--accent-rgb), .45); box-shadow: 0 14px 28px -16px rgba(var(--accent-rgb), .55); }
.preset.active .pcheck { opacity: 1; transform: none; }

/* rodapé */
.panel-foot { padding: 16px 28px 24px; border-top: 1px solid var(--line); background: rgba(255,255,255,.35); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-label { display: block; font-size: 9.5px; letter-spacing: .22em; text-transform: uppercase; color: var(--ink-faint); }
.stat-val { display: block; margin-top: 3px; font-family: var(--font-ui); font-weight: 300; font-size: 23px; line-height: 1.15; letter-spacing: -0.02em; font-variant-numeric: lining-nums tabular-nums; }
.stat-val small { font-family: var(--font-ui); font-size: 11px; color: var(--ink-dim); margin-left: 2px; }
.summary { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 16px; min-height: 22px; }
.summary li { font-size: 10.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: rgba(0,0,0,.05); color: var(--ink-dim); animation: pop .5s var(--spring) both; }
.summary li b { color: var(--ink); }
@keyframes pop { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: none; } }
.foot-actions { display: flex; gap: 8px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 18px; border-radius: 14px; font-size: 13px; font-weight: 600; transition: transform .35s var(--spring), background .3s, box-shadow .3s; }
.btn:active { transform: scale(.96); }
.btn-ghost { background: rgba(0,0,0,.05); }
.btn-ghost:hover { background: rgba(0,0,0,.09); }
.btn-icon { width: 46px; padding: 0; flex: none; }
.btn-primary { flex: 1; color: #fff; background: var(--ink); box-shadow: 0 12px 24px -12px rgba(0,0,0,.5); }
.btn-primary:hover { background: #000; box-shadow: 0 16px 30px -12px rgba(var(--accent-rgb), .55); }

/* ---------- Barra contextual ---------- */
.ctx {
  position: fixed; left: var(--x, 0px); top: var(--y, 0px); z-index: 15;
  display: flex; align-items: center; gap: 2px; padding: 5px;
  border-radius: 16px;
  background: var(--glass-strong);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid rgba(255,255,255,.8);
  box-shadow: 0 18px 40px -16px rgba(40,30,20,.35);
  opacity: 0; pointer-events: none;
  transform: translate(-50%, -100%) translateY(8px) scale(.88);
  transform-origin: 50% 100%;
  transition: opacity .3s var(--ease), transform .45s var(--spring);
  will-change: transform, left, top;
}
.ctx.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -100%) scale(1); }
.ctx.dragging { opacity: 0; pointer-events: none; }
.ctx-btn { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; transition: background .25s, color .25s, transform .3s var(--spring); }
.ctx-btn:hover { background: rgba(0,0,0,.06); }
.ctx-btn:active { transform: scale(.9); }
.ctx-btn.danger:hover { background: rgba(225, 60, 40, .1); color: #d2402a; }
.ctx-sep { width: 1px; height: 20px; background: rgba(0,0,0,.1); margin: 0 4px; }
.ctx-fabrics { display: flex; gap: 6px; padding: 0 4px; }
.ctx-fab { width: 22px; height: 22px; border-radius: 50%; background-size: 220%; background-position: center; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); transition: transform .35s var(--spring), box-shadow .3s; }
.ctx-fab:hover { transform: scale(1.15); }
.ctx-fab.active { box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 0 0 2px #fff, 0 0 0 3.5px var(--accent); }

/* ---------- Barra de vistas ---------- */
.viewbar {
  position: fixed; z-index: 12; bottom: 28px;
  left: calc((100vw - var(--panel-w) - 40px) / 2); translate: -50% 0;
  display: flex; align-items: center; gap: 2px; padding: 5px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  border: 1px solid rgba(255,255,255,.7);
  box-shadow: var(--shadow);
  animation: fadeUp 1s .6s var(--ease) both;
}
.view-btn { height: 36px; padding: 0 16px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--ink-dim); transition: color .3s, background .3s; }
.view-btn:hover { color: var(--ink); }
.view-btn.active { color: #fff; background: var(--ink); }
.viewbar-sep { width: 1px; height: 20px; background: rgba(0,0,0,.1); margin: 0 6px; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-dim); transition: color .3s, background .3s, transform .3s var(--spring); }
.icon-btn:not(:disabled):hover { color: var(--ink); background: rgba(0,0,0,.05); }
.icon-btn:not(:disabled):active { transform: scale(.9); }
.icon-btn.active { color: var(--accent); }

/* ---------- Estado vazio ---------- */
.empty {
  position: fixed; z-index: 4; pointer-events: none;
  left: calc((100vw - var(--panel-w) - 40px) / 2); top: 54%;
  transform: translate(-50%, -50%);
  text-align: center; opacity: 0; transition: opacity .6s var(--ease);
}
.empty.show { opacity: 1; }
.empty-ring { width: 120px; height: 120px; margin: 0 auto 18px; border-radius: 26px; border: 1.5px dashed rgba(29,28,26,.25); animation: ringPulse 2.6s ease-in-out infinite; }
.empty p { font-size: 11px; letter-spacing: .24em; text-transform: uppercase; color: var(--ink-faint); }
@keyframes ringPulse { 0%,100% { transform: scale(.94) rotate(0deg); opacity: .6; } 50% { transform: scale(1) rotate(3deg); opacity: 1; } }

/* ---------- Dicas / toast ---------- */
.hint {
  position: fixed; z-index: 11; bottom: 88px;
  left: calc((100vw - var(--panel-w) - 40px) / 2); translate: -50% 0;
  display: flex; gap: 18px; font-size: 11px; color: var(--ink-faint);
  transition: opacity .8s var(--ease);
}
.hint.hide { opacity: 0; }
kbd { font: inherit; font-weight: 700; font-size: 10px; color: var(--ink-dim); padding: 2px 6px; border-radius: 6px; background: rgba(255,255,255,.7); box-shadow: 0 1px 0 rgba(0,0,0,.1); margin-right: 4px; }

.toast {
  position: fixed; z-index: 50; top: 30px;
  left: calc((100vw - var(--panel-w) - 40px) / 2);
  transform: translate(-50%, -20px);
  padding: 11px 18px; border-radius: 999px;
  background: var(--ink); color: #fff; font-size: 12px; font-weight: 500;
  box-shadow: 0 16px 40px -14px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none;
  transition: opacity .4s var(--ease), transform .5s var(--spring);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* fantasma do card arrastado (antes de entrar na cena) */
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 60; width: 110px; pointer-events: none;
  transform: translate(-50%, -50%); opacity: .9;
  filter: drop-shadow(0 18px 24px rgba(40,30,20,.3));
  transition: opacity .2s, width .25s var(--ease);
}
.drag-ghost.gone { opacity: 0; width: 60px; }

/* ---------- Responsivo ---------- */
@media (max-width: 1240px) and (min-width: 861px) {
  .hint { display: none; }
  .view-btn { padding: 0 11px; }
  .viewbar { left: 24px; translate: none; }
  .model-title h1 { font-size: 30px; }
}

@media (max-width: 860px) {
  :root { --panel-w: 0px; }
  .topbar { right: 0; padding: 18px 20px; }
  .brand-logo { height: 24px; }
  .brand-sub { display: none; }
  .model-title h1 { font-size: 26px; }
  .model-title .eyebrow { margin-bottom: 4px; }

  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    height: 46vh; border-radius: 22px 22px 0 0;
    transition: height .5s var(--ease);
    animation: fadeUp 1s .2s var(--ease) both;
  }
  .panel.collapsed { height: 210px; }
  .sheet-grip { display: block; position: absolute; top: 0; left: 0; right: 0; height: 22px; z-index: 2; }
  .sheet-grip span { display: block; width: 38px; height: 4px; border-radius: 4px; background: rgba(0,0,0,.15); margin: 9px auto 0; }
  .panel-head { display: none; }
  .sections { padding: 16px 18px 12px; }
  .section:first-child { border-top: 0; padding-top: 4px; }
  .panel-foot { padding: 10px 18px calc(12px + env(safe-area-inset-bottom)); }
  .panel-foot .stats { display: none; }
  .summary { display: none; }
  .btn { height: 42px; }
  .btn-icon { width: 42px; }

  .viewbar, .hint, .empty, .toast { left: 50%; }
  .viewbar { top: 78px; bottom: auto; }
  .view-btn { padding: 0 10px; font-size: 11px; height: 32px; }
  .icon-btn { width: 32px; height: 32px; }
  .viewbar-sep { margin: 0 3px; }
  #btn-full, #btn-frame { display: none; }
  .hint { display: none; }
  .empty { top: 34%; }
  .toast { top: auto; bottom: calc(48vh + 10px); }
}

/* ---------- Modo demonstração (vídeo) ---------- */
body.demo .topbar, body.demo .panel, body.demo .viewbar, body.demo .hint, body.demo #labels,
body.demo .ctx, body.demo .empty, body.demo .toast, body.demo .backdrop, body.demo #viewer { visibility: hidden; }
body.demo { background: #111; }
#demo-out { position: fixed; inset: 0; width: 100vw; height: 100vh; object-fit: contain; z-index: 50; background: #111; }
#demo-status {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 60;
  padding: 8px 16px; border-radius: 999px; background: rgba(0,0,0,.7); color: #fff;
  font: 500 12px var(--font-ui); letter-spacing: .04em;
}
