:root {
  --bg: #f5f4f0; --panel: #ffffff; --ink: #1d1e22; --sub: #6b6c72; --line: #e2e0d8;
  --grid: #e8e5db; --grid5: #d3cfc1; --accent: #18a058; --accent-ink: #fff; --sel: #2f6fe4; --hi: #e5484d;
  --wall: #2b2d33; --room: rgba(24, 160, 88, 0.07); --shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16171a; --panel: #1f2125; --ink: #e8e8ea; --sub: #9a9ba1; --line: #2e3035;
    --grid: #23252a; --grid5: #34373d; --accent: #2fbf71; --accent-ink: #0b1a10; --sel: #6b9bff; --hi: #ff6369;
    --wall: #d9dade; --room: rgba(47, 191, 113, 0.08); --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif; display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }

.top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: calc(env(safe-area-inset-top) + 8px); background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; letter-spacing: -0.02em; font-size: 17px; color: var(--accent); text-decoration: none; }
.floors { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.fl { flex: none; padding: 5px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; color: var(--sub); }
.fl.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.fl.add { border-style: dashed; }
.grow { flex: 1; }
.pill { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; }
.icon { background: none; border: 0; font-size: 20px; padding: 4px 8px; }

.body { flex: 1; display: flex; min-height: 0; }
.lib { width: 220px; flex: none; border-right: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 8px; }
.lib h4 { margin: 10px 4px 4px; font-size: 12px; color: var(--sub); }
.lib .note { margin: 4px; }
.li { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 9px; padding: 5px 6px; }
.li:hover { background: var(--bg); }
.li.on { background: color-mix(in srgb, var(--accent) 16%, transparent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.li canvas { width: 40px; height: 28px; flex: none; }
.li small { color: var(--sub); margin-left: auto; font-size: 11px; }

.stage { flex: 1; position: relative; min-width: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.hint { position: absolute; left: 12px; top: 10px; max-width: calc(100% - 300px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; color: var(--sub); font-size: 12.5px; pointer-events: none; box-shadow: var(--shadow); }
.hint:empty { display: none; }
.sum { position: absolute; left: 12px; bottom: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 12.5px; font-weight: 600; box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
.sum:empty { display: none; }
.props { position: absolute; right: 12px; top: 10px; width: 260px; max-height: calc(100% - 20px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.props h3 { margin: 0 0 8px; font-size: 15px; }
.props label { display: block; font-size: 12px; color: var(--sub); margin: 8px 0 3px; }
.props input, .props select { width: 100%; }
.props .row { display: flex; gap: 6px; margin-top: 10px; }
.props .row > * { flex: 1; }
.props .big { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.btn, .props .row button { padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.note { color: var(--sub); font-size: 12.5px; margin: 6px 0; }
.warn { color: var(--hi); }

.tools { display: flex; justify-content: center; gap: 2px; padding: 6px 8px; padding-bottom: calc(env(safe-area-inset-bottom) + 6px); background: var(--panel); border-top: 1px solid var(--line); }
.tool { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 62px; padding: 4px 8px; border: 0; background: none; border-radius: 10px; font-size: 11.5px; color: var(--sub); }
.tool span { font-size: 17px; line-height: 20px; color: var(--ink); }
.tool.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--ink); }

.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.sheet[hidden] { display: none; }
.sheet-card { background: var(--panel); border-radius: 16px; width: min(680px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.sheet-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sheet-head b { flex: 1; }
.sheet-body { padding: 12px 14px 16px; overflow: auto; }
.sheet-body h4 { margin: 14px 0 6px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.mlist { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.mlist button { text-align: left; padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; }
.mlist small { display: block; font-weight: 500; color: var(--sub); margin-top: 2px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
td, th { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; }
th { color: var(--sub); font-weight: 600; }
td.n { text-align: right; }
.chk { display: flex; gap: 8px; align-items: center; margin: 5px 0; font-weight: 600; }
.chk input { width: auto; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 118px); transform: translateX(-50%); background: #1d1e22; color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 13px; z-index: 30; width: max-content; max-width: calc(100vw - 32px); text-align: center; }
.toast[hidden] { display: none; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  .lib { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 58px); top: auto; width: auto; max-height: 46vh; border-right: 0; border-top: 1px solid var(--line); z-index: 10; box-shadow: var(--shadow); border-radius: 16px 16px 0 0; display: none; }
  .lib.open { display: block; }
  .lib .grp { display: flex; flex-wrap: wrap; gap: 4px; }
  .lib .li { width: auto; flex-direction: column; gap: 2px; font-size: 11.5px; min-width: 76px; max-width: 96px; text-align: center; }
  .lib .li small { margin: 0; }
  .tools { justify-content: space-between; }
  .tool { min-width: 0; flex: 1; padding: 4px 1px; font-size: 10.5px; white-space: nowrap; letter-spacing: -0.03em; }
  .tools { padding-left: 4px; padding-right: 4px; gap: 0; }
  .toast { bottom: calc(env(safe-area-inset-bottom) + 118px); }
  .props { top: auto; bottom: 10px; right: 10px; left: 10px; width: auto; max-height: 48%; }
  .hint { max-width: calc(100% - 24px); }
  .sum { bottom: auto; top: 10px; left: auto; right: 12px; }
  .hint:not(:empty) ~ .sum { display: none; }
}
