:root {
  --bg: #eef0ef;
  --card: rgba(255, 255, 255, 0.95);
  --ink: #1c1e21;
  --muted: #676c72;
  --line: #e3e1dc;
  --soft: #f3f2ee;
  --accent: #2463d1;
  --accent-soft: #e6eefc;
  --amber: #b87503;
  --amber-soft: #fdf3dd;
  --shadow: 0 6px 24px rgba(20, 24, 30, 0.14), 0 1px 3px rgba(20, 24, 30, 0.08);
  --radius: 12px;
  --gap: 14px;
  --foot-h: 30px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
#app { position: fixed; inset: 0; overflow: hidden; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.icon { width: 36px; height: 36px; border: 0; border-radius: 9px; background: transparent; display: grid; place-items: center;
  cursor: pointer; flex: none; }
.icon:hover { background: var(--soft); }
.icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* header */
#top { position: absolute; top: var(--gap); left: var(--gap); display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); max-width: calc(100% - 2 * var(--gap)); z-index: 5; }
#top .title { min-width: 0; padding: 0 4px; }
#top h1 { font-size: 16px; margin: 0; letter-spacing: 0.01em; white-space: nowrap; }
#top p { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* openings list */
#list { position: absolute; top: 84px; left: var(--gap); bottom: calc(var(--foot-h) + 72px); width: 304px; display: flex;
  flex-direction: column; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 4; overflow: hidden; }
#list.closed { display: none; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 8px 14px; border-bottom: 1px solid var(--line); }
#list-count { color: var(--muted); font-size: 12px; }
#list-body { overflow-y: auto; padding: 4px 6px 10px; flex: 1; -webkit-overflow-scrolling: touch; }
.list-foot { margin: 0; padding: 8px 14px 10px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.grp { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 12px 8px 4px; }
.row { width: 100%; display: grid; grid-template-columns: 44px 1fr auto; gap: 2px 8px; align-items: center; text-align: left;
  border: 0; background: transparent; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.row:hover { background: var(--soft); }
.row.on { background: var(--accent-soft); }
.row b { font-size: 14px; }
.row .room { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { grid-column: 2; font-size: 12px; color: var(--muted); }
.row .q { grid-row: 1 / span 2; grid-column: 3; }
.pill { display: inline-block; min-width: 20px; padding: 0 6px; height: 20px; line-height: 20px; border-radius: 10px; font-size: 12px;
  font-weight: 600; text-align: center; background: var(--amber-soft); color: var(--amber); }
.pill:empty { display: none; }
body.qmode .row:not(.hasq) { opacity: 0.45; }
.tag-pending { font-size: 11px; color: var(--amber); }

/* panel */
#panel { position: absolute; top: var(--gap); right: var(--gap); width: 372px; max-height: calc(100% - var(--foot-h) - 2 * var(--gap));
  overflow-y: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 6;
  -webkit-overflow-scrolling: touch; }
#panel[hidden] { display: none; }
.p-head { position: sticky; top: 0; background: var(--card); padding: 14px 10px 10px 16px; border-bottom: 1px solid var(--line);
  display: flex; gap: 10px; align-items: flex-start; z-index: 1; }
.p-head .mk { font-size: 26px; font-weight: 700; line-height: 1; }
.p-head .pr { font-size: 13px; color: var(--muted); margin-top: 4px; }
.p-head .grow { flex: 1; min-width: 0; }
.p-body { padding: 12px 16px 16px; }
.kv { display: grid; grid-template-columns: 112px 1fr; gap: 5px 12px; margin: 0 0 12px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-size: 14px; }
.kv dd .sub { display: block; color: var(--muted); font-size: 12px; }
.kv.src { grid-template-columns: 96px 1fr; margin: 0; }
.kv.src dt, .kv.src dd { font-size: 12px; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 8px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); font-weight: 600; }
.btn { border: 1px solid var(--line); background: #fff; padding: 6px 12px; border-radius: 10px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: #c9c6bf; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn[disabled] { opacity: 0.55; cursor: default; }
.sec { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.sec h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.sec ul { margin: 0; padding-left: 18px; }
.sec li { margin: 0 0 6px; }
.qbox { background: var(--amber-soft); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.qbox h4 { color: var(--amber); }
.qbox li b { font-weight: 600; }
.note { font-size: 13px; }
.navrow { display: flex; justify-content: space-between; margin-top: 14px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--soft); color: var(--muted); margin-left: 6px; vertical-align: 2px; }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.dim { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 6px 0 4px; }
.dim span:nth-child(even) { font-weight: 600; text-align: right; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; border: 1px solid rgba(0,0,0,0.15); }
input[type=range] { width: 100%; accent-color: var(--ink); }

/* toolbar */
#toolbar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--foot-h) + 12px); display: flex; gap: 8px;
  align-items: center; padding: 6px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); z-index: 5; max-width: calc(100% - 2 * var(--gap)); }
.tool { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap; font-size: 13px; }
.tool:hover { background: var(--soft); }
.tool[aria-pressed=true] { background: var(--amber-soft); color: var(--amber); font-weight: 600; }
#finish-note { position: absolute; bottom: calc(var(--foot-h) + 64px); left: 50%; transform: translateX(-50%); font-size: 11px;
  color: var(--muted); background: rgba(255, 255, 255, 0.82); padding: 2px 8px; border-radius: 8px; z-index: 4; white-space: nowrap; }
body.detail #toolbar, body.detail #finish-note, body.detail #list, body.detail #compass { display: none; }

/* finishes */
.pop { position: absolute; z-index: 7; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 16px 14px;
  width: 348px; left: 50%; transform: translateX(-50%); bottom: calc(var(--foot-h) + 78px); max-height: calc(100% - 140px); overflow-y: auto; }
.pop[hidden] { display: none; }
.pop-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 2px; }
.pop h3 { font-size: 12px; margin: 14px 0 6px; font-weight: 600; }
.pop h3 span { font-weight: 400; color: var(--muted); margin-left: 4px; }
.pop p { margin: 4px 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.sw.on { box-shadow: 0 0 0 2px var(--ink); }
.sw.wood { border-radius: 8px; width: 74px; height: 30px; font-size: 12px; color: #2a1a0d; font-weight: 600; text-shadow: 0 0 3px rgba(255,255,255,0.6); }

/* compass */
#compass { position: absolute; right: var(--gap); bottom: calc(var(--foot-h) + 14px); width: 46px; height: 46px; z-index: 4;
  background: var(--card); border-radius: 50%; box-shadow: var(--shadow); }
#compass svg { width: 100%; height: 100%; }
#compass circle { fill: none; stroke: var(--line); }
#compass .n { fill: #c0392b; }
#compass .s { fill: #9aa0a6; }
#compass text { font-size: 6px; font-weight: 700; text-anchor: middle; fill: var(--ink); }
#needle { transform-origin: 20px 20px; }

/* footer */
#foot { position: absolute; left: 0; right: 0; bottom: 0; min-height: var(--foot-h); padding: 7px 16px; font-size: 11px; color: #4d5157;
  background: rgba(255, 255, 255, 0.86); border-top: 1px solid var(--line); z-index: 3; text-align: center; }

/* labels in the model */
.tag { pointer-events: auto; cursor: pointer; transform: translateY(-14px); background: rgba(255, 255, 255, 0.95); border-radius: 7px;
  padding: 2px 7px; font-size: 12px; font-weight: 700; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); white-space: nowrap; user-select: none; }
.tag .n { font-weight: 600; color: var(--amber); margin-left: 4px; }
.tag.q { border: 1.5px solid var(--amber); }
.tag.sel { background: var(--accent); color: #fff; }
.tag.sel .n { color: #ffe7b0; }
.tag.pend { background: #fff8e8; color: #6b4b06; border: 1.5px dashed var(--amber); font-weight: 600; }
.dimlabel { background: rgba(28, 30, 33, 0.86); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 5px; white-space: nowrap; }

/* loading and modal */
#loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; background: var(--bg); z-index: 20;
  transition: opacity 0.4s; color: var(--muted); }
#loading.done { opacity: 0; pointer-events: none; }
.bar { width: 180px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--ink); }
.modal { position: absolute; inset: 0; background: rgba(20, 22, 26, 0.34); display: grid; place-items: center; z-index: 30; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); width: min(560px, 100%); max-height: 86vh; overflow-y: auto; padding: 4px 20px 18px; }
.modal-card h4 { margin: 14px 0 4px; font-size: 13px; }
.modal-card p, .modal-card li { font-size: 13px; }
.modal-card ul { padding-left: 18px; margin: 4px 0; }

/* phone */
@media (max-width: 760px) {
  :root { --gap: 8px; --foot-h: 42px; }
  #top { left: 0; right: 0; top: 0; max-width: none; border-radius: 0 0 12px 12px; padding: calc(4px + env(safe-area-inset-top)) 6px 4px; }
  #top h1 { font-size: 15px; }
  #top .title { flex: 1; }
  #list { top: 0; left: 0; bottom: 0; width: min(88vw, 340px); border-radius: 0 12px 12px 0; z-index: 12; padding-top: env(safe-area-inset-top); }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 48vh; border-radius: 16px 16px 0 0; z-index: 11;
    padding-bottom: env(safe-area-inset-bottom); }
  .p-head { padding: 10px 8px 8px 14px; }
  .p-head .mk { font-size: 22px; }
  #toolbar { bottom: calc(var(--foot-h) + 8px); gap: 2px 4px; padding: 4px; flex-wrap: wrap; justify-content: center; width: calc(100% - 16px); }
  #views { width: 100%; }
  #views button { flex: 1; padding: 6px 4px; }
  .tool { padding: 6px 10px; flex: 1; }
  #finish-note { bottom: auto; top: 60px; left: auto; right: 8px; transform: none; }
  #compass { bottom: auto; top: 84px; right: 8px; width: 40px; height: 40px; }
  .pop { left: 0; right: 0; bottom: 0; width: auto; transform: none; border-radius: 16px 16px 0 0; max-height: 70vh; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  #foot { font-size: 10px; padding: 5px 10px calc(5px + env(safe-area-inset-bottom)); }
  body.sheet-open #foot, body.sheet-open #toolbar, body.sheet-open #finish-note { display: none; }
}
