:root {
  --ink: #14201c; --ivory: #f6f2ea; --paper: #fbf9f5; --brass: #b8924f; --brass-2: #a07d3f;
  --muted: #66706b; --line: #ddd5c6; --r: 8px;
  --sans: "Manrope", system-ui, sans-serif; --serif: "Fraunces", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--sans); color: var(--ink); background: #cfd8d6; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene.is-dragging { cursor: grabbing; }
#scene.is-placing { cursor: crosshair; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
kbd { font: 600 11px var(--sans); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; background: #fff; color: var(--ink); }

/* Barra superior */
.bar {
  position: fixed; top: 12px; left: 12px; right: 12px; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  background: rgba(251, 249, 245, .96); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; box-shadow: 0 8px 24px -12px rgba(0,0,0,.25);
}
.iconbtn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--r); color: var(--ink); text-decoration: none; flex: none; }
.iconbtn:hover { background: #efe9de; }
.bar__title { display: flex; flex-direction: column; line-height: 1.2; margin-right: auto; min-width: 0; }
.bar__title strong { font: 400 18px var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar__title small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg { display: flex; background: #efe9de; border-radius: var(--r); padding: 3px; flex: none; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.is-on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.cta { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: var(--r); border: 0; background: var(--brass); color: #fff; font-weight: 600; font-size: 14px; text-decoration: none; flex: none; }
.cta:hover { background: var(--brass-2); }

/* Painel lateral */
.panel {
  position: fixed; z-index: 9; top: 84px; left: 12px; bottom: 12px; width: 280px;
  background: rgba(251, 249, 245, .97); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; box-shadow: 0 8px 24px -12px rgba(0,0,0,.25);
  transition: transform .25s cubic-bezier(.2,.7,.2,1);
}
.panel__handle { display: none; }
.panel__body { overflow-y: auto; padding: 16px; }
.panel h2 { font: 400 18px var(--serif); margin: 4px 0 2px; }
.panel__hint { font-size: 12px; color: var(--muted); margin: 0 0 12px; }
.catalog { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 24px; }
.catalog button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  border: 1px solid var(--line); background: #fff; border-radius: var(--r); padding: 10px;
  font-size: 13px; font-weight: 600; color: var(--ink); transition: border-color .15s;
}
.catalog button small { font-weight: 500; color: var(--muted); font-size: 11px; }
.catalog button:hover { border-color: var(--ink); }
.catalog button.is-on { border-color: var(--brass); box-shadow: 0 0 0 2px rgba(184,146,79,.3); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); padding: 0; }
.swatches button.is-on { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--brass); }
.panel__foot { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.txtbtn { border: 0; background: none; padding: 6px 0; color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.txtbtn:hover { color: var(--ink); }

/* Barra de seleção */
.selbar {
  position: fixed; z-index: 10; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; background: var(--ink); color: var(--ivory);
  border-radius: 12px; padding: 6px 6px 6px 16px; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5);
}
.selbar[hidden] { display: none; }
.selbar span { font-weight: 600; font-size: 14px; margin-right: 8px; white-space: nowrap; }
.selbar button { border: 0; background: rgba(255,255,255,.1); color: var(--ivory); padding: 8px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; display: flex; gap: 6px; align-items: center; }
.selbar button:hover { background: rgba(255,255,255,.18); }
.selbar button.danger:hover { background: #a2443a; }
.selbar kbd { background: transparent; color: rgba(246,242,234,.7); border-color: rgba(246,242,234,.3); }

.toast {
  position: fixed; z-index: 11; left: 50%; top: 84px; transform: translate(-50%, -8px);
  background: var(--ink); color: var(--ivory); padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* Ajuda inicial */
.help { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(20,32,28,.45); padding: 16px; }
.help[hidden] { display: none; }
.help__card { background: var(--paper); border-radius: 16px; padding: 32px; max-width: 400px; width: 100%; }
.help__card h1 { font: 400 28px var(--serif); margin: 0 0 16px; }
.help__card ul { padding: 0; margin: 0 0 24px; list-style: none; }
.help__card li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.help__touch { display: none; }
.is-touch .help__card ul:first-of-type { display: none; }
.is-touch .help__touch { display: block; }
.help .cta { width: 100%; justify-content: center; min-height: 48px; }

/* Joystick (toque) */
.joy { position: fixed; z-index: 10; right: 24px; bottom: 24px; width: 120px; height: 120px; border-radius: 50%; background: rgba(20,32,28,.35); border: 2px solid rgba(255,255,255,.5); touch-action: none; }
.joy[hidden] { display: none; }
.joy__knob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%; background: rgba(251,249,245,.92); }

@media (max-width: 760px) {
  .bar { flex-wrap: wrap; }
  .bar .cta { display: none; }
  .bar__title { flex: 1; }
  .seg { order: 3; width: 100%; }
  .seg button { flex: 1; }
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh; border-radius: 16px 16px 0 0; }
  .panel.is-closed { transform: translateY(calc(100% - 48px)); }
  .panel__handle { display: block; border: 0; background: none; height: 48px; font-weight: 700; font-size: 14px; border-bottom: 1px solid var(--line); flex: none; }
  .catalog { grid-template-columns: 1fr 1fr 1fr; }
  .selbar { bottom: 64px; }
  .selbar kbd { display: none; }
  .joy { bottom: 72px; right: 16px; }
  .toast { top: 128px; }
}
