html,
body {
  height: 100%;
  max-width: 100%;
  margin: 0;
  background: #808080;
  color: #101010;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial,
    sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  width: 100%;
  min-width: 0;
}

#topbar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 16px;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  padding: 8px 10px;
  background: #c0c0c0;
  border-bottom: 2px solid #808080;
  box-shadow: inset 1px 1px 0 #ffffff, inset -1px -1px 0 #808080;
  touch-action: manipulation;
}

#titleCluster {
  display: flex;
  flex: none;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

#servicesBar {
  position: relative;
  flex: none;
  height: 58px;
  min-width: 0;
  max-width: 100%;
  background: #c0c0c0;
  border-bottom: 2px solid #808080;
  box-shadow: inset 1px 1px 0 #ffffff, inset -1px -1px 0 #808080;
}

#servicesBar[hidden] {
  display: none;
}

#servicesBar::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 26px;
  background: #c0c0c0;
  border-left: 2px solid #808080;
  box-shadow: inset 1px 0 0 #ffffff, inset -1px 0 0 #808080;
}

#servicesCanvas {
  image-rendering: auto;
  cursor: pointer;
}

.title {
  font-weight: 700;
}

.help {
  opacity: 0.75;
  font-size: 12px;
}

#pyramidControl,
#fineZoomControl,
#gridControl {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

#pyramidSelect {
  font: inherit;
  color: #101010;
  background: #c0c0c0;
  border: 2px solid #808080;
  box-shadow: inset 1px 1px 0 #808080, inset -1px -1px 0 #ffffff;
}

#fineZoom,
#gridOpacity {
  width: 120px;
  min-width: 80px;
  accent-color: #808080;
  touch-action: auto;
}

#fineZoomReadout {
  display: inline-block;
  box-sizing: border-box;
  flex: none;
  width: 96px;
  padding: 0 6px;
  line-height: 18px;
  overflow: hidden;
  white-space: nowrap;
  background: #e0e0e0;
  box-shadow: inset 1px 1px 0 #808080, inset -1px -1px 0 #ffffff;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

#status {
  box-sizing: border-box;
  margin-left: auto;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  padding: 0 6px;
  line-height: 18px;
  background: #e0e0e0;
  box-shadow: inset 1px 1px 0 #808080, inset -1px -1px 0 #ffffff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  overflow: hidden;
  background: #c0c0c0;
  box-shadow: inset 1px 1px 0 #ffffff, inset -1px -1px 0 #808080;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#servicesBar,
#servicesCanvas {
  touch-action: none;
}

canvas {
  position: absolute;
  inset: 0;
  width: calc(100% - 26px);
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

#imgCanvas {
  pointer-events: none;
}

#vscroll {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 26px;
  overflow: hidden;
  background: #c0c0c0;
  border-left: 2px solid #808080;
  box-shadow: inset 1px 0 0 #ffffff, inset -1px 0 0 #808080;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#vscrollUp,
#vscrollDown {
  height: 26px;
  background: #c0c0c0;
  box-shadow: inset 1px 1px 0 #ffffff, inset -1px -1px 0 #808080;
}

#vscrollUp {
  position: relative;
}

#vscrollDown {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
}

#vscrollUp::before,
#vscrollDown::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
}

#vscrollUp::before {
  border-bottom: 9px solid #202020;
}

#vscrollDown::before {
  border-top: 9px solid #202020;
}

#vscrollTrack {
  position: absolute;
  top: 26px;
  bottom: 26px;
  left: 0;
  right: 0;
  background: #e0e0e0;
  box-shadow: inset 1px 1px 0 #c0c0c0, inset -1px -1px 0 #ffffff;
}

#vscrollThumb {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 120px;
  background: #c0c0c0;
  box-shadow: inset 1px 1px 0 #ffffff, inset -1px -1px 0 #808080;
  cursor: grab;
}

#vscrollThumb:active {
  cursor: grabbing;
}

#footer {
  flex: none;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  padding: 4px 10px;
  background: #c0c0c0;
  border-top: 2px solid #808080;
  box-shadow: inset 1px 1px 0 #ffffff;
  font-size: 12px;
}

@media (max-width: 1100px) {
  #topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    overflow: hidden;
  }

  #titleCluster {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  #fineZoomControl,
  #gridControl,
  #status {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
  }

  #fineZoom,
  #gridOpacity {
    flex: 1 1 auto;
    width: auto;
    min-width: 80px;
  }

  #status {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    overflow-wrap: anywhere;
  }
}

html.narrow #topbar {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  overflow: hidden;
}

html.narrow #titleCluster {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

html.narrow #fineZoomControl,
html.narrow #gridControl,
html.narrow #status {
  width: 100%;
  max-width: 100%;
  margin-left: 0;
}

html.narrow #fineZoom,
html.narrow #gridOpacity {
  flex: 1 1 auto;
  width: auto;
  min-width: 80px;
}

html.narrow #status {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  overflow-wrap: anywhere;
}

#footer span {
  margin-right: 12px;
}

#footer a {
  color: #000080;
}

/* Phone held sideways: stack the controls down the left half.
   A desktop window is taller than this and uses a fine pointer, so it stays one row. */
@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) {
  body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 3fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "controls services"
      "controls stage"
      "footer stage";
  }

  #topbar,
  html.narrow #topbar {
    grid-area: controls;
    flex-direction: column;
    align-items: stretch;
    align-content: flex-start;
    gap: 6px;
    width: auto;
    max-width: none;
    min-height: 0;
    overflow: auto;
    border-bottom: none;
    border-right: 2px solid #808080;
  }

  #servicesBar {
    grid-area: services;
  }

  #stage {
    grid-area: stage;
  }

  #footer {
    grid-area: footer;
    border-right: 2px solid #808080;
  }

  #fineZoomControl,
  #gridControl,
  #status,
  html.narrow #fineZoomControl,
  html.narrow #gridControl,
  html.narrow #status {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
  }
}

