:root {
  --navy: #1f2a5c;
  --navy-2: #2c3a78;
  --red: #c8323a;
  --ink: #1d2230;
  --muted: #5d6475;
  --panel: rgba(255, 255, 255, 0.94);
  --line: #dfe2ea;
  --bg-top: #e9edf3;
  --bg-bottom: #c9d0db;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg-bottom); }
#app { position: relative; width: 100%; height: 100%; background: linear-gradient(var(--bg-top), var(--bg-bottom)); }
#c { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }

/* control panel */
#panel {
  position: absolute; top: 14px; left: 14px; width: 300px; max-height: calc(100% - 28px);
  background: var(--panel); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(20, 28, 60, 0.18);
  display: flex; flex-direction: column; overflow: hidden; backdrop-filter: blur(6px);
}
#panel header { position: relative; padding: 14px 16px 10px; border-bottom: 3px solid var(--red); background: var(--navy); color: #fff; }
.eyebrow { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.8; }
#panel h1 { margin: 2px 0 0; font-size: 19px; font-weight: 650; }
#collapse { position: absolute; top: 12px; right: 10px; color: #fff; }
#panel.collapsed #panel-body { display: none; }
#panel.collapsed #collapse svg { transform: rotate(180deg); }
#panel-body { padding: 12px 16px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
select {
  font: inherit; font-size: 15px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  color: var(--ink); width: 100%;
}
select:focus-visible, button:focus-visible, input:focus-visible { outline: 2px solid var(--navy-2); outline-offset: 2px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; font: inherit; font-size: 13px; padding: 8px 4px; border: 0; border-right: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; min-height: 36px;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: #f1f3f8; }
.seg button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.seg button:disabled { color: #aab0bd; cursor: default; background: #fafbfc; }
.seg.wrap { flex-wrap: wrap; border: 0; gap: 6px; overflow: visible; }
.seg.wrap button { flex: 1 1 auto; border: 1px solid var(--line); border-radius: 8px; }

.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--navy); }
.check small { color: var(--muted); font-size: 12px; }
.check.disabled { color: #aab0bd; cursor: default; }

#info { border-top: 1px solid var(--line); padding-top: 10px; }
#info h2 { margin: 0 0 4px; font-size: 15px; }
#info p { margin: 0; font-size: 13.5px; line-height: 1.45; color: #394052; }

#panel footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.hint { font-size: 11.5px; color: var(--muted); }
.link { font: inherit; font-size: 12.5px; background: none; border: 0; color: var(--navy-2); text-decoration: underline; cursor: pointer; padding: 4px; }

.icon { background: none; border: 0; cursor: pointer; padding: 6px; border-radius: 6px; display: inline-flex; color: var(--ink); }
#tools { position: absolute; top: 14px; right: 14px; }
#tools .icon { background: var(--panel); box-shadow: 0 2px 10px rgba(20, 28, 60, 0.15); padding: 9px; }

/* measuring */
#app.measuring #c { cursor: crosshair; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.mlabel {
  position: absolute; transform: translate(-50%, -130%); white-space: nowrap;
  background: var(--navy); color: #fff; font-size: 13px; font-weight: 600; padding: 4px 8px; border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.mlabel small { font-weight: 400; opacity: 0.8; margin-left: 4px; }

/* map-style scale bar: alternating dark/light segments with end ticks, feet over metres */
#scalebar {
  position: absolute; right: 62px; top: 14px; pointer-events: none;   /* top right, beside the full-screen button */
  background: rgba(255, 255, 255, 0.86); border-radius: 8px; padding: 6px 9px 5px;
  box-shadow: 0 2px 10px rgba(20, 28, 60, 0.15); font-size: 12px; font-weight: 600; color: var(--ink);
}
.sb-row { display: flex; align-items: center; gap: 7px; height: 16px; }
.sb-bar {
  height: 6px; border: 1.5px solid var(--ink); border-top: 0; min-width: 20px; transition: width 0.15s;
  background: repeating-linear-gradient(90deg, var(--ink) 0 25%, #fff 25% 50%);
  background-size: 100% 100%;
}
.sb-bar.m { border-top: 1.5px solid var(--ink); border-bottom: 0; }
.sb-note { font-size: 10.5px; font-weight: 500; color: var(--muted); margin-top: 1px; }
/* the point the scale bar refers to in the 3D views (not needed in the flat Plan view) */
#centre-dot {
  position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; pointer-events: none;
  border-radius: 50%; border: 2px solid #fff; background: var(--red); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  opacity: 0.85;
}
#scalebar[hidden], #centre-dot[hidden] { display: none; }

/* loading */
#loading {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(340px, 80%);
  background: var(--panel); border-radius: var(--radius); padding: 10px 14px; box-shadow: 0 6px 24px rgba(20, 28, 60, 0.18);
  font-size: 13px; text-align: center; transition: opacity 0.4s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.bar { height: 6px; background: #e3e6ee; border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
#bar-fill { height: 100%; width: 0; background: var(--red); transition: width 0.2s; }

/* credits */
dialog { max-width: 560px; width: calc(100% - 32px); border: 0; border-radius: var(--radius); padding: 20px 22px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); font-size: 14px; line-height: 1.5; }
dialog::backdrop { background: rgba(20, 28, 60, 0.45); }
dialog h2 { margin-top: 0; }
dialog a { color: var(--navy-2); }
.primary { font: inherit; background: var(--navy); color: #fff; border: 0; border-radius: 8px; padding: 8px 18px; cursor: pointer; }

/* phones: the panel becomes a bottom sheet */
@media (max-width: 640px) {
  #panel { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 55%; border-radius: var(--radius) var(--radius) 0 0; }
  #panel header { padding: 10px 14px 8px; }
  #panel h1 { font-size: 16px; }
  #panel-body { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); gap: 10px; }
  #panel.collapsed #collapse svg { transform: none; }
  #collapse svg { transform: rotate(180deg); }
  #info p { font-size: 13px; }
  #loading { bottom: auto; top: 14px; }}
