:root {
  --bg: #f6f4ef; --panel: #ffffff; --ink: #1d2733; --muted: #6b7684; --line: #e3dfd6;
  --accent: #1f6f5c; --accent-ink: #ffffff; --warn: #a15c07; --user: #e9f1ee; --shadow: 0 6px 24px rgba(20, 30, 40, .14);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); }
#app { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; height: 100dvh; }
body.viewonly #app { grid-template-columns: 1fr; }
body.viewonly #chat, body.viewonly #history-btn, body.viewonly #share { display: none; }

button, .btn, select { font: inherit; color: inherit; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; cursor: pointer; }
button:hover, .btn:hover { border-color: #c9c3b6; }
button:disabled { opacity: .5; cursor: default; }
#send { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; padding: 7px 18px; }
.ghost { background: transparent; }
.grow { flex: 1; }
select { padding: 6px 8px; max-width: 220px; }

/* chat */
#chat { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-height: 0; }
#chat header { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
#chat header select { flex: 1; min-width: 0; max-width: none; font-weight: 600; }
#notice { margin: 10px; padding: 10px 12px; border-radius: 8px; background: #fff6e5; color: var(--warn); font-size: 14px; }
#messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.msg { max-width: 94%; padding: 9px 12px; border-radius: 12px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: #f5f3ee; border-bottom-left-radius: 4px; }
.msg.error { align-self: stretch; background: #fdecea; color: #8a1f17; }
.msg p { margin: 0 0 8px; } .msg p:last-child, .msg ul:last-child, .msg ol:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0 0 8px; padding-left: 20px; }
.msg code { background: rgba(0, 0, 0, .06); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.msg h3 { margin: 4px 0 6px; font-size: 15px; }
.activity { align-self: flex-start; font-size: 13px; color: var(--muted); border-left: 2px solid var(--line); padding: 2px 0 2px 10px; }
.activity summary { cursor: pointer; list-style: none; display: flex; gap: 8px; align-items: center; }
.activity summary::-webkit-details-marker { display: none; }
.activity .steps { margin-top: 4px; display: flex; flex-direction: column; gap: 2px; }
.activity .step.bad { color: var(--warn); }
.spin { width: 11px; height: 11px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
.thinking { font-style: italic; }

#issues { border-top: 1px solid var(--line); max-height: 30%; overflow-y: auto; padding: 8px 12px; font-size: 14px; background: #fffaf0; }
.issues-head { font-weight: 600; margin-bottom: 4px; }
#issues ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
#issues li { display: flex; gap: 8px; align-items: flex-start; }
#issues li button { padding: 2px 8px; font-size: 12px; flex: none; }
#notes { margin-top: 6px; color: var(--muted); } #notes summary { cursor: pointer; } #notes ul { margin-top: 6px; }
#issues .sev { flex: none; font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--warn); margin-top: 3px; width: 16px; }

#composer { border-top: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
#composer textarea { width: 100%; resize: vertical; min-height: 54px; max-height: 40vh; font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fcfbf8; color: inherit; }
#composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#composer .row { display: flex; gap: 8px; align-items: center; }
#files { display: flex; flex-wrap: wrap; gap: 6px; }
#files:empty { display: none; }
.chip { font-size: 13px; background: var(--user); border-radius: 999px; padding: 3px 4px 3px 10px; display: flex; gap: 4px; align-items: center; }
.chip button { border: 0; background: transparent; padding: 0 6px; font-size: 15px; line-height: 1; }
#cost { font-size: 12px; color: var(--muted); min-height: 16px; font-variant-numeric: tabular-nums; }

/* stage */
#stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#view { position: absolute; inset: 0; }
#view canvas { display: block; }
#empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; background: var(--bg); }
#empty h1 { font-size: clamp(22px, 3vw, 32px); margin: 0 0 10px; max-width: 18em; }
#empty p { margin: 4px auto; max-width: 34em; color: var(--muted); }
#empty .small { font-size: 14px; }
#bar { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; pointer-events: none; }
#bar > * { pointer-events: auto; }
.seg { display: flex; padding: 3px; gap: 2px; background: rgba(255, 255, 255, .95); border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 2px 10px rgba(20, 30, 40, .1); }
.seg button { border: 0; background: transparent; padding: 7px 13px; border-radius: 8px; font-size: 14px; white-space: nowrap; }
.seg button:hover { background: rgba(0, 0, 0, .05); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg.tools button { font-size: 13px; padding: 6px 11px; }
.seg.tools button.open { background: var(--user); }

#floors { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 4px; align-items: stretch; background: rgba(255, 255, 255, .95); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 2px 10px rgba(20, 30, 40, .1); max-width: 150px; }
.floors-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); text-align: center; padding: 2px 0; }
#floor-list { display: flex; flex-direction: column; gap: 2px; }
#floors button { border: 0; background: transparent; padding: 7px 10px; border-radius: 8px; font-size: 13px; text-align: center; }
#floors button:hover:not(:disabled) { background: rgba(0, 0, 0, .05); }
#floors button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
#floors #lift { border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 2px; padding-top: 8px; color: var(--muted); }
#floors #lift.on { background: var(--user); color: var(--ink); }

#walk-hud { position: absolute; left: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; pointer-events: none; }
#walk-hud > * { pointer-events: auto; }
#where { background: rgba(255, 255, 255, .95); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; box-shadow: 0 2px 10px rgba(20, 30, 40, .1); }
#where:empty { display: none; }
#map { width: 220px; height: 220px; background: rgba(255, 255, 255, .95); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 2px 10px rgba(20, 30, 40, .1); cursor: pointer; touch-action: none; }
.hint, .hint-pill { font-size: 12px; color: var(--ink); background: rgba(255, 255, 255, .85); border-radius: 999px; padding: 3px 10px; }
.hint-pill { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); white-space: nowrap; pointer-events: none; }

#compare-hud { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; background: rgba(255, 255, 255, .95); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; font-size: 13px; box-shadow: 0 2px 10px rgba(20, 30, 40, .1); max-width: calc(100% - 20px); flex-wrap: wrap; justify-content: center; }
#compare-hud select { border: 0; background: transparent; padding: 2px; font-size: 13px; }
.legend { display: flex; gap: 5px; align-items: center; color: var(--muted); white-space: nowrap; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 6px; }
.slider, .check { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.slider input { width: 100px; accent-color: var(--accent); }
.slider.wide { margin: 8px 0; font-size: 13px; } .slider.wide input { flex: 1; } .slider.wide select { flex: 1; max-width: none; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.quick button { font-size: 13px; padding: 6px; }
#hour-out { width: 3.2em; font-variant-numeric: tabular-nums; text-align: right; }
.panel { position: absolute; top: 60px; right: 10px; width: min(320px, calc(100% - 20px)); max-height: calc(100% - 78px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 12px; }
.panel h2 { font-size: 14px; margin: 0 0 8px; }
.panel .opt { margin-bottom: 10px; }
.panel .opt label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button { padding: 4px 8px 4px 4px; font-size: 12px; display: flex; gap: 6px; align-items: center; }
.swatches button.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.swatches i { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, .15); display: block; }
.panel .free { font-size: 12px; color: var(--muted); margin-top: 4px; }
#history ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 4px; }
#history li { display: flex; gap: 8px; align-items: center; font-size: 13px; }
#history li span { flex: 1; }
#history li button { padding: 2px 8px; font-size: 12px; }
#drop { position: absolute; inset: 12px; border: 3px dashed var(--accent); border-radius: 16px; background: rgba(31, 111, 92, .1); display: grid; place-content: center; font-size: 20px; font-weight: 600; color: var(--accent); pointer-events: none; }
#drop[hidden], #empty[hidden], .panel[hidden], #bar[hidden], #floors[hidden], #walk-hud[hidden], #compare-hud[hidden], .hint-pill[hidden], #lift[hidden] { display: none; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 52dvh 48dvh; }
  #stage { grid-row: 1; } #chat { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); }
  #map { width: 130px; height: 130px; }
  #walk-hud .hint, .hint-pill { display: none; }
  .seg button { padding: 6px 9px; font-size: 13px; }
  #floors { top: auto; bottom: 10px; transform: none; }
}

/* chat panel toggle */
body.nochat #app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
body.nochat #chat { display: none; }
#chat-show { position: absolute; left: 10px; top: 10px; z-index: 2; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; padding: 9px 14px; border-radius: 11px; box-shadow: 0 2px 10px rgba(20, 30, 40, .18); }
#chat-show[hidden] { display: none; }
#chat-show.dot::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #ffd36b; margin-left: 7px; vertical-align: 1px; }
body.nochat #bar { left: 84px; }
body.nochat #walk-hud { bottom: 10px; }
body.viewonly #chat-show { display: none; }
@media (max-width: 760px) {
  /* On a phone the view tabs need the full width, so they sit under the Chat button. */
  body.nochat #bar { left: 10px; top: 56px; }
  body.nochat .panel { top: 150px; }
}

/* inspiration */
#composer .row { flex-wrap: wrap; }
.chip.inspo { background: #f6ead9; }
.chip .kind { border: 0; background: transparent; padding: 0 2px 0 0; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); cursor: pointer; }
.panel.wide { width: min(420px, calc(100% - 20px)); }
#inspo .brief { margin: 0 0 12px; font-size: 13px; }
#inspo .brief b { display: block; margin-bottom: 2px; }
#inspo .thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#inspo figure { margin: 0; font-size: 11px; color: var(--muted); }
#inspo img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: #eee; }
#inspo figcaption { margin-top: 2px; line-height: 1.25; }
#inspo-btn[hidden] { display: none; }

/* click to edit, measure */
.panel.left { right: auto; left: 10px; width: min(300px, calc(100% - 20px)); }
#edit h2 { margin-bottom: 2px; } #edit .sub { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
#edit .rowb { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
#edit .rowb button { font-size: 13px; padding: 5px 9px; }
#edit .danger { color: #a3261c; }
#edit .swatches { max-height: 210px; overflow-y: auto; }
.hint-pill.top { bottom: auto; top: 62px; pointer-events: auto; font-size: 13px; padding: 5px 12px; box-shadow: 0 2px 10px rgba(20, 30, 40, .1); }
.seg.tools button.active { background: var(--accent); color: var(--accent-ink); }
body.viewonly #edit-btn, body.viewonly #undo, body.viewonly #redo { display: none; }
#undo, #redo { font-size: 16px; line-height: 1; } #undo:disabled, #redo:disabled { opacity: .35; cursor: default; }
#edit input.find { width: 100%; margin: 0 0 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 13px; background: transparent; color: inherit; }
#edit .adds { max-height: 300px; } #edit .note { font-size: 12px; background: rgba(200, 150, 40, .14); border-radius: 8px; padding: 8px; margin-bottom: 10px; }

/* accounts, credit, stills */
#estimate { font-size: 13px; background: #f3efe6; border-radius: 8px; padding: 6px 10px; }
#estimate[hidden] { display: none; }
#account { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: 12px; }
#topup button { font-size: 12px; padding: 3px 8px; margin-left: 4px; }
#topup[hidden], #signout[hidden] { display: none; }
#auth { position: fixed; inset: 0; background: var(--bg); display: grid; place-content: center; z-index: 50; padding: 20px; }
#auth[hidden] { display: none; }
#auth form { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
#auth h1 { margin: 0; font-size: 22px; } #auth p { margin: 0; color: var(--muted); font-size: 14px; }
#auth label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
#auth input { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; }
#auth .row { display: flex; gap: 8px; } #auth .row button { flex: 1; } #auth-in { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
#stills .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#stills img { width: 100%; border-radius: 8px; display: block; cursor: zoom-in; }
#stills .make { width: 100%; margin-bottom: 8px; background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
#still-btn[hidden] { display: none; }
body.viewonly #still-btn, body.viewonly #inspo-btn, body.viewonly #options-btn { display: none; }

@media (max-width: 900px) {
  /* Many tools, little width: let the row scroll sideways. */
  .seg.tools { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .seg.tools::-webkit-scrollbar { display: none; }
  #bar { flex-wrap: wrap; }
}

.quick button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

#code-box[hidden] { display: none; } #code-box { display: inline-flex; gap: 6px; margin-top: 6px; }
#code-in { font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; width: 150px; text-transform: uppercase; background: var(--panel); color: inherit; }
#code-go { font-size: 13px; padding: 5px 10px; }
a.link { color: var(--accent); font-size: 12px; } a.link[hidden] { display: none; }

/* working together: what an editor or a viewer does not get */
body.role-viewer #composer, body.role-viewer #edit-btn, body.role-viewer #undo, body.role-viewer #redo, body.role-viewer #options-btn,
body.role-viewer #history-btn, body.role-viewer #issues, body.role-viewer #still-btn { display: none; }
body.role-viewer #share, body.role-editor #share, body.role-viewer #rename, body.role-editor #rename { display: none; }
body.role-editor.no-ask #composer { display: none; }
#rolebar { font-size: 13px; background: var(--user); border-radius: 10px; padding: 8px 10px; margin: 8px 12px 0; }
#rolebar[hidden] { display: none; } #rolebar button { margin-left: 6px; }
#sharing h2 { margin-top: 14px; } #sharing h2:first-child { margin-top: 0; }
#sharing .line { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
#sharing .line:last-of-type { border-bottom: 0; } #sharing .line span { overflow: hidden; text-overflow: ellipsis; }
#sharing .rowb { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; } #sharing button, #sharing select { font-size: 13px; padding: 5px 9px; }
#sharing label.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin-top: 10px; white-space: normal; } #sharing label.check span { min-width: 0; flex: 1; }
#history .by { color: var(--muted); font-size: 12px; }
#auth-code-row[hidden] { display: none; } #auth label small { color: var(--muted); }
