*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  overflow-wrap: break-word;
  hyphens: auto;
  touch-action: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  user-select: none;
  cursor: default;
}

:root {
  --fg: #fff;
  --bg: #333;
}

html,
body,
svg,
canvas {
  position: absolute;
  inset: 0;
  height: 100svh;
  overflow: hidden;
}

body {
  display: grid; /* So that things can easily center themselves */
  font-size: 16px;
  font-family: system-ui;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--fg);
  background-color: var(--bg);
}

svg,
canvas {
  width: 100%;
  height: 100%;
}

svg {
  text-anchor: middle;
  font-family: monospace;
}

#spark {
  left: auto;
  box-shadow: 0 0.5px 4px #8882;
}

text.spark {
  font-size: 6px;
  text-anchor: end;
}

#ErrorMessage {
  position: relative;
  place-self: center;
  padding: 3em 4em 2em;
  border: 4px solid #222;
  background: #0007;
  backdrop-filter: blur(32px);
  z-index: 200;

  &.hidden {
    display: none;
  }

  a {
    display: inline-block;
    padding-top: 1em;
    font-size: 0.8em;
    font-weight: 700;
    color: #ccc;
    cursor: pointer;
    &:hover {
      color: #fff;
    }
    &:first-of-type {
      margin-right: 1em;
    }
    &:last-of-type {
      float: right;
    }
  }

  p {
    white-space: pre-wrap;
  }
}

#settings {
  position: absolute;
  display: none;
  inset: 0;
  place-content: center;

  &.active {
    display: grid;
  }
}

#settings > div {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  --last-column: 5;
  grid-auto-flow: row;
  padding: 1.5em;
  gap: 2em 1.5em;
  background: #f7f7f7;
  border: 1px solid #ccc;
  border-radius: 4px;
  color: black;
  box-shadow: 0 0.2em 2em #0002;
}

h1 {
  grid-column: 1 / var(--last-column);
  font-size: 1.3em;
  span {
    padding-left: 0.1em;
    font-size: 0.8em;
    font-weight: 200;
  }
}

.option {
  padding: 0.6em;
  margin: 0.8em 0;
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 2px;

  &.disabled {
    pointer-events: none;
    opacity: 0.5;
  }
}

#debug {
  position: fixed;
  top: 0;
  right: -400px;
  width: 400px;
  height: 100vh;
  z-index: 300;
}

#debug.active {
  right: 0;
}

#debug > div {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100%;
  padding: 0;
  gap: 0;
  background: rgba(26, 26, 26, 0.9);
  border-left: 1px solid #444;
  color: #fff;

  font-family: "Courier New", monospace;
  font-size: 0.9em;
  overflow-y: auto;
}

.debug-pause {
  background: #333;
  border: 1px solid #555;
  border-radius: 4px;
  color: #fff;
  font-size: 0.85em;
  cursor: pointer;
  padding: 0.3em 0.7em;
  margin: 1em 1em 0;
  display: block;
  transition: all 0.2s;
}

.debug-pause:hover {
  background: #444;
  border-color: #777;
}

.spike-threshold-control {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5em;
  margin-top: 0.75em;
  color: #aaa;
  font-size: 0.85em;
}

.spike-threshold-control input {
  width: 100%;
  accent-color: #00ff88;
}

.spike-threshold-control output {
  min-width: 2.5em;
  color: #fff;
  text-align: right;
}

.frame-spikes-content {
  margin-top: 0.75em;
}

.debug-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2em;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-left: auto;
  padding: 0;
}

#debug .debug-close {
  align-self: start;
  margin-top: 0.5em;
}

.debug-delete {
  background: #333;
  border: 1px solid #555;
  border-radius: 4px;
  color: #fff;
  font-size: 0.8em;
  padding: 0.2em 0.5em;
  cursor: pointer;
  transition: all 0.2s;
  margin-right: 0.5em;
}

.debug-delete:hover {
  background: #ff4444;
  border-color: #ff4444;
}

.debug-tabs {
  display: flex;
  align-items: end;
  gap: 0;
  border-bottom: 1px solid #444;
  padding: 0 1em;
}

.debug-tab {
  padding: 0.4em 0.8em;
  background: #2a2a2a;
  border: 1px solid #444;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  margin-bottom: -1px;
  position: relative;
}

.debug-tab:hover {
  background: #333;
}

.debug-tab.active {
  background: #00ff88;
  color: #000;
  border-color: #00ff88;
  border-bottom: 1px solid #00ff88;
}

.debug-content {
  overflow-y: auto;
  height: 100%;
}

.debug-content section {
  margin-bottom: 1.5em;
}

.debug-content section h3 {
  color: #00ff88;
  margin-bottom: 0.5em;
  font-size: 1em;
}

.debug-content section h4 {
  color: #88ddff;
  margin: 1em 0 0.5em 0;
  font-size: 0.9em;
}

.perf-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5em;
  padding: 1em;
}

.perf-info > div {
  padding: 0.5em;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 4px;
}

.perf-info div strong {
  color: #ffaa00;
}

.frame-budget-chart {
  overflow: hidden;
}

.frame-budget-title {
  margin-bottom: 0.5em;
}

.frame-spikes-title {
  color: #aaa;
  font-size: 0.75em;
  font-weight: bold;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.frame-spikes-title span {
  color: #777;
  font-weight: normal;
}

.frame-budget-chart-detail {
  padding-top: 0.75em;
  border-top: 1px solid #444;
}

.frame-budget-chart-detail .frame-budget-title {
  color: #aaa;
  font-size: 0.85em;
}

.perf-info .frame-budget-chart-detail .frame-budget-title strong {
  color: #aaa;
  font-size: 0.8em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.frame-budget-bar {
  display: flex;
  width: 100%;
  height: 18px;
  padding: 0 !important;
  overflow: hidden;
  background: #444 !important;
  border: 0 !important;
  border-radius: 3px !important;
}

.frame-budget-segment {
  flex: 0 0 auto;
  height: 100%;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
}

.frame-budget-legend {
  display: grid;
  gap: 0.2em;
  margin-top: 0.5em;
}

.frame-budget-legend-item {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) max-content;
  align-items: center;
  gap: 0.5em;
  min-width: 0;
  padding: 0 !important;
  border: 0 !important;
  font-family: monospace;
  font-size: 0.75em;
}

.frame-budget-legend-item span {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.command-call-tree-system {
  margin-top: 0.75em;
  color: #aaa;
  font-family: monospace;
  font-size: 0.75em;
  font-weight: bold;
}

.command-call-tree-system:first-child {
  margin-top: 0;
}

.command-call-tree-roots {
  margin-top: 0.2em;
}

.command-call-tree-branch {
  min-width: 0;
}

.command-call-tree-node {
  min-height: 1.4em;
}

.command-call-tree-children {
  margin-left: 4px;
  padding-left: 12px;
  border-left: 1px solid #444;
}

.command-call-tree-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.command-call-tree-time {
  padding-left: 0.4em;
  white-space: nowrap;
}


.fps-graph-container {
  margin: 1em;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 4px;
  margin-top: 0.5em;
  height: 100px;
}

#fps-graph {
  position: relative;
  width: 100%;
  height: 100px;
  border: 1px solid #333;
  display: block;
}


.scene-graph-tree {
  width: 100%;
  padding: 0.5em;
}

.tree-node {
  margin: 0.2em 0;
}

.tree-node-content {
  padding: 0.2em 0.6em;
  border-radius: 2px;
  font-size: 0.8em;
  font-family: monospace;
  line-height: 1.4;
}

.tree-node-content:hover {
  background: #444;
}

.tree-node-content strong {
  color: #88ddff;
}

.tree-children {
  margin-left: 10px;
  border-left: 1px solid #555;
  padding-left: 2px;
}

.deploy {
  padding: 0.2em 0 0;
  margin-bottom: 0em;
  border: 1px solid transparent;
  opacity: 0.5;
}

.entity-details-panel {
  position: fixed;
  right: 319px;
  top: -1px;
  width: 300px;
  height: 100vh;
  z-index: 10001;
  display: grid;
  grid-template-rows: auto 1fr;
  height: calc(100vh - 20px);
  padding: 0;
  gap: 0;
  background: rgba(26, 26, 26, 0.9);
  border: 1px solid #444;
  color: #fff;
  font-family: "Courier New", monospace;
  font-size: 0.9em;
}

.entity-details-panel .header {
  display: flex;
  align-items: center;
  gap: 0.5em;
  border-bottom: 1px solid #444;
  padding: 0.5em 1em;
}

.entity-details-panel .header .title {
  color: #00ff88;
  font-size: 1em;
  flex: 1;
}

.entity-details-panel .header .close-button {
  background: #333;
  border: 1px solid #555;
  border-radius: 4px;
  color: #fff;
  font-size: 1.2em;
  line-height: 1;
  width: 1.8em;
  height: 1.8em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.entity-details-panel .header .close-button:hover {
  background: #ff4444;
  border-color: #ff4444;
}

.entity-details-panel .content {
  overflow-y: auto;
}

.entity-details-panel .template-info {
  margin-bottom: 1.5em;
}

.entity-details-panel .template-info strong {
  color: #ffaa00;
}

.entity-details-panel .props-title {
  color: #88ddff;
  margin: 1em 0 0.5em 0;
  font-size: 0.9em;
}

.entity-details-panel .props-tree {
  height: 100%;
  overflow-y: auto;
  width: 100%;
  padding: 0.5em;
}

.entity-details-panel .tree-node-content:hover {
  background: #444;
}

.log-container {
  overflow-y: auto;
  background: #1a1a1a;
  border: 1px solid #333;
  padding: 8px;
  font-family: monospace;
  font-size: 12px;
  line-height: 1.4;
}
