:root {
  --bg:        #0e1116;
  --bg-2:      #161b22;
  --bg-3:      #1c232d;
  --line:      #2a313c;
  --fg:        #e6edf3;
  --muted:     #8b949e;
  --accent:    #4c8dff;
  --accent-2:  #7c5cff;
  --good:      #3fb950;
  --warn:      #d29922;
  --radius:    10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--sans);
  font-size: 14px; display: flex; flex-direction: column; overflow: hidden;
}

/* Topbar */
#topbar {
  height: 52px; flex: 0 0 52px; display: flex; align-items: center; gap: 24px;
  padding: 0 18px; background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: baseline; gap: 8px;
}
.brand-home { color: inherit; border-radius: 5px; line-height: 1; text-decoration: none; }
.brand-home:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.brand-mark {
  display: inline-block; font-family: Baskerville, "Baskerville Old Face", "Hoefler Text", "Times New Roman", serif;
  font-weight: bold; font-size: 19px; letter-spacing: 0; white-space: nowrap;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
}
.brand-gamma {
  display: inline-block; font-size: 1.22em; transform: translateY(-.18em);
  background: linear-gradient(90deg, var(--accent), #6b6dff); -webkit-background-clip: text;
  background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
}
.brand-mark sub { margin-left: -.04em; font-size: .58em; vertical-align: -.12em; }
.brand-sub { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.tab:hover { color: var(--fg); background: var(--bg-3); }
.tab.active { color: var(--fg); background: var(--bg-3); border-color: var(--line); }
.topbar-right { margin-left: auto; }
.badge {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  background: var(--bg-3); border: 1px solid var(--line); padding: 4px 8px; border-radius: 6px;
}

/* Layout */
#layout { flex: 1 1 auto; display: flex; min-height: 0; }
#viewport { flex: 1 1 auto; position: relative; background: radial-gradient(120% 120% at 50% 0%, #141a22, #0c0f14); min-width: 0; }
#viewer-container { position: absolute; inset: 0; }
#viewer-container canvas { display: block; }
.viewer-status {
  position: absolute; top: 12px; left: 12px; font-family: var(--mono); font-size: 11px;
  color: var(--muted); background: rgba(0,0,0,.4); padding: 4px 8px; border-radius: 6px;
  pointer-events: none;
}
.startup-loader {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 50% 35%, rgba(32, 48, 73, .78), rgba(8, 11, 16, .94) 58%);
  backdrop-filter: blur(12px); opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .28s ease, visibility .28s ease;
}
.startup-loader.active { opacity: 1; visibility: visible; }
.startup-loader-card {
  position: relative; width: min(480px, 100%); overflow: hidden; padding: 28px 30px 24px;
  background: linear-gradient(145deg, rgba(28, 35, 45, .96), rgba(14, 17, 22, .96));
  border: 1px solid rgba(124, 151, 194, .28); border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .5), inset 0 1px rgba(255, 255, 255, .04);
}
.startup-loader-card::before {
  content: ''; position: absolute; inset: 0 auto auto 0; width: 100%; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(76, 141, 255, .8), transparent);
}
.startup-loader-brand {
  display: flex; align-items: center; gap: 10px; color: #9fb6d9; font-size: 11px; font-weight: 700;
  letter-spacing: .11em; text-transform: uppercase;
}
.startup-loader-orbit {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(76, 141, 255, .22);
  border-top-color: var(--accent); border-right-color: var(--accent-2); animation: startup-spin .9s linear infinite;
  box-shadow: 0 0 14px rgba(76, 141, 255, .28);
}
.startup-loader-title { margin-top: 20px; font-size: 25px; font-weight: 720; letter-spacing: -.025em; }
.startup-loader-track {
  height: 7px; margin-top: 22px; overflow: hidden; border-radius: 999px; background: rgba(139, 148, 158, .14);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .35);
}
.startup-loader-progress {
  position: relative; width: 0; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 18px rgba(76, 141, 255, .45); transition: width .35s ease;
}
.startup-loader-progress::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .42), transparent);
  animation: startup-shimmer 1.4s ease-in-out infinite;
}
.startup-loader-percent { margin-top: 7px; color: #aac2e9; font-family: var(--mono); font-size: 11px; text-align: right; }
.startup-loader.error .startup-loader-orbit { animation: none; border-color: #f85149; box-shadow: 0 0 14px rgba(248, 81, 73, .28); }
.startup-loader.error .startup-loader-progress { background: #f85149; }
@keyframes startup-spin { to { transform: rotate(360deg); } }
@keyframes startup-shimmer { 55%, 100% { transform: translateX(100%); } }
.rt-speed {
  position: absolute; top: 12px; right: 12px; font-family: var(--mono); font-size: 11px;
  color: var(--fg); background: rgba(0,0,0,.4); padding: 4px 8px; border-radius: 6px;
  pointer-events: none; font-variant-numeric: tabular-nums;
}
.rt-speed.slow { color: #f0a020; }
.rt-speed.veryslow { color: #e0533a; }
.robot-tip {
  position: absolute; font-family: var(--mono); font-size: 11px; color: var(--fg);
  background: rgba(10,13,18,.92); border: 1px solid var(--accent); border-radius: 6px;
  padding: 3px 8px; pointer-events: none; z-index: 6; white-space: nowrap; transform: translate(12px, 12px);
}
.sim-overlay {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; background: rgba(22,27,34,.85);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; backdrop-filter: blur(6px);
}
.sim-overlay button {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--fg); cursor: pointer; font-size: 15px;
}
.sim-overlay button:hover { border-color: var(--accent); }
.sim-overlay button.active { border-color: var(--accent); background: var(--accent); color: #fff; }
/* hover tooltips for the icon-only overlay buttons */
.sim-overlay button[data-tip] { position: relative; }
.sim-overlay button[data-tip]::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-family: var(--mono); font-size: 11px; line-height: 1; color: var(--fg);
  background: rgba(10,13,18,.96); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px;
  opacity: 0; pointer-events: none; transition: opacity .12s ease .15s; z-index: 5;
}
.sim-overlay button[data-tip]:hover::after { opacity: 1; }

/* Domain randomization menu */
.dr-card summary { cursor: pointer; list-style: none; user-select: none; }
.dr-card summary::-webkit-details-marker { display: none; }
.dr-body { margin-top: 10px; display: flex; flex-direction: column; gap: 9px; transition: opacity .15s ease, filter .15s ease; }
body.fleet-trajectory .dr-body { opacity: .42; filter: grayscale(.7); }
body.fleet-trajectory .dr-body label, body.fleet-trajectory .dr-body input, body.fleet-trajectory .dr-body button { cursor: not-allowed; }
.dr-row label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.dr-row input[type=range] { width: 100%; }
.dr-row.disabled { opacity: .5; }
.dr-row input[type=range]:disabled { cursor: not-allowed; }
.dr-row input[type=range]:disabled::-webkit-slider-thumb { background: var(--muted); cursor: not-allowed; }
.dr-btns { display: flex; gap: 8px; }
.dr-btns button { flex: 1; }
.dr-check { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--fg); cursor: pointer; padding: 2px 0; }
.dr-check input[type=checkbox] {
  appearance: none; -webkit-appearance: none; margin: 0; width: 34px; height: 19px; border-radius: 10px;
  background: var(--bg-3); border: 1px solid var(--line); position: relative; cursor: pointer; flex-shrink: 0; transition: background .15s, border-color .15s;
}
.dr-check input[type=checkbox]::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%;
  background: var(--muted); transition: transform .15s, background .15s;
}
.dr-check input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
.dr-check input[type=checkbox]:checked::after { transform: translateX(15px); background: #fff; }
.dr-note { font-size: 10px; line-height: 1.5; }
.dr-grp-title { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 4px; border-top: 1px solid var(--line); padding-top: 8px; }
.dr-grp-title:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
.dr-check .muted { font-size: 10px; }

/* Panel */
#panel {
  flex: 0 0 340px; width: 340px; background: var(--bg-2); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 14px;
}

/* floating control-drawer toggle + backdrop — hidden on desktop, shown on narrow screens */
#panel-toggle {
  display: none; position: fixed; z-index: 501; right: 16px; bottom: 16px;
  width: 50px; height: 50px; border-radius: 50%; cursor: pointer; border: none; font-size: 21px;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px rgba(0,0,0,.45); align-items: center; justify-content: center;
}
#panel-backdrop { display: none; position: fixed; inset: 52px 0 0 0; z-index: 499; background: rgba(0,0,0,.5); }

/* Mobile / narrow: the 340px right bar becomes an off-canvas drawer, viewport takes the full width */
@media (max-width: 760px) {
  .brand-sub { display: none; }
  #topbar { gap: 12px; padding: 0 12px; }
  .tab { padding: 6px 10px; font-size: 12px; }
  #panel {
    position: fixed; top: 52px; right: 0; bottom: 0; width: min(88vw, 340px); z-index: 500;
    transform: translateX(101%); transition: transform .25s ease; box-shadow: -10px 0 34px rgba(0,0,0,.5);
  }
  body.panel-open #panel { transform: translateX(0); }
  body.panel-open #panel-backdrop { display: block; }
  #panel-toggle { display: flex; }
  .startup-loader-card { padding: 24px 22px 20px; }
  .startup-loader-title { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .startup-loader, .startup-loader-progress { transition: none; }
  .startup-loader-orbit, .startup-loader-progress::after { animation: none; }
}
.tab-pane { display: none; flex-direction: column; gap: 14px; }
.tab-pane.active { display: flex; }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.robot-select {
  width: 100%; background: var(--bg-3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; font-size: 14px; font-family: var(--sans);
}
#robot-select {
  appearance: none; -webkit-appearance: none; padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23aeb8ca' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center; background-size: 10px 6px;
}
.policy-label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.policy-divider { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.policy-reset-row { margin-top: 14px; }

.slider-row { margin-bottom: 12px; }
.slider-row label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.slider-row .sv { color: var(--accent); font-family: var(--mono); }
input[type=range] {
  width: 100%; -webkit-appearance: none; height: 5px; border-radius: 3px;
  background: var(--bg-3); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--bg-2);
}

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.cmd-btns { flex-wrap: nowrap; gap: 5px; }
.cmd-btns .btn-ghost { flex: 1 1 0; min-width: 0; padding: 8px 2px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cmd-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.cmd-head .card-title { margin-bottom: 0; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode-toggle { flex: 0 0 auto; border: 1px solid var(--line); background: var(--bg-3); color: var(--fg); border-radius: 999px; padding: 2px 9px; font-size: 15px; line-height: 1.2; cursor: pointer; white-space: nowrap; }
.mode-toggle:hover { border-color: var(--accent); }
.slider-row.roam-locked { opacity: .5; }
.slider-row input[type=range]:disabled { cursor: not-allowed; }
.slider-row input[type=range]:disabled::-webkit-slider-thumb { background: var(--muted); cursor: not-allowed; }
.btn-primary, .btn-ghost {
  border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid var(--line);
}
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:disabled { background: var(--bg-3); color: var(--muted); border-color: var(--line); cursor: not-allowed; }
.btn-ghost { background: var(--bg-3); color: var(--fg); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-ghost:disabled { color: var(--muted); cursor: not-allowed; opacity: .5; }
.btn-ghost.active { border-color: var(--accent); background: var(--accent); color: #fff; }
/* all-scope roam, SOME but not all roaming: a dimmer/translucent accent (half-filled) — clearly 'partial' vs the solid .active */
.btn-ghost.mixed { border-color: var(--accent); background: rgba(76, 141, 255, 0.32); color: var(--fg); }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }

.kv { font-family: var(--mono); font-size: 12px; line-height: 1.7; white-space: pre-wrap; }

/* Convert tab */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 24px 14px;
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--bg-3); }
.dz-icon { font-size: 26px; color: var(--muted); margin-bottom: 8px; }
.dz-inner > div { margin: 3px 0; }
.convert-report { margin: 12px 0; font-family: var(--mono); font-size: 11px; line-height: 1.6; }
.convert-report .ok { color: var(--good); }
.convert-report .err { color: #f85149; }
.convert-report .warn { color: var(--warn); }
.robot-select#convert-mainxml { margin-bottom: 10px; }

/* Structural-check report (before → after) */
.check-summary { font-family: var(--mono); font-size: 11px; color: var(--muted); margin: -4px 0 10px; }
.check-summary b { color: var(--fg); }
.check-summary b.fail-text { color: #f85149; }
.check-report { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.check-row { display: flex; gap: 8px; align-items: baseline; padding: 3px 4px; border-radius: 5px; }
.check-row.improved { background: rgba(63,185,80,.09); }
.check-pills { flex: 0 0 auto; white-space: nowrap; display: flex; align-items: center; gap: 3px; }
.check-body { font-family: var(--mono); font-size: 11px; line-height: 1.45; min-width: 0; }
.check-name { color: var(--fg); font-weight: 600; }
.check-detail { color: var(--muted); }
.pill { display: inline-block; font-family: var(--mono); font-size: 9px; font-weight: 700; letter-spacing: .04em; padding: 1px 5px; border-radius: 4px; border: 1px solid transparent; }
.pill.pass { color: var(--good); background: rgba(63,185,80,.13); border-color: rgba(63,185,80,.35); }
.pill.warn { color: var(--warn); background: rgba(210,153,34,.13); border-color: rgba(210,153,34,.35); }
.pill.fail { color: #f85149; background: rgba(248,81,73,.13); border-color: rgba(248,81,73,.4); }
.pill.info { color: var(--accent); background: rgba(76,141,255,.12); border-color: rgba(76,141,255,.35); }
.pill.none { color: var(--muted); background: transparent; border-color: var(--line); }
.check-pills .arrow { color: var(--muted); font-size: 10px; }
.convert-notes { margin-top: 12px; font-size: 11px; line-height: 1.55; }
.convert-notes .notes-title { font-weight: 700; color: var(--fg); margin-bottom: 4px; }
.convert-notes .note { color: var(--good); }
.convert-notes .note.muted { color: var(--muted); margin-top: 6px; }
.disclaimer { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.tree { background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; }
code { font-family: var(--mono); background: var(--bg-3); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
pre code { background: none; padding: 0; }
