:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --line: #d9d6cf;
  --ink: #1f1f1f;
  --muted: #6b6a66;
  --accent: #1d6fd1;
  --accent-soft: #e3eefb;
  --danger: #c23b22;
  --topbar-h: 48px;
  --toolbar-w: 190px;
  --props-w: 270px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); }
body {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-columns: var(--toolbar-w) 1fr var(--props-w);
  grid-template-areas: "top top top" "tools canvas props";
  height: 100vh;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
kbd { background: #eee; border: 1px solid #ccc; border-radius: 3px; padding: 0 4px; font-size: 11px; }

#topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
#topbar .group { display: flex; align-items: center; gap: 6px; position: relative; }
#topbar .group.right { margin-left: auto; flex-shrink: 0; }
#topbar .group:first-child { flex-shrink: 0; }
.brand { font-weight: 600; margin-right: 6px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { width: 24px; height: 24px; display: block; }
button.text { white-space: nowrap; padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
button.text:hover { background: var(--accent-soft); }
button.text.active { background: var(--ink); color: #fff; border-color: var(--ink); }
button.user { padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--accent-soft); color: var(--ink); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.user::before { content: "@"; color: var(--muted); }
.dialog.login { text-align: center; max-width: 340px; padding: 32px 28px 24px; }
.biglogo { width: 48px; height: 48px; margin-bottom: 12px; }
.dialog.login h2 { font-size: 18px; margin: 0 0 6px; letter-spacing: -0.01em; }
.dialog.login .tagline { margin: 0 0 20px; line-height: 1.45; }
.login-tabs { display: flex; background: #eeece6; border-radius: 9px; padding: 3px; margin: 0 0 12px; }
.dialog .login-tabs button { flex: 1; border: 0; margin: 0; background: transparent; padding: 6px; border-radius: 7px; color: var(--muted); box-shadow: none; }
.dialog .login-tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
#loginForm { display: flex; gap: 8px; }
#loginForm input { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 15px; background: #fff; }
#loginForm input:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }
#loginForm button { margin: 0; padding: 0 16px; background: var(--ink); color: #fff; border-color: var(--ink); border-radius: 9px; font-weight: 600; }
#loginForm button:disabled { opacity: .5; }
.dialog.login #loginMsg { margin: 14px 0 0; line-height: 1.45; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
#loginMsg.error { color: var(--danger); }
#props input[type=range] { flex: 1; }
#props .bgprev { max-width: 100%; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; display: block; }
#topbar select, #props select, #props input[type=text], #props input[type=number] {
  padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
button.icon {
  width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
  font-size: 15px; line-height: 1;
}
button.icon:hover { background: var(--accent-soft); }
.menu {
  position: absolute; top: 34px; left: 0; z-index: 20;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.12); padding: 4px; min-width: 190px;
  display: flex; flex-direction: column;
}
.menu button { text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 5px; }
.menu button:hover { background: var(--accent-soft); }
.menu button.danger { color: var(--danger); }
.status { color: var(--muted); font-size: 12px; min-width: 0; text-align: right; white-space: nowrap; }
.status.dirty { color: #b57a00; }
.status.error { color: var(--danger); }
.toggle { display: flex; align-items: center; gap: 4px; color: var(--muted); white-space: nowrap; }

#floorTabs { gap: 4px; min-width: 0; flex: 0 1 auto; }
#floorTabs .tab { white-space: nowrap; min-width: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis;
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
#floorTabs .tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
#floorTabs .tab.add { color: var(--muted); }
#floorTabs .tabgroup { position: relative; display: inline-flex; min-width: 0; flex: 0 1 auto; }
#floorTabs .tab.add, #floorTabs .tab.caret { flex-shrink: 0; }
#floorTabs .tab.has-versions { border-top-right-radius: 0; border-bottom-right-radius: 0; }
#floorTabs .tab.caret { padding: 5px 7px; border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; font-size: 11px; }
#floorTabs .tab.caret.active { border-left: 1px solid rgba(255,255,255,.25); }
#floorTabs .floormenu { top: 34px; left: 0; min-width: 200px; }
#floorTabs .floormenu button.current { font-weight: 600; }

#toolbar {
  grid-area: tools;
  background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 8px;
}
.section { margin-bottom: 10px; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 8px 4px 4px; }
.tool {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 8px; border: 1px solid transparent; border-radius: 6px; background: none; text-align: left;
}
.tool:hover { background: var(--accent-soft); }
.tool.active { background: var(--ink); color: #fff; }
.tool .ico { width: 18px; text-align: center; font-size: 14px; }
.fixtures { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.fixtures button {
  border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 4px 2px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--muted);
}
.fixtures button svg { width: 44px; height: 30px; }
.fixtures button:hover { background: var(--accent-soft); }
.fixtures button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }

#canvasWrap { grid-area: canvas; position: relative; overflow: hidden; background: #fbfaf7; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
#canvas.tool-select { cursor: default; }
#canvas.tool-room, #canvas.tool-wall, #canvas.tool-door, #canvas.tool-window, #canvas.tool-fixture, #canvas.tool-label { cursor: crosshair; }
#canvas.panning { cursor: grabbing; }
#canvas text { pointer-events: none; }
#canvas .room-label { font-size: 200px; font-family: inherit; }
#canvas .handle { fill: #fff; stroke: var(--accent); stroke-width: 1.5px; vector-effect: non-scaling-stroke; cursor: pointer; }
#canvas .handle.mid { fill: var(--accent-soft); opacity: .8; cursor: copy; }
#canvas .handle.active { fill: var(--accent); }
#canvas .sel-outline { fill: none; stroke: var(--accent); stroke-width: 1.5px; vector-effect: non-scaling-stroke; stroke-dasharray: 6 4; pointer-events: none; }
.hint {
  position: absolute; left: 12px; bottom: 12px; pointer-events: none;
  background: rgba(31,31,31,.85); color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px;
  max-width: 60%;
}
.hint:empty { display: none; }
#zoomCtl {
  position: absolute; right: 12px; bottom: 12px; display: flex; gap: 2px; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 2px;
}
#zoomCtl button { border: 0; background: none; width: 28px; height: 26px; border-radius: 4px; }
#zoomCtl button:hover { background: var(--accent-soft); }
#zoomCtl span { min-width: 44px; text-align: center; font-size: 12px; color: var(--muted); }

#props {
  grid-area: props; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 12px;
}
#props h3 { margin: 0 0 8px; font-size: 13px; }
#props h4 { margin: 14px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
#props .row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
#props .row label { width: 78px; color: var(--muted); flex-shrink: 0; }
#props .row label[data-scrub] { cursor: ew-resize; user-select: none; -webkit-user-select: none; border-bottom: 1px dotted transparent; }
#props .row label[data-scrub]:hover, #props .row label.scrubbing { color: var(--accent); border-bottom-color: var(--accent); }
#props .row input, #props .row select { flex: 1; min-width: 0; }
#props .row input[type=text] { width: 100%; }
#props .row .unit { color: var(--muted); font-size: 11px; width: 28px; }
#props .btnrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
#props .btnrow button { padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
#props .btnrow button:hover { background: var(--accent-soft); }
#props .btnrow button.danger { color: var(--danger); }
#props .muted { color: var(--muted); }
#props p { margin: 6px 0; line-height: 1.45; }
#props .swatches { display: flex; gap: 4px; flex-wrap: wrap; }
#props .swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
#props .swatch.active { border-color: var(--ink); }
#props .seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex: 1; }
#props .seg button { flex: 1; border: 0; background: #fff; padding: 4px 2px; font-size: 11px; white-space: nowrap; }
#props .seg button.active { background: var(--ink); color: #fff; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; display: flex; align-items: center; justify-content: center; }
.dialog { background: #fff; border-radius: 12px; padding: 20px 24px; max-width: 560px; width: 92%; max-height: 85vh; overflow: auto; }
.dialog h2 { margin: 0 0 10px; font-size: 16px; }
.dialog ul { padding-left: 18px; line-height: 1.5; }
.dialog li { margin-bottom: 4px; }
.dialog button { margin-top: 8px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }

@media (max-width: 1400px) {
  .brand { font-size: 0; gap: 0; }
  .toggle { display: none; }
}
@media (max-width: 900px) {
  :root { --toolbar-w: 150px; --props-w: 220px; }
  button.text { display: none; }
}
@media print {
  #topbar, #toolbar, #props, #zoomCtl, .hint { display: none !important; }
  body { display: block; }
  #canvasWrap { position: fixed; inset: 0; background: #fff; }
}
[hidden] { display: none !important; }
.mcpurl { display: block; font-size: 11px; word-break: break-all; background: #f4f3ef; padding: 6px 8px; border-radius: 6px; }
body.clean { grid-template-columns: 0 1fr 0; grid-template-rows: 0 1fr; }
body.clean #topbar, body.clean #toolbar, body.clean #props, body.clean #zoomCtl, body.clean .hint { display: none !important; }
body.clean #canvasWrap { background: #fff; }
button.text.play { background: var(--ink); color: #fff; border-color: var(--ink); }
button.text.play:hover { background: #333; }
#walk { position: fixed; inset: 0; z-index: 70; background: #000; }
#walkCanvas { display: block; width: 100vw; height: 100vh; cursor: crosshair; }
.walk-hud { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; align-items: center; gap: 10px; color: #fff; font-size: 13px; pointer-events: none; }
.walk-hud > * { pointer-events: auto; }
.walk-hud span { background: rgba(0,0,0,.55); padding: 6px 10px; border-radius: 6px; }
.walk-hud .walk-room { font-weight: 600; font-size: 14px; }
.walk-hud select, .walk-hud button { margin-left: auto; padding: 5px 8px; border-radius: 6px; border: 1px solid rgba(255,255,255,.3); background: rgba(0,0,0,.6); color: #fff; }
.walk-hud button { margin-left: 0; }
.walk-crosshair { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; border: 1.5px solid rgba(255,255,255,.8); pointer-events: none; }
.walk-hint { position: absolute; left: 50%; top: 56%; transform: translateX(-50%); background: rgba(0,0,0,.6); color: #fff; padding: 6px 12px; border-radius: 6px; font-size: 13px; pointer-events: none; }
/* Username and connector URL are masked until hovered, so screenshots do not leak them. */
button.user::after { content: "••••••"; letter-spacing: 1px; }
button.user:hover::after, button.user:focus-visible::after { content: attr(data-user); letter-spacing: normal; }
.mcpurl .secret::after { content: "••••••"; }
.mcpurl:hover .secret::after { content: attr(data-user); }
/* Right panel: tidier layout, collapsible sections, hideable with ⌘\ */
#props { position: relative; }
#props h3 { font-size: 14px; margin: 0 0 2px; padding-right: 28px; }
#props .sub { color: var(--muted); margin: 0 0 4px; line-height: 1.4; }
#props .areas { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; margin-bottom: 8px; }
#props .areas .num { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#props .areas .total { border-top: 1px solid var(--line); padding-top: 5px; margin-top: 2px; font-weight: 600; color: var(--ink); }
#props details { border-top: 1px solid var(--line); margin-top: 14px; }
#props summary { cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 0 4px; list-style: none; display: flex; align-items: center; gap: 6px; user-select: none; -webkit-user-select: none; }
#props summary::-webkit-details-marker { display: none; }
#props summary::before { content: "›"; font-size: 14px; line-height: 1; transition: transform .15s; }
#props details[open] summary::before { transform: rotate(90deg); }
#props summary:hover { color: var(--ink); }
.panelbtn { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); font-size: 16px; line-height: 1; z-index: 3; }
.panelbtn:hover { background: var(--accent-soft); color: var(--ink); }
#propsShow { top: 12px; right: 12px; }
body.noprops { grid-template-columns: var(--toolbar-w) 1fr 0; }
body.noprops #props { display: none; }
body.clean .panelbtn { display: none !important; }
