/* Cold instrument housing around a lit table.
   The chrome is dark and recessive; the viewport is a light studio so that grey
   building geometry reads the way it does on a drafting table. One warm signal
   colour (amber) carries selection state and nothing else. */

:root {
  --hull:        #1a222b;
  --hull-deep:   #121920;
  --plate:       #222e3a;
  --plate-hi:    #2b3947;
  --rule:        #34434f;
  --rule-soft:   #27323d;

  --legend:      #dde5ec;
  --legend-dim:  #8b9cac;
  --legend-faint:#647585;

  --signal:      #f0a44b;
  --signal-deep: #b9752b;
  --ground:      #74c27c;

  --gap:      14px;
  --radius:   3px;
  --dur:      120ms;

  --sans: "Segoe UI Variable Text", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--hull-deep);
  color: var(--legend);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

canvas { display: block; touch-action: none; }

#stage { position: fixed; inset: 0; }

/* Chrome sits on the glass. Pointer events are re-enabled per panel so the
   model stays grabbable everywhere else. */
#chrome {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: grid;
  grid-template-rows: auto 1fr auto;
  /* Zero minimums, so a panel wider than a phone scrolls inside itself
     instead of widening the grid past the screen. */
  grid-template-columns: minmax(0, 1fr);
}
#chrome > div:last-child { grid-template-columns: minmax(0, 1fr); }
#chrome > * { pointer-events: none; }
.panel { pointer-events: auto; }

/* ---------------------------------------------------------------- top rail */

#top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--gap);
}

#identity {
  background: color-mix(in srgb, var(--hull) 88%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 10px 12px 10px;
  min-width: 260px;
  /* backdrop-filter makes this its own stacking context, so the open model
     list can only rise above the logo if the whole card does. */
  position: relative;
  z-index: 5;
  max-width: 420px;
}

/* The selector stands in for the title, so it is set like one: large, bold,
   and without a boxed field around it. */
#picker { position: relative; }
#picker-button {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
  text-align: left;
  color: var(--legend);
  background: transparent
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='M3 5l4 4 4-4' fill='none' stroke='%238b9cac' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat right 4px center;
  border: none;
  border-bottom: 1px solid var(--rule-soft);
  border-radius: 0;
  padding: 2px 24px 6px 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#picker-button:hover { border-color: var(--rule); }
#picker-button:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }
#picker-button:disabled { cursor: default; background-image: none; }

/* The open list: a picture of each export's start view beside its name, so
   you can see what you are about to load before loading it. */
#picker-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: -6px;
  width: max(100% + 12px, 420px);
  max-width: calc(100vw - 2 * var(--gap));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--hull);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: 0 14px 38px rgba(0, 0, 0, .45);
}
#picker-list[hidden] { display: none; }
#picker-list li {
  display: grid;
  grid-template-columns: 160px 1fr;
  align-items: center;
  gap: 12px;
  padding: 7px 12px 7px 7px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 14px;
  color: var(--legend);
  outline: none;
}
#picker-list li + li { margin-top: 2px; }
#picker-list li:hover,
#picker-list li:focus { background: var(--plate); }
#picker-list li[aria-selected="true"] { box-shadow: inset 2px 0 0 var(--signal); }
#picker-list li[aria-selected="true"] .pick-name { color: var(--signal); }
#picker-list .pick-thumb {
  width: 160px;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 2px;
  border: 1px solid var(--rule-soft);
  background: var(--hull-deep);
  display: block;
}
#picker-list .pick-thumb.none {
  display: grid;
  place-items: center;
  font-size: 10px;
  color: var(--legend-faint);
}
#picker-list .pick-name { min-width: 0; overflow-wrap: anywhere; line-height: 1.35; }

#counts {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--rule-soft);
  font-size: 11px;
  color: var(--legend-faint);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}
#counts b { color: var(--legend-dim); font-weight: 500; font-family: var(--mono); }

/* ------------------------------------------------------------------- brand */

/* Company mark, top right, on the same dark plate as the rest of the chrome
   so the white logo reads. Sized by height; the image keeps its own ratio. */
#brand {
  display: flex;
  align-items: center;
  background: color-mix(in srgb, var(--hull) 88%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 8px 14px;
  height: 46px;
}
#brand img { display: block; height: 100%; width: auto; }
#brand:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* --------------------------------------------------------------- tool rail */

/* The property drawer takes the right edge, so the centred rails shift left by
   half its width to stay centred on the visible model rather than the window. */
#section, #backdrops, #tools { transition: transform 180ms cubic-bezier(.2,.7,.3,1); }
body.drawer-open #section,
body.drawer-open #backdrops,
body.drawer-open #tools { transform: translateX(-168px); }
@media (prefers-reduced-motion: reduce) { #section, #backdrops, #tools { transition: none; } }

#tools {
  justify-self: center;
  align-self: end;
  margin-bottom: var(--gap);
  display: flex;
  align-items: stretch;
  background: color-mix(in srgb, var(--hull) 90%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Hairlines between tools, not boxes around them. */
#tools button + button { border-left: 1px solid var(--rule-soft); }
#tools .sep { width: 1px; background: var(--rule); }

#tools button {
  font: inherit;
  font-size: 12px;
  color: var(--legend-dim);
  background: none;
  border: none;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur), background var(--dur);
}
/* Sits with the view selector, because it is about which views exist - not a
   view tool. The rail below is for manipulating what is already on screen. */
#links { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-top: 9px; }
#admin-actions { display: inline-flex; gap: 6px; }
#admin-actions[hidden] { display: none; }
#admin-actions button {
  font: inherit;
  font-size: 11px;
  color: var(--signal);
  background: none;
  border: 1px solid color-mix(in srgb, var(--signal) 45%, transparent);
  border-radius: 2px;
  padding: 2px 8px;
  cursor: pointer;
}
#admin-actions button:hover:not(:disabled) { background: color-mix(in srgb, var(--signal) 14%, transparent); }
#admin-actions button:disabled { color: var(--legend-faint); border-color: var(--rule-soft); cursor: default; }

#library-link {
  display: inline-block;
  font-size: 11px;
  color: var(--legend-dim);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1px;
}
#library-link:hover { color: var(--signal); border-color: var(--signal); }
#library-link:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

#tools button:hover:not(:disabled) { color: var(--legend); background: var(--plate); }
#tools button:disabled { color: var(--legend-faint); cursor: default; }
#tools button[aria-pressed="true"] { color: var(--signal); background: color-mix(in srgb, var(--signal) 12%, transparent); }
#tools button:focus-visible { outline: 2px solid var(--signal); outline-offset: -2px; }

/* ------------------------------------------------------------ section rail */

#section {
  justify-self: center;
  align-self: end;
  margin-bottom: 6px;
  display: none;
  align-items: center;
  gap: 10px;
  background: color-mix(in srgb, var(--hull) 90%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 7px 12px;
}
#section[data-open="true"] { display: flex; }
#section .axes { display: flex; border: 1px solid var(--rule-soft); border-radius: 2px; overflow: hidden; }
#section .axes button {
  font: inherit; font-size: 12px; font-family: var(--mono);
  color: var(--legend-dim); background: none; border: none;
  padding: 3px 9px; cursor: pointer;
}
#section .axes button + button { border-left: 1px solid var(--rule-soft); }
#section .axes button[aria-pressed="true"] { color: var(--hull-deep); background: var(--signal); }
/* An axis with a cut on it, while another axis is being edited. */
#section .axes button { position: relative; }
#section .axes button.cut::after {
  content: ""; position: absolute; top: 3px; right: 3px;
  width: 4px; height: 4px; border-radius: 50%; background: var(--signal);
}
#section .axes button.cut[aria-pressed="true"]::after { background: var(--hull-deep); }
#section .side { font-size: 11px; color: var(--legend-faint); min-width: 38px; }
#section .side:first-of-type { text-align: right; }
#section .plain {
  font: inherit; font-size: 12px; color: var(--legend-dim);
  background: none; border: 1px solid var(--rule-soft); border-radius: 2px;
  padding: 3px 9px; cursor: pointer;
}
#section .plain:hover { color: var(--legend); border-color: var(--rule); }

/* Two range inputs on one track: each is transparent and ignores the pointer
   except on its own handle. The lit segment between the handles is what the
   cut keeps; --lo and --hi are set from app.js. 7px is half a handle, so the
   segment ends where the handles' centres are. */
#section .dual { --lo: 0; --hi: 1; position: relative; width: 220px; height: 22px; }
#section .dual::before,
#section .dual .keep {
  content: ""; position: absolute; top: 50%; height: 3px; margin-top: -1.5px; border-radius: 2px;
}
#section .dual::before { left: 7px; right: 7px; background: var(--rule); }
#section .dual .keep {
  left: calc(7px + var(--lo) * (100% - 14px));
  right: calc(7px + (1 - var(--hi)) * (100% - 14px));
  background: var(--signal);
}
#section .dual input {
  position: absolute; inset: 0; z-index: 2;
  width: 100%; height: 22px; margin: 0;
  background: none; pointer-events: none;
  -webkit-appearance: none; appearance: none;
}
#section .dual input::-webkit-slider-runnable-track { height: 22px; background: none; }
#section .dual input::-moz-range-track { background: none; }
#section .dual input::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; cursor: ew-resize;
  width: 14px; height: 14px; margin-top: 4px; border-radius: 50%;
  background: var(--signal); border: 2px solid var(--hull-deep);
}
#section .dual input::-moz-range-thumb {
  pointer-events: auto; cursor: ew-resize;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--signal); border: 2px solid var(--hull-deep);
}
#section .dual input:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--legend); outline-offset: 1px; }
#section .dual input:focus-visible::-moz-range-thumb { outline: 2px solid var(--legend); outline-offset: 1px; }

/* ---------------------------------------------------------- background rail */

#backdrops {
  justify-self: center;
  align-self: end;
  margin-bottom: 6px;
  display: none;
  gap: 6px;
  background: color-mix(in srgb, var(--hull) 90%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 7px;
}
#backdrops[data-open="true"] { display: flex; }
#backdrops button {
  display: grid; justify-items: center; gap: 4px;
  font: inherit; font-size: 11px; color: var(--legend-dim);
  background: none; border: 1px solid transparent; border-radius: 2px;
  padding: 4px; cursor: pointer;
}
#backdrops button i {
  display: block; width: 44px; height: 30px; border-radius: 2px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--legend) 18%, transparent);
}
#backdrops button:hover { color: var(--legend); border-color: var(--rule); }
#backdrops button[aria-pressed="true"] { color: var(--signal); border-color: var(--signal); }
#backdrops button:focus-visible { outline: 2px solid var(--signal); outline-offset: -2px; }

/* Element tools act on a picked element, and picking is for admins. */
body.public .el-tool { display: none; }

/* --------------------------------------------------------- property drawer */

#props {
  position: fixed;
  top: var(--gap);
  right: var(--gap);
  bottom: var(--gap);
  width: 322px;
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--hull) 93%, transparent);
  backdrop-filter: blur(16px);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  transform: translateX(calc(100% + var(--gap)));
  transition: transform 180ms cubic-bezier(.2,.7,.3,1);
  overflow: hidden;
}
#props[data-open="true"] { transform: none; }
@media (prefers-reduced-motion: reduce) { #props { transition: none; } }

#props header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule);
  flex: none;
}
#props .row { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
#el-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  word-break: break-word;
}
#close {
  flex: none;
  font: inherit; font-size: 16px; line-height: 1;
  color: var(--legend-faint); background: none; border: none;
  padding: 2px 4px; cursor: pointer;
}
#close:hover { color: var(--legend); }

/* Category reads as a stamped legend plate, not a pill. */
#el-meta { display: flex; align-items: center; gap: 10px; margin-top: 7px; flex-wrap: wrap; }
#el-cat {
  font-size: 11px;
  color: var(--legend-dim);
  border-left: 2px solid var(--signal-deep);
  padding-left: 7px;
}
#el-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--legend-faint);
  font-variant-numeric: tabular-nums;
}

#props .body { overflow-y: auto; padding: 4px 0 14px; flex: 1; scrollbar-width: thin; }
#props .body::-webkit-scrollbar { width: 9px; }
#props .body::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 9px; }

.group { padding: 11px 14px 2px; }
.group + .group { border-top: 1px solid var(--rule-soft); margin-top: 3px; }
.group > h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--legend-dim);
  margin: 0 0 7px;
}

/* Type parameters describe the family type rather than this instance, so they
   sit below a real divider with the type named once. */
.type-head {
  padding: 14px 14px 0;
  margin-top: 10px;
  border-top: 1px solid var(--rule);
}
.type-head h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--signal);
}
.type-head h3 span { color: var(--legend-dim); font-weight: 400; }
.type-head + .group { border-top: none; margin-top: 0; }

.empty { color: var(--legend-faint); font-size: 12px; margin: 0; }

dl { margin: 0; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.15fr); gap: 3px 10px; }
dt { font-size: 12px; color: var(--legend-faint); min-width: 0; overflow-wrap: anywhere; }
dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--legend);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ status */

/* Transient notices only - anything permanent belongs in the identity panel,
   where it cannot collide with the centred tool rail. */
#status {
  position: fixed;
  left: var(--gap);
  bottom: var(--gap);
  font-size: 11px;
  color: var(--legend-faint);
  pointer-events: none;
  max-width: 26vw;
}
#status:empty { display: none; }
#status b { color: var(--legend-dim); font-weight: 500; }

/* The "new view ready" nudge is the one place the chrome asks for attention,
   so it gets the signal colour and nothing else does. */
#status button {
  font: inherit;
  font-size: 11px;
  color: var(--signal);
  background: color-mix(in srgb, var(--signal) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--signal) 40%, transparent);
  border-radius: 2px;
  padding: 3px 8px;
  margin-left: 2px;
  cursor: pointer;
}
#status button:hover { background: color-mix(in srgb, var(--signal) 22%, transparent); }
#status button:focus-visible { outline: 2px solid var(--signal); outline-offset: 1px; }

/* ----------------------------------------------------------------- loading */

#boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: var(--hull-deep);
  transition: opacity 260ms;
  z-index: 10;
}
#boot[hidden] { opacity: 0; pointer-events: none; display: grid; }
#boot p { margin: 0; font-size: 12px; color: var(--legend-dim); }
/* What is on its way: the export's saved start view and its name. */
#boot-thumb {
  width: min(420px, 80vw);
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  opacity: .9;
}
#boot-thumb[hidden] { display: none; }
#boot #boot-name { font-size: 16px; font-weight: 600; color: var(--legend); }
#boot #boot-name:empty { display: none; }
#bar { width: 210px; height: 2px; background: var(--rule-soft); overflow: hidden; }
#bar i { display: block; height: 100%; width: 0; background: var(--signal); transition: width 140ms linear; }
#boot.error p { color: #e0736a; max-width: 34em; text-align: center; line-height: 1.6; }
#boot.error #bar { display: none; }

/* ------------------------------------------------------------------ mobile */

@media (max-width: 760px) {
  /* The wordmark is ~11:1, so beside the title card it runs off a phone.
     Stack it under the card instead, small. */
  #top { flex-direction: column; align-items: stretch; gap: 8px; }
  #identity { min-width: 0; max-width: none; }
  #picker-button { font-size: 17px; }
  #picker-list { left: -13px; width: calc(100vw - 2 * var(--gap)); }
  #picker-list li { grid-template-columns: 96px 1fr; }
  #picker-list .pick-thumb { width: 96px; }
  #brand { align-self: flex-start; height: 30px; padding: 6px 10px; max-width: 100%; }
  #brand img { max-width: 100%; object-fit: contain; }
  #section { max-width: calc(100vw - 2 * var(--gap)); gap: 7px; padding: 7px 9px; }
  #section .dual { width: auto; flex: 1; min-width: 80px; }
  #section .side { min-width: 0; }
  #backdrops { max-width: calc(100vw - 2 * var(--gap)); overflow-x: auto; scrollbar-width: none; }
  #backdrops button { flex: none; }
  body.drawer-open #backdrops { transform: none; }
  #props { top: auto; left: var(--gap); width: auto; height: 52vh; }
  #props { transform: translateY(calc(100% + var(--gap))); }
  #props[data-open="true"] { transform: none; }
  #tools { max-width: calc(100vw - 2 * var(--gap)); overflow-x: auto; scrollbar-width: none; }
  #tools button { padding: 10px 10px; flex: none; }
  body.drawer-open #section,
  body.drawer-open #tools { transform: none; }
  #status { display: none; }
}
