html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #ffffff;
}

body {
  cursor: crosshair;
  font-family: "Avenir Next", "SF Pro Rounded", "Trebuchet MS", sans-serif;
}

body.dark-mode {
  background: #12151d;
}

#world {
  display: block;
  width: 100vw;
  height: 100vh;
  background: #ffffff;
  touch-action: none;
}

.welcome-note {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-0.9deg);
  z-index: 32;
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 28px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow: auto;
  padding: 18px 22px 16px;
  border: 3px solid rgba(20, 20, 20, 0.94);
  border-radius: 18px;
  background: rgba(255, 253, 244, 0.98);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.22), 6px 6px 0 rgba(0, 0, 0, 0.1);
}

.welcome-note::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1.5px dashed rgba(0, 0, 0, 0.26);
  border-radius: 13px;
  pointer-events: none;
}

.welcome-note h2 {
  margin: 0 0 6px;
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.welcome-note p {
  margin: 6px 0 0;
  font-size: 16px;
  line-height: 1.35;
  color: rgba(20, 20, 20, 0.9);
}

.welcome-close {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 2;
  width: auto;
  height: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: rgba(20, 20, 20, 0.92);
  padding: 0 2px;
  font-size: 30px;
  font-weight: 800;
  line-height: 0.9;
  cursor: pointer;
  transform: rotate(-4deg);
}

.welcome-note.hidden {
  display: none;
}

.ui-controls {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  right: 20px;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.gravity-toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  border: 3px solid rgba(20, 20, 20, 0.95);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  color: rgba(20, 20, 20, 0.95);
  cursor: pointer;
  transform: rotate(-1.2deg);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.2), 3px 3px 0 rgba(0, 0, 0, 0.08);
}

.gravity-toggle::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1.5px dashed rgba(0, 0, 0, 0.28);
  border-radius: 10px;
  pointer-events: none;
}

.gravity-toggle:focus-visible {
  outline: 3px solid rgba(0, 0, 0, 0.35);
  outline-offset: 2px;
}

.gravity-label {
  position: relative;
  z-index: 1;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.gravity-icon {
  position: relative;
  z-index: 1;
  width: 36px;
  height: 36px;
  display: block;
  transform: rotate(0deg);
  transition: transform 160ms ease-out, opacity 160ms ease-out;
}

.gravity-toggle.off {
  background: rgba(255, 255, 255, 0.82);
  opacity: 0.86;
  transform: rotate(1.2deg);
}

.gravity-toggle.off .gravity-icon {
  transform: rotate(180deg);
}

.touch-tool-toggle {
  display: none;
}

.touch-tool-toggle,
.theme-toggle {
  padding: 8px 12px;
  border: 3px solid rgba(20, 20, 20, 0.95);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: rgba(20, 20, 20, 0.95);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transform: rotate(1.1deg);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.2), 3px 3px 0 rgba(0, 0, 0, 0.08);
}

.touch-tool-toggle.erase {
  background: rgba(20, 20, 20, 0.9);
  color: rgba(255, 255, 255, 0.95);
}

body.touch-device .touch-tool-toggle {
  display: inline-flex;
}

.theme-toggle.active {
  background: rgba(20, 20, 20, 0.9);
  color: rgba(255, 255, 255, 0.95);
}

body.dark-mode .gravity-toggle,
body.dark-mode .touch-tool-toggle,
body.dark-mode .theme-toggle {
  border-color: rgba(245, 245, 245, 0.9);
  background: rgba(18, 22, 30, 0.92);
  color: rgba(245, 245, 245, 0.96);
  box-shadow: 1px 1px 0 rgba(255, 255, 255, 0.15), 3px 3px 0 rgba(0, 0, 0, 0.45);
}

body.dark-mode .gravity-toggle::after {
  border-color: rgba(255, 255, 255, 0.3);
}

body.dark-mode .gravity-icon {
  filter: invert(1) brightness(1.05);
}

body.dark-mode .touch-tool-toggle.erase,
body.dark-mode .theme-toggle.active {
  background: rgba(245, 245, 245, 0.92);
  color: rgba(10, 10, 10, 0.95);
}

body.dark-mode .welcome-note {
  border-color: rgba(245, 245, 245, 0.9);
  background: rgba(21, 25, 35, 0.97);
  box-shadow: 2px 2px 0 rgba(255, 255, 255, 0.14), 6px 6px 0 rgba(0, 0, 0, 0.52);
}

body.dark-mode .welcome-note::after {
  border-color: rgba(255, 255, 255, 0.28);
}

body.dark-mode .welcome-note h2,
body.dark-mode .welcome-note p {
  color: rgba(245, 248, 255, 0.95);
}

body.dark-mode .welcome-close {
  color: rgba(245, 248, 255, 0.96);
}

@media (max-width: 700px) {
  .welcome-note {
    left: 16px;
    right: 16px;
    width: auto;
    top: 50%;
    transform: translateY(-50%) rotate(-0.45deg);
    max-height: calc(100vh - 20px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    padding: 14px 16px 12px;
    border-radius: 14px;
  }

  .welcome-note h2 {
    font-size: 24px;
    margin-right: 30px;
  }

  .welcome-note p {
    font-size: 14px;
    line-height: 1.3;
  }

  .welcome-close {
    top: 6px;
    right: 10px;
    font-size: 28px;
  }

  .ui-controls {
    top: calc(env(safe-area-inset-top, 0px) + 24px);
    right: 12px;
    gap: 6px;
    align-items: center;
  }

  .gravity-toggle {
    height: 44px;
    padding: 0 10px;
    border-radius: 12px;
  }

  .gravity-label {
    font-size: 12px;
  }

  .gravity-icon {
    width: 30px;
    height: 30px;
  }

  .touch-tool-toggle {
    height: 44px;
    padding: 0 12px;
    border-radius: 12px;
    align-items: center;
    justify-content: center;
  }

  .theme-toggle {
    height: 44px;
    padding: 0 12px;
    border-radius: 12px;
    align-items: center;
    justify-content: center;
  }
}
