html {
  font-family: sans-serif;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  box-sizing: border-box;
  font-size: 16px;
}

html *,
html *::before,
html *::after {
  box-sizing: inherit;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

main,
#draw-canvas,
canvas {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  height: auto;
  width: auto;
}

main {
  cursor: crosshair;
}

main.panning,
main.panning-intent {
  cursor: move;
}

main::after {
  content: '';
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  position: absolute;
  z-index: -1;
}

.button {
  position: absolute;
  z-index: 3;
  top: 20px;
  border-radius: 50%;
  cursor: pointer;
  background: white;
  box-shadow: 0 0 0 1px rgba(0,0,0,.1);
  height: 30px;
  width: 30px;
  transition: opacity .2s linear;
}

.button.hidden {
  opacity: 0;
  pointer-events: none;
}

.button::before,
.button::after {
  content: '';
  display: block;
  position: absolute;
}

.button:hover {
  box-shadow: 0 0 0 2px rgba(0,0,127,.5);
}

.button > .tooltip {
  display: none;
  position: absolute;
  top: calc(50% + 10px);
  left: calc(50% + 10px);
  transform: rotate(45deg);
  pointer-events: none;
  transform-origin: left bottom;
  line-height: 1;
  white-space: nowrap;
  background: white;
  box-shadow: 0 0 0 2px white;
}

.button:hover > .tooltip {
  display: inline-block;
}

main.drawing .button,
main.panning .button {
  pointer-events: none;
}

.button.active {
  box-shadow: 0 0 0 2px rgba(0,127,0,.5);
}

.panel {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  width: auto;
  background: rgba(255,255,255,.9);
  cursor: default;
}

.panel-close {
  display: block;
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  position: absolute;
  top: 60px;
  left: 20px;
  height: 30px;
  width: 30px;
  padding: 10px;
  cursor: pointer;
  transform: rotate(45deg);
}

.panel-close::before,
.panel-close::after {
  content: '';
  display: block;
  position: absolute;
}

.panel-close::before {
  left: 13px;
  top: 5px;
  bottom: 5px;
  border-right: solid 4px black;
}

.panel-close::after {
  top: 13px;
  left: 5px;
  right: 5px;
  border-bottom: solid 4px black;
}

.slider {
  position: absolute;
  top: calc(50% - 1px);
  left: 50%;
  width: calc(100% - 280px);
  max-width: 300px;
  height: 0;
  border-bottom: solid 2px rgba(0,0,0,.1);
  transform: translateX(-50%);
}

.slider > div {
  position: absolute;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: #777;
  left: -10px;
  top: -9px;
  cursor: pointer;
  transition: transform .2s ease;
}

.slider::before,
.slider::after {
  content: '';
  display: block;
  position: absolute;
  top: 1px;
}

.slider::before {
  transform: translate(-50%, -50%);
}

.slider::after {
  transform: translate(50%, -50%);
}

#pen {
  position: absolute;
  z-index: 3;
  top: 20px;
  right: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,1);
  border: solid 25px white;
  cursor: default;
  box-shadow: 0 0 0 1px rgba(0,0,0,.1), 0 0 0 1px rgba(0,0,0,.1) inset;
  height: 60px;
  width: 60px;
}

main.drawing #pen,
main.panning #pen {
  pointer-events: none;
}

#pen-mode {
  left: 20px;
}

#pen-mode::before,
#pen-mode::after {
  transform: rotate(-45deg);
}

#pen-mode.draw-mode::before {
  top: 11px;
  left: 5px;
  width: 0;
  height: 0;
  border: solid 4px transparent;
  border-right: solid 3px black;
  border-left: none;
  transform-origin: 9px 4px;
}

#pen-mode.draw-mode::after {
  top: 11px;
  left: 10px;
  height: 8px;
  width: 13px;
  border-left: solid 8px black;
  border-right: solid 4px black;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  transform-origin: 4px 4px;
}

#pen-mode.erase-mode::before {
  top: 10px;
  left: 6px;
  height: 10px;
  width: 5px;
  border: solid 1px black;
  border-top-left-radius: 2px;
  border-bottom-left-radius: 2px;
  transform-origin: 9px 5px;
}

#pen-mode.erase-mode::after {
  top: 10px;
  right: 6px;
  height: 10px;
  width: 11px;
  background: black;
  border-top-right-radius: 2px;
  border-bottom-right-radius: 2px;
  transform-origin: 2px 5px;
}

#pen-size {
  left: 60px;
}

#pen-size::before {
  top: 12px;
  left: 4px;
  background: black;
  border-radius: 50%;
  height: 6px;
  width: 6px;
}

#pen-size::after {
  top: 9px;
  right: 5px;
  background: black;
  border-radius: 50%;
  height: 12px;
  width: 12px;
}

#pen-colour {
  left: 100px;
  background: black;
  border: solid 4px white;
}

#pen-colour::before {
  top: 9px;
  left: 11px;
  width: 12px;
  height: 14px;
  background: white;
  border-bottom-right-radius: 12px 14px;
}

#pen-colour::after {
  top: 17px;
  left: 8px;
  background: black;
  height: 5px;
  width: 5px;
  border-radius: 50%;
}

#pen-colour > div:not(.tooltip) {
  position: absolute;
  z-index: 1;
  height: 3px;
  width: 11px;
  background: black;
  top: 9px;
  left: 11px;
  border-bottom-right-radius: 3px;
}

#pen-colour > div:not(.tooltip)::before,
#pen-colour > div:not(.tooltip)::after {
  content: '';
  position: absolute;
  display: block;
}

#pen-colour > div:not(.tooltip)::before {
  height: 4px;
  width: 4px;
  background: white;
  border-radius: 50%;
  top: -4px;
  left: 2px;
  box-shadow: -6px -2px 0 white, -10px 3px 0 white;
}

#pen-colour > div:not(.tooltip)::after {
  height: 5px;
  width: 5px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: -2px;
}

#pen-opacity {
  left: 140px;
}

#pen-opacity::before {
  right: 15px;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: auto;
  border: dotted 2px black;
  border-right: none;
  border-top-left-radius: 11px;
  border-bottom-left-radius: 11px;
}

#pen-opacity::after {
  left: 15px;
  top: 4px;
  bottom: 4px;
  right: 4px;
  width: auto;
  background: black;
  border-top-right-radius: 11px;
  border-bottom-right-radius: 11px;
}

#draw-layer {
  left: 180px;
}

#draw-layer::before {
  height: 18px;
  width: 18px;
  left: 6px;
  top: 9px;
  background: black;
  border-radius: 3px;
  transform: scale(1,.33) rotate(-45deg);
}

#draw-layer::after {
  height: 18px;
  width: 18px;
  left: 6px;
  top: 4px;
  background: white;
  border: solid 3px black;
  border-radius: 3px;
  transform: scale(1,.33) rotate(-45deg);
  box-shadow: -4px 4px 0 white;
}

#new-canvas {
  left: 220px;
}

#new-canvas::before {
  height: 18px;
  width: 14px;
  border: solid 2px black;
  border-radius: 2px;
  left: 8px;
  top: 6px;
}

#new-canvas::after {
  height: 8px;
  width: 8px;
  right: 8px;
  top: 6px;
  border: solid 4px black;
  border-top-color: transparent;
  border-right-color: transparent;
  border-bottom-left-radius: 2px;
  background: white;
}

#download {
  left: 260px;
  background: black;
  border: solid 5px white;
}

#download::before {
  top: 11px;
  left: calc(50% - 5px);
  border: solid 5px transparent;
  border-top-color: white;
  border-bottom: none;
}

#download::after {
  top: 6px;
  left: calc(50% - 2px);
  width: 4px;
  height: 5px;
  background: white;
}

#button-share {
  left: 300px;
  border: solid 5px white;
}

#button-share::before,
#button-share::after {
  width: 12px;
  background: black;
  height: 2px;
  left: 3px;
  top: 9px;
}

#button-share::before {
  transform: rotate(-33deg);
  transform-origin: 0 0;
}

#button-share::after {
  transform: rotate(33deg);
  transform-origin: 0 100%;
}

#button-share > div:not(.tooltip) {
  position: relative;
  height: 6px;
  width: 6px;
  background: black;
  border-radius: 50%;
  left: 0;
  top: calc(50% - 3px);
  box-shadow: 12px -7px 0 black, 12px 7px 0 black;
}

.pen-colour-panel .pen-colour {
  display: block;
  position: absolute;
  height: 40px;
  width: 40px;
  border-radius: 50%;
  border: solid 4px white;
  box-shadow: 0 0 0 1px rgba(0,0,0,.1), 0 0 0 1px rgba(0,0,0,.1) inset;
  cursor: pointer;
}

.pen-colour-panel .pen-colour:hover {
  box-shadow: 0 0 0 3px rgba(0,0,127,.5), 0 0 0 1px rgba(0,0,0,.1) inset;
}

.pen-colour-panel .pen-colour.active {
  box-shadow: 0 0 0 3px rgba(0,127,0,.5), 0 0 0 1px rgba(0,0,0,.1) inset;
}

.pen-colour-panel .pen-colour:nth-of-type(1)  { top: calc(50% - 70px); left: calc(50% - 95px); }
.pen-colour-panel .pen-colour:nth-of-type(2)  { top: calc(50% - 70px); left: calc(50% - 45px); }
.pen-colour-panel .pen-colour:nth-of-type(3)  { top: calc(50% - 70px); left: calc(50% + 5px); }
.pen-colour-panel .pen-colour:nth-of-type(4)  { top: calc(50% - 70px); left: calc(50% + 55px); }

.pen-colour-panel .pen-colour:nth-of-type(5)  { top: calc(50% - 20px); left: calc(50% - 95px); }
.pen-colour-panel .pen-colour:nth-of-type(6)  { top: calc(50% - 20px); left: calc(50% - 45px); }
.pen-colour-panel .pen-colour:nth-of-type(7)  { top: calc(50% - 20px); left: calc(50% + 5px); }
.pen-colour-panel .pen-colour:nth-of-type(8)  { top: calc(50% - 20px); left: calc(50% + 55px); }

.pen-colour-panel .pen-colour:nth-of-type(9)  { top: calc(50% + 30px); left: calc(50% - 95px); }
.pen-colour-panel .pen-colour:nth-of-type(10) { top: calc(50% + 30px); left: calc(50% - 45px); }
.pen-colour-panel .pen-colour:nth-of-type(11) { top: calc(50% + 30px); left: calc(50% + 5px); }
.pen-colour-panel .pen-colour:nth-of-type(12) { top: calc(50% + 30px); left: calc(50% + 55px); }

.draw-layer-panel .canvas-layer {
  display: block;
  position: absolute;
  height: 60px;
  width: 60px;
  border-radius: 50%;
  border: solid 5px white;
  box-shadow: 0 0 0 1px rgba(0,0,0,.1), 0 0 0 1px rgba(0,0,0,.1) inset;
  cursor: pointer;
  background: white;
  left: calc(50% - 25px);
}

.draw-layer-panel .canvas-layer:not(:first-of-type)::after {
  content: '';
  position: absolute;
  top: calc(100% + 5px);
  bottom: -15px;
  left: calc(50% - 1px);
  width: 2px;
  background: rgba(0,0,0,.1);
}

.draw-layer-panel .canvas-layer:hover {
  box-shadow: 0 0 0 3px rgba(0,0,127,.5), 0 0 0 1px rgba(0,0,0,.1) inset;
}

.draw-layer-panel .canvas-layer.active {
  box-shadow: 0 0 0 3px rgba(0,127,0,.5), 0 0 0 1px rgba(0,0,0,.1) inset;
}

.draw-layer-panel .canvas-layer[data-id="3"] { top: calc(50% - 95px); }
.draw-layer-panel .canvas-layer[data-id="2"] { top: calc(50% - 25px); }
.draw-layer-panel .canvas-layer[data-id="1"] { top: calc(50% + 45px); }

.draw-layer-panel .canvas-layer .toggle-visibility {
  position: absolute;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  border: solid 10px rgba(0,127,0,.5);
  left: -40px;
  top: calc(50% - 10px);
  cursor: pointer;
}

.draw-layer-panel .canvas-layer .toggle-visibility.off {
  border-width: 2px;
}

.slider.size-slider::before,
.slider.size-slider::after,
.slider.opacity-slider::before,
.slider.opacity-slider::after {
  background: black;
  border-radius: 50%;
}

.slider.size-slider::before {
  height: 5px;
  width: 5px;
  left: -20px;
}

.slider.size-slider::after {
  height: 50px;
  width: 50px;
  right: -45px;
}

.slider.opacity-slider::before,
.slider.opacity-slider::after {
  height: 50px;
  width: 50px;
}

.slider.opacity-slider::before {
  left: -45px;
  background: white;
  border: dotted 4px black;
}

.slider.opacity-slider::after {
  right: -45px;
}

@media all and (orientation: portrait) {

  .button {
    left: 20px !important;
  }

  .button .tooltip {
    transform: none;
    top: calc(50% - .5em);
    left: calc(50% + 1.5em);
  }

  .panel-close {
    left: 60px;
    top: 20px;
  }

  #pen-mode {
    top: 20px;
  }

  #pen-size {
    top: 60px;
  }

  #pen-colour {
    top: 100px;
  }

  #pen-opacity {
    top: 140px;
  }

  #draw-layer {
    top: 180px;
  }

  #new-canvas {
    top: 220px;
  }

  #download {
    top: 260px;
  }

  #button-share {
    top: 300px;
  }

}
