:root {
  /* Foundry workspace: cool navy-charcoal chassis, single blue accent
     (matched to the FORWARD ops console). */
  --bg: #181b22;
  --panel: #1f232c;
  --panel-2: #272c37;
  --border: #2a2f3a;
  --text: #dfe3ea;
  --muted: #828b98;
  --accent: #2f5fe0;       /* Foundry blue */
  --accent-2: #5b8def;     /* brighter blue (hover/selection) */
  --danger: #f0617f;       /* rose — kept distinct from the blue accent */
  --good: #3ddc84;
  --shadow: 0 8px 24px rgba(8,12,24,.5);
  --glass: rgba(24,27,34,.95);   /* floating panels/pills over the canvas */
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  user-select: none;
}

body {
  display: grid;
  grid-template-rows: 56px 1fr;
  grid-template-columns: 80px 1fr;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 15;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand {
  font-weight: 600;
  letter-spacing: .2px;
}

.help-menu {
  left: 0;
  right: auto;
  width: 330px;
  max-width: 86vw;
  max-height: 74vh;
  overflow-y: auto;
  padding: 0;
  gap: 0;
}
.help-section {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}
.help-section:first-child { border-top: none; }
.help-section h4 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.help-section h4 .step { color: var(--muted); font-weight: 600; margin-right: 2px; }
.help-section p { margin: 0 0 6px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.help-section p:last-child { margin-bottom: 0; }
.help-section ul { margin: 4px 0 0; padding-left: 16px; }
.help-section li { font-size: 12px; color: var(--muted); line-height: 1.5; margin-bottom: 5px; }
.help-section li:last-child { margin-bottom: 0; }
.help-section b { color: var(--text); font-weight: 600; }
.help-section a { color: var(--accent); text-decoration: none; }
.help-section a:hover { text-decoration: underline; }
.help-section.credits h4 { color: var(--muted); font-size: 12px; }
.keys-list { list-style: none; padding-left: 2px; margin-top: 2px; }
.keys-list li { margin-bottom: 7px; }
.help-menu kbd {
  display: inline-block;
  font-family: inherit;
  font-size: 10.5px;
  line-height: 1;
  padding: 2px 5px;
  margin: 0 1px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
}

.view-toggle {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.view-toggle button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}
.view-toggle button.active {
  background: var(--accent);
  color: white;
}

.topbar-right {
  display: flex;
  gap: 10px;
  align-items: center;
}

.file-btn {
  background: var(--accent);
  color: white;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.file-btn:hover { filter: brightness(1.1); }

button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 8px;
}
button.ghost:hover { background: var(--panel-2); }
button.danger { color: var(--danger); }

/* Top-bar grouping: segmented button pairs + a thin separator */
.topbar-sep { width: 1px; align-self: stretch; background: var(--border); margin: 5px 0; }
.btn-group { display: inline-flex; }
.btn-group button.ghost { border-radius: 0; border-right-width: 0; }
.btn-group button.ghost:first-child { border-top-left-radius: 8px; border-bottom-left-radius: 8px; }
.btn-group button.ghost:last-child { border-top-right-radius: 8px; border-bottom-right-radius: 8px; border-right-width: 1px; }
.icon-btn { padding: 7px 11px; font-size: 15px; line-height: 1; }

/* "Hit Esc to deselect" chip in the top bar; only shown when a selection exists. */
.esc-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  margin-left: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.esc-hint kbd {
  font: inherit;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  color: var(--text);
}
.esc-hint[hidden] { display: none; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 240px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 10;
}
.dropdown-menu button {
  background: transparent;
  color: var(--text);
  border: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
}
.dropdown-menu button:hover { background: var(--panel); }
.dropdown-menu .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}
.dropdown-menu .row input[type="range"] { flex: 1; }
.dropdown-menu .row input[type="number"],
.dropdown-menu .row select {
  width: 110px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
}
.dropdown-menu .row input[type="number"] { width: 70px; }
.dropdown-menu .menu-sec {
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 10px 3px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.dropdown-menu .menu-sec:first-child { border-top: none; margin-top: 0; padding-top: 4px; }

.toolbar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  z-index: 4;
}
.tool {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  transition: all .12s;
}
.tool .ico {
  font-size: 18px;
  line-height: 1;
}
.tool .key {
  margin-top: 2px;
  font-size: 9px;
  line-height: 1;
  padding: 1px 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--muted);
}
.tool.active .key {
  color: #fff;
  border-color: rgba(255,255,255,.5);
}
.tool:hover { background: var(--panel-2); color: var(--text); }
.tool.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.divider {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}
.scale-info {
  font-size: 10px;
  color: var(--muted);
  padding: 4px;
  text-align: center;
  line-height: 1.4;
  white-space: pre-line;
}

.stage {
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.palette {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 210px;
  z-index: 6;
  background: var(--glass);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.palette-head {
  padding: 12px 14px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.palette-close {
  flex: none;
  width: 22px; height: 22px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  border-radius: 5px;
  cursor: pointer;
  padding: 0;
}
.palette-close:hover { color: var(--text); border-color: var(--border); background: rgba(255,255,255,.04); }
.palette-hint { display: block; font-weight: 400; font-size: 10px; color: var(--muted); margin-top: 3px; }
.palette-body { overflow-y: auto; padding: 8px; }
.palette-cat { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 10px 6px 4px; }
.palette-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 10px;
  margin-bottom: 4px;
  text-align: left;
  cursor: pointer;
}
.palette-item:hover { border-color: var(--accent); }
.palette-item.armed { border-color: var(--accent); background: rgba(47,95,224,.18); }
.palette-item .dim { font-size: 10px; color: var(--muted); }

.item-panel {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  max-width: 92vw;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(3px);
}
.ip-title { font-size: 13px; font-weight: 600; }
.ip-row { display: flex; gap: 14px; }
.ip-dim { display: flex; align-items: center; gap: 4px; }
.ip-dim button {
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  font-size: 15px; line-height: 1;
}
.ip-dim button:hover { border-color: var(--accent); }
.ip-val { min-width: 46px; text-align: center; font-size: 12px; color: var(--text); }
.ip-axis { font-size: 10px; color: var(--muted); }
.ip-actions { display: flex; gap: 6px; }
.ip-actions button {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: 7px; font-size: 12px;
}
.ip-actions button:hover { border-color: var(--accent); }
.ip-actions button.danger { color: var(--danger); }
.ip-actions button.danger:hover { border-color: var(--danger); }

.readout {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 150px;
  font-size: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(3px);
  pointer-events: none;
}
.readout-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0;
  color: var(--muted);
}
.readout-row b { color: var(--text); font-weight: 600; }
.readout-area { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; }
.readout-area b { color: var(--accent); font-size: 14px; }
.view {
  position: absolute;
  inset: 0;
  display: none;
}
.view.active { display: block; }

canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--glass);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  backdrop-filter: blur(3px);
}

.tool-tip {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 34px 9px 14px;
  max-width: 480px;
  font-size: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(3px);
}
.tool-tip[hidden] { display: none; }
.tool-tip .tip-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 3px;
}
.tool-tip .tip-body {
  color: var(--muted);
  line-height: 1.45;
}
.tool-tip .tip-body b { color: var(--text); font-weight: 600; }
.tool-tip .tip-body kbd {
  display: inline-block;
  font-size: 10px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
}
.tool-tip .tip-close {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  border-radius: 5px;
  padding: 0;
}
.tool-tip .tip-close:hover { color: var(--text); border-color: var(--border); background: rgba(255,255,255,.04); }

/* Centered welcome card for the empty first-run state */
.hint.welcome {
  bottom: auto; top: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel-2);
  border-radius: 14px;
  padding: 22px 26px;
  text-align: center;
  pointer-events: auto;
  box-shadow: var(--shadow);
  max-width: 360px;
}
.welcome-title { font-size: 17px; font-weight: 600; color: var(--text); }
.welcome-sub { font-size: 13px; color: var(--muted); margin: 6px 0 16px; }
.welcome-actions { display: flex; gap: 10px; justify-content: center; }

.walk-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
}
.walk-hud .crosshair {
  color: rgba(255,255,255,.7);
  font-size: 22px;
}
.walk-hud .walk-instructions {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--glass);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text);
}

.walk-paused {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,12,17,.45);
  backdrop-filter: blur(2px);
  pointer-events: none; /* clicks pass through to the canvas to re-lock */
}
.walk-paused-card {
  text-align: center;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 34px;
  box-shadow: var(--shadow);
}
.walk-paused-title { font-size: 13px; color: var(--muted); letter-spacing: .12em; text-transform: uppercase; }
.walk-paused-sub { font-size: 22px; font-weight: 600; margin: 6px 0 10px; color: var(--text); }
.walk-paused-hint { font-size: 12px; color: var(--muted); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  width: 380px;
  box-shadow: var(--shadow);
}
.modal-title { font-weight: 600; margin-bottom: 12px; }
.modal-body { font-size: 13px; color: var(--muted); margin-bottom: 16px; line-height: 1.5; }
.modal-body input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  margin-top: 8px;
  font-size: 13px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions button {
  padding: 7px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
}
.modal-actions button.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 30;
  box-shadow: var(--shadow);
}

/* ---------- Responsive / touch ---------- */

/* Tablet & narrow desktop: let the packed top bar wrap instead of overflowing,
   and give buttons bigger tap targets. The grid layout (toolbar + stage) is
   unchanged — only the chrome relaxes. */
@media (max-width: 1024px) {
  body { grid-template-rows: auto 1fr; }
  .topbar {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 8px 12px;
  }
  .brand-group { flex-wrap: wrap; }
  .topbar-right { flex-wrap: wrap; justify-content: flex-end; }
  .esc-hint { display: none; }              /* keyboard-only hint, irrelevant on touch */
  /* Roomier hit targets for fingers. */
  .tool { padding: 10px 4px; }
  button.ghost { padding: 9px 13px; }
  .dropdown-menu button, .dropdown-menu .row { padding: 11px 12px; }
  .palette-item { padding: 10px 12px; }
  .ip-dim button { width: 30px; height: 30px; }
  /* Dropdowns can outgrow a short screen once the bar wraps — let them scroll. */
  .dropdown-menu { max-height: 70vh; overflow-y: auto; }
}

/* Phone-sized: keep it usable for looking around, but surface a one-time note
   that the editor wants a bigger screen. */
.smallscreen-note {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 11, 13, 0.82);
  backdrop-filter: blur(4px);
}
.smallscreen-note[hidden] { display: none; }
.ssn-card {
  max-width: 320px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: var(--shadow);
}
.ssn-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.ssn-card p { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0 0 16px; }
