.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.is-builder .site-header .wrap { width: calc(100% - 2rem); min-height: 56px; }
.is-builder .brand img { width: 120px; }

.builder { position: relative; display: grid; grid-template-columns: 268px minmax(0, 1fr) 308px; grid-template-rows: auto minmax(0, 1fr); height: calc(100vh - 57px); height: calc(100dvh - 57px); min-height: 520px; border-bottom: 3px solid var(--ink); background: #fff; font-size: .94rem; line-height: 1.45; }
.builder h2 { font-size: 1.2rem; margin: 0; }
.builder h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.builder button, .builder input, .builder select { font-family: var(--body); color: var(--ink); }
.bar { grid-column: 1 / -1; display: flex; align-items: center; gap: .8rem; padding: .45rem .8rem; border-bottom: 1px solid var(--line); min-width: 0; }
.bar .name input { width: 220px; border: 1px solid transparent; border-radius: 8px; padding: .35rem .5rem; font: 600 1.05rem var(--display); }
.bar .name input:hover, .bar .name input:focus { border-color: var(--line); }
#save-state { font-size: .8rem; color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.bar-tools { display: flex; gap: .35rem; }
.tool { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-width: 38px; height: 38px; padding: 0 .55rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-weight: 700; font-size: .88rem; flex: none; }
.tool:hover:not(:disabled) { background: var(--mist); border-color: var(--ink); }
.tool:disabled { opacity: .35; cursor: default; }
.tool.primary { background: var(--coral); border-color: var(--ink); }
.tool.danger { color: #b3152f; }
.tool[aria-pressed="true"] { background: var(--ink); color: #fff; }

.library, .panel { min-height: 0; display: flex; flex-direction: column; background: #fff; }
.library { border-right: 1px solid var(--line); }
.panel { border-left: 1px solid var(--line); }
.sheet-head { display: none; align-items: center; justify-content: space-between; padding: .4rem .8rem; }
.lib-tabs { display: flex; flex-wrap: wrap; gap: .3rem; padding: .6rem; border-bottom: 1px solid var(--line); }
.lib-tabs button { border: 0; background: #f4f1fb; border-radius: 999px; padding: .3rem .7rem; font-size: .83rem; font-weight: 700; cursor: pointer; }
.lib-tabs button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.lib-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: .5rem; padding: .6rem; }
.lib-item { display: flex; flex-direction: column; align-items: center; gap: .25rem; width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: .4rem; cursor: grab; font-size: .77rem; line-height: 1.2; text-align: center; user-select: none; }
.lib-item:hover { border-color: var(--ink); background: var(--mist); }
.lib-item svg, .lib-item img { width: 100%; height: 76px; object-fit: contain; pointer-events: none; }
.lib-item svg.dark { background: #8d84a0; border-radius: 8px; }
.ghost-drag { position: fixed; width: 110px; transform: translate(-50%, -50%); pointer-events: none; opacity: .8; z-index: 60; }
.lib-asset { position: relative; }
.lib-remove { position: absolute; top: 2px; right: 2px; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 1.1rem; line-height: 1; }
.upload-box { grid-column: 1 / -1; background: var(--mist); border-radius: 12px; padding: .8rem; }
.upload-box p { font-size: .8rem; margin: .7rem 0 0; }

.work { position: relative; min-width: 0; min-height: 0; background: #f3f1f8 radial-gradient(#d8d2e8 1px, transparent 1px) 0 0 / 18px 18px; overflow: hidden; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; touch-action: none; user-select: none; cursor: default; }
#stage text { user-select: none; }
#stage.busy #items g[filter] { filter: none; }
#stage #room { pointer-events: none; }
#stage .movable { cursor: move; }
.empty-hint { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: #fff; border: 2px dashed var(--ink); border-radius: 14px; padding: .7rem 1rem; text-align: center; pointer-events: none; width: max-content; max-width: 80%; margin: 0; }
.view-tools { position: absolute; left: .6rem; top: .6rem; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; max-width: calc(100% - 1.2rem); }
.view-tools .check { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 0 .55rem; height: 38px; }
.check { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; cursor: pointer; }
.selbar { position: absolute; left: 50%; bottom: .7rem; transform: translateX(-50%); background: #fff; border: 2px solid var(--ink); border-radius: 16px; padding: .4rem .5rem; box-shadow: 0 6px 20px #2b1b4a33; width: max-content; max-width: calc(100% - 1rem); }
.selbar p { margin: 0 0 .3rem; font-size: .8rem; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; margin-inline: auto; }
.sel-row { display: flex; flex-wrap: wrap; justify-content: center; gap: .25rem; }
.mobile-only { display: none !important; }
.a-left .ico, .a-right .ico, .a-up .ico, .a-down .ico { display: none; }
.a-up::before { content: '▲'; }
.a-down::before { content: '▼'; }
.a-left::before { content: '◀'; }
.a-right::before { content: '▶'; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-bottom: 3px solid transparent; background: none; padding: .65rem .2rem; font-weight: 700; font-size: .84rem; cursor: pointer; }
.tabs button[aria-selected="true"] { border-color: var(--coral); background: #fff4f5; }
.pane { flex: 1; overflow-y: auto; padding: .8rem; min-height: 0; }
.pane fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.hint { color: var(--soft); font-size: .85rem; }
.hint.warn { background: #fff2cc; border-radius: 8px; padding: .5rem .7rem; color: var(--ink); }
.field { display: grid; gap: .2rem; font-size: .8rem; font-weight: 700; margin-bottom: .6rem; min-width: 0; }
.field input, .field select { width: 100%; min-width: 0; padding: .45rem .55rem; border: 1px solid #c9c1dc; border-radius: 8px; font-size: .95rem; background: #fff; }
.field input[type="range"] { padding: 0; border: 0; accent-color: var(--violet); min-height: 34px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .45rem; margin: .5rem 0 .8rem; }
.color-row { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; margin: .5rem 0; }
.color-row > span { font-size: .8rem; font-weight: 700; width: 100%; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #a99fc0; cursor: pointer; padding: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--ink); }
input[type="color"] { width: 40px; height: 34px; padding: 2px; border: 1px solid #c9c1dc; border-radius: 8px; background: #fff; cursor: pointer; }
.palette-list { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.palette-list button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: .4rem; font-size: .76rem; cursor: pointer; }
.palette-list button[aria-pressed="true"] { border: 2px solid var(--ink); }
.palette-list span, .dots { display: flex; align-items: center; gap: 0; }
.palette-list i { flex: 1; height: 16px; }
.palette-list span { margin-bottom: .25rem; border-radius: 4px; overflow: hidden; }
.layers { list-style: none; margin: 0; padding: 0; }
.layers li { display: flex; align-items: center; gap: .25rem; border: 1px solid var(--line); border-radius: 10px; padding: .2rem .3rem; margin-bottom: .3rem; background: #fff; }
.layers li.active { border: 2px solid var(--violet); background: #f5f0ff; }
.layers li.off .layer-name { opacity: .45; text-decoration: line-through; }
.layers li.dragging { opacity: .6; box-shadow: 0 4px 14px #2b1b4a40; }
.grip { cursor: grab; touch-action: none; padding: .3rem .35rem; color: var(--soft); user-select: none; }
.layer-name { flex: 1; min-width: 0; text-align: left; background: none; border: 0; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: .35rem 0; font-size: .85rem; }
.layer-btns { display: flex; gap: 2px; }
.layer-btns button { width: 30px; height: 32px; display: grid; place-items: center; border: 0; background: none; border-radius: 6px; cursor: pointer; font-size: .7rem; padding: 0; }
.layer-btns button:hover { background: var(--mist); }
.layer-btns button[aria-pressed="true"] { background: var(--sun); }
.layer-btns .ico { width: 17px; height: 17px; }
.item-list { list-style: none; margin: 0; padding: 0; }
.item-list li { display: flex; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.item-list b { min-width: 2.2rem; font: 600 1.1rem var(--display); }
.item-list strong { display: block; font-size: .88rem; }
.item-list small { display: block; color: var(--soft); font-size: .78rem; }
.dots { gap: 3px; flex-wrap: wrap; }
.dots i { width: 13px; height: 13px; border-radius: 50%; border: 1px solid #0003; }
.dots small { margin-left: .25rem; }

.mobile-nav { display: none; }
.builder dialog { width: min(720px, calc(100% - 1.2rem)); max-height: 90vh; max-height: 90dvh; border: 3px solid var(--ink); border-radius: 20px; padding: 0; color: var(--ink); }
.builder dialog::backdrop { background: #2b1b4a99; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1.1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
#dialog-body { padding: 1rem 1.1rem 1.2rem; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .7rem; margin-top: 1rem; }
.models { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; }
.models legend { font-weight: 700; margin-bottom: .5rem; }
.model { display: flex; flex-direction: column; gap: .3rem; border: 2px solid var(--line); border-radius: 12px; padding: .45rem; cursor: pointer; position: relative; }
.model input { position: absolute; opacity: 0; }
.model:has(input:checked) { border-color: var(--ink); background: var(--mist); box-shadow: 0 0 0 2px var(--cyan); }
.model:has(input:focus-visible) { outline: 3px solid var(--violet); }
.model svg, .blank-thumb { width: 100%; aspect-ratio: 300 / 312; border-radius: 8px; }
.blank-thumb { display: grid; place-items: center; border: 2px dashed #b5abcd; color: var(--soft); }
.model strong { font-size: .85rem; line-height: 1.2; }
.model small { font-size: .74rem; color: var(--soft); line-height: 1.3; }
.export-preview { background: #f3f1f8; border-radius: 12px; padding: .6rem; margin-bottom: .8rem; }
.export-preview svg { display: block; width: 100%; height: 34vh; }
.project-list { list-style: none; padding: 0; margin: 0; }
.project-list li { display: grid; grid-template-columns: 96px 1fr; gap: .8rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.project-list .mini svg { width: 96px; height: 100px; }
.project-list small { display: block; color: var(--soft); }
.toast { position: fixed; left: 50%; bottom: 5rem; transform: translate(-50%, 20px); background: var(--ink); color: #fff; border-radius: 12px; padding: .65rem 1rem; width: max-content; max-width: calc(100% - 2rem); opacity: 0; visibility: hidden; transition: .2s; z-index: 70; text-align: center; }
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

@media (max-width: 1180px) and (min-width: 961px) {
  .builder { grid-template-columns: 218px minmax(0, 1fr) 270px; }
  .bar .tool span { display: none; }
}

@media (max-width: 960px) {
  .builder { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; height: calc(100vh - 57px); height: calc(100dvh - 57px); min-height: 460px; }
  .bar { flex-wrap: wrap; gap: .3rem .5rem; padding: .35rem .5rem; }
  .bar .name { flex: 1; min-width: 120px; }
  .bar .name input { width: 100%; }
  #save-state { flex: 0 1 auto; font-size: .7rem; max-width: 45%; }
  .bar-tools { width: 100%; justify-content: space-between; }
  .bar .tool span { display: none; }
  .work { grid-row: 2; }
  .library, .panel { position: absolute; left: 0; right: 0; bottom: 56px; height: min(56%, 460px); z-index: 15; border: 3px solid var(--ink); border-bottom: 0; border-radius: 20px 20px 0 0; display: none; box-shadow: 0 -8px 30px #2b1b4a40; }
  .builder[data-sheet="library"] .library, .builder[data-sheet="panel"] .panel { display: flex; }
  .builder[data-sheet] .selbar { display: none; }
  .sheet-head { display: flex; }
  .lib-tabs { flex-wrap: nowrap; overflow-x: auto; flex: none; }
  .lib-tabs button { flex: none; padding: .45rem .8rem; }
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .field input, .field select { font-size: 1rem; min-height: 40px; }
  .mobile-nav { grid-row: 3; display: grid; grid-template-columns: repeat(5, 1fr); height: 56px; border-top: 2px solid var(--ink); background: #fff; z-index: 16; }
  .mobile-nav button { border: 0; background: none; font-weight: 700; font-size: .82rem; cursor: pointer; }
  .mobile-nav button[aria-pressed="true"] { background: var(--sun); }
  .view-tools .check { font-size: .74rem; padding: 0 .4rem; }
  .mobile-only { display: inline-flex !important; }
  .sel-row.mobile-only { display: flex !important; margin-bottom: .25rem; }
  .selbar { bottom: .4rem; width: calc(100% - .8rem); max-width: 430px; }
  .selbar .sel-row { display: grid !important; grid-template-columns: repeat(8, 1fr); }
  .selbar .tool { min-width: 0; width: 100%; height: 40px; padding: 0; }
  .models { grid-template-columns: 1fr 1fr; }
  .toast { bottom: auto; top: 7.5rem; }
}
@media (max-width: 960px) and (max-height: 560px) {
  .builder { height: 560px; }
}
